From 5c27f2c653083f48cb9f4b07ffe46ef0fb88db2b Mon Sep 17 00:00:00 2001 From: Benjamin Toby Date: Wed, 4 Dec 2024 06:28:32 +0100 Subject: [PATCH] Updates --- index.js | 14 ++++++++++---- package.json | 6 +++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index bbe63c8..106e40c 100644 --- a/index.js +++ b/index.js @@ -17,6 +17,10 @@ const processesStrings = []; /** @type {ChildProcess[]} */ let processes = []; +const isWindows = process.platform.match(/win/i); +const isMac = process.platform.match(/darwin/i); +const isLinux = process.platform.match(/linux/i); + //////////////////////////////////////////// //////////////////////////////////////////// //////////////////////////////////////////// @@ -159,8 +163,8 @@ if (!processesStrings?.[0]) { /** @type {import("child_process").SpawnOptions} */ const spawnOptions = { cwd: process.cwd(), - shell: process.platform.match(/win/i) ? "bash.exe" : undefined, - stdio: ["pipe", "inherit", "inherit"], + shell: isWindows ? "bash.exe" : undefined, + stdio: "inherit", detached: false, }; @@ -172,12 +176,14 @@ function startProcesses() { const processString = processesStrings[i]; const processStringArray = processString.split(" "); const targetProcess = processStringArray.shift(); + if (targetProcess) { const childProcess = spawn( targetProcess, processStringArray, spawnOptions ); + if (childProcess) { processes.push(childProcess); } else { @@ -280,7 +286,7 @@ function killProcessForce(pid) { return; } try { - if (process.platform.match(/win/i)) { + if (isWindows) { execSync(`taskkill /F /PID ${pid} /T`); } else { execSync(`kill -9 ${pid}`); @@ -295,6 +301,6 @@ startProcesses(); setInterval(() => { console.log( - `Turbo Sync Running for ${process.uptime().toLocaleString()}s ...` + `Batchrun Running for ${process.uptime().toLocaleString()}s ...` ); }, 60000); diff --git a/package.json b/package.json index dec8c50..41f3e07 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "batchrun", - "version": "1.0.7", + "name": "@moduletrace/batchrun", + "version": "1.0.0", "description": "Run and manage multiple processes concurrently in one terminal", "main": "index.js", "bin": { @@ -9,7 +9,7 @@ }, "repository": { "type": "git", - "url": "https://github.com/BenjaminToby/batch-run" + "url": "https://git.tben.me/Moduletrace/batchrun" }, "keywords": [ "process",