Skip to content

Commit

Permalink
fix: added supported for relative theme path (#414)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasdavis authored Nov 18, 2020
1 parent 6ea90af commit ca91032
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const path = require('path');

const normalizeTheme = (value, defaultValue) => {
const theme = value || defaultValue;
// TODO - This is not great, but bypasses this function if it is a relative path
if (theme[0] === '.') {
return theme;
}
return theme.match('jsonresume-theme-.*')
? theme
: `jsonresume-theme-${theme}`;
Expand All @@ -22,9 +26,8 @@ lib.preFlow(async (err, results) => {
.version(pkg.version)
.option(
'-t, --theme <theme name>',
'Specify theme used by `export` (default: even)',
'Specify theme used by `export` and `serve` (default: even) or specify a path starting with . (use . for current directory or ../some/other/dir)',
normalizeTheme,
'jsonresume-theme-even',
)
.option('-f, --format <file type extension>', 'Used by `export`.')
.option(
Expand Down
7 changes: 6 additions & 1 deletion lib/builder/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const themeServer =
process.env.THEME_SERVER || 'https://themes.jsonresume.org/theme/';

const path = require('path');
const fs = require('fs');
const request = require('superagent');
const chalk = require('chalk');
Expand Down Expand Up @@ -51,9 +51,14 @@ module.exports = (theme, _dir, resumeFilename, cb) => {

let render;
try {
if (theme[0] === '.') {
theme = path.join(process.cwd(), theme, 'index.js');
}
render = require(theme).render;
} catch (e) {
// The file does not exist.
console.log('The specified local theme failed with the error below');
console.log(chalk.red(e));
}

if (render && typeof render === 'function') {
Expand Down
3 changes: 3 additions & 0 deletions lib/export-resume/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ const createHtml = (resumeJson, fileName, theme, format, callback) => {
};

const getThemePkg = (theme) => {
if (theme[0] === '.') {
theme = path.join(process.cwd(), theme, 'index.js');
}
try {
const themePkg = require(theme);
return themePkg;
Expand Down

0 comments on commit ca91032

Please sign in to comment.