resume-cli 3.7.0 → 3.7.2
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/build/export-resume.js +8 -14
- package/build/export-resume.test.js +59 -0
- package/build/render-html.js +18 -7
- package/build/render-html.test.js +85 -1
- package/build/serve.js +0 -6
- package/build/serve.test.js +41 -0
- package/build/validate.js +3 -3
- package/package.json +4 -5
package/build/export-resume.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _renderHtml =
|
|
3
|
+
var _renderHtml = _interopRequireWildcard(require("./render-html"));
|
|
4
4
|
var _util = require("util");
|
|
5
5
|
var _fs = _interopRequireDefault(require("fs"));
|
|
6
6
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
7
8
|
const writeFile = (0, _util.promisify)(_fs.default.writeFile);
|
|
8
9
|
const path = require('path');
|
|
9
10
|
const puppeteer = require('puppeteer');
|
|
@@ -87,19 +88,12 @@ const extractFileFormat = fileName => {
|
|
|
87
88
|
return fileName.substring(dotPos + 1).toLowerCase();
|
|
88
89
|
};
|
|
89
90
|
const getThemePkg = theme => {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const themePkg = require(theme);
|
|
97
|
-
return themePkg;
|
|
98
|
-
} catch (err) {
|
|
99
|
-
// Theme not installed. Throw a typed error so the caller can render an
|
|
100
|
-
// actionable, stack-trace-free message and exit with a non-zero code.
|
|
101
|
-
throw new ThemeNotFoundError(theme);
|
|
102
|
-
}
|
|
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));
|
|
103
97
|
};
|
|
104
98
|
async function createHtml(resumeJson, fileName, themePath, format, callback) {
|
|
105
99
|
let html;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const exportResume = require('./export-resume');
|
|
4
|
+
const {
|
|
5
|
+
ThemeNotFoundError
|
|
6
|
+
} = require('./theme-errors');
|
|
7
|
+
describe('exportResume', () => {
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
jest.restoreAllMocks();
|
|
10
|
+
});
|
|
11
|
+
it('surfaces ThemeNotFoundError from the PDF path for unresolvable themes', done => {
|
|
12
|
+
// PDF export resolves the theme (via the shared renderHTML resolver)
|
|
13
|
+
// before puppeteer is ever launched, so a missing theme fails fast with a
|
|
14
|
+
// typed error instead of a raw require() stack trace.
|
|
15
|
+
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
16
|
+
exportResume({
|
|
17
|
+
resume: {
|
|
18
|
+
basics: {
|
|
19
|
+
name: 'test'
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
fileName: 'out.pdf',
|
|
23
|
+
theme: 'jsonresume-theme-definitely-not-installed',
|
|
24
|
+
format: 'pdf'
|
|
25
|
+
}, (error, fileName, format) => {
|
|
26
|
+
try {
|
|
27
|
+
expect(error).toBeInstanceOf(ThemeNotFoundError);
|
|
28
|
+
expect(error.theme).toBe('jsonresume-theme-definitely-not-installed');
|
|
29
|
+
expect(fileName).toBe('out');
|
|
30
|
+
expect(format).toBe('.pdf');
|
|
31
|
+
// ThemeNotFoundError is reported by the caller; no raw dump here.
|
|
32
|
+
expect(errorSpy).not.toHaveBeenCalled();
|
|
33
|
+
done();
|
|
34
|
+
} catch (assertion) {
|
|
35
|
+
done(assertion);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
it('surfaces ThemeNotFoundError from the HTML path for unresolvable themes', done => {
|
|
40
|
+
jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
41
|
+
exportResume({
|
|
42
|
+
resume: {
|
|
43
|
+
basics: {
|
|
44
|
+
name: 'test'
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
fileName: 'out.html',
|
|
48
|
+
theme: 'jsonresume-theme-definitely-not-installed',
|
|
49
|
+
format: 'html'
|
|
50
|
+
}, error => {
|
|
51
|
+
try {
|
|
52
|
+
expect(error).toBeInstanceOf(ThemeNotFoundError);
|
|
53
|
+
done();
|
|
54
|
+
} catch (assertion) {
|
|
55
|
+
done(assertion);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
});
|
package/build/render-html.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = void 0;
|
|
6
|
+
exports.resolveThemePath = exports.default = void 0;
|
|
7
7
|
var _themeErrors = require("./theme-errors");
|
|
8
8
|
const tryResolve = (...args) => {
|
|
9
9
|
try {
|
|
@@ -12,10 +12,12 @@ const tryResolve = (...args) => {
|
|
|
12
12
|
return false;
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
|
|
16
|
+
// Resolve a theme reference (relative path, full package name, or short name
|
|
17
|
+
// missing the `jsonresume-theme-` prefix) to an absolute module path. Shared
|
|
18
|
+
// by every code path that loads a theme (HTML render, PDF export) so a theme
|
|
19
|
+
// that renders to HTML can never spuriously fail to resolve elsewhere.
|
|
20
|
+
const resolveThemePath = themePath => {
|
|
19
21
|
const cwd = process.cwd();
|
|
20
22
|
let path;
|
|
21
23
|
if (themePath[0] === '.') {
|
|
@@ -31,7 +33,9 @@ var _default = async ({
|
|
|
31
33
|
paths: [cwd]
|
|
32
34
|
});
|
|
33
35
|
}
|
|
34
|
-
|
|
36
|
+
// Only fall back to the `jsonresume-theme-` prefix for bare short names;
|
|
37
|
+
// scoped or otherwise non-alphanumeric-leading specifiers are used as-is.
|
|
38
|
+
if (!path && /^[a-z0-9]/i.test(themePath)) {
|
|
35
39
|
path = tryResolve(`jsonresume-theme-${themePath}`, {
|
|
36
40
|
paths: [cwd]
|
|
37
41
|
});
|
|
@@ -39,7 +43,14 @@ var _default = async ({
|
|
|
39
43
|
if (!path) {
|
|
40
44
|
throw new _themeErrors.ThemeNotFoundError(themePath);
|
|
41
45
|
}
|
|
42
|
-
|
|
46
|
+
return path;
|
|
47
|
+
};
|
|
48
|
+
exports.resolveThemePath = resolveThemePath;
|
|
49
|
+
var _default = async ({
|
|
50
|
+
resume,
|
|
51
|
+
themePath
|
|
52
|
+
}) => {
|
|
53
|
+
const theme = require(resolveThemePath(themePath));
|
|
43
54
|
if (typeof theme?.render !== 'function') {
|
|
44
55
|
throw new Error('theme.render is not a function');
|
|
45
56
|
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
4
|
+
var _os = _interopRequireDefault(require("os"));
|
|
5
|
+
var _path = _interopRequireDefault(require("path"));
|
|
6
|
+
var _renderHtml = _interopRequireWildcard(require("./render-html"));
|
|
7
|
+
var _themeErrors = require("./theme-errors");
|
|
8
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
4
9
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
5
10
|
describe('renderHTML', () => {
|
|
6
11
|
beforeAll(() => {
|
|
@@ -55,4 +60,83 @@ describe('renderHTML', () => {
|
|
|
55
60
|
})).toStartWith('<!doctype html>');
|
|
56
61
|
});
|
|
57
62
|
});
|
|
63
|
+
});
|
|
64
|
+
describe('resolveThemePath', () => {
|
|
65
|
+
// On-disk fixtures: a fake install root with a node_modules directory so we
|
|
66
|
+
// can exercise real require.resolve behavior without touching the repo.
|
|
67
|
+
let root;
|
|
68
|
+
let cwdSpy;
|
|
69
|
+
const makeTheme = (dirName, {
|
|
70
|
+
main
|
|
71
|
+
} = {}) => {
|
|
72
|
+
const themeDir = _path.default.join(root, 'node_modules', dirName);
|
|
73
|
+
const entryFile = _path.default.join(themeDir, main || 'index.js');
|
|
74
|
+
_fs.default.mkdirSync(_path.default.dirname(entryFile), {
|
|
75
|
+
recursive: true
|
|
76
|
+
});
|
|
77
|
+
const pkg = {
|
|
78
|
+
name: dirName,
|
|
79
|
+
version: '1.0.0'
|
|
80
|
+
};
|
|
81
|
+
if (main) {
|
|
82
|
+
pkg.main = main;
|
|
83
|
+
}
|
|
84
|
+
_fs.default.writeFileSync(_path.default.join(themeDir, 'package.json'), JSON.stringify(pkg));
|
|
85
|
+
_fs.default.writeFileSync(entryFile, 'module.exports = { render: () => "<!doctype html>" };');
|
|
86
|
+
};
|
|
87
|
+
beforeAll(() => {
|
|
88
|
+
root = _fs.default.realpathSync(_fs.default.mkdtempSync(_path.default.join(_os.default.tmpdir(), 'resume-cli-themes-')));
|
|
89
|
+
makeTheme('jsonresume-theme-short');
|
|
90
|
+
// A literal directory the (previously broken) prefix fallback would have
|
|
91
|
+
// matched for the scoped-looking specifier "@scoped".
|
|
92
|
+
makeTheme('jsonresume-theme-@scoped');
|
|
93
|
+
makeTheme('jsonresume-theme-nested', {
|
|
94
|
+
main: 'lib/entry.js'
|
|
95
|
+
});
|
|
96
|
+
_fs.default.mkdirSync(_path.default.join(root, 'sub'), {
|
|
97
|
+
recursive: true
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
afterAll(() => {
|
|
101
|
+
_fs.default.rmSync(root, {
|
|
102
|
+
recursive: true,
|
|
103
|
+
force: true
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
afterEach(() => {
|
|
107
|
+
if (cwdSpy) {
|
|
108
|
+
cwdSpy.mockRestore();
|
|
109
|
+
cwdSpy = undefined;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
const mockCwd = dir => {
|
|
113
|
+
cwdSpy = jest.spyOn(process, 'cwd').mockReturnValue(dir);
|
|
114
|
+
};
|
|
115
|
+
it('adds the jsonresume-theme- prefix for bare short names', () => {
|
|
116
|
+
mockCwd(root);
|
|
117
|
+
expect((0, _renderHtml.resolveThemePath)('short')).toBe(_path.default.join(root, 'node_modules', 'jsonresume-theme-short', 'index.js'));
|
|
118
|
+
});
|
|
119
|
+
it('does not apply the prefix fallback to scoped specifiers', () => {
|
|
120
|
+
mockCwd(root);
|
|
121
|
+
// The old guard tested the wrong variable (`path`, always false here) and
|
|
122
|
+
// coerced it to the string "false", so the fallback ran unconditionally
|
|
123
|
+
// and "@scoped" would have resolved to jsonresume-theme-@scoped.
|
|
124
|
+
expect(() => (0, _renderHtml.resolveThemePath)('@scoped')).toThrow(_themeErrors.ThemeNotFoundError);
|
|
125
|
+
});
|
|
126
|
+
it('resolves themes hoisted to a parent node_modules', () => {
|
|
127
|
+
mockCwd(_path.default.join(root, 'sub'));
|
|
128
|
+
expect((0, _renderHtml.resolveThemePath)('jsonresume-theme-short')).toBe(_path.default.join(root, 'node_modules', 'jsonresume-theme-short', 'index.js'));
|
|
129
|
+
});
|
|
130
|
+
it('resolves package.json main entries that are not index.js', () => {
|
|
131
|
+
mockCwd(root);
|
|
132
|
+
expect((0, _renderHtml.resolveThemePath)('jsonresume-theme-nested')).toBe(_path.default.join(root, 'node_modules', 'jsonresume-theme-nested', 'lib', 'entry.js'));
|
|
133
|
+
});
|
|
134
|
+
it('throws ThemeNotFoundError for unknown themes', () => {
|
|
135
|
+
mockCwd(root);
|
|
136
|
+
expect(() => (0, _renderHtml.resolveThemePath)('definitely-not-installed')).toThrow(_themeErrors.ThemeNotFoundError);
|
|
137
|
+
});
|
|
138
|
+
it('throws ThemeNotFoundError for unresolvable relative paths', () => {
|
|
139
|
+
mockCwd(root);
|
|
140
|
+
expect(() => (0, _renderHtml.resolveThemePath)('./missing-local-theme')).toThrow(_themeErrors.ThemeNotFoundError);
|
|
141
|
+
});
|
|
58
142
|
});
|
package/build/serve.js
CHANGED
|
@@ -6,12 +6,6 @@ const readline = require('readline');
|
|
|
6
6
|
const bs = require('browser-sync').create();
|
|
7
7
|
const builder = require('./builder');
|
|
8
8
|
const reBuildResume = (theme, dir, resumeFilename, cb) => {
|
|
9
|
-
console.log({
|
|
10
|
-
theme,
|
|
11
|
-
dir,
|
|
12
|
-
resumeFilename,
|
|
13
|
-
cb
|
|
14
|
-
});
|
|
15
9
|
builder(theme, dir, resumeFilename, (err, html) => {
|
|
16
10
|
if (err) {
|
|
17
11
|
readline.cursorTo(process.stdout, 0);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
jest.mock('browser-sync', () => ({
|
|
4
|
+
create: jest.fn(() => ({
|
|
5
|
+
watch: jest.fn(() => ({
|
|
6
|
+
on: jest.fn()
|
|
7
|
+
})),
|
|
8
|
+
init: jest.fn(),
|
|
9
|
+
reload: jest.fn()
|
|
10
|
+
}))
|
|
11
|
+
}));
|
|
12
|
+
jest.mock('./builder', () => jest.fn((theme, dir, resumeFilename, cb) => cb(null, '<html>ok</html>')));
|
|
13
|
+
const fs = require('fs');
|
|
14
|
+
const serve = require('./serve');
|
|
15
|
+
describe('serve', () => {
|
|
16
|
+
let logSpy;
|
|
17
|
+
const options = {
|
|
18
|
+
port: 4000,
|
|
19
|
+
theme: 'jsonresume-theme-even',
|
|
20
|
+
silent: true,
|
|
21
|
+
dir: 'public',
|
|
22
|
+
resumeFilename: 'resume.json'
|
|
23
|
+
};
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
logSpy = jest.spyOn(console, 'log').mockImplementation(() => {});
|
|
26
|
+
jest.spyOn(fs, 'existsSync').mockReturnValue(true);
|
|
27
|
+
jest.spyOn(fs, 'writeFile').mockImplementation((file, data, cb) => cb(null));
|
|
28
|
+
});
|
|
29
|
+
afterEach(() => {
|
|
30
|
+
jest.restoreAllMocks();
|
|
31
|
+
});
|
|
32
|
+
it('prints the preview URL', () => {
|
|
33
|
+
serve(options);
|
|
34
|
+
expect(logSpy).toHaveBeenCalledWith('Preview: http://localhost:4000');
|
|
35
|
+
});
|
|
36
|
+
it('does not emit leftover debug objects on rebuild', () => {
|
|
37
|
+
serve(options);
|
|
38
|
+
const objectArgs = logSpy.mock.calls.flat().filter(arg => typeof arg === 'object' && arg !== null);
|
|
39
|
+
expect(objectArgs).toEqual([]);
|
|
40
|
+
});
|
|
41
|
+
});
|
package/build/validate.js
CHANGED
|
@@ -12,9 +12,9 @@ var _default = async ({
|
|
|
12
12
|
resume,
|
|
13
13
|
schema
|
|
14
14
|
}) => {
|
|
15
|
-
// strict:false is
|
|
16
|
-
// draft-07 document
|
|
17
|
-
//
|
|
15
|
+
// strict:false is the ecosystem baseline: the schema passed in may be an
|
|
16
|
+
// externally authored draft-07 document (custom/theme schemas) that is not
|
|
17
|
+
// strict-mode clean, and strict mode would reject it instead of validating.
|
|
18
18
|
const ajv = new _ajv.default({
|
|
19
19
|
allErrors: true,
|
|
20
20
|
strict: false
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "resume-cli",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.2",
|
|
4
4
|
"description": "The JSON Resume command line interface",
|
|
5
5
|
"main": "build/main.js",
|
|
6
6
|
"engines": {
|
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"ajv": "^8.17.1",
|
|
24
24
|
"ajv-formats": "^3.0.1",
|
|
25
|
-
"async": "^3.2.0",
|
|
26
25
|
"browser-sync": "^2.29.3",
|
|
27
26
|
"btoa": "^1.2.1",
|
|
28
27
|
"chalk": "^4.1.0",
|
|
@@ -41,8 +40,8 @@
|
|
|
41
40
|
"superagent": "^6.0.0",
|
|
42
41
|
"yaml-js": "^0.2.3",
|
|
43
42
|
"yesno": "^0.3.1",
|
|
44
|
-
"@jsonresume/
|
|
45
|
-
"@jsonresume/
|
|
43
|
+
"@jsonresume/ats-validator": "0.3.0",
|
|
44
|
+
"@jsonresume/schema": "1.3.1"
|
|
46
45
|
},
|
|
47
46
|
"devDependencies": {
|
|
48
47
|
"@babel/cli": "^7.25.0",
|
|
@@ -53,7 +52,7 @@
|
|
|
53
52
|
"babel-jest": "^29.7.0",
|
|
54
53
|
"dedent": "0.7.0",
|
|
55
54
|
"eslint": "7.15.0",
|
|
56
|
-
"eslint-config-prettier": "
|
|
55
|
+
"eslint-config-prettier": "^10.1.8",
|
|
57
56
|
"eslint-plugin-jest": "24.1.3",
|
|
58
57
|
"eslint-plugin-prettier": "3.2.0",
|
|
59
58
|
"flat": "5.0.2",
|