1 | import bundle from './bundle'
|
2 | import chalk from 'chalk'
|
3 | import getConfig from './get-config'
|
4 | import HELP from './help'
|
5 | import isSudo from 'is-sudo'
|
6 | import serve from './serve'
|
7 | import watch from './watch'
|
8 |
|
9 | process.on('uncaughtException', err => {
|
10 | console.error('Uncaught exception:', err.stack)
|
11 | })
|
12 |
|
13 | const getApps = () => (
|
14 | process.argv[3] ? process.argv.slice(3, process.argv.length) : [process.cwd()]
|
15 | ).map(getConfig)
|
16 |
|
17 | switch(process.argv[2]) {
|
18 | case 'bundle':
|
19 | getApps().forEach(bundle)
|
20 | break
|
21 |
|
22 | case 'start':
|
23 | isSudo(is => {
|
24 | if (!is) {
|
25 | console.error(chalk.red(`Please run "sudo ${process.argv.join(' ')}" instead`))
|
26 | return
|
27 | }
|
28 |
|
29 | console.log(chalk.blue('PacPan is starting'))
|
30 | console.log(chalk.gray('To exit it, press ctrl+c'))
|
31 | const apps = getApps()
|
32 | serve(apps)
|
33 | const watchers = apps.map(watch)
|
34 | const cleanup = () => watchers.forEach(w => w())
|
35 |
|
36 |
|
37 | process.on('exit', cleanup)
|
38 | process.on('SIGINT', cleanup)
|
39 | })
|
40 | break
|
41 |
|
42 | case 'help':
|
43 | default:
|
44 | console.log(HELP)
|
45 | break
|
46 | }
|