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[]} */
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);

View File

@ -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",