UNPKG

1.08 kBJavaScriptView Raw
1import bundle from './bundle'
2import chalk from 'chalk'
3import getConfig from './get-config'
4import HELP from './help'
5import isSudo from 'is-sudo'
6import serve from './serve'
7import watch from './watch'
8
9process.on('uncaughtException', err => {
10 console.error('Uncaught exception:', err.stack)
11})
12
13const getApps = () => (
14 process.argv[3] ? process.argv.slice(3, process.argv.length) : [process.cwd()]
15).map(getConfig)
16
17switch(process.argv[2]) {
18case 'bundle':
19 getApps().forEach(bundle)
20 break
21
22case '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 // clean up the temp file on exit and ctrl+c event
37 process.on('exit', cleanup)
38 process.on('SIGINT', cleanup)
39 })
40 break
41
42case 'help':
43default:
44 console.log(HELP)
45 break
46}