-
Notifications
You must be signed in to change notification settings - Fork 334
/
nwb.js
79 lines (66 loc) · 1.88 KB
/
nwb.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env node
import parseArgs from 'minimist'
import pkg from '../../package.json'
let args = parseArgs(process.argv.slice(2), {
alias: {
h: 'help',
v: 'version'
},
boolean: ['help', 'version']
})
if (args.version) {
console.log(`v${pkg.version}`)
process.exit(0)
}
if (args.help || args._.length === 0) {
console.log(`
Usage: nwb <command>
Options:
-h, --help display this help message
-v, --version print nwb's version
Project creation commands:
new react-app <name> create a React app
new react-component <name> create a React component with a demo app
new web-module <name> create a web module
-f force creation, don't ask any questions
Development commands:
build clean and build
clean delete build
test run tests
--coverage create code coverage report
--server keep running tests on every change
serve serve an app, or a component's demo app, with hot reloading
--fallback serve the index page from any path
--info show webpack module info
--port port to run the dev server on [3000]
`)
process.exit(0)
}
let command = args._[0]
let unknownCommand = () => {
console.error(`nwb: unknown command: ${command}`)
process.exit(1)
}
// Validate the command is in foo-bar-baz format before trying to resolve a
// module path with it.
if (!/^[a-z]+(?:-[a-z]+)*$/.test(command)) {
unknownCommand()
}
let commandModulePath
try {
commandModulePath = require.resolve(`../commands/${command}`)
}
catch (e) {
unknownCommand()
}
try {
let commandModule = require(commandModulePath)
if (typeof commandModule == 'function') {
commandModule(args)
}
}
catch (e) {
console.error(`nwb: error running ${command}:`)
console.error(e.stack)
process.exit(1)
}