resume-cli 3.7.3 → 3.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -1
- package/build/export-resume.js +15 -12
- package/build/get-resume.js +23 -2
- package/build/get-resume.test.js +16 -0
- package/build/init.js +29 -6
- package/build/init.test.js +45 -0
- package/build/list-themes.js +20 -9
- package/build/list-themes.test.js +25 -0
- package/build/main.js +11 -12
- package/build/main.test.js +4 -2
- package/build/render-html.js +109 -5
- package/build/render-html.test.js +48 -0
- package/build/test-utils/mocked-volume-builder.js +13 -0
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -71,6 +71,20 @@ Invalid resume: 2 problems found
|
|
|
71
71
|
|
|
72
72
|
Validate against a custom schema with `--schema <path>`.
|
|
73
73
|
|
|
74
|
+
### Comments in your resume (`.jsonc`)
|
|
75
|
+
|
|
76
|
+
Name the file `resume.jsonc` to write comments and trailing commas; pass it
|
|
77
|
+
with `--resume`:
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
resume validate --resume resume.jsonc
|
|
81
|
+
resume export resume.html --resume resume.jsonc
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Comments are dropped when the file is read, so validation and themes see the
|
|
85
|
+
same data as the equivalent plain JSON. (The registry still needs plain JSON
|
|
86
|
+
in your `resume.json` gist.)
|
|
87
|
+
|
|
74
88
|
### `resume export [fileName]`
|
|
75
89
|
|
|
76
90
|
Exports your resume to one of four formats:
|
|
@@ -104,7 +118,15 @@ Please npm install the theme you wish to use before attempting to export it.
|
|
|
104
118
|
Options:
|
|
105
119
|
|
|
106
120
|
- `--format <file type>` Example: `--format pdf`
|
|
107
|
-
- `--theme <name>` Example: `--theme even` (only used for `.html` / `.pdf`)
|
|
121
|
+
- `--theme <name>` Example: `--theme even` (only used for `.html` / `.pdf`; defaults to `even`). Scoped packages such as `@jsonresume/jsonresume-theme-<name>` are passed by their full name.
|
|
122
|
+
|
|
123
|
+
PDF export runs headless Chrome via Puppeteer. On Linux CI and in containers,
|
|
124
|
+
where Chrome usually can't start its sandbox, set
|
|
125
|
+
`RESUME_PUPPETEER_NO_SANDBOX=1`:
|
|
126
|
+
|
|
127
|
+
```
|
|
128
|
+
RESUME_PUPPETEER_NO_SANDBOX=1 resume export resume.pdf
|
|
129
|
+
```
|
|
108
130
|
|
|
109
131
|
### `resume audit [fileName]`
|
|
110
132
|
|
package/build/export-resume.js
CHANGED
|
@@ -87,14 +87,6 @@ const extractFileFormat = fileName => {
|
|
|
87
87
|
}
|
|
88
88
|
return fileName.substring(dotPos + 1).toLowerCase();
|
|
89
89
|
};
|
|
90
|
-
const getThemePkg = theme => {
|
|
91
|
-
// Resolve with the same rules renderHTML uses (require-path lookup with a
|
|
92
|
-
// `jsonresume-theme-` prefix fallback) so a theme that renders to HTML can
|
|
93
|
-
// never spuriously fail PDF export (hoisted installs, non-index entries).
|
|
94
|
-
// resolveThemePath throws ThemeNotFoundError so the caller can render an
|
|
95
|
-
// actionable, stack-trace-free message and exit with a non-zero code.
|
|
96
|
-
return require((0, _renderHtml.resolveThemePath)(theme));
|
|
97
|
-
};
|
|
98
90
|
async function createHtml(resumeJson, fileName, themePath, format, callback) {
|
|
99
91
|
let html;
|
|
100
92
|
try {
|
|
@@ -128,7 +120,9 @@ async function createThemeless(resumeJson, fileName, formatter, callback) {
|
|
|
128
120
|
}
|
|
129
121
|
const createPdf = (resumeJson, fileName, theme, format, callback) => {
|
|
130
122
|
(async () => {
|
|
131
|
-
|
|
123
|
+
// Same loader renderHTML uses, so a theme that renders to HTML can never
|
|
124
|
+
// spuriously fail PDF export. Throws ThemeNotFoundError for the caller.
|
|
125
|
+
const themePkg = await (0, _renderHtml.loadTheme)(theme);
|
|
132
126
|
const puppeteerLaunchArgs = [];
|
|
133
127
|
if (process.env.RESUME_PUPPETEER_NO_SANDBOX) {
|
|
134
128
|
puppeteerLaunchArgs.push('--no-sandbox');
|
|
@@ -137,9 +131,18 @@ const createPdf = (resumeJson, fileName, theme, format, callback) => {
|
|
|
137
131
|
resume: resumeJson,
|
|
138
132
|
themePath: theme
|
|
139
133
|
});
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
134
|
+
let browser;
|
|
135
|
+
try {
|
|
136
|
+
browser = await puppeteer.launch({
|
|
137
|
+
args: puppeteerLaunchArgs
|
|
138
|
+
});
|
|
139
|
+
} catch (err) {
|
|
140
|
+
if (!process.env.RESUME_PUPPETEER_NO_SANDBOX) {
|
|
141
|
+
// The usual cause on Linux CI and in containers
|
|
142
|
+
err.message += '\nIf Chrome cannot start its sandbox (common on Linux CI and in containers), retry with RESUME_PUPPETEER_NO_SANDBOX=1.';
|
|
143
|
+
}
|
|
144
|
+
throw err;
|
|
145
|
+
}
|
|
143
146
|
const page = await browser.newPage();
|
|
144
147
|
await page.emulateMediaType(themePkg.pdfRenderOptions && themePkg.pdfRenderOptions.mediaType || 'screen');
|
|
145
148
|
await page.goto(`data:text/html;base64,${btoa(unescape(encodeURIComponent(html)))}`, {
|
package/build/get-resume.js
CHANGED
|
@@ -10,16 +10,37 @@ var _path = require("path");
|
|
|
10
10
|
var _quaffLoader = _interopRequireDefault(require("./quaff-loader"));
|
|
11
11
|
var _streamToString = _interopRequireDefault(require("stream-to-string"));
|
|
12
12
|
var _yamlJs = _interopRequireDefault(require("yaml-js"));
|
|
13
|
+
var _jsoncParser = require("jsonc-parser");
|
|
13
14
|
var _util = require("util");
|
|
14
15
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
16
|
const {
|
|
16
17
|
createReadStream
|
|
17
18
|
} = _fs.default;
|
|
18
19
|
const stat = (0, _util.promisify)(_fs.default.stat);
|
|
20
|
+
|
|
21
|
+
// JSON with comments and trailing commas (#318). Comments are dropped; the
|
|
22
|
+
// parsed data is the same as the equivalent plain JSON.
|
|
23
|
+
const JSONC_MIME = 'application/jsonc';
|
|
24
|
+
const parseJsoncOrThrow = string => {
|
|
25
|
+
const errors = [];
|
|
26
|
+
const value = (0, _jsoncParser.parse)(string, errors, {
|
|
27
|
+
allowTrailingComma: true
|
|
28
|
+
});
|
|
29
|
+
if (errors.length) {
|
|
30
|
+
const [{
|
|
31
|
+
error,
|
|
32
|
+
offset
|
|
33
|
+
}] = errors;
|
|
34
|
+
throw new Error(`Invalid JSONC: ${(0, _jsoncParser.printParseErrorCode)(error)} at offset ${offset}`);
|
|
35
|
+
}
|
|
36
|
+
return value;
|
|
37
|
+
};
|
|
19
38
|
const parsers = {
|
|
20
39
|
'text/yaml': string => _yamlJs.default.load(string),
|
|
21
|
-
'application/json': string => JSON.parse(string)
|
|
40
|
+
'application/json': string => JSON.parse(string),
|
|
41
|
+
[JSONC_MIME]: parseJsoncOrThrow
|
|
22
42
|
};
|
|
43
|
+
const mimeFor = path => /\.jsonc$/i.test(path) ? JSONC_MIME : (0, _mimeTypes.lookup)(path);
|
|
23
44
|
var _default = async ({
|
|
24
45
|
path,
|
|
25
46
|
mime: inputMime
|
|
@@ -33,7 +54,7 @@ var _default = async ({
|
|
|
33
54
|
return (0, _quaffLoader.default)(path);
|
|
34
55
|
}
|
|
35
56
|
if (!input) {
|
|
36
|
-
mime = inputMime || (
|
|
57
|
+
mime = inputMime || mimeFor(path);
|
|
37
58
|
input = createReadStream((0, _path.resolve)(process.cwd(), path));
|
|
38
59
|
}
|
|
39
60
|
if (!input) {
|
package/build/get-resume.test.js
CHANGED
|
@@ -37,6 +37,22 @@ describe('get-resume', () => {
|
|
|
37
37
|
}
|
|
38
38
|
`);
|
|
39
39
|
});
|
|
40
|
+
it('should consume jsonc, dropping comments without altering data', async () => {
|
|
41
|
+
expect(await (0, _getResume.default)({
|
|
42
|
+
path: '/resume.jsonc'
|
|
43
|
+
})).toEqual({
|
|
44
|
+
basics: {
|
|
45
|
+
name: 'thomas',
|
|
46
|
+
email: 'thomas@example.com',
|
|
47
|
+
url: 'https://example.com/a//b'
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
it('should reject malformed jsonc', async () => {
|
|
52
|
+
await expect((0, _getResume.default)({
|
|
53
|
+
path: '/malformed-resume.jsonc'
|
|
54
|
+
})).rejects.toThrow(/Invalid JSONC/);
|
|
55
|
+
});
|
|
40
56
|
it('should read from process.stdin when path is a dash', async () => {
|
|
41
57
|
const stdin = (0, _mockStdin.stdin)();
|
|
42
58
|
const gotResume = (0, _getResume.default)({
|
package/build/init.js
CHANGED
|
@@ -16,16 +16,34 @@ const writeFile = (0, _util.promisify)(_fs.default.writeFile);
|
|
|
16
16
|
const read = (0, _util.promisify)(_read.default);
|
|
17
17
|
const resume = require('@jsonresume/schema/sample.resume.json');
|
|
18
18
|
var _default = async ({
|
|
19
|
-
resumePath
|
|
19
|
+
resumePath,
|
|
20
|
+
interactive = process.stdin.isTTY
|
|
20
21
|
}) => {
|
|
21
22
|
if (await (0, _fileExists.default)(resumePath)) {
|
|
22
23
|
console.log(_chalk.default.yellow('There is already a resume.json file in this directory.'));
|
|
24
|
+
if (!interactive) {
|
|
25
|
+
// Can't ask, so never overwrite silently.
|
|
26
|
+
console.error(`Not overwriting ${resumePath}: stdin is not interactive. Delete it or run \`resume init\` in a terminal.`);
|
|
27
|
+
process.exitCode = 1;
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
23
30
|
if (!(await (0, _yesno.default)({
|
|
24
31
|
question: 'Do you want to override?'
|
|
25
32
|
}))) {
|
|
26
33
|
return;
|
|
27
34
|
}
|
|
28
35
|
}
|
|
36
|
+
if (!interactive) {
|
|
37
|
+
// No TTY (CI, piped stdin): write the resume as if every prompt was left
|
|
38
|
+
// blank rather than exiting without a word.
|
|
39
|
+
console.log('stdin is not interactive; skipping the name/email prompts.');
|
|
40
|
+
await writeFile(resumePath, JSON.stringify(personalize({
|
|
41
|
+
name: '',
|
|
42
|
+
email: ''
|
|
43
|
+
}), undefined, 2));
|
|
44
|
+
printNextSteps(resumePath);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
29
47
|
console.log(`This utility will generate a file at ${resumePath}.`);
|
|
30
48
|
console.log('Fill out your name and email to get started, or leave the fields blank.');
|
|
31
49
|
console.log('All fields are optional.\n');
|
|
@@ -36,11 +54,17 @@ var _default = async ({
|
|
|
36
54
|
const email = await read({
|
|
37
55
|
prompt: 'email: '
|
|
38
56
|
});
|
|
39
|
-
|
|
57
|
+
await writeFile(resumePath, JSON.stringify(personalize({
|
|
40
58
|
name,
|
|
41
59
|
email
|
|
42
|
-
})
|
|
43
|
-
|
|
60
|
+
}), undefined, 2));
|
|
61
|
+
printNextSteps(resumePath);
|
|
62
|
+
};
|
|
63
|
+
exports.default = _default;
|
|
64
|
+
function personalize(fields) {
|
|
65
|
+
return Object.entries(fields).reduce((acc, [key, value]) => (0, _objectPathImmutable.set)(acc, `basics.${key}`, value), resume);
|
|
66
|
+
}
|
|
67
|
+
function printNextSteps(resumePath) {
|
|
44
68
|
console.log(`Your resume has been created at ${resumePath}`);
|
|
45
69
|
console.log('');
|
|
46
70
|
console.log('To generate a formatted .html .md .txt or .pdf resume from your resume');
|
|
@@ -49,5 +73,4 @@ var _default = async ({
|
|
|
49
73
|
console.log('Example: `resume export myresume.pdf --theme even`');
|
|
50
74
|
console.log('Or simply type: `resume export` and follow the prompts.');
|
|
51
75
|
console.log('');
|
|
52
|
-
}
|
|
53
|
-
exports.default = _default;
|
|
76
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
4
|
+
var _os = _interopRequireDefault(require("os"));
|
|
5
|
+
var _path = _interopRequireDefault(require("path"));
|
|
6
|
+
var _init = _interopRequireDefault(require("./init"));
|
|
7
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
describe('init without an interactive terminal', () => {
|
|
9
|
+
let dir;
|
|
10
|
+
let log;
|
|
11
|
+
let error;
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
dir = _fs.default.mkdtempSync(_path.default.join(_os.default.tmpdir(), 'resume-cli-init-'));
|
|
14
|
+
log = jest.spyOn(console, 'log').mockImplementation(() => {});
|
|
15
|
+
error = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
16
|
+
process.exitCode = undefined;
|
|
17
|
+
});
|
|
18
|
+
afterEach(() => {
|
|
19
|
+
log.mockRestore();
|
|
20
|
+
error.mockRestore();
|
|
21
|
+
process.exitCode = undefined;
|
|
22
|
+
});
|
|
23
|
+
it('writes a resume with blank name and email instead of exiting silently', async () => {
|
|
24
|
+
const resumePath = _path.default.join(dir, 'resume.json');
|
|
25
|
+
await (0, _init.default)({
|
|
26
|
+
resumePath,
|
|
27
|
+
interactive: false
|
|
28
|
+
});
|
|
29
|
+
const written = JSON.parse(_fs.default.readFileSync(resumePath, 'utf8'));
|
|
30
|
+
expect(written.basics.name).toBe('');
|
|
31
|
+
expect(written.basics.email).toBe('');
|
|
32
|
+
expect(log).toHaveBeenCalledWith(expect.stringContaining('not interactive'));
|
|
33
|
+
});
|
|
34
|
+
it('refuses to overwrite an existing resume and exits non-zero', async () => {
|
|
35
|
+
const resumePath = _path.default.join(dir, 'resume.json');
|
|
36
|
+
_fs.default.writeFileSync(resumePath, '{"basics":{"name":"Keep me"}}');
|
|
37
|
+
await (0, _init.default)({
|
|
38
|
+
resumePath,
|
|
39
|
+
interactive: false
|
|
40
|
+
});
|
|
41
|
+
expect(JSON.parse(_fs.default.readFileSync(resumePath, 'utf8')).basics.name).toBe('Keep me');
|
|
42
|
+
expect(process.exitCode).toBe(1);
|
|
43
|
+
expect(error).toHaveBeenCalledWith(expect.stringContaining('Not overwriting'));
|
|
44
|
+
});
|
|
45
|
+
});
|
package/build/list-themes.js
CHANGED
|
@@ -18,10 +18,12 @@ const readThemePkg = themeDir => {
|
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
// List the immediate child directories of a node_modules folder that look like
|
|
21
|
-
// JSON Resume theme packages (`jsonresume-theme
|
|
22
|
-
// theme
|
|
23
|
-
//
|
|
24
|
-
|
|
21
|
+
// JSON Resume theme packages (`jsonresume-theme-*`, including scoped ones such
|
|
22
|
+
// as `@jsonresume/jsonresume-theme-*`). Returns one entry per theme with its
|
|
23
|
+
// slug (the name passed to `--theme`; the full name for scoped packages), full
|
|
24
|
+
// package name, version and description. Missing/unreadable folders yield an
|
|
25
|
+
// empty list.
|
|
26
|
+
const listThemesInDir = (nodeModulesDir, scope = null) => {
|
|
25
27
|
let entries;
|
|
26
28
|
try {
|
|
27
29
|
entries = fs.readdirSync(nodeModulesDir, {
|
|
@@ -34,21 +36,30 @@ const listThemesInDir = nodeModulesDir => {
|
|
|
34
36
|
for (const entry of entries) {
|
|
35
37
|
// Tolerate environments where `withFileTypes` is unavailable.
|
|
36
38
|
const name = entry.name || entry;
|
|
37
|
-
if (typeof name !== 'string'
|
|
39
|
+
if (typeof name !== 'string') {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (!scope && name.startsWith('@')) {
|
|
43
|
+
themes.push(...listThemesInDir(path.join(nodeModulesDir, name), name));
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (!name.startsWith(THEME_PREFIX)) {
|
|
38
47
|
continue;
|
|
39
48
|
}
|
|
40
49
|
// Ignore the prefix itself with nothing after it.
|
|
41
|
-
const
|
|
42
|
-
if (!
|
|
50
|
+
const shortName = name.slice(THEME_PREFIX.length);
|
|
51
|
+
if (!shortName) {
|
|
43
52
|
continue;
|
|
44
53
|
}
|
|
45
54
|
const pkg = readThemePkg(path.join(nodeModulesDir, name));
|
|
46
55
|
if (!pkg) {
|
|
47
56
|
continue;
|
|
48
57
|
}
|
|
58
|
+
const fullName = scope ? `${scope}/${name}` : name;
|
|
49
59
|
themes.push({
|
|
50
|
-
|
|
51
|
-
|
|
60
|
+
// Scoped themes are passed to --theme by their full name
|
|
61
|
+
slug: scope ? fullName : shortName,
|
|
62
|
+
name: fullName,
|
|
52
63
|
version: typeof pkg.version === 'string' ? pkg.version : null,
|
|
53
64
|
description: typeof pkg.description === 'string' ? pkg.description : null
|
|
54
65
|
});
|
|
@@ -165,4 +165,29 @@ describe('formatThemesList', () => {
|
|
|
165
165
|
expect(output).toContain('npm install jsonresume-theme-even');
|
|
166
166
|
expect(output).toContain('https://jsonresume.org/themes/');
|
|
167
167
|
});
|
|
168
|
+
});
|
|
169
|
+
describe('scoped themes', () => {
|
|
170
|
+
it('discovers @scope/jsonresume-theme-* packages by their full name', () => {
|
|
171
|
+
const root = _fs.default.mkdtempSync(_path.default.join(_os.default.tmpdir(), 'resume-cli-scoped-'));
|
|
172
|
+
const dir = _path.default.join(root, 'node_modules', '@jsonresume', 'jsonresume-theme-claude');
|
|
173
|
+
_fs.default.mkdirSync(dir, {
|
|
174
|
+
recursive: true
|
|
175
|
+
});
|
|
176
|
+
_fs.default.writeFileSync(_path.default.join(dir, 'package.json'), JSON.stringify({
|
|
177
|
+
name: '@jsonresume/jsonresume-theme-claude',
|
|
178
|
+
version: '1.0.0'
|
|
179
|
+
}));
|
|
180
|
+
// A non-theme scoped package is ignored
|
|
181
|
+
_fs.default.mkdirSync(_path.default.join(root, 'node_modules', '@jsonresume', 'core'), {
|
|
182
|
+
recursive: true
|
|
183
|
+
});
|
|
184
|
+
const themes = (0, _listThemes.discoverThemes)({
|
|
185
|
+
cwd: root
|
|
186
|
+
});
|
|
187
|
+
expect(themes).toEqual([expect.objectContaining({
|
|
188
|
+
slug: '@jsonresume/jsonresume-theme-claude',
|
|
189
|
+
name: '@jsonresume/jsonresume-theme-claude',
|
|
190
|
+
version: '1.0.0'
|
|
191
|
+
})]);
|
|
192
|
+
});
|
|
168
193
|
});
|
package/build/main.js
CHANGED
|
@@ -42,14 +42,18 @@ const globalNodeModules = () => {
|
|
|
42
42
|
};
|
|
43
43
|
const normalizeTheme = (value, defaultValue) => {
|
|
44
44
|
const theme = value || defaultValue;
|
|
45
|
-
//
|
|
46
|
-
|
|
45
|
+
// Paths and scoped packages (`@scope/name`) are used as-is; only bare short
|
|
46
|
+
// names get the `jsonresume-theme-` prefix.
|
|
47
|
+
if (theme[0] === '.' || theme[0] === '/' || theme[0] === '@') {
|
|
47
48
|
return theme;
|
|
48
49
|
}
|
|
49
50
|
return theme.match('jsonresume-theme-.*') ? theme : `jsonresume-theme-${theme}`;
|
|
50
51
|
};
|
|
51
52
|
(async () => {
|
|
52
|
-
program.name('resume').usage('[command] [options]').version(pkg.version).option('-F, --force', 'Used by `publish` and `export` - bypasses schema testing.').option('-t, --theme <theme name>', 'Theme used by `export` and `serve` (browse themes at https://jsonresume.org/themes/), or a path starting with . (use . for current directory or ../some/other/dir)', normalizeTheme,
|
|
53
|
+
program.name('resume').usage('[command] [options]').version(pkg.version).option('-F, --force', 'Used by `publish` and `export` - bypasses schema testing.').option('-t, --theme <theme name>', 'Theme used by `export` and `serve` (browse themes at https://jsonresume.org/themes/), or a path starting with . (use . for current directory or ../some/other/dir)', normalizeTheme,
|
|
54
|
+
// `even` ships with the CLI and renders sparse resumes; `elegant` (the
|
|
55
|
+
// old default) throws when optional sections are missing.
|
|
56
|
+
'jsonresume-theme-even').option('-f, --format <file type extension>', 'Used by `export`.').option('-r, --resume <resume filename>', "path to the resume in json format. Use '-' to read from stdin", 'resume.json').option('-p, --port <port>', 'Used by `serve` (default: 4000)', 4000).option('-s, --silent', 'Used by `serve` to tell it if open browser auto or not.', false).option('-d, --dir <path>', 'Used by `serve` to indicate a public directory path.', 'public').option('--schema <relativePath>', 'Used by `validate` to validate against a custom schema.');
|
|
53
57
|
program.command('init').description('Initialize a resume.json file').action(async () => {
|
|
54
58
|
await (0, _init.default)({
|
|
55
59
|
resumePath: program.resume
|
|
@@ -82,7 +86,7 @@ const normalizeTheme = (value, defaultValue) => {
|
|
|
82
86
|
process.exitCode = 1;
|
|
83
87
|
}
|
|
84
88
|
});
|
|
85
|
-
program.command('export [fileName]').description('Export locally to .html, .pdf, .md (markdown) or .txt (text). Supply a --format <file format> flag and argument to specify export format. .md and .txt need no theme; pick a theme for .html/.pdf with --theme (https://jsonresume.org/themes/).').action(async fileName => {
|
|
89
|
+
program.command('export [fileName]').description('Export locally to .html, .pdf, .md (markdown) or .txt (text). Supply a --format <file format> flag and argument to specify export format. .md and .txt need no theme; pick a theme for .html/.pdf with --theme (https://jsonresume.org/themes/). For .pdf on Linux CI or in containers, set RESUME_PUPPETEER_NO_SANDBOX=1.').action(async fileName => {
|
|
86
90
|
const resume = await (0, _loadResume.default)(program.resume);
|
|
87
91
|
if (resume === null) {
|
|
88
92
|
return;
|
|
@@ -107,7 +111,8 @@ const normalizeTheme = (value, defaultValue) => {
|
|
|
107
111
|
program.command('themes').description('List JSON Resume themes installed in node_modules (the slug to pass to --theme). Browse the full gallery at https://jsonresume.org/themes/.').action(async () => {
|
|
108
112
|
const themes = discoverThemes({
|
|
109
113
|
cwd: process.cwd(),
|
|
110
|
-
|
|
114
|
+
// plus the CLI's own install, where its bundled themes live
|
|
115
|
+
extraNodeModules: [...globalNodeModules(), path.join(__dirname, '..', 'node_modules'), path.join(__dirname, '..', '..')]
|
|
111
116
|
});
|
|
112
117
|
console.log(formatThemesList(themes));
|
|
113
118
|
});
|
|
@@ -116,15 +121,9 @@ const normalizeTheme = (value, defaultValue) => {
|
|
|
116
121
|
if (resume === null) {
|
|
117
122
|
return;
|
|
118
123
|
}
|
|
119
|
-
// The global `-t/--theme` option (default: elegant) is shared by every
|
|
120
|
-
// command, but `elegant` throws on minimal resumes. Default `audit` to
|
|
121
|
-
// the bundled, robust `even` theme unless the user explicitly asked for
|
|
122
|
-
// a theme on the command line.
|
|
123
|
-
const themeGiven = process.argv.some(arg => arg === '-t' || arg === '--theme');
|
|
124
|
-
const themePath = themeGiven ? program.theme : 'jsonresume-theme-even';
|
|
125
124
|
await (0, _audit.default)({
|
|
126
125
|
resume,
|
|
127
|
-
themePath
|
|
126
|
+
themePath: program.theme
|
|
128
127
|
});
|
|
129
128
|
});
|
|
130
129
|
program.command('serve').description('Serve resume at http://localhost:4000/').action(async () => {
|
package/build/main.test.js
CHANGED
|
@@ -65,7 +65,7 @@ describe('cli configuration', () => {
|
|
|
65
65
|
https://jsonresume.org/themes/), or a
|
|
66
66
|
path starting with . (use . for current
|
|
67
67
|
directory or ../some/other/dir) (default:
|
|
68
|
-
"jsonresume-theme-
|
|
68
|
+
"jsonresume-theme-even")
|
|
69
69
|
-f, --format <file type extension> Used by \`export\`.
|
|
70
70
|
-r, --resume <resume filename> path to the resume in json format. Use
|
|
71
71
|
'-' to read from stdin (default:
|
|
@@ -89,7 +89,9 @@ describe('cli configuration', () => {
|
|
|
89
89
|
to specify export format. .md and .txt
|
|
90
90
|
need no theme; pick a theme for
|
|
91
91
|
.html/.pdf with --theme
|
|
92
|
-
(https://jsonresume.org/themes/).
|
|
92
|
+
(https://jsonresume.org/themes/). For
|
|
93
|
+
.pdf on Linux CI or in containers, set
|
|
94
|
+
RESUME_PUPPETEER_NO_SANDBOX=1.
|
|
93
95
|
themes List JSON Resume themes installed in
|
|
94
96
|
node_modules (the slug to pass to
|
|
95
97
|
--theme). Browse the full gallery at
|
package/build/render-html.js
CHANGED
|
@@ -3,8 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.resolveThemePath = exports.default = void 0;
|
|
6
|
+
exports.withStringLocations = exports.resolveThemePath = exports.loadTheme = exports.default = void 0;
|
|
7
7
|
var _themeErrors = require("./theme-errors");
|
|
8
|
+
const {
|
|
9
|
+
pathToFileURL
|
|
10
|
+
} = require('url');
|
|
8
11
|
const tryResolve = (...args) => {
|
|
9
12
|
try {
|
|
10
13
|
return require.resolve(...args);
|
|
@@ -19,6 +22,9 @@ const tryResolve = (...args) => {
|
|
|
19
22
|
// that renders to HTML can never spuriously fail to resolve elsewhere.
|
|
20
23
|
const resolveThemePath = themePath => {
|
|
21
24
|
const cwd = process.cwd();
|
|
25
|
+
// The user's project first, then the CLI's own install, so the themes the
|
|
26
|
+
// CLI ships with resolve on global and npx installs too.
|
|
27
|
+
const paths = [cwd, __dirname];
|
|
22
28
|
let path;
|
|
23
29
|
if (themePath[0] === '.') {
|
|
24
30
|
path = tryResolve(require('path').join(cwd, themePath), {
|
|
@@ -30,14 +36,14 @@ const resolveThemePath = themePath => {
|
|
|
30
36
|
}
|
|
31
37
|
if (!path) {
|
|
32
38
|
path = tryResolve(themePath, {
|
|
33
|
-
paths
|
|
39
|
+
paths
|
|
34
40
|
});
|
|
35
41
|
}
|
|
36
42
|
// Only fall back to the `jsonresume-theme-` prefix for bare short names;
|
|
37
43
|
// scoped or otherwise non-alphanumeric-leading specifiers are used as-is.
|
|
38
44
|
if (!path && /^[a-z0-9]/i.test(themePath)) {
|
|
39
45
|
path = tryResolve(`jsonresume-theme-${themePath}`, {
|
|
40
|
-
paths
|
|
46
|
+
paths
|
|
41
47
|
});
|
|
42
48
|
}
|
|
43
49
|
if (!path) {
|
|
@@ -45,15 +51,113 @@ const resolveThemePath = themePath => {
|
|
|
45
51
|
}
|
|
46
52
|
return path;
|
|
47
53
|
};
|
|
54
|
+
|
|
55
|
+
// Babel compiles `import()` to `require()`, so keep a real dynamic import for
|
|
56
|
+
// ESM-only themes on Node versions whose require() cannot load ESM.
|
|
57
|
+
// eslint-disable-next-line no-new-func
|
|
48
58
|
exports.resolveThemePath = resolveThemePath;
|
|
59
|
+
const importModule = new Function('specifier', 'return import(specifier)');
|
|
60
|
+
|
|
61
|
+
// Whether Node treats a file as ESM: `.mjs`, or `.js` under a package.json
|
|
62
|
+
// with `"type": "module"`.
|
|
63
|
+
const isEsm = file => {
|
|
64
|
+
const {
|
|
65
|
+
dirname,
|
|
66
|
+
extname,
|
|
67
|
+
join
|
|
68
|
+
} = require('path');
|
|
69
|
+
const ext = extname(file);
|
|
70
|
+
if (ext === '.mjs') return true;
|
|
71
|
+
if (ext === '.cjs') return false;
|
|
72
|
+
for (let dir = dirname(file);; dir = dirname(dir)) {
|
|
73
|
+
try {
|
|
74
|
+
const pkg = JSON.parse(require('fs').readFileSync(join(dir, 'package.json'), 'utf8'));
|
|
75
|
+
return pkg.type === 'module';
|
|
76
|
+
} catch (err) {
|
|
77
|
+
if (dirname(dir) === dir) return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// The ESM entry of the package containing `file` (its `exports` `import`
|
|
83
|
+
// condition, or `module`), or null.
|
|
84
|
+
const esmEntry = file => {
|
|
85
|
+
const {
|
|
86
|
+
dirname,
|
|
87
|
+
join
|
|
88
|
+
} = require('path');
|
|
89
|
+
for (let dir = dirname(file); dirname(dir) !== dir; dir = dirname(dir)) {
|
|
90
|
+
let pkg;
|
|
91
|
+
try {
|
|
92
|
+
pkg = JSON.parse(require('fs').readFileSync(join(dir, 'package.json'), 'utf8'));
|
|
93
|
+
} catch (err) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (!pkg.name) continue;
|
|
97
|
+
const root = pkg.exports?.['.'] ?? pkg.exports;
|
|
98
|
+
let target = root?.import ?? pkg.module;
|
|
99
|
+
if (target && typeof target === 'object') target = target.default;
|
|
100
|
+
return typeof target === 'string' ? join(dir, target) : null;
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// Load a theme module, CommonJS or ESM. ESM themes are imported rather than
|
|
106
|
+
// required: require() of ESM resolves the theme's own dependencies with the
|
|
107
|
+
// `require` condition, which breaks import-only packages. Likewise, a theme
|
|
108
|
+
// whose CommonJS build can't load (e.g. it requires an import-only
|
|
109
|
+
// dependency, as jsonresume-theme-even >= 0.2x does) falls back to its ESM
|
|
110
|
+
// entry. Themes may export `render` by name or on their default export.
|
|
111
|
+
const loadTheme = async themePath => {
|
|
112
|
+
const resolved = resolveThemePath(themePath);
|
|
113
|
+
let mod;
|
|
114
|
+
if (isEsm(resolved)) {
|
|
115
|
+
mod = await importModule(pathToFileURL(resolved).href);
|
|
116
|
+
} else {
|
|
117
|
+
try {
|
|
118
|
+
mod = require(resolved);
|
|
119
|
+
} catch (err) {
|
|
120
|
+
const esm = ['ERR_REQUIRE_ESM', 'ERR_PACKAGE_PATH_NOT_EXPORTED'].includes(err.code) && esmEntry(resolved);
|
|
121
|
+
if (!esm) throw err;
|
|
122
|
+
mod = await importModule(pathToFileURL(esm).href);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return typeof mod?.render === 'function' ? mod : mod?.default ?? mod;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
// Entry locations may be structured objects (#323); themes written for
|
|
129
|
+
// strings would print "[object Object]". Same rule as @jsonresume/utils'
|
|
130
|
+
// withStringLocations (kept inline: that package is ESM-only).
|
|
131
|
+
exports.loadTheme = loadTheme;
|
|
132
|
+
const LOCATED_SECTIONS = ['work', 'volunteer', 'education'];
|
|
133
|
+
const withStringLocations = resume => {
|
|
134
|
+
if (!resume || typeof resume !== 'object') return resume;
|
|
135
|
+
const out = {
|
|
136
|
+
...resume
|
|
137
|
+
};
|
|
138
|
+
for (const section of LOCATED_SECTIONS) {
|
|
139
|
+
if (!Array.isArray(resume[section])) continue;
|
|
140
|
+
out[section] = resume[section].map(entry => {
|
|
141
|
+
const location = entry && entry.location;
|
|
142
|
+
if (!location || typeof location !== 'object') return entry;
|
|
143
|
+
const text = [location.city, location.region, location.countryCode].filter(Boolean).join(', ');
|
|
144
|
+
return {
|
|
145
|
+
...entry,
|
|
146
|
+
location: text
|
|
147
|
+
};
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
return out;
|
|
151
|
+
};
|
|
152
|
+
exports.withStringLocations = withStringLocations;
|
|
49
153
|
var _default = async ({
|
|
50
154
|
resume,
|
|
51
155
|
themePath
|
|
52
156
|
}) => {
|
|
53
|
-
const theme =
|
|
157
|
+
const theme = await loadTheme(themePath);
|
|
54
158
|
if (typeof theme?.render !== 'function') {
|
|
55
159
|
throw new Error('theme.render is not a function');
|
|
56
160
|
}
|
|
57
|
-
return theme.render(resume);
|
|
161
|
+
return theme.render(withStringLocations(resume));
|
|
58
162
|
};
|
|
59
163
|
exports.default = _default;
|
|
@@ -139,4 +139,52 @@ describe('resolveThemePath', () => {
|
|
|
139
139
|
mockCwd(root);
|
|
140
140
|
expect(() => (0, _renderHtml.resolveThemePath)('./missing-local-theme')).toThrow(_themeErrors.ThemeNotFoundError);
|
|
141
141
|
});
|
|
142
|
+
});
|
|
143
|
+
describe('loadTheme', () => {
|
|
144
|
+
it('uses the default export when the module does not export render itself', async () => {
|
|
145
|
+
const dir = _fs.default.mkdtempSync(_path.default.join(_os.default.tmpdir(), 'resume-cli-default-'));
|
|
146
|
+
_fs.default.writeFileSync(_path.default.join(dir, 'index.js'), "module.exports = { default: { render: () => 'from-default' } };");
|
|
147
|
+
const cwd = process.cwd();
|
|
148
|
+
process.chdir(_path.default.dirname(dir));
|
|
149
|
+
try {
|
|
150
|
+
const theme = await (0, _renderHtml.loadTheme)(`./${_path.default.basename(dir)}`);
|
|
151
|
+
expect(theme.render()).toBe('from-default');
|
|
152
|
+
} finally {
|
|
153
|
+
process.chdir(cwd);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
it("falls back to the CLI's own install for themes the project doesn't have", () => {
|
|
157
|
+
const empty = _fs.default.mkdtempSync(_path.default.join(_os.default.tmpdir(), 'resume-cli-empty-'));
|
|
158
|
+
const cwd = process.cwd();
|
|
159
|
+
process.chdir(empty);
|
|
160
|
+
try {
|
|
161
|
+
// jsonresume-theme-even is a CLI dependency, not installed in `empty`
|
|
162
|
+
expect((0, _renderHtml.resolveThemePath)('jsonresume-theme-even')).toContain('jsonresume-theme-even');
|
|
163
|
+
} finally {
|
|
164
|
+
process.chdir(cwd);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
describe('withStringLocations', () => {
|
|
169
|
+
it('formats structured entry locations for themes and leaves strings', () => {
|
|
170
|
+
const out = (0, _renderHtml.withStringLocations)({
|
|
171
|
+
work: [{
|
|
172
|
+
location: {
|
|
173
|
+
city: 'Oslo',
|
|
174
|
+
countryCode: 'NO'
|
|
175
|
+
}
|
|
176
|
+
}, {
|
|
177
|
+
location: 'Remote'
|
|
178
|
+
}],
|
|
179
|
+
education: [{
|
|
180
|
+
location: {
|
|
181
|
+
city: 'Lagos',
|
|
182
|
+
region: 'LA',
|
|
183
|
+
countryCode: 'NG'
|
|
184
|
+
}
|
|
185
|
+
}]
|
|
186
|
+
});
|
|
187
|
+
expect(out.work.map(w => w.location)).toEqual(['Oslo, NO', 'Remote']);
|
|
188
|
+
expect(out.education[0].location).toBe('Lagos, LA, NG');
|
|
189
|
+
});
|
|
142
190
|
});
|
|
@@ -27,6 +27,19 @@ module.exports = ({
|
|
|
27
27
|
email: 'thomas@example.com'
|
|
28
28
|
}
|
|
29
29
|
}),
|
|
30
|
+
// JSONC: comments (including // and /* inside strings, which must
|
|
31
|
+
// survive) and a trailing comma
|
|
32
|
+
'resume.jsonc': dedent`
|
|
33
|
+
{
|
|
34
|
+
// who I am
|
|
35
|
+
"basics": {
|
|
36
|
+
"name": "thomas", /* shown on every theme */
|
|
37
|
+
"email": "thomas@example.com",
|
|
38
|
+
"url": "https://example.com/a//b",
|
|
39
|
+
},
|
|
40
|
+
}
|
|
41
|
+
`,
|
|
42
|
+
'malformed-resume.jsonc': '{ "basics": { "name": "x" ',
|
|
30
43
|
'resume.yaml': dedent`
|
|
31
44
|
basics:
|
|
32
45
|
name: thomas
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "resume-cli",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.8.0",
|
|
4
4
|
"description": "The JSON Resume command line interface",
|
|
5
5
|
"main": "build/main.js",
|
|
6
6
|
"engines": {
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
],
|
|
14
14
|
"repository": {
|
|
15
15
|
"type": "git",
|
|
16
|
-
"url": "https://github.com/jsonresume/
|
|
16
|
+
"url": "https://github.com/jsonresume/jsonresume.org.git",
|
|
17
|
+
"directory": "packages/cli"
|
|
17
18
|
},
|
|
18
19
|
"license": "MIT",
|
|
19
20
|
"bin": {
|
|
@@ -29,6 +30,7 @@
|
|
|
29
30
|
"dotenv": "^8.2.0",
|
|
30
31
|
"file-exists": "^5.0.1",
|
|
31
32
|
"jest-extended": "^0.11.5",
|
|
33
|
+
"jsonc-parser": "^3.3.1",
|
|
32
34
|
"jsonresume-theme-elegant": "^1.16.1",
|
|
33
35
|
"jsonresume-theme-even": "0.6.0",
|
|
34
36
|
"mime-types": "^2.1.27",
|
|
@@ -41,7 +43,7 @@
|
|
|
41
43
|
"yaml-js": "^0.2.3",
|
|
42
44
|
"yesno": "^0.3.1",
|
|
43
45
|
"@jsonresume/ats-validator": "0.3.0",
|
|
44
|
-
"@jsonresume/schema": "1.
|
|
46
|
+
"@jsonresume/schema": "1.4.0"
|
|
45
47
|
},
|
|
46
48
|
"devDependencies": {
|
|
47
49
|
"@babel/cli": "^7.25.0",
|