updates
This commit is contained in:
parent
bf0e798aa8
commit
714f50314f
47
index.js
47
index.js
@ -26,8 +26,16 @@ const rl = readline.createInterface({
|
|||||||
output: process.stdout,
|
output: process.stdout,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Listen for user input
|
|
||||||
rl.on("line", (input) => {
|
rl.on("line", (input) => {
|
||||||
|
readCommands(input);
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read Lines and execute commands
|
||||||
|
* @param {string} input
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
function readCommands(input) {
|
||||||
if (input?.match(/^(reload|restart|reboot)$/i)) {
|
if (input?.match(/^(reload|restart|reboot)$/i)) {
|
||||||
console.log(` - ${colors.FgBlue}Reloading processes ...${colors.Reset}`);
|
console.log(` - ${colors.FgBlue}Reloading processes ...${colors.Reset}`);
|
||||||
restartAll();
|
restartAll();
|
||||||
@ -66,7 +74,7 @@ rl.on("line", (input) => {
|
|||||||
console.log(` - ${colors.FgGreen}Processes Killed ${processedIndexesString} ...${colors.Reset}`);
|
console.log(` - ${colors.FgGreen}Processes Killed ${processedIndexesString} ...${colors.Reset}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
process.stdin.on("keypress", (character, key) => {
|
process.stdin.on("keypress", (character, key) => {
|
||||||
if (key.ctrl && key.name === "r") {
|
if (key.ctrl && key.name === "r") {
|
||||||
@ -122,7 +130,7 @@ if (!processesStrings?.[0]) {
|
|||||||
const spawnOptions = {
|
const spawnOptions = {
|
||||||
cwd: process.cwd(),
|
cwd: process.cwd(),
|
||||||
shell: process.platform.match(/win/i) ? "bash.exe" : undefined,
|
shell: process.platform.match(/win/i) ? "bash.exe" : undefined,
|
||||||
stdio: "inherit",
|
stdio: ["pipe", "inherit", "inherit"],
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -134,8 +142,37 @@ function startProcesses() {
|
|||||||
const processStringArray = processString.split(" ");
|
const processStringArray = processString.split(" ");
|
||||||
const targetProcess = processStringArray.shift();
|
const targetProcess = processStringArray.shift();
|
||||||
if (targetProcess) {
|
if (targetProcess) {
|
||||||
const process = spawn(targetProcess, processStringArray, spawnOptions);
|
const childProcess = spawn(targetProcess, processStringArray, spawnOptions);
|
||||||
processes.push(process);
|
if (childProcess) {
|
||||||
|
processes.push(childProcess);
|
||||||
|
|
||||||
|
// childProcess.stdin?.on("keypress", (character, key) => {
|
||||||
|
// if (key.ctrl && key.name === "r") {
|
||||||
|
// console.log(` - ${colors.FgBlue}Reloading processes ...${colors.Reset}`);
|
||||||
|
// restartAll();
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
|
// childProcess.on("error", (error) => {
|
||||||
|
// console.log(` - ${colors.FgRed}Error:${colors.Reset} ${error.message}`);
|
||||||
|
// killOne(i.toString());
|
||||||
|
// });
|
||||||
|
|
||||||
|
// childProcess.on("exit", (code, signal) => {
|
||||||
|
// console.log(` - ${colors.FgRed}Error:${colors.Reset} Process ${i} exited with code ${code} and signal ${signal}`);
|
||||||
|
// killOne(i.toString());
|
||||||
|
// });
|
||||||
|
|
||||||
|
// childProcess.on("message", (code, signal) => {
|
||||||
|
// console.log(` - ${colors.FgRed}Error:${colors.Reset} Process ${i} exited with code ${code} and signal ${signal}`);
|
||||||
|
// killOne(i.toString());
|
||||||
|
// });
|
||||||
|
|
||||||
|
// childProcess.stdin?.pipe(process.stdin);
|
||||||
|
} else {
|
||||||
|
console.error(` - ${colors.FgRed}Error:${colors.Reset} Failed to start process ${i}`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
console.error(` - ${colors.FgRed}Error:${colors.Reset} A target process is not defined in \`${processString}\``);
|
console.error(` - ${colors.FgRed}Error:${colors.Reset} A target process is not defined in \`${processString}\``);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "batchrun",
|
"name": "batchrun",
|
||||||
"version": "1.0.6",
|
"version": "1.0.7",
|
||||||
"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