forked from jsonresume/resume-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
executable file
Β·139 lines (127 loc) Β· 4.02 KB
/
Copy pathmain.js
File metadata and controls
executable file
Β·139 lines (127 loc) Β· 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env node
import 'dotenv/config';
import init from './init';
import getResume from './get-resume';
import getSchema from './get-schema';
import validate from './validate';
const pkg = require('../package.json');
const exportResume = require('./export-resume');
const serve = require('./serve');
const program = require('commander');
const chalk = require('chalk');
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}`;
};
(async () => {
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>',
'Specify theme used by `export` and `serve` 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('--papersize <papersize>', 'Used by `export`.', 'Letter')
.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.',
);
program
.command('init')
.description('Initialize a resume.json file')
.action(async () => {
await init({ resumePath: program.resume });
});
program
.command('validate')
.description("Validate your resume's schema")
.action(async () => {
const resume = await getResume({ path: program.resume });
const schema = await getSchema({ path: program.schema });
try {
await validate({
resume,
schema,
});
} catch (e) {
console.error(e.message);
process.exitCode = 1;
}
});
program
.command('export [fileName]')
.description(
'Export locally to .html or .pdf. Supply a --format <file format> flag and argument to specify export format. ' +
'Supply --papersize flag and argument to specify export page format when rendering a PDF.',
)
.option('--papersize <papersize>', 'Paper size to use with PDF', 'Letter')
.action(async (fileName) => {
const resume = await getResume({ path: program.resume });
exportResume(
{ ...program, resume, fileName },
(err, fileName, format) => {
console.log(
chalk.green(
'\nDone! Find your new',
format,
'resume at:\n',
path.resolve(process.cwd(), fileName + format),
),
);
},
);
});
program
.command('serve')
.description('Serve resume at http://localhost:4000/')
.action(async () => {
serve({
...program,
resumeFilename: program.resume,
});
});
await program.parseAsync(process.argv);
const validCommands = program.commands.map((cmd) => {
return cmd._name;
});
// https://github.com/tj/commander.js/blob/master/CHANGELOG.md#testing-for-no-arguments
if (program.rawArgs.length < 3) {
console.log(chalk.cyan('resume-cli:'), 'https://jsonresume.org', '\n');
program.help();
} else if (validCommands.indexOf(process.argv[2]) === -1) {
console.log(chalk.red('Invalid argument:'), process.argv[2]);
console.log(chalk.cyan('resume-cli:'), 'https://jsonresume.org', '\n');
program.help();
}
})();