Skip to content

Commit

Permalink
fix: fix some child_process problems
Browse files Browse the repository at this point in the history
  • Loading branch information
jeasonnow committed Jul 19, 2023
1 parent 3c7e7f6 commit 79a4860
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions plugins/pakeCliDevPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand All @@ -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;

const devCommand = 'npm';
const devArgs = ['run', 'tauri', 'dev', '--', '--config', './src-tauri/.pake/tauri.conf.json', '--features', 'cli-build'];
devChildProcess = spawn(devCommand, devArgs, {detached: true});


dev.stdout.on('data', (data) => {
console.error(chalk.green(data.toString()));
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);
});
});
}
Expand Down

0 comments on commit 79a4860

Please sign in to comment.