-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.js
executable file
·62 lines (55 loc) · 1.2 KB
/
cli.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
#!/usr/bin/env node
const path = require('path')
const meow = require('meow')
const start = require('./index')
require('update-notifier')({
pkg: require('./package.json')
}).notify()
const cli = meow(`
Usage
$ micro-react <component>
Options
--port, -p Server port
--raw, -r Serve raw output with no doctype declaration
--bundle, -b Render with bundled javascript
--noWrap, -n Opt out of wrapping component in a div
`, {
flags: {
port: {
type: 'string',
alias: 'p'
},
raw: {
type: 'boolean',
alias: 'r'
},
bundle: {
type: 'boolean',
alias: 'b'
},
noWrap: {
type: 'boolean',
default: false,
alias: 'n'
}
}
})
const [ file ] = cli.input
const filename = path.join(process.cwd(), file)
const opts = Object.assign({}, cli.flags, {
filename,
port: parseInt(cli.flags.port || 3000)
})
start(opts)
.then(server => {
if (!server.address()) {
console.log(`failed to start server on ${cli.flags.port || 3000}`)
process.exit(1)
}
const { port } = server.address()
console.log(`listening on port ${port}`)
})
.catch(err => {
console.log(err)
process.exit(1)
})