forked from storybookjs/vue-cli-plugin-storybook
/
options.js
56 lines (48 loc) · 1.91 KB
/
options.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
const { Command } = require('commander');
function parseList(str) {
return str.split(',');
}
const sharedOptions = [
['-s, --static-dir <dir-names>', 'Directory where to load static files from', parseList],
['-c, --config-dir [dir-name]', 'Directory where to load Storybook configurations from'],
['--quiet', 'Suppress verbose build output'],
];
// Parsed from storybook repo.
// tags/v4.1.4: storybook/lib/core/src/server/cli/prod.js
const prodOptions = [
...sharedOptions,
['-o, --output-dir [dir-name]', 'Directory where to store built files'],
['-w, --watch', 'Enable watch mode'],
];
// Parsed from storybook repo.
// tags/v4.1.4: storybook/lib/core/src/server/cli/dev.js
const devOptions = [
...sharedOptions,
['-p, --port [number]', 'Port to run Storybook', str => parseInt(str, 10)],
['-h, --host [string]', 'Host to run Storybook'],
['--https', 'Serve Storybook over HTTPS. Note: You must provide your own certificate information.'],
['--ssl-ca <ca>', 'Provide an SSL certificate authority. (Optional with --https, required if using a self-signed certificate)', parseList],
['--ssl-cert <cert>', 'Provide an SSL certificate. (Required with --https)'],
['--ssl-key <key>', 'Provide an SSL key. (Required with --https)'],
['--smoke-test', 'Exit after successful start'],
['--ci', "CI mode (skip interactive prompts, don't open browser"],
];
const generateVueCliOptions = options => options.reduce(
(vueCliOptions, [arg, desc]) => ({ ...vueCliOptions, [arg]: desc }),
{},
);
const MOCK_EXECUTABLE_ARGV = ['node', 'vue-cli-plugin-storybook'];
const generateCommanderProgram = (argv, options) => {
const program = new Command();
options.forEach(([arg, desc, transform]) => {
program.option(arg, desc, transform);
});
program.parse(MOCK_EXECUTABLE_ARGV.concat(argv));
return program;
};
module.exports = {
prodOptions,
devOptions,
generateCommanderProgram,
generateVueCliOptions,
};