1 | const cac = require('cac')
|
2 | const loudRejection = require('loud-rejection')
|
3 | const update = require('update-notifier')
|
4 | const pkg = require('../package.json')
|
5 |
|
6 | loudRejection()
|
7 |
|
8 | update({ pkg }).notify()
|
9 |
|
10 | function getOpts(input, flags, mode) {
|
11 | const opts = Object.keys(flags).reduce((res, next) => {
|
12 | if (typeof flags[next] !== 'undefined') {
|
13 | res[next] = flags[next]
|
14 | }
|
15 | return res
|
16 | }, {})
|
17 |
|
18 | if (input.length > 0) {
|
19 | opts.entry = input
|
20 | }
|
21 | return Object.assign({ mode }, opts)
|
22 | }
|
23 |
|
24 | function createHandler(mode) {
|
25 | return (input, flags) => {
|
26 | const run = require('./run')
|
27 | run(getOpts(input, flags, mode)).catch(run.handleError)
|
28 | }
|
29 | }
|
30 |
|
31 | const cli = cac()
|
32 |
|
33 | cli.option('dist', {
|
34 | alias: 'd',
|
35 | desc: 'Output directory'
|
36 | })
|
37 | .option('config', {
|
38 | alias: 'c',
|
39 | desc: 'Use custom path to config file'
|
40 | })
|
41 | .option('templateCompiler', {
|
42 | desc: 'Use full build of Vue'
|
43 | })
|
44 | .option('noClear', {
|
45 | desc: 'Do not clear screen'
|
46 | })
|
47 | .option('inspectOptions', {
|
48 | desc: 'Output final options'
|
49 | })
|
50 |
|
51 | cli
|
52 | .command('build', 'Build app in production mode', createHandler('production'))
|
53 | .option('generateStats', {
|
54 | desc: 'Generate webpack stats for the bundle file'
|
55 | })
|
56 |
|
57 | cli
|
58 | .command('*', {
|
59 | desc: 'Run app in development mode',
|
60 | alias: 'dev'
|
61 | }, createHandler('development'))
|
62 | .option('port', {
|
63 | desc: 'Custom dev server port'
|
64 | })
|
65 | .option('proxy', {
|
66 | desc: 'Proxy API request',
|
67 | type: 'string'
|
68 | })
|
69 | .option('open', {
|
70 | alias: 'o',
|
71 | desc: 'Open App after compiling'
|
72 | })
|
73 |
|
74 | cli.command('watch', 'Run app in watch mode', createHandler('watch'))
|
75 | cli.command('test', 'Run app in test mode', createHandler('test'))
|
76 |
|
77 | cli.parse()
|