Newer
Older
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
const cluster = require('cluster')
process.env.NODE_PATH = 'src'
async function runWorker() {
const yargs = require('yargs')
const bootstrap = require('bootstrap')
await bootstrap.boot()
yargs(process.argv.slice(2))
.scriptName('cmd')
.commandDir(bootstrap.fs.path('src', 'console'))
.demandCommand()
.recommendCommands()
.help()
.argv
}
async function runMaster() {
const bootstrap = require('bootstrap')
await bootstrap.boot()
let resolve, reject
const defer = new Promise((res, rej) => {
resolve = res
reject = rej
})
const child = cluster.fork({
NODE_PATH: 'src',
...process.env,
})
child.once('error', reject)
child.on('exit', resolve)
await defer
}
async function run() {
if (cluster.isWorker) {
await runMaster()
} else {
await runWorker()
}
}
run()
.catch(e => {
console.error(e)
process.exit(1)
})