UNPKG

2.15 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('jsx', {
45 desc: 'Specify JSX transformer, like "vue", "react" or any JSX pragma'
46})
47.option('rawErrors', {
48 desc: 'Output original webpack errors'
49})
50.option('no-clear', {
51 desc: 'Do not clear screen'
52})
53.option('inspectOptions', {
54 desc: 'Output final options'
55})
56
57cli
58 .command('build', 'Build app in production mode', createHandler('production'))
59 .option('generate-stats', {
60 desc: 'Generate webpack stats for the bundle file'
61 })
62 .option('no-progress', {
63 desc: 'Disable progress bar'
64 })
65 .option('library', {
66 desc: 'Build as a library'
67 })
68
69cli
70 .command('*', {
71 desc: 'Run app in development mode',
72 alias: 'dev'
73 }, createHandler('development'))
74 .option('port', {
75 desc: 'Custom dev server port'
76 })
77 .option('proxy', {
78 desc: 'Proxy API request',
79 type: 'string'
80 })
81 .option('open', {
82 alias: 'o',
83 desc: 'Open App after compiling'
84 })
85 .option('restartOnFileChanges', {
86 alias: 'rs',
87 desc: 'Restart Poi on file changes'
88 })
89
90cli
91 .command('watch', 'Run app in watch mode', createHandler('watch'))
92 .option('restart-on-file-changes', {
93 alias: 'rs',
94 desc: 'Restart Poi on file changes'
95 })
96
97cli.command('test', 'Run app in test mode', createHandler('test'))
98
99cli.parse()