UNPKG

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