From 79a4860f3557425ed9c07b11483eb3a34181cac8 Mon Sep 17 00:00:00 2001 From: jeasonnow Date: Wed, 19 Jul 2023 13:29:40 +0800 Subject: [PATCH] fix: fix some child_process problems --- plugins/pakeCliDevPlugin.js | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/plugins/pakeCliDevPlugin.js b/plugins/pakeCliDevPlugin.js index 2932c51..367e4ad 100644 --- a/plugins/pakeCliDevPlugin.js +++ b/plugins/pakeCliDevPlugin.js @@ -4,13 +4,19 @@ import {spawn, exec} from 'child_process'; // just run in development mode export default function pakeCliDevPlugin() { + let devChildProcess; + let cliChildProcess; + + let devHasStarted = false; + return { name: 'pake-cli-dev-plugin', buildEnd() { const command = 'node'; const cliCmdArgs = ['./dist/dev.js']; - const cliChildProcess = spawn(command, cliCmdArgs); + + cliChildProcess = spawn(command, cliCmdArgs, {detached: true}); cliChildProcess.stdout.on('data', (data) => { console.log(chalk.green(data.toString())); @@ -22,20 +28,25 @@ export default function pakeCliDevPlugin() { cliChildProcess.on('close', async (code) => { console.log(chalk.yellow(`cli running end with code: ${code}`)); - cliChildProcess.kill(); - const dev = await exec('npm run tauri dev -- --config ./src-tauri/.pake/tauri.conf.json --features cli-build'); + if (devHasStarted) return; + devHasStarted = true; - dev.stdout.on('data', (data) => { - console.error(chalk.green(data.toString())); + const devCommand = 'npm'; + 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())); }); - dev.on('close', () => { - dev.kill(); - console.log(chalk.green('rebuild start')); + devChildProcess.on('close', (code) => { + console.log(chalk.yellow(`dev running end: ${code}`)); + process.exit(code); }); }); }