1 | #!/usr/bin/env node
|
2 | const commander = require('commander')
|
3 |
|
4 | function run(command, ...args) {
|
5 |
|
6 | const cmd = require(`../commands/${command}`)
|
7 | return cmd(...args)
|
8 | }
|
9 |
|
10 | const options = {
|
11 | entry: [
|
12 | '-e, --entry <entry>',
|
13 | 'Webpack entry file (default: src/index.js)'
|
14 | ],
|
15 | output: ['-o, --out <output>', 'Output path (default: build)'],
|
16 | html: ['--html <file>', 'Html page (default: src/index.html)'],
|
17 | noHtml: ['--no-html', 'Disable building html'],
|
18 | config: ['-c, --config <config>', 'Webpack config file'],
|
19 | env: [
|
20 | '--env <value>',
|
21 | 'Set value of the NODE_ENV variable',
|
22 | /^(development|production)$/
|
23 | ],
|
24 | target: [
|
25 | '--target <value>',
|
26 | 'Prepare bundle for running in server or browser',
|
27 | /^(node|web|universal)$/
|
28 | ],
|
29 | assetsCaching: [
|
30 | '--assets-caching',
|
31 | 'Optimize build for caching static assets'
|
32 | ]
|
33 | }
|
34 |
|
35 | commander.version(require('../package.json').version)
|
36 |
|
37 | commander
|
38 | .command('build')
|
39 | .description('Create an optimized production build')
|
40 | .option(...options.entry)
|
41 | .option(...options.output)
|
42 | .option(...options.html)
|
43 | .option(...options.noHtml)
|
44 | .option(...options.config)
|
45 | .option(...options.env, 'production')
|
46 | .option(...options.target, 'web')
|
47 | .option(...options.assetsCaching)
|
48 | .option('--ssr', 'Server side rendering')
|
49 | .action(cmd => run('build', cmd))
|
50 |
|
51 | commander
|
52 | .command('start')
|
53 | .description('Start the development server')
|
54 | .option(...options.entry)
|
55 | .option(...options.output)
|
56 | .option(...options.html)
|
57 | .option(...options.noHtml)
|
58 | .option(...options.config)
|
59 | .action(cmd => run('start', cmd))
|
60 |
|
61 | commander
|
62 | .command('watch')
|
63 | .description('Create development build and rebuild on change')
|
64 | .option(...options.entry)
|
65 | .option(...options.output)
|
66 | .option(...options.html)
|
67 | .option(...options.noHtml)
|
68 | .option(...options.config)
|
69 | .option(...options.env, 'production')
|
70 | .option(...options.target, 'web')
|
71 | .option(...options.assetsCaching)
|
72 | .action(cmd => run('watch', cmd))
|
73 |
|
74 | commander
|
75 | .command('lib')
|
76 | .description('Build as library')
|
77 | .option(...options.env, 'production')
|
78 | .option(...options.target, 'web')
|
79 | .option('--watch', 'Compile source with babel and rebuild on change')
|
80 | .option('--source-maps', 'Embed source maps into compiled files')
|
81 | .action(cmd => run('lib', cmd))
|
82 |
|
83 | commander
|
84 | .command('link')
|
85 | .description('Link gnoll executable to child packages of the lerna project')
|
86 | .action(cmd => run('link', cmd))
|
87 |
|
88 | commander.parse(process.argv)
|
89 |
|
90 | const COMMANDS = ['watch', 'build', 'start', 'lib', 'link']
|
91 | const command = process.argv[2]
|
92 | if (!command) {
|
93 | commander.outputHelp()
|
94 | } else if (COMMANDS.indexOf(command) === -1) {
|
95 | console.log(`Error: unknown command "${command}"`)
|
96 | }
|