This commit is contained in:
Benjamin Toby 2024-12-04 06:28:32 +01:00
parent f4364524ef
commit 5c27f2c653
2 changed files with 13 additions and 7 deletions

View File

@ -17,6 +17,10 @@ const processesStrings = [];
/** @type {ChildProcess[]} */ /** @type {ChildProcess[]} */
let processes = []; 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} */ /** @type {import("child_process").SpawnOptions} */
const spawnOptions = { const spawnOptions = {
cwd: process.cwd(), cwd: process.cwd(),
shell: process.platform.match(/win/i) ? "bash.exe" : undefined, shell: isWindows ? "bash.exe" : undefined,
stdio: ["pipe", "inherit", "inherit"], stdio: "inherit",
detached: false, detached: false,
}; };
@ -172,12 +176,14 @@ function startProcesses() {
const processString = processesStrings[i]; const processString = processesStrings[i];
const processStringArray = processString.split(" "); const processStringArray = processString.split(" ");
const targetProcess = processStringArray.shift(); const targetProcess = processStringArray.shift();
if (targetProcess) { if (targetProcess) {
const childProcess = spawn( const childProcess = spawn(
targetProcess, targetProcess,
processStringArray, processStringArray,
spawnOptions spawnOptions
); );
if (childProcess) { if (childProcess) {
processes.push(childProcess); processes.push(childProcess);
} else { } else {
@ -280,7 +286,7 @@ function killProcessForce(pid) {
return; return;
} }
try { try {
if (process.platform.match(/win/i)) { if (isWindows) {
execSync(`taskkill /F /PID ${pid} /T`); execSync(`taskkill /F /PID ${pid} /T`);
} else { } else {
execSync(`kill -9 ${pid}`); execSync(`kill -9 ${pid}`);
@ -295,6 +301,6 @@ startProcesses();
setInterval(() => { setInterval(() => {
console.log( console.log(
`Turbo Sync Running for ${process.uptime().toLocaleString()}s ...` `Batchrun Running for ${process.uptime().toLocaleString()}s ...`
); );
}, 60000); }, 60000);

View File

@ -1,6 +1,6 @@
{ {
"name": "batchrun", "name": "@moduletrace/batchrun",
"version": "1.0.7", "version": "1.0.0",
"description": "Run and manage multiple processes concurrently in one terminal", "description": "Run and manage multiple processes concurrently in one terminal",
"main": "index.js", "main": "index.js",
"bin": { "bin": {
@ -9,7 +9,7 @@
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/BenjaminToby/batch-run" "url": "https://git.tben.me/Moduletrace/batchrun"
}, },
"keywords": [ "keywords": [
"process", "process",