Updates
This commit is contained in:
parent
5c27f2c653
commit
6d9121ef66
4
.npmrc
4
.npmrc
@ -1,2 +1,2 @@
|
|||||||
registry=https://git.tben.me/api/packages/Moduletrace/npm/
|
@moduletrace:registry=https://git.tben.me/api/packages/moduletrace/npm/
|
||||||
//git.tben.me/api/packages/Moduletrace/npm/:_authToken=${GITBEN_NPM_TOKEN}
|
//git.tben.me/api/packages/moduletrace/npm/:_authToken=${GITBEN_NPM_TOKEN}
|
||||||
|
87
index.js
87
index.js
@ -11,6 +11,25 @@ const colors = require("./console-colors");
|
|||||||
////////////////////////////////////////////
|
////////////////////////////////////////////
|
||||||
////////////////////////////////////////////
|
////////////////////////////////////////////
|
||||||
|
|
||||||
|
setInterval(() => {
|
||||||
|
console.log(
|
||||||
|
`Batchrun Running for ${process.uptime().toLocaleString()}s ...`
|
||||||
|
);
|
||||||
|
}, 60000);
|
||||||
|
|
||||||
|
////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////
|
||||||
|
|
||||||
|
if (process.argv[process.argv.length - 1]?.match(/^--version$|^-v$/)) {
|
||||||
|
console.log(`Batchrun v${require("./package.json").version}`);
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////
|
||||||
|
|
||||||
/** @type {string[]} */
|
/** @type {string[]} */
|
||||||
const processesStrings = [];
|
const processesStrings = [];
|
||||||
|
|
||||||
@ -40,12 +59,12 @@ rl.on("line", (input) => {
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
function readCommands(input) {
|
function readCommands(input) {
|
||||||
if (input?.match(/^(reload|restart|reboot)$/i)) {
|
if (input?.match(/^(reload|restart|reboot|r)$/i)) {
|
||||||
console.log(
|
console.log(
|
||||||
` - ${colors.FgBlue}Reloading processes ...${colors.Reset}`
|
` - ${colors.FgBlue}Reloading processes ...${colors.Reset}`
|
||||||
);
|
);
|
||||||
restartAll();
|
restartAll();
|
||||||
} else if (input?.match(/^(reload|restart|reboot) \d/i)) {
|
} else if (input?.match(/^(reload|restart|reboot|r) \d/i)) {
|
||||||
const processedIndexesString = input.split(" ")[1];
|
const processedIndexesString = input.split(" ")[1];
|
||||||
const processedIndexes = processedIndexesString
|
const processedIndexes = processedIndexesString
|
||||||
? processedIndexesString.split(",")
|
? processedIndexesString.split(",")
|
||||||
@ -109,11 +128,48 @@ process.stdin.on("keypress", (character, key) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cleanup function to kill all child processes
|
||||||
|
*/
|
||||||
|
function cleanupChildProcesses() {
|
||||||
|
for (const childProcess of processes) {
|
||||||
|
try {
|
||||||
|
if (childProcess.pid) {
|
||||||
|
console.log(
|
||||||
|
` - ${colors.FgYellow}Killing process PID: ${childProcess.pid}${colors.Reset}`
|
||||||
|
);
|
||||||
|
killProcessForce(childProcess.pid);
|
||||||
|
}
|
||||||
|
childProcess.kill();
|
||||||
|
} catch (error) {
|
||||||
|
console.error(
|
||||||
|
` - ${colors.FgRed}Error:${colors.Reset} Failed to kill process PID: ${childProcess.pid}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
processes = [];
|
||||||
|
}
|
||||||
|
|
||||||
process.on("exit", (code) => {
|
process.on("exit", (code) => {
|
||||||
console.log(
|
console.log(
|
||||||
` - ${colors.FgBlue}Process exited with code ${code}${colors.Reset}`
|
` - ${colors.FgBlue}Process exited with code ${code}${colors.Reset}`
|
||||||
);
|
);
|
||||||
rl.close();
|
rl.close();
|
||||||
|
cleanupChildProcesses();
|
||||||
|
});
|
||||||
|
|
||||||
|
process.on("SIGINT", () => {
|
||||||
|
console.log(
|
||||||
|
` - ${colors.FgYellow}SIGINT received, exiting...${colors.Reset}`
|
||||||
|
);
|
||||||
|
process.exit();
|
||||||
|
});
|
||||||
|
|
||||||
|
process.on("SIGTERM", () => {
|
||||||
|
console.log(
|
||||||
|
` - ${colors.FgYellow}SIGTERM received, exiting...${colors.Reset}`
|
||||||
|
);
|
||||||
|
process.exit();
|
||||||
});
|
});
|
||||||
|
|
||||||
////////////////////////////////////////////
|
////////////////////////////////////////////
|
||||||
@ -164,7 +220,7 @@ if (!processesStrings?.[0]) {
|
|||||||
const spawnOptions = {
|
const spawnOptions = {
|
||||||
cwd: process.cwd(),
|
cwd: process.cwd(),
|
||||||
shell: isWindows ? "bash.exe" : undefined,
|
shell: isWindows ? "bash.exe" : undefined,
|
||||||
stdio: "inherit",
|
stdio: ["pipe", "inherit", "inherit"],
|
||||||
detached: false,
|
detached: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -185,6 +241,24 @@ function startProcesses() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (childProcess) {
|
if (childProcess) {
|
||||||
|
childProcess.on("exit", (code, signal) => {
|
||||||
|
console.log(
|
||||||
|
` - ${colors.FgRed}Process ${i} exited with code ${code} and signal ${signal}${colors.Reset}`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
childProcess.on("error", (err) => {
|
||||||
|
console.error(
|
||||||
|
` - ${colors.FgYellow}Error:${colors.Reset} Failed to start process ${i}: ${err.message}`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
childProcess.on("close", (code, signal) => {
|
||||||
|
console.log(
|
||||||
|
` - ${colors.FgRed}Process ${i} closed with code ${code} and signal ${signal}${colors.Reset}`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
processes.push(childProcess);
|
processes.push(childProcess);
|
||||||
} else {
|
} else {
|
||||||
console.error(
|
console.error(
|
||||||
@ -297,10 +371,5 @@ function killProcessForce(pid) {
|
|||||||
console.log(
|
console.log(
|
||||||
` - ${colors.FgGreen}Started ${processesStrings.length} processes${colors.Reset}`
|
` - ${colors.FgGreen}Started ${processesStrings.length} processes${colors.Reset}`
|
||||||
);
|
);
|
||||||
startProcesses();
|
|
||||||
|
|
||||||
setInterval(() => {
|
startProcesses();
|
||||||
console.log(
|
|
||||||
`Batchrun Running for ${process.uptime().toLocaleString()}s ...`
|
|
||||||
);
|
|
||||||
}, 60000);
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@moduletrace/batchrun",
|
"name": "@moduletrace/batchrun",
|
||||||
"version": "1.0.0",
|
"version": "1.0.1",
|
||||||
"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": {
|
||||||
|
Loading…
Reference in New Issue
Block a user