UNPKG

1.66 kBJavaScriptView Raw
1const cac = require('cac')
2const loudRejection = require('loud-rejection')
3const update = require('update-notifier')
4const pkg = require('../package.json')
5
6loudRejection()
7
8update({ pkg }).notify()
9
10function 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
24function createHandler(mode) {
25 return (input, flags) => {
26 const run = require('./run')
27 run(getOpts(input, flags, mode)).catch(run.handleError)
28 }
29}
30
31const cli = cac()
32
33cli.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
51cli
52 .command('build', 'Build app in production mode', createHandler('production'))
53 .option('generateStats', {
54 desc: 'Generate webpack stats for the bundle file'
55 })
56
57cli
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
74cli.command('watch', 'Run app in watch mode', createHandler('watch'))
75cli.command('test', 'Run app in test mode', createHandler('test'))
76
77cli.parse()