forked from magesuite/magepack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·50 lines (42 loc) · 1.55 KB
/
cli.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
#!/usr/bin/env node
const program = require('commander');
const logger = require('./lib/utils/logger');
const version = require('./package.json').version;
program.name('magepack').usage('[generate|bundle] <options...>');
program
.version(version, '-v, --version', 'Output the current version.')
.helpOption('-h, --help', 'Show this command summary.')
.addHelpCommand(false);
program
.command('generate')
.description(
'Generate optimization configuration based on given page URLs.'
)
.requiredOption('--cms-url <url>', 'CMS page URL.')
.requiredOption('--category-url <url>', 'Category page URL.')
.requiredOption('--product-url <url>', 'Product page URL.')
.option('-u, --auth-username <user>', 'Basic authentication username.')
.option('-p, --auth-password <password>', 'Basic authentication password.')
.option('-d, --debug', 'Enable logging of debugging information.')
.action((config) => {
if (config.debug) {
logger.level = 5;
}
require('./lib/generate')(config).catch(logger.error);
});
program
.command('bundle')
.description('Bundle JavaScript files using given configuration file.')
.option(
'-c, --config <path>',
'Configuration file path.',
'magepack.config.js'
)
.option('-d, --debug', 'Enable logging of debugging information.')
.action(({ config, debug }) => {
if (debug) {
logger.level = 5;
}
require('./lib/bundle')(config).catch(logger.error);
});
program.parse(process.argv);