-
Notifications
You must be signed in to change notification settings - Fork 377
/
index.js
executable file
路121 lines (110 loc) 路 3.25 KB
/
index.js
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
#!/usr/bin/env node
require('dotenv').config();
const pkg = require('./package.json');
const lib = require('./lib');
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}`;
};
lib.preFlow(async (err, results) => {
const resumeJson = results.getResume;
program
.usage('[command] [options]')
.version(pkg.version)
.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(
'-r, --resume <resume filename>',
'Used by `serve` (default: resume.json)',
path.join(process.cwd(), '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 `test` to validate against a custom schema.',
);
program
.command('init')
.description('Initialize a resume.json file')
.action(() => {
lib.init();
});
program
.command('test')
.description('Schema validation test your resume.json')
.action(async () => {
await lib.test(resumeJson);
});
program
.command('export [fileName]')
.description(
'Export locally to .html or .pdf. Supply a --format <file format> flag and argument to specify export format.',
)
.action((fileName) => {
lib.exportResume(
resumeJson,
fileName,
program.theme,
program.format,
(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(() => {
lib.serve(
program.port,
program.theme,
program.silent,
program.dir,
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();
}
});