UNPKG

2.29 kBJavaScriptView Raw
1const chalk = require('chalk')
2const yargs = require('yargs')
3const loudRejection = require('loud-rejection')
4const update = require('update-notifier')
5const pkg = require('../package.json')
6
7loudRejection()
8
9update({ pkg }).notify()
10
11function getOpts(argv, mode) {
12 const opts = Object.keys(argv).reduce((curr, next) => {
13 if (typeof argv[next] !== 'undefined' && next !== 'mode') {
14 curr[next] = argv[next]
15 }
16 return curr
17 }, {})
18 const cmd = argv._[0]
19 let entry
20 if (['build', 'dev', 'watch', 'test'].indexOf(cmd) > -1) {
21 entry = argv._.slice(1)
22 } else {
23 entry = argv._
24 }
25 if (entry.length > 0) {
26 opts.entry = entry
27 }
28 return Object.assign({ mode }, opts)
29}
30
31function createHandler(mode) {
32 return argv => {
33 const run = require('./run')
34 run(getOpts(argv, mode)).catch(run.handleError)
35 }
36}
37
38const sharedOptions = {
39 dist: {
40 alias: 'd',
41 desc: 'Output directory'
42 },
43 config: {
44 alias: 'c',
45 desc: 'Use custom path to config file'
46 },
47 templateCompiler: {
48 desc: 'Use full build of Vue'
49 },
50 'no-clear': {
51 desc: 'Do not clear screen'
52 }
53}
54
55yargs // eslint-disable-line no-unused-expressions
56 .usage(`\n${chalk.yellow('poi')} [command] [options]`)
57 .command(['build'], 'Build app in production mode', cli => {
58 cli.options(Object.assign({}, sharedOptions, {
59 generateStats: {
60 desc: 'Generate webpack stats for the bundle file'
61 }
62 }))
63 }, createHandler('production'))
64 .command(['*', 'dev'], 'Run app in development mode', cli => {
65 cli.options(Object.assign({}, sharedOptions, {
66 port: {
67 desc: 'Custom dev server port',
68 type: 'number'
69 },
70 host: {
71 desc: 'Custom dev server hostname',
72 type: 'string'
73 },
74 proxy: {
75 desc: 'Proxy API request',
76 type: 'string'
77 },
78 open: {
79 alias: 'o',
80 desc: 'Open App after compiling'
81 }
82 }))
83 }, createHandler('development'))
84 .command('watch', 'Run app in watch mode', () => {}, createHandler('watch'))
85 .command('test', 'Run app in test mode', () => {}, createHandler('test'))
86 .version(pkg.version)
87 .alias('version', 'v')
88 .alias('help', 'h')
89 .epilogue('for more information, find our manual at https://poi.js.org')
90 .help()
91 .argv