Newer
Older
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()
}
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()
}
}