-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbin.js
executable file
·50 lines (43 loc) · 1.03 KB
/
bin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env node
/**
* @file bin
* @author imcuttle <[email protected]>
* @date 2018/10/28
*
*/
const live = require('./')
const pkg = require('./package')
const nps = require('path')
const dv = {
port: 9090,
baseUrl: '/'
}
const argv = require('minimist')(process.argv.slice(2), {
default: dv,
alias: {
help: 'h',
version: 'v',
port: 'p',
'base-url': 'b'
},
boolean: ['cz-in-global', 'help', 'version']
})
const opt = {
port: argv.port,
baseUrl: argv['base-url']
}
const root = !argv._[0] ? process.cwd() : nps.resolve(argv._[0])
if (argv.help) {
console.log(` Usage
$ ${pkg.name} <path> [options]
Options
--help, -h Show help information in stdout
--version, -v Show version information in stdout
--port, -p Assign ${pkg.name}'s server port [Default: ${dv.port}]
--base-url, -b Assign base url [Default: ${dv.baseUrl}]
`)
} else if (argv.version) {
console.log(pkg.version)
} else {
live(root, opt)
}