Skip to content

Commit d79212a

Browse files
AviVahlErisDS
authored andcommittedMar 31, 2020
fix: migrate from optimist to yargs (#1666)
closes #1658 - adapted code from master to latest yargs (`.option` calls). ``` 4.x: found 188 vulnerabilities (169 low, 4 moderate, 14 high, 1 critical) in 5815 scanned packages 4.x with this PR: found 32 vulnerabilities (17 low, 1 moderate, 13 high, 1 critical) in 5829 scanned packages ```
1 parent b440c38 commit d79212a

File tree

3 files changed

+2446
-2224
lines changed

3 files changed

+2446
-2224
lines changed
 

‎bin/handlebars

+107-112
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,122 @@
11
#!/usr/bin/env node
22

3-
var optimist = require('optimist')
4-
.usage('Precompile handlebar templates.\nUsage: $0 [template|directory]...', {
5-
'f': {
6-
'type': 'string',
7-
'description': 'Output File',
8-
'alias': 'output'
9-
},
10-
'map': {
11-
'type': 'string',
12-
'description': 'Source Map File'
13-
},
14-
'a': {
15-
'type': 'boolean',
16-
'description': 'Exports amd style (require.js)',
17-
'alias': 'amd'
18-
},
19-
'c': {
20-
'type': 'string',
21-
'description': 'Exports CommonJS style, path to Handlebars module',
22-
'alias': 'commonjs',
23-
'default': null
24-
},
25-
'h': {
26-
'type': 'string',
27-
'description': 'Path to handlebar.js (only valid for amd-style)',
28-
'alias': 'handlebarPath',
29-
'default': ''
30-
},
31-
'k': {
32-
'type': 'string',
33-
'description': 'Known helpers',
34-
'alias': 'known'
35-
},
36-
'o': {
37-
'type': 'boolean',
38-
'description': 'Known helpers only',
39-
'alias': 'knownOnly'
40-
},
41-
'm': {
42-
'type': 'boolean',
43-
'description': 'Minimize output',
44-
'alias': 'min'
45-
},
46-
'n': {
47-
'type': 'string',
48-
'description': 'Template namespace',
49-
'alias': 'namespace',
50-
'default': 'Handlebars.templates'
51-
},
52-
's': {
53-
'type': 'boolean',
54-
'description': 'Output template function only.',
55-
'alias': 'simple'
56-
},
57-
'N': {
58-
'type': 'string',
59-
'description': 'Name of passed string templates. Optional if running in a simple mode. Required when operating on multiple templates.',
60-
'alias': 'name'
61-
},
62-
'i': {
63-
'type': 'string',
64-
'description': 'Generates a template from the passed CLI argument.\n"-" is treated as a special value and causes stdin to be read for the template value.',
65-
'alias': 'string'
66-
},
67-
'r': {
68-
'type': 'string',
69-
'description': 'Template root. Base value that will be stripped from template names.',
70-
'alias': 'root'
71-
},
72-
'p': {
73-
'type': 'boolean',
74-
'description': 'Compiling a partial template',
75-
'alias': 'partial'
76-
},
77-
'd': {
78-
'type': 'boolean',
79-
'description': 'Include data when compiling',
80-
'alias': 'data'
81-
},
82-
'e': {
83-
'type': 'string',
84-
'description': 'Template extension.',
85-
'alias': 'extension',
86-
'default': 'handlebars'
87-
},
88-
'b': {
89-
'type': 'boolean',
90-
'description': 'Removes the BOM (Byte Order Mark) from the beginning of the templates.',
91-
'alias': 'bom'
92-
},
93-
'v': {
94-
'type': 'boolean',
95-
'description': 'Prints the current compiler version',
96-
'alias': 'version'
97-
},
3+
const yargs = require('yargs')
4+
.usage('Precompile handlebar templates.\nUsage: $0 [template|directory]...')
5+
.option('f', {
6+
type: 'string',
7+
description: 'Output File',
8+
alias: 'output'
9+
})
10+
.option('map', {
11+
type: 'string',
12+
description: 'Source Map File'
13+
})
14+
.option('a', {
15+
type: 'boolean',
16+
description: 'Exports amd style (require.js)',
17+
alias: 'amd'
18+
})
19+
.option('c', {
20+
type: 'string',
21+
description: 'Exports CommonJS style, path to Handlebars module',
22+
alias: 'commonjs',
23+
default: null
24+
})
25+
.option('h', {
26+
type: 'string',
27+
description: 'Path to handlebar.js (only valid for amd-style)',
28+
alias: 'handlebarPath',
29+
default: ''
30+
})
31+
.option('k', {
32+
type: 'string',
33+
description: 'Known helpers',
34+
alias: 'known'
35+
})
36+
.option('o', {
37+
type: 'boolean',
38+
description: 'Known helpers only',
39+
alias: 'knownOnly'
40+
})
41+
.option('m', {
42+
type: 'boolean',
43+
description: 'Minimize output',
44+
alias: 'min'
45+
})
46+
.option('n', {
47+
type: 'string',
48+
description: 'Template namespace',
49+
alias: 'namespace',
50+
default: 'Handlebars.templates'
51+
})
52+
.option('s', {
53+
type: 'boolean',
54+
description: 'Output template function only.',
55+
alias: 'simple'
56+
})
57+
.option('N', {
58+
type: 'string',
59+
description:
60+
'Name of passed string templates. Optional if running in a simple mode. Required when operating on multiple templates.',
61+
alias: 'name'
62+
})
63+
.option('i', {
64+
type: 'string',
65+
description:
66+
'Generates a template from the passed CLI argument.\n"-" is treated as a special value and causes stdin to be read for the template value.',
67+
alias: 'string'
68+
})
69+
.option('r', {
70+
type: 'string',
71+
description:
72+
'Template root. Base value that will be stripped from template names.',
73+
alias: 'root'
74+
})
75+
.option('p', {
76+
type: 'boolean',
77+
description: 'Compiling a partial template',
78+
alias: 'partial'
79+
})
80+
.option('d', {
81+
type: 'boolean',
82+
description: 'Include data when compiling',
83+
alias: 'data'
84+
})
85+
.option('e', {
86+
type: 'string',
87+
description: 'Template extension.',
88+
alias: 'extension',
89+
default: 'handlebars'
90+
})
91+
.option('b', {
92+
type: 'boolean',
93+
description:
94+
'Removes the BOM (Byte Order Mark) from the beginning of the templates.',
95+
alias: 'bom'
96+
})
97+
.option('v', {
98+
type: 'boolean',
99+
description: 'Prints the current compiler version',
100+
alias: 'version'
101+
})
102+
.option('help', {
103+
type: 'boolean',
104+
description: 'Outputs this message'
105+
})
106+
.wrap(120);
98107

99-
'help': {
100-
'type': 'boolean',
101-
'description': 'Outputs this message'
102-
}
103-
})
104-
105-
.wrap(120)
106-
.check(function(argv) {
107-
if (argv.version) {
108-
return;
109-
}
110-
});
111-
112-
113-
var argv = optimist.argv;
108+
const argv = yargs.argv;
114109
argv.files = argv._;
115110
delete argv._;
116111

117-
var Precompiler = require('../dist/cjs/precompiler');
112+
const Precompiler = require('../dist/cjs/precompiler');
118113
Precompiler.loadTemplates(argv, function(err, opts) {
119114
if (err) {
120115
throw err;
121116
}
122117

123118
if (opts.help || (!opts.templates.length && !opts.version)) {
124-
optimist.showHelp();
119+
yargs.showHelp();
125120
} else {
126121
Precompiler.cli(opts);
127122
}

‎package-lock.json

+2,337-2,110
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
},
2323
"dependencies": {
2424
"neo-async": "^2.6.0",
25-
"optimist": "^0.6.1",
26-
"source-map": "^0.6.1"
25+
"source-map": "^0.6.1",
26+
"yargs": "^15.3.1"
2727
},
2828
"optionalDependencies": {
2929
"uglify-js": "^3.1.4"

0 commit comments

Comments
 (0)
Please sign in to comment.