-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.js
80 lines (71 loc) · 1.94 KB
/
main.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
80
import commander from 'commander'
import { description, version } from '../package.json'
import build from './cmd/build'
import clean from './cmd/clean'
import epub from './cmd/epub'
import init from './cmd/init'
import print from './cmd/print'
import serve from './cmd/serve'
commander
// Add version
.version(version, '-v, --version')
// Add description
.description(description)
commander.on('--help', () => {
console.log('')
console.log('Examples:')
console.log(' $ markbook --help')
console.log('')
console.log(
"To see the options for a specific command, use 'markbook <cmd> --help'"
)
console.log('Such as:')
console.log(' $ markbook init --help')
})
commander
.command('build [dir]')
.description('Build a book')
.option('-o, --open', 'Open in the book in a web browser')
.action(build)
commander
.command('clean [dir]')
.description("Delete a book's outputs")
.action(clean)
commander
.command('epub [dir]')
.description('Generate an ePub file')
.action(epub)
commander
.command('init [dir]')
.description('Create a new book')
.option('-a, --author [author]', 'Author name')
.option('-T, --title [title]', 'Book title')
.option('-d, --desc [desc]', 'Book description')
.option('-t, --theme', 'Copy the theme to the directory')
.action(init)
commander
.command('print [dir]')
.description('Render to a PDF file')
.action(print)
commander
.command('serve [dir]')
.description(
'Serves a book at http://localhost:8080, and rebuilds it on changes'
)
.option(
'-h, --hostname [hostname]',
'Hostname to listen on for HTTP connections [localhost]',
'localhost'
)
.option(
'-p, --port [port]',
'Port to listen on for HTTP connections [8080]',
parseInt,
8080
)
.option('-o, --open', 'Open in the book in a web browser')
.action(serve)
commander.parse(process.argv)
if (!commander.args.length || typeof commander.args[1] !== 'object') {
commander.help()
}