Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added supported for relative theme path #414

Merged
merged 1 commit into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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