2023-03-03 13:45:38 +00:00
|
|
|
/**
|
|
|
|
* This file is used to wrap the CLI entrypoint in a restartable process.
|
|
|
|
*/
|
|
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
import { execa } from 'execa'
|
|
|
|
import { EXIT_CODE_RESTART } from './constants'
|
|
|
|
|
|
|
|
const cliEntry = fileURLToPath(new URL('../dist/cli-run.mjs', import.meta.url))
|
|
|
|
|
|
|
|
async function startSubprocess (preArgs: string[], postArgs: string[]) {
|
|
|
|
const child = await execa(
|
|
|
|
'node',
|
|
|
|
[
|
|
|
|
...preArgs,
|
|
|
|
cliEntry,
|
|
|
|
...postArgs
|
|
|
|
],
|
|
|
|
{
|
|
|
|
reject: false,
|
|
|
|
stdio: 'inherit',
|
|
|
|
env: {
|
|
|
|
...process.env,
|
|
|
|
NUXI_CLI_WRAPPER: 'true'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
if (child.exitCode === EXIT_CODE_RESTART) {
|
|
|
|
await startSubprocess(preArgs, postArgs)
|
|
|
|
} else {
|
|
|
|
process.exit(child.exitCode)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const args = process.argv.slice(2)
|
|
|
|
// only enable wrapper in dev command
|
|
|
|
if (args[0] === 'dev') {
|
2023-03-03 13:51:47 +00:00
|
|
|
startSubprocess([], args)
|
2023-03-03 13:45:38 +00:00
|
|
|
} else {
|
2023-03-03 13:51:47 +00:00
|
|
|
import(cliEntry)
|
2023-03-03 13:45:38 +00:00
|
|
|
}
|