Updates
This commit is contained in:
		
							parent
							
								
									6d9121ef66
								
							
						
					
					
						commit
						ba2cd9d765
					
				
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -1,2 +1,3 @@ | |||||||
| node_modules | node_modules | ||||||
| /test | /test | ||||||
|  | tsconfig.tsbuildinfo | ||||||
|  | |||||||
							
								
								
									
										31
									
								
								console-colors.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								console-colors.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,31 @@ | |||||||
|  | const colors = { | ||||||
|  |     Reset: "\x1b[0m", | ||||||
|  |     Bright: "\x1b[1m", | ||||||
|  |     Dim: "\x1b[2m", | ||||||
|  |     Underscore: "\x1b[4m", | ||||||
|  |     Blink: "\x1b[5m", | ||||||
|  |     Reverse: "\x1b[7m", | ||||||
|  |     Hidden: "\x1b[8m", | ||||||
|  | 
 | ||||||
|  |     FgBlack: "\x1b[30m", | ||||||
|  |     FgRed: "\x1b[31m", | ||||||
|  |     FgGreen: "\x1b[32m", | ||||||
|  |     FgYellow: "\x1b[33m", | ||||||
|  |     FgBlue: "\x1b[34m", | ||||||
|  |     FgMagenta: "\x1b[35m", | ||||||
|  |     FgCyan: "\x1b[36m", | ||||||
|  |     FgWhite: "\x1b[37m", | ||||||
|  |     FgGray: "\x1b[90m", | ||||||
|  | 
 | ||||||
|  |     BgBlack: "\x1b[40m", | ||||||
|  |     BgRed: "\x1b[41m", | ||||||
|  |     BgGreen: "\x1b[42m", | ||||||
|  |     BgYellow: "\x1b[43m", | ||||||
|  |     BgBlue: "\x1b[44m", | ||||||
|  |     BgMagenta: "\x1b[45m", | ||||||
|  |     BgCyan: "\x1b[46m", | ||||||
|  |     BgWhite: "\x1b[47m", | ||||||
|  |     BgGray: "\x1b[100m", | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | export default colors; | ||||||
							
								
								
									
										28
									
								
								dist/console-colors.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								dist/console-colors.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,28 @@ | |||||||
|  | declare const colors: { | ||||||
|  |     Reset: string; | ||||||
|  |     Bright: string; | ||||||
|  |     Dim: string; | ||||||
|  |     Underscore: string; | ||||||
|  |     Blink: string; | ||||||
|  |     Reverse: string; | ||||||
|  |     Hidden: string; | ||||||
|  |     FgBlack: string; | ||||||
|  |     FgRed: string; | ||||||
|  |     FgGreen: string; | ||||||
|  |     FgYellow: string; | ||||||
|  |     FgBlue: string; | ||||||
|  |     FgMagenta: string; | ||||||
|  |     FgCyan: string; | ||||||
|  |     FgWhite: string; | ||||||
|  |     FgGray: string; | ||||||
|  |     BgBlack: string; | ||||||
|  |     BgRed: string; | ||||||
|  |     BgGreen: string; | ||||||
|  |     BgYellow: string; | ||||||
|  |     BgBlue: string; | ||||||
|  |     BgMagenta: string; | ||||||
|  |     BgCyan: string; | ||||||
|  |     BgWhite: string; | ||||||
|  |     BgGray: string; | ||||||
|  | }; | ||||||
|  | export default colors; | ||||||
							
								
								
									
										61
									
								
								console-colors.js → dist/console-colors.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										61
									
								
								console-colors.js → dist/console-colors.js
									
									
									
									
										vendored
									
									
								
							| @ -1,31 +1,30 @@ | |||||||
| const colors = { | "use strict"; | ||||||
|     Reset: "\x1b[0m", | Object.defineProperty(exports, "__esModule", { value: true }); | ||||||
|     Bright: "\x1b[1m", | const colors = { | ||||||
|     Dim: "\x1b[2m", |     Reset: "\x1b[0m", | ||||||
|     Underscore: "\x1b[4m", |     Bright: "\x1b[1m", | ||||||
|     Blink: "\x1b[5m", |     Dim: "\x1b[2m", | ||||||
|     Reverse: "\x1b[7m", |     Underscore: "\x1b[4m", | ||||||
|     Hidden: "\x1b[8m", |     Blink: "\x1b[5m", | ||||||
| 
 |     Reverse: "\x1b[7m", | ||||||
|     FgBlack: "\x1b[30m", |     Hidden: "\x1b[8m", | ||||||
|     FgRed: "\x1b[31m", |     FgBlack: "\x1b[30m", | ||||||
|     FgGreen: "\x1b[32m", |     FgRed: "\x1b[31m", | ||||||
|     FgYellow: "\x1b[33m", |     FgGreen: "\x1b[32m", | ||||||
|     FgBlue: "\x1b[34m", |     FgYellow: "\x1b[33m", | ||||||
|     FgMagenta: "\x1b[35m", |     FgBlue: "\x1b[34m", | ||||||
|     FgCyan: "\x1b[36m", |     FgMagenta: "\x1b[35m", | ||||||
|     FgWhite: "\x1b[37m", |     FgCyan: "\x1b[36m", | ||||||
|     FgGray: "\x1b[90m", |     FgWhite: "\x1b[37m", | ||||||
| 
 |     FgGray: "\x1b[90m", | ||||||
|     BgBlack: "\x1b[40m", |     BgBlack: "\x1b[40m", | ||||||
|     BgRed: "\x1b[41m", |     BgRed: "\x1b[41m", | ||||||
|     BgGreen: "\x1b[42m", |     BgGreen: "\x1b[42m", | ||||||
|     BgYellow: "\x1b[43m", |     BgYellow: "\x1b[43m", | ||||||
|     BgBlue: "\x1b[44m", |     BgBlue: "\x1b[44m", | ||||||
|     BgMagenta: "\x1b[45m", |     BgMagenta: "\x1b[45m", | ||||||
|     BgCyan: "\x1b[46m", |     BgCyan: "\x1b[46m", | ||||||
|     BgWhite: "\x1b[47m", |     BgWhite: "\x1b[47m", | ||||||
|     BgGray: "\x1b[100m", |     BgGray: "\x1b[100m", | ||||||
| }; | }; | ||||||
| 
 | exports.default = colors; | ||||||
| module.exports = colors; |  | ||||||
							
								
								
									
										1
									
								
								dist/index.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								dist/index.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1 @@ | |||||||
|  | export {}; | ||||||
							
								
								
									
										276
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										276
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,276 @@ | |||||||
|  | "use strict"; | ||||||
|  | var __importDefault = (this && this.__importDefault) || function (mod) { | ||||||
|  |     return (mod && mod.__esModule) ? mod : { "default": mod }; | ||||||
|  | }; | ||||||
|  | var _a; | ||||||
|  | Object.defineProperty(exports, "__esModule", { value: true }); | ||||||
|  | const fs_1 = __importDefault(require("fs")); | ||||||
|  | const path_1 = __importDefault(require("path")); | ||||||
|  | const child_process_1 = require("child_process"); | ||||||
|  | const readline_1 = __importDefault(require("readline")); | ||||||
|  | const console_colors_1 = __importDefault(require("./console-colors")); | ||||||
|  | setInterval(() => { | ||||||
|  |     console.log(`Batchrun Running for ${process.uptime().toLocaleString()}s ...`); | ||||||
|  | }, 60000); | ||||||
|  | if ((_a = process.argv[process.argv.length - 1]) === null || _a === void 0 ? void 0 : _a.match(/^--version$|^-v$/)) { | ||||||
|  |     console.log(`Batchrun v${require("./package.json").version}`); | ||||||
|  |     process.exit(); | ||||||
|  | } | ||||||
|  | const processesStrings = []; | ||||||
|  | let processes = []; | ||||||
|  | const isWindows = process.platform.match(/win/i); | ||||||
|  | const isMac = process.platform.match(/darwin/i); | ||||||
|  | const isLinux = process.platform.match(/linux/i); | ||||||
|  | ////////////////////////////////////////////
 | ||||||
|  | ////////////////////////////////////////////
 | ||||||
|  | ////////////////////////////////////////////
 | ||||||
|  | const rl = readline_1.default.createInterface({ | ||||||
|  |     input: process.stdin, | ||||||
|  |     output: process.stdout, | ||||||
|  | }); | ||||||
|  | rl.on("line", (input) => { | ||||||
|  |     readCommands(input); | ||||||
|  | }); | ||||||
|  | /** | ||||||
|  |  * Read Lines and execute commands | ||||||
|  |  * @param {string} input | ||||||
|  |  * @returns | ||||||
|  |  */ | ||||||
|  | function readCommands(input) { | ||||||
|  |     if (input === null || input === void 0 ? void 0 : input.match(/^(reload|restart|reboot|r)$/i)) { | ||||||
|  |         console.log(` - ${console_colors_1.default.FgBlue}Reloading processes ...${console_colors_1.default.Reset}`); | ||||||
|  |         restartAll(); | ||||||
|  |     } | ||||||
|  |     else if (input === null || input === void 0 ? void 0 : input.match(/^(reload|restart|reboot|r) \d/i)) { | ||||||
|  |         const processedIndexesString = input.split(" ")[1]; | ||||||
|  |         const processedIndexes = processedIndexesString | ||||||
|  |             ? processedIndexesString.split(",") | ||||||
|  |             : null; | ||||||
|  |         if (!(processedIndexes === null || processedIndexes === void 0 ? void 0 : processedIndexes.length)) { | ||||||
|  |             console.log(` - ${console_colors_1.default.FgRed}Error:${console_colors_1.default.Reset} No processes to reload`); | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |         else { | ||||||
|  |             console.log(` - ${console_colors_1.default.FgBlue}Reloading processes ${processedIndexesString} ...${console_colors_1.default.Reset}`); | ||||||
|  |             processedIndexes.forEach((index) => { | ||||||
|  |                 restartOne(parseInt(index)); | ||||||
|  |             }); | ||||||
|  |             console.log(` - ${console_colors_1.default.FgGreen}Processes Restarted Successfully ${processedIndexesString} ...${console_colors_1.default.Reset}`); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     if (input === null || input === void 0 ? void 0 : input.match(/^kill$/i)) { | ||||||
|  |         console.log(` - ${console_colors_1.default.FgYellow}Killing processes ...${console_colors_1.default.Reset}`); | ||||||
|  |         process.exit(); | ||||||
|  |     } | ||||||
|  |     else if (input === null || input === void 0 ? void 0 : input.match(/^kill \d/i)) { | ||||||
|  |         const processedIndexesString = input.split(" ")[1]; | ||||||
|  |         const processedIndexes = processedIndexesString | ||||||
|  |             ? processedIndexesString.split(",") | ||||||
|  |             : null; | ||||||
|  |         if (!(processedIndexes === null || processedIndexes === void 0 ? void 0 : processedIndexes.length)) { | ||||||
|  |             console.log(` - ${console_colors_1.default.FgRed}Error:${console_colors_1.default.Reset} No processes to reload`); | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |         else { | ||||||
|  |             console.log(` - ${console_colors_1.default.FgYellow}Killing processes ${processedIndexesString} ...${console_colors_1.default.Reset}`); | ||||||
|  |             processedIndexes.forEach((index) => { | ||||||
|  |                 killOne(index); | ||||||
|  |             }); | ||||||
|  |             console.log(` - ${console_colors_1.default.FgGreen}Processes Killed ${processedIndexesString} ...${console_colors_1.default.Reset}`); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | process.stdin.on("keypress", (character, key) => { | ||||||
|  |     if (key.ctrl && key.name === "r") { | ||||||
|  |         console.log(` - ${console_colors_1.default.FgBlue}Reloading processes ...${console_colors_1.default.Reset}`); | ||||||
|  |         restartAll(); | ||||||
|  |     } | ||||||
|  | }); | ||||||
|  | /** | ||||||
|  |  * Cleanup function to kill all child processes | ||||||
|  |  */ | ||||||
|  | function cleanupChildProcesses() { | ||||||
|  |     for (const childProcess of processes) { | ||||||
|  |         try { | ||||||
|  |             if (childProcess.pid) { | ||||||
|  |                 console.log(` - ${console_colors_1.default.FgYellow}Killing process PID: ${childProcess.pid}${console_colors_1.default.Reset}`); | ||||||
|  |                 killProcessForce(childProcess.pid); | ||||||
|  |             } | ||||||
|  |             childProcess.kill(); | ||||||
|  |         } | ||||||
|  |         catch (error) { | ||||||
|  |             console.error(` - ${console_colors_1.default.FgRed}Error:${console_colors_1.default.Reset} Failed to kill process PID: ${childProcess.pid}`); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     processes = []; | ||||||
|  | } | ||||||
|  | process.on("exit", (code) => { | ||||||
|  |     console.log(` - ${console_colors_1.default.FgBlue}Process exited with code ${code}${console_colors_1.default.Reset}`); | ||||||
|  |     rl.close(); | ||||||
|  |     cleanupChildProcesses(); | ||||||
|  | }); | ||||||
|  | process.on("SIGINT", () => { | ||||||
|  |     console.log(` - ${console_colors_1.default.FgYellow}SIGINT received, exiting...${console_colors_1.default.Reset}`); | ||||||
|  |     process.exit(); | ||||||
|  | }); | ||||||
|  | process.on("SIGTERM", () => { | ||||||
|  |     console.log(` - ${console_colors_1.default.FgYellow}SIGTERM received, exiting...${console_colors_1.default.Reset}`); | ||||||
|  |     process.exit(); | ||||||
|  | }); | ||||||
|  | ////////////////////////////////////////////
 | ||||||
|  | ////////////////////////////////////////////
 | ||||||
|  | ////////////////////////////////////////////
 | ||||||
|  | const argvProcessListIndex = process.argv.indexOf("batch-run") + 1; | ||||||
|  | const argvProcessList = process.argv.at(-1); | ||||||
|  | const processesFilePath = path_1.default.resolve(process.cwd(), "batchrun.config.json"); | ||||||
|  | if ((argvProcessList === null || argvProcessList === void 0 ? void 0 : argvProcessList.match(/batchrun/i)) && !fs_1.default.existsSync(processesFilePath)) { | ||||||
|  |     console.error(` - ${console_colors_1.default.FgRed}Error:${console_colors_1.default.Reset} No arguments to run`); | ||||||
|  |     process.exit(1); | ||||||
|  | } | ||||||
|  | if (fs_1.default.existsSync(processesFilePath)) { | ||||||
|  |     const processesFile = fs_1.default.readFileSync(processesFilePath, "utf8"); | ||||||
|  |     const processesArray = JSON.parse(processesFile); | ||||||
|  |     for (let i = 0; i < processesArray.length; i++) { | ||||||
|  |         const processString = processesArray[i]; | ||||||
|  |         const strippedProcessString = processString.trim(); | ||||||
|  |         processesStrings.push(strippedProcessString); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | else if (argvProcessList) { | ||||||
|  |     const processesArray = argvProcessList.split(","); | ||||||
|  |     for (let i = 0; i < processesArray.length; i++) { | ||||||
|  |         const processString = processesArray[i]; | ||||||
|  |         const strippedProcessString = processString.trim(); | ||||||
|  |         processesStrings.push(strippedProcessString); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | else { | ||||||
|  |     console.error(` - ${console_colors_1.default.FgRed}Error:${console_colors_1.default.Reset} No arguments to run or \`batchrun.config.json\` file present`); | ||||||
|  |     process.exit(1); | ||||||
|  | } | ||||||
|  | if (!(processesStrings === null || processesStrings === void 0 ? void 0 : processesStrings[0])) { | ||||||
|  |     console.error(` - ${console_colors_1.default.FgRed}Error:${console_colors_1.default.Reset} No processes to run`); | ||||||
|  |     process.exit(1); | ||||||
|  | } | ||||||
|  | /** @type {import("child_process").SpawnOptions} */ | ||||||
|  | const spawnOptions = { | ||||||
|  |     cwd: process.cwd(), | ||||||
|  |     shell: isWindows ? "bash.exe" : undefined, | ||||||
|  |     stdio: ["pipe", "inherit", "inherit"], | ||||||
|  |     detached: false, | ||||||
|  | }; | ||||||
|  | /** | ||||||
|  |  * Start all processes | ||||||
|  |  */ | ||||||
|  | function startProcesses() { | ||||||
|  |     for (let i = 0; i < processesStrings.length; i++) { | ||||||
|  |         const processString = processesStrings[i]; | ||||||
|  |         const processStringArray = processString.split(" "); | ||||||
|  |         const targetProcess = processStringArray.shift(); | ||||||
|  |         if (targetProcess) { | ||||||
|  |             const childProcess = (0, child_process_1.spawn)(targetProcess, processStringArray, spawnOptions); | ||||||
|  |             if (childProcess) { | ||||||
|  |                 childProcess.on("exit", (code, signal) => { | ||||||
|  |                     console.log(` - ${console_colors_1.default.FgRed}Process ${i} exited with code ${code} and signal ${signal}${console_colors_1.default.Reset}`); | ||||||
|  |                 }); | ||||||
|  |                 childProcess.on("error", (err) => { | ||||||
|  |                     console.error(` - ${console_colors_1.default.FgYellow}Error:${console_colors_1.default.Reset} Failed to start process ${i}: ${err.message}`); | ||||||
|  |                 }); | ||||||
|  |                 childProcess.on("close", (code, signal) => { | ||||||
|  |                     console.log(` - ${console_colors_1.default.FgRed}Process ${i} closed with code ${code} and signal ${signal}${console_colors_1.default.Reset}`); | ||||||
|  |                 }); | ||||||
|  |                 processes.push(childProcess); | ||||||
|  |             } | ||||||
|  |             else { | ||||||
|  |                 console.error(` - ${console_colors_1.default.FgRed}Error:${console_colors_1.default.Reset} Failed to start process ${i}`); | ||||||
|  |                 process.exit(1); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         else { | ||||||
|  |             console.error(` - ${console_colors_1.default.FgRed}Error:${console_colors_1.default.Reset} A target process is not defined in \`${processString}\``); | ||||||
|  |             process.exit(1); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | /** | ||||||
|  |  * Restart All Processes | ||||||
|  |  */ | ||||||
|  | function restartAll() { | ||||||
|  |     for (let i = 0; i < processes.length; i++) { | ||||||
|  |         const childProcess = processes[i]; | ||||||
|  |         try { | ||||||
|  |             if (childProcess.pid) | ||||||
|  |                 killProcessForce(childProcess.pid); | ||||||
|  |             childProcess.kill(); | ||||||
|  |             // processes.splice(i, 1);
 | ||||||
|  |         } | ||||||
|  |         catch (error) { | ||||||
|  |             console.log(` - ${console_colors_1.default.FgRed}Error:${console_colors_1.default.Reset} Failed to kill process ${childProcess.pid}`); | ||||||
|  |             process.exit(); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     console.log(` - ${console_colors_1.default.FgGreen}Restarted ${processes.length} processes${console_colors_1.default.Reset}`); | ||||||
|  |     processes = []; | ||||||
|  |     setTimeout(() => { | ||||||
|  |         startProcesses(); | ||||||
|  |     }, 500); | ||||||
|  | } | ||||||
|  | /** | ||||||
|  |  * Restart a single process | ||||||
|  |  * @param {string} index | ||||||
|  |  */ | ||||||
|  | function restartOne(index) { | ||||||
|  |     const childProcess = processes[index]; | ||||||
|  |     try { | ||||||
|  |         if (childProcess.pid) | ||||||
|  |             killProcessForce(childProcess.pid); | ||||||
|  |         childProcess.kill(); | ||||||
|  |     } | ||||||
|  |     catch (error) { | ||||||
|  |         console.log(` - ${console_colors_1.default.FgRed}Error:${console_colors_1.default.Reset} Failed to kill process ${childProcess.pid}`); | ||||||
|  |         process.exit(); | ||||||
|  |     } | ||||||
|  |     const processString = processesStrings[index]; | ||||||
|  |     const processStringArray = processString.split(" "); | ||||||
|  |     const targetProcess = processStringArray.shift(); | ||||||
|  |     if (!targetProcess) | ||||||
|  |         return; | ||||||
|  |     const newChildProcess = (0, child_process_1.spawn)(targetProcess, processStringArray, spawnOptions); | ||||||
|  |     processes.splice(index, 1, newChildProcess); | ||||||
|  | } | ||||||
|  | /** | ||||||
|  |  * Kill a single process | ||||||
|  |  * @param {string} index | ||||||
|  |  */ | ||||||
|  | function killOne(index) { | ||||||
|  |     const childProcess = processes[parseInt(index)]; | ||||||
|  |     if (childProcess.pid) | ||||||
|  |         killProcessForce(childProcess.pid); | ||||||
|  |     childProcess.kill(); | ||||||
|  |     try { | ||||||
|  |     } | ||||||
|  |     catch (error) { | ||||||
|  |         console.log(` - ${console_colors_1.default.FgRed}Error:${console_colors_1.default.Reset} Failed to kill process ${childProcess.pid}`); | ||||||
|  |         process.exit(); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | /** | ||||||
|  |  * Kill a process by PID | ||||||
|  |  * @param {number} pid | ||||||
|  |  */ | ||||||
|  | function killProcessForce(pid) { | ||||||
|  |     if (typeof pid !== "number") { | ||||||
|  |         return; | ||||||
|  |     } | ||||||
|  |     try { | ||||||
|  |         if (isWindows) { | ||||||
|  |             (0, child_process_1.execSync)(`taskkill /F /PID ${pid} /T`); | ||||||
|  |         } | ||||||
|  |         else { | ||||||
|  |             (0, child_process_1.execSync)(`kill -9 ${pid}`); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     catch (error) { } | ||||||
|  | } | ||||||
|  | console.log(` - ${console_colors_1.default.FgGreen}Started ${processesStrings.length} processes${console_colors_1.default.Reset}`); | ||||||
|  | startProcesses(); | ||||||
| @ -1,15 +1,8 @@ | |||||||
| #! /usr/bin/env node | import fs from "fs"; | ||||||
| // @ts-check
 | import path from "path"; | ||||||
| 
 | import { spawn, ChildProcess, execSync } from "child_process"; | ||||||
| const fs = require("fs"); | import readline from "readline"; | ||||||
| const path = require("path"); | import colors from "./console-colors"; | ||||||
| const { spawn, ChildProcess, execSync } = require("child_process"); |  | ||||||
| const readline = require("readline"); |  | ||||||
| const colors = require("./console-colors"); |  | ||||||
| 
 |  | ||||||
| ////////////////////////////////////////////
 |  | ||||||
| ////////////////////////////////////////////
 |  | ||||||
| ////////////////////////////////////////////
 |  | ||||||
| 
 | 
 | ||||||
| setInterval(() => { | setInterval(() => { | ||||||
|     console.log( |     console.log( | ||||||
| @ -17,24 +10,14 @@ setInterval(() => { | |||||||
|     ); |     ); | ||||||
| }, 60000); | }, 60000); | ||||||
| 
 | 
 | ||||||
| ////////////////////////////////////////////
 |  | ||||||
| ////////////////////////////////////////////
 |  | ||||||
| ////////////////////////////////////////////
 |  | ||||||
| 
 |  | ||||||
| if (process.argv[process.argv.length - 1]?.match(/^--version$|^-v$/)) { | if (process.argv[process.argv.length - 1]?.match(/^--version$|^-v$/)) { | ||||||
|     console.log(`Batchrun v${require("./package.json").version}`); |     console.log(`Batchrun v${require("./package.json").version}`); | ||||||
|     process.exit(); |     process.exit(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ////////////////////////////////////////////
 | const processesStrings: string[] = []; | ||||||
| ////////////////////////////////////////////
 |  | ||||||
| ////////////////////////////////////////////
 |  | ||||||
| 
 | 
 | ||||||
| /** @type {string[]} */ | let processes: ChildProcess[] = []; | ||||||
| const processesStrings = []; |  | ||||||
| 
 |  | ||||||
| /** @type {ChildProcess[]} */ |  | ||||||
| let processes = []; |  | ||||||
| 
 | 
 | ||||||
| const isWindows = process.platform.match(/win/i); | const isWindows = process.platform.match(/win/i); | ||||||
| const isMac = process.platform.match(/darwin/i); | const isMac = process.platform.match(/darwin/i); | ||||||
| @ -58,7 +41,7 @@ rl.on("line", (input) => { | |||||||
|  * @param {string} input |  * @param {string} input | ||||||
|  * @returns |  * @returns | ||||||
|  */ |  */ | ||||||
| function readCommands(input) { | function readCommands(input: string) { | ||||||
|     if (input?.match(/^(reload|restart|reboot|r)$/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}` | ||||||
| @ -80,7 +63,7 @@ function readCommands(input) { | |||||||
|                 ` - ${colors.FgBlue}Reloading processes ${processedIndexesString} ...${colors.Reset}` |                 ` - ${colors.FgBlue}Reloading processes ${processedIndexesString} ...${colors.Reset}` | ||||||
|             ); |             ); | ||||||
|             processedIndexes.forEach((index) => { |             processedIndexes.forEach((index) => { | ||||||
|                 restartOne(index); |                 restartOne(parseInt(index)); | ||||||
|             }); |             }); | ||||||
|             console.log( |             console.log( | ||||||
|                 ` - ${colors.FgGreen}Processes Restarted Successfully ${processedIndexesString} ...${colors.Reset}` |                 ` - ${colors.FgGreen}Processes Restarted Successfully ${processedIndexesString} ...${colors.Reset}` | ||||||
| @ -217,7 +200,7 @@ if (!processesStrings?.[0]) { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** @type {import("child_process").SpawnOptions} */ | /** @type {import("child_process").SpawnOptions} */ | ||||||
| const spawnOptions = { | const spawnOptions: import("child_process").SpawnOptions = { | ||||||
|     cwd: process.cwd(), |     cwd: process.cwd(), | ||||||
|     shell: isWindows ? "bash.exe" : undefined, |     shell: isWindows ? "bash.exe" : undefined, | ||||||
|     stdio: ["pipe", "inherit", "inherit"], |     stdio: ["pipe", "inherit", "inherit"], | ||||||
| @ -309,8 +292,8 @@ function restartAll() { | |||||||
|  * Restart a single process |  * Restart a single process | ||||||
|  * @param {string} index |  * @param {string} index | ||||||
|  */ |  */ | ||||||
| function restartOne(index) { | function restartOne(index: number) { | ||||||
|     const childProcess = processes[parseInt(index)]; |     const childProcess = processes[index]; | ||||||
| 
 | 
 | ||||||
|     try { |     try { | ||||||
|         if (childProcess.pid) killProcessForce(childProcess.pid); |         if (childProcess.pid) killProcessForce(childProcess.pid); | ||||||
| @ -325,19 +308,22 @@ function restartOne(index) { | |||||||
|     const processString = processesStrings[index]; |     const processString = processesStrings[index]; | ||||||
|     const processStringArray = processString.split(" "); |     const processStringArray = processString.split(" "); | ||||||
|     const targetProcess = processStringArray.shift(); |     const targetProcess = processStringArray.shift(); | ||||||
|  | 
 | ||||||
|  |     if (!targetProcess) return; | ||||||
|  | 
 | ||||||
|     const newChildProcess = spawn( |     const newChildProcess = spawn( | ||||||
|         targetProcess, |         targetProcess, | ||||||
|         processStringArray, |         processStringArray, | ||||||
|         spawnOptions |         spawnOptions | ||||||
|     ); |     ); | ||||||
|     processes.splice(parseInt(index), 1, newChildProcess); |     processes.splice(index, 1, newChildProcess); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Kill a single process |  * Kill a single process | ||||||
|  * @param {string} index |  * @param {string} index | ||||||
|  */ |  */ | ||||||
| function killOne(index) { | function killOne(index: string) { | ||||||
|     const childProcess = processes[parseInt(index)]; |     const childProcess = processes[parseInt(index)]; | ||||||
|     if (childProcess.pid) killProcessForce(childProcess.pid); |     if (childProcess.pid) killProcessForce(childProcess.pid); | ||||||
|     childProcess.kill(); |     childProcess.kill(); | ||||||
| @ -355,7 +341,7 @@ function killOne(index) { | |||||||
|  * Kill a process by PID |  * Kill a process by PID | ||||||
|  * @param {number} pid |  * @param {number} pid | ||||||
|  */ |  */ | ||||||
| function killProcessForce(pid) { | function killProcessForce(pid: number) { | ||||||
|     if (typeof pid !== "number") { |     if (typeof pid !== "number") { | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
							
								
								
									
										37
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										37
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							| @ -1,37 +0,0 @@ | |||||||
| { |  | ||||||
|     "name": "batchrun", |  | ||||||
|     "version": "1.0.7", |  | ||||||
|     "lockfileVersion": 3, |  | ||||||
|     "requires": true, |  | ||||||
|     "packages": { |  | ||||||
|         "": { |  | ||||||
|             "name": "batchrun", |  | ||||||
|             "version": "1.0.7", |  | ||||||
|             "license": "MIT", |  | ||||||
|             "bin": { |  | ||||||
|                 "batch-run": "index.js", |  | ||||||
|                 "batchrun": "index.js" |  | ||||||
|             }, |  | ||||||
|             "devDependencies": { |  | ||||||
|                 "@types/node": "^22.8.7" |  | ||||||
|             } |  | ||||||
|         }, |  | ||||||
|         "node_modules/@types/node": { |  | ||||||
|             "version": "22.8.7", |  | ||||||
|             "resolved": "https://registry.npmjs.org/@types/node/-/node-22.8.7.tgz", |  | ||||||
|             "integrity": "sha512-LidcG+2UeYIWcMuMUpBKOnryBWG/rnmOHQR5apjn8myTQcx3rinFRn7DcIFhMnS0PPFSC6OafdIKEad0lj6U0Q==", |  | ||||||
|             "dev": true, |  | ||||||
|             "license": "MIT", |  | ||||||
|             "dependencies": { |  | ||||||
|                 "undici-types": "~6.19.8" |  | ||||||
|             } |  | ||||||
|         }, |  | ||||||
|         "node_modules/undici-types": { |  | ||||||
|             "version": "6.19.8", |  | ||||||
|             "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", |  | ||||||
|             "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==", |  | ||||||
|             "dev": true, |  | ||||||
|             "license": "MIT" |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
							
								
								
									
										17
									
								
								package.json
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								package.json
									
									
									
									
									
								
							| @ -1,11 +1,14 @@ | |||||||
| { | { | ||||||
|     "name": "@moduletrace/batchrun", |     "name": "@moduletrace/batchrun", | ||||||
|     "version": "1.0.1", |     "version": "1.0.3", | ||||||
|     "description": "Run and manage multiple processes concurrently in one terminal", |     "description": "Run and manage multiple processes concurrently in one terminal", | ||||||
|     "main": "index.js", |     "main": "dist/index.js", | ||||||
|     "bin": { |     "bin": { | ||||||
|         "batch-run": "./index.js", |         "batch-run": "dist/index.js", | ||||||
|         "batchrun": "./index.js" |         "batchrun": "dist/index.js" | ||||||
|  |     }, | ||||||
|  |     "scripts": { | ||||||
|  |         "build:binary": "bun build --compile --minify --sourcemap --bytecode ./index.js --outfile bin/batchrun" | ||||||
|     }, |     }, | ||||||
|     "repository": { |     "repository": { | ||||||
|         "type": "git", |         "type": "git", | ||||||
| @ -23,6 +26,10 @@ | |||||||
|     "author": "Benjamin Toby", |     "author": "Benjamin Toby", | ||||||
|     "license": "MIT", |     "license": "MIT", | ||||||
|     "devDependencies": { |     "devDependencies": { | ||||||
|         "@types/node": "^22.8.7" |         "@types/node": "^22.8.7", | ||||||
|  |         "@types/bun": "latest" | ||||||
|  |     }, | ||||||
|  |     "peerDependencies": { | ||||||
|  |         "typescript": "^5.0.0" | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
							
								
								
									
										14
									
								
								publish.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										14
									
								
								publish.sh
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,14 @@ | |||||||
|  | #!/bin/bash | ||||||
|  | 
 | ||||||
|  | tsc | ||||||
|  | 
 | ||||||
|  | if [ -z "$1" ]; then | ||||||
|  |     msg="Updates" | ||||||
|  | else | ||||||
|  |     msg="$1" | ||||||
|  | fi | ||||||
|  | 
 | ||||||
|  | git add . | ||||||
|  | git commit -m "$msg" | ||||||
|  | git push | ||||||
|  | bun publish | ||||||
							
								
								
									
										11
									
								
								push.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										11
									
								
								push.sh
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,11 @@ | |||||||
|  | #!/bin/bash | ||||||
|  | 
 | ||||||
|  | if [ -z "$1" ]; then | ||||||
|  |     msg="Updates" | ||||||
|  | else | ||||||
|  |     msg="$1" | ||||||
|  | fi | ||||||
|  | 
 | ||||||
|  | git add . | ||||||
|  | git commit -m "$msg" | ||||||
|  | git push | ||||||
							
								
								
									
										21
									
								
								tsconfig.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								tsconfig.json
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,21 @@ | |||||||
|  | { | ||||||
|  |     "compilerOptions": { | ||||||
|  |         "target": "ES2015", | ||||||
|  |         "module": "commonjs", | ||||||
|  |         "maxNodeModuleJsDepth": 10, | ||||||
|  |         "esModuleInterop": true, | ||||||
|  |         "forceConsistentCasingInFileNames": true, | ||||||
|  |         "strict": true, | ||||||
|  |         "skipLibCheck": true, | ||||||
|  |         "lib": ["dom", "dom.iterable", "esnext"], | ||||||
|  |         "allowJs": true, | ||||||
|  |         "incremental": true, | ||||||
|  |         "resolveJsonModule": true, | ||||||
|  |         "jsx": "preserve", | ||||||
|  |         "moduleResolution": "node", | ||||||
|  |         "declaration": true, | ||||||
|  |         "outDir": "dist" | ||||||
|  |     }, | ||||||
|  |     "include": ["**/*.ts"], | ||||||
|  |     "exclude": ["node_modules", "dist"] | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Benjamin Toby
						Benjamin Toby