fix: fix some child_process problems
This commit is contained in:
@@ -4,13 +4,19 @@ import {spawn, exec} from 'child_process';
|
|||||||
|
|
||||||
// just run in development mode
|
// just run in development mode
|
||||||
export default function pakeCliDevPlugin() {
|
export default function pakeCliDevPlugin() {
|
||||||
|
let devChildProcess;
|
||||||
|
let cliChildProcess;
|
||||||
|
|
||||||
|
let devHasStarted = false;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: 'pake-cli-dev-plugin',
|
name: 'pake-cli-dev-plugin',
|
||||||
buildEnd() {
|
buildEnd() {
|
||||||
|
|
||||||
const command = 'node';
|
const command = 'node';
|
||||||
const cliCmdArgs = ['./dist/dev.js'];
|
const cliCmdArgs = ['./dist/dev.js'];
|
||||||
const cliChildProcess = spawn(command, cliCmdArgs);
|
|
||||||
|
cliChildProcess = spawn(command, cliCmdArgs, {detached: true});
|
||||||
|
|
||||||
cliChildProcess.stdout.on('data', (data) => {
|
cliChildProcess.stdout.on('data', (data) => {
|
||||||
console.log(chalk.green(data.toString()));
|
console.log(chalk.green(data.toString()));
|
||||||
@@ -22,20 +28,25 @@ export default function pakeCliDevPlugin() {
|
|||||||
|
|
||||||
cliChildProcess.on('close', async (code) => {
|
cliChildProcess.on('close', async (code) => {
|
||||||
console.log(chalk.yellow(`cli running end with code: ${code}`));
|
console.log(chalk.yellow(`cli running end with code: ${code}`));
|
||||||
cliChildProcess.kill();
|
if (devHasStarted) return;
|
||||||
const dev = await exec('npm run tauri dev -- --config ./src-tauri/.pake/tauri.conf.json --features cli-build');
|
devHasStarted = true;
|
||||||
|
|
||||||
dev.stdout.on('data', (data) => {
|
const devCommand = 'npm';
|
||||||
console.error(chalk.green(data.toString()));
|
const devArgs = ['run', 'tauri', 'dev', '--', '--config', './src-tauri/.pake/tauri.conf.json', '--features', 'cli-build'];
|
||||||
|
devChildProcess = spawn(devCommand, devArgs, {detached: true});
|
||||||
|
|
||||||
|
|
||||||
|
devChildProcess.stdout.on('data', (data) => {
|
||||||
|
console.log(chalk.green(data.toString()));
|
||||||
});
|
});
|
||||||
|
|
||||||
dev.stderr.on('data', (data) => {
|
devChildProcess.stderr.on('data', (data) => {
|
||||||
console.error(chalk.yellow(data.toString()));
|
console.error(chalk.yellow(data.toString()));
|
||||||
});
|
});
|
||||||
|
|
||||||
dev.on('close', () => {
|
devChildProcess.on('close', (code) => {
|
||||||
dev.kill();
|
console.log(chalk.yellow(`dev running end: ${code}`));
|
||||||
console.log(chalk.green('rebuild start'));
|
process.exit(code);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user