neex 0.1.8 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -238
- package/bun.lock +669 -0
- package/dist/src/cli.js +457 -24
- package/dist/src/index.js +1 -3
- package/dist/src/logger.js +0 -36
- package/dist/src/process-manager.js +146 -607
- package/dist/src/runner.js +78 -112
- package/package.json +7 -5
- package/dist/src/commands/dev-commands.js +0 -190
- package/dist/src/commands/index.js +0 -21
- package/dist/src/commands/process-commands.js +0 -679
- package/dist/src/commands/run-commands.js +0 -87
- package/dist/src/commands/server-commands.js +0 -50
- package/dist/src/dev-runner.js +0 -209
- package/dist/src/utils.js +0 -10
- package/dist/src/watcher.js +0 -245
- package/feet.txt +0 -16
package/dist/src/cli.js
CHANGED
|
@@ -3,48 +3,481 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
// src/cli.ts -
|
|
6
|
+
// src/cli.ts - Updated version
|
|
7
7
|
const commander_1 = require("commander");
|
|
8
|
-
const index_js_1 = require("./
|
|
8
|
+
const index_js_1 = require("./index.js");
|
|
9
9
|
const chalk_1 = __importDefault(require("chalk"));
|
|
10
10
|
const figures_1 = __importDefault(require("figures"));
|
|
11
|
+
const chokidar_1 = require("chokidar");
|
|
12
|
+
const child_process_1 = require("child_process");
|
|
13
|
+
const path_1 = require("path");
|
|
14
|
+
const fs_1 = require("fs");
|
|
15
|
+
const process_manager_js_1 = require("./process-manager.js");
|
|
11
16
|
const { version } = require('../../package.json');
|
|
12
17
|
function cli() {
|
|
13
18
|
const program = new commander_1.Command();
|
|
14
|
-
|
|
15
|
-
const cleanupHandlers = [];
|
|
19
|
+
let cleanupRunner = null;
|
|
16
20
|
program
|
|
17
21
|
.name('neex')
|
|
18
|
-
.description('Professional script runner with
|
|
22
|
+
.description('Professional script runner with beautiful colored output')
|
|
19
23
|
.version(version);
|
|
20
|
-
//
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
// Development command for Express.js projects
|
|
25
|
+
program
|
|
26
|
+
.command('dev <entry>')
|
|
27
|
+
.description('Run Express.js project in development mode with TypeScript support')
|
|
28
|
+
.option('-p, --port <number>', 'Port to run the server on', '3000')
|
|
29
|
+
.option('-w, --watch <path>', 'Path to watch for changes', 'src')
|
|
30
|
+
.option('-c, --no-color', 'Disable colored output')
|
|
31
|
+
.action(async (entry, options) => {
|
|
32
|
+
try {
|
|
33
|
+
const entryPath = (0, path_1.resolve)(process.cwd(), entry);
|
|
34
|
+
if (!(0, fs_1.existsSync)(entryPath)) {
|
|
35
|
+
throw new Error(`Entry file ${entry} not found`);
|
|
36
|
+
}
|
|
37
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} Starting development server...`));
|
|
38
|
+
let server = (0, child_process_1.spawn)('ts-node', [
|
|
39
|
+
'-r', 'tsconfig-paths/register',
|
|
40
|
+
entryPath
|
|
41
|
+
], {
|
|
42
|
+
stdio: 'inherit',
|
|
43
|
+
env: {
|
|
44
|
+
...process.env,
|
|
45
|
+
PORT: options.port
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
// Setup file watching
|
|
49
|
+
const watcher = (0, chokidar_1.watch)(options.watch, {
|
|
50
|
+
ignored: /(^|[\/\\])\../,
|
|
51
|
+
persistent: true
|
|
52
|
+
});
|
|
53
|
+
watcher.on('change', (path) => {
|
|
54
|
+
console.log(chalk_1.default.yellow(`${figures_1.default.info} File ${path} changed. Restarting...`));
|
|
55
|
+
server.kill();
|
|
56
|
+
server = (0, child_process_1.spawn)('ts-node', [
|
|
57
|
+
'-r', 'tsconfig-paths/register',
|
|
58
|
+
entryPath
|
|
59
|
+
], {
|
|
60
|
+
stdio: 'inherit',
|
|
61
|
+
env: {
|
|
62
|
+
...process.env,
|
|
63
|
+
PORT: options.port
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
cleanupRunner = () => {
|
|
68
|
+
server.kill();
|
|
69
|
+
watcher.close();
|
|
70
|
+
};
|
|
71
|
+
server.on('error', (err) => {
|
|
72
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} Server error: ${err.message}`));
|
|
73
|
+
process.exit(1);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
if (error instanceof Error) {
|
|
78
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} Error: ${error.message}`));
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} An unknown error occurred`));
|
|
82
|
+
}
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
// Build command for TypeScript compilation
|
|
87
|
+
program
|
|
88
|
+
.command('build')
|
|
89
|
+
.description('Build TypeScript project')
|
|
90
|
+
.option('-o, --outDir <dir>', 'Output directory', 'dist')
|
|
91
|
+
.action(async (options) => {
|
|
92
|
+
try {
|
|
93
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} Building project...`));
|
|
94
|
+
const build = (0, child_process_1.spawn)('tsc', [
|
|
95
|
+
'--outDir', options.outDir
|
|
96
|
+
], {
|
|
97
|
+
stdio: 'inherit'
|
|
98
|
+
});
|
|
99
|
+
build.on('close', (code) => {
|
|
100
|
+
if (code === 0) {
|
|
101
|
+
console.log(chalk_1.default.green(`${figures_1.default.tick} Build completed successfully`));
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} Build failed with code ${code}`));
|
|
105
|
+
process.exit(code !== null && code !== void 0 ? code : 1);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
if (error instanceof Error) {
|
|
111
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} Error: ${error.message}`));
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} An unknown error occurred`));
|
|
115
|
+
}
|
|
116
|
+
process.exit(1);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
// Start command for production
|
|
120
|
+
program
|
|
121
|
+
.command('start <entry>')
|
|
122
|
+
.description('Start Express.js project in production mode')
|
|
123
|
+
.option('-p, --port <number>', 'Port to run the server on', '3000')
|
|
124
|
+
.action(async (entry, options) => {
|
|
125
|
+
try {
|
|
126
|
+
const entryPath = (0, path_1.resolve)(process.cwd(), entry);
|
|
127
|
+
if (!(0, fs_1.existsSync)(entryPath)) {
|
|
128
|
+
throw new Error(`Entry file ${entry} not found`);
|
|
129
|
+
}
|
|
130
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} Starting production server...`));
|
|
131
|
+
const server = (0, child_process_1.spawn)('node', [entryPath], {
|
|
132
|
+
stdio: 'inherit',
|
|
133
|
+
env: {
|
|
134
|
+
...process.env,
|
|
135
|
+
PORT: options.port,
|
|
136
|
+
NODE_ENV: 'production'
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
cleanupRunner = () => {
|
|
140
|
+
server.kill();
|
|
141
|
+
};
|
|
142
|
+
server.on('error', (err) => {
|
|
143
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} Server error: ${err.message}`));
|
|
144
|
+
process.exit(1);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
if (error instanceof Error) {
|
|
149
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} Error: ${error.message}`));
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} An unknown error occurred`));
|
|
153
|
+
}
|
|
154
|
+
process.exit(1);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
// Main command for sequential execution (similar to )
|
|
158
|
+
program
|
|
159
|
+
.command('sequential <commands...>')
|
|
160
|
+
.alias('s')
|
|
161
|
+
.description('Run commands sequentially')
|
|
162
|
+
.option('-c, --no-color', 'Disable colored output')
|
|
163
|
+
.option('-t, --no-timing', 'Hide timing information')
|
|
164
|
+
.option('-p, --no-prefix', 'Hide command prefix')
|
|
165
|
+
.option('-s, --stop-on-error', 'Stop on first error')
|
|
166
|
+
.option('-o, --no-output', 'Hide command output')
|
|
167
|
+
.option('-m, --minimal', 'Use minimal output format')
|
|
168
|
+
.action(async (commands, options) => {
|
|
169
|
+
try {
|
|
170
|
+
await (0, index_js_1.run)(commands, {
|
|
171
|
+
parallel: false,
|
|
172
|
+
color: options.color,
|
|
173
|
+
showTiming: options.timing,
|
|
174
|
+
prefix: options.prefix,
|
|
175
|
+
stopOnError: options.stopOnError,
|
|
176
|
+
printOutput: options.output,
|
|
177
|
+
minimalOutput: options.minimal,
|
|
178
|
+
registerCleanup: (cleanup) => { cleanupRunner = cleanup; }
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
if (error instanceof Error) {
|
|
183
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} Error: ${error.message}`));
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} An unknown error occurred`));
|
|
187
|
+
}
|
|
188
|
+
process.exit(1);
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
// runx command: parallel execution by default (with alias 'p'), can run sequentially with -q
|
|
192
|
+
program
|
|
193
|
+
.command('parallel <commands...>', { isDefault: true })
|
|
194
|
+
.alias('p')
|
|
195
|
+
.description('Run commands in parallel (default) or sequentially with -q. Alias: p')
|
|
196
|
+
.option('-c, --no-color', 'Disable colored output')
|
|
197
|
+
.option('-t, --no-timing', 'Hide timing information')
|
|
198
|
+
.option('-p, --no-prefix', 'Hide command prefix')
|
|
199
|
+
.option('-s, --stop-on-error', 'Stop on first error')
|
|
200
|
+
.option('-o, --no-output', 'Hide command output')
|
|
201
|
+
.option('-m, --minimal', 'Use minimal output format')
|
|
202
|
+
.option('-x, --max-parallel <number>', 'Maximum number of parallel processes', parseInt)
|
|
203
|
+
.option('-q, --sequential', 'Run commands sequentially instead of in parallel')
|
|
204
|
+
.action(async (commands, options) => {
|
|
205
|
+
try {
|
|
206
|
+
await (0, index_js_1.run)(commands, {
|
|
207
|
+
parallel: !options.sequential,
|
|
208
|
+
maxParallel: options.maxParallel,
|
|
209
|
+
color: options.color,
|
|
210
|
+
showTiming: options.timing,
|
|
211
|
+
prefix: options.prefix,
|
|
212
|
+
stopOnError: options.stopOnError,
|
|
213
|
+
printOutput: options.output,
|
|
214
|
+
minimalOutput: options.minimal,
|
|
215
|
+
registerCleanup: (cleanup) => { cleanupRunner = cleanup; }
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
if (error instanceof Error) {
|
|
220
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} Error: ${error.message}`));
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} An unknown error occurred`));
|
|
224
|
+
}
|
|
225
|
+
process.exit(1);
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
// Process Management Commands
|
|
229
|
+
program
|
|
230
|
+
.command('startx <path>')
|
|
231
|
+
.description('Start a process with monitoring and auto-restart')
|
|
232
|
+
.option('-n, --name <name>', 'Process name')
|
|
233
|
+
.option('-w, --watch', 'Watch for file changes and auto-restart')
|
|
234
|
+
.option('-r, --max-restarts <number>', 'Maximum number of restart attempts', '5')
|
|
235
|
+
.option('-d, --restart-delay <number>', 'Delay between restarts in milliseconds', '1000')
|
|
236
|
+
.action(async (path, options) => {
|
|
237
|
+
try {
|
|
238
|
+
const process = await process_manager_js_1.processManager.startx(path, {
|
|
239
|
+
name: options.name,
|
|
240
|
+
watch: options.watch,
|
|
241
|
+
maxRestarts: parseInt(options.maxRestarts),
|
|
242
|
+
restartDelay: parseInt(options.restartDelay)
|
|
243
|
+
});
|
|
244
|
+
console.log(chalk_1.default.green(`${figures_1.default.tick} Process started successfully`));
|
|
245
|
+
console.log(chalk_1.default.blue(`ID: ${process.id}`));
|
|
246
|
+
console.log(chalk_1.default.blue(`Name: ${process.name}`));
|
|
247
|
+
console.log(chalk_1.default.blue(`PID: ${process.pid}`));
|
|
248
|
+
console.log(chalk_1.default.blue(`Max Restarts: ${process.maxRestarts}`));
|
|
249
|
+
console.log(chalk_1.default.blue(`Restart Delay: ${process.restartDelay}ms`));
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
if (error instanceof Error) {
|
|
253
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} Error: ${error.message}`));
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} An unknown error occurred`));
|
|
257
|
+
}
|
|
258
|
+
process.exit(1);
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
program
|
|
262
|
+
.command('stopx <id>')
|
|
263
|
+
.description('Stop a running process')
|
|
264
|
+
.option('-f, --force', 'Force stop the process')
|
|
265
|
+
.action(async (id, options) => {
|
|
266
|
+
try {
|
|
267
|
+
await process_manager_js_1.processManager.stopx(id);
|
|
268
|
+
console.log(chalk_1.default.green(`${figures_1.default.tick} Process stopped successfully`));
|
|
269
|
+
}
|
|
270
|
+
catch (error) {
|
|
271
|
+
if (error instanceof Error) {
|
|
272
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} Error: ${error.message}`));
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} An unknown error occurred`));
|
|
276
|
+
}
|
|
277
|
+
process.exit(1);
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
program
|
|
281
|
+
.command('list')
|
|
282
|
+
.description('List all running processes')
|
|
283
|
+
.option('-a, --all', 'Show all processes including stopped ones')
|
|
284
|
+
.option('-j, --json', 'Output in JSON format')
|
|
285
|
+
.action((options) => {
|
|
286
|
+
const processes = process_manager_js_1.processManager.list();
|
|
287
|
+
const filteredProcesses = options.all ? processes : processes.filter(p => p.status === 'running');
|
|
288
|
+
if (filteredProcesses.length === 0) {
|
|
289
|
+
console.log(chalk_1.default.yellow(`${figures_1.default.info} No processes running`));
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
if (options.json) {
|
|
293
|
+
console.log(JSON.stringify(filteredProcesses, null, 2));
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} Running Processes:`));
|
|
297
|
+
filteredProcesses.forEach(process => {
|
|
298
|
+
const statusColor = process.status === 'running' ? 'green' :
|
|
299
|
+
process.status === 'error' ? 'red' :
|
|
300
|
+
process.status === 'restarting' ? 'yellow' : 'gray';
|
|
301
|
+
console.log(chalk_1.default.blue(`\nID: ${process.id}`));
|
|
302
|
+
console.log(`Name: ${process.name}`);
|
|
303
|
+
console.log(`Status: ${chalk_1.default[statusColor](process.status)}`);
|
|
304
|
+
console.log(`PID: ${process.pid}`);
|
|
305
|
+
console.log(`Uptime: ${Math.floor(process.uptime)}s`);
|
|
306
|
+
console.log(`Memory: ${process.memory.toFixed(2)}MB`);
|
|
307
|
+
console.log(`Restarts: ${process.restarts}/${process.maxRestarts}`);
|
|
308
|
+
if (process.lastError) {
|
|
309
|
+
console.log(`Last Error: ${chalk_1.default.red(process.lastError)}`);
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
program
|
|
314
|
+
.command('monit <id>')
|
|
315
|
+
.description('Monitor a specific process')
|
|
316
|
+
.option('-i, --interval <number>', 'Update interval in milliseconds', '1000')
|
|
317
|
+
.action((id, options) => {
|
|
318
|
+
try {
|
|
319
|
+
const processInfo = process_manager_js_1.processManager.monit(id);
|
|
320
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} Process Monitor:`));
|
|
321
|
+
console.log(chalk_1.default.blue(`\nID: ${processInfo.id}`));
|
|
322
|
+
console.log(`Name: ${processInfo.name}`);
|
|
323
|
+
console.log(`Status: ${processInfo.status}`);
|
|
324
|
+
console.log(`PID: ${processInfo.pid}`);
|
|
325
|
+
console.log(`Uptime: ${Math.floor(processInfo.uptime)}s`);
|
|
326
|
+
console.log(`Memory: ${processInfo.memory.toFixed(2)}MB`);
|
|
327
|
+
console.log(`Restarts: ${processInfo.restarts}/${processInfo.maxRestarts}`);
|
|
328
|
+
if (processInfo.lastError) {
|
|
329
|
+
console.log(`Last Error: ${chalk_1.default.red(processInfo.lastError)}`);
|
|
330
|
+
}
|
|
331
|
+
console.log(chalk_1.default.blue(`\nRecent Logs:`));
|
|
332
|
+
processInfo.logs.forEach(log => {
|
|
333
|
+
if (log.includes('error') || log.includes('Error')) {
|
|
334
|
+
console.log(chalk_1.default.red(log));
|
|
335
|
+
}
|
|
336
|
+
else if (log.includes('warn') || log.includes('Warn')) {
|
|
337
|
+
console.log(chalk_1.default.yellow(log));
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
console.log(log);
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
// Start real-time monitoring
|
|
344
|
+
const interval = setInterval(() => {
|
|
345
|
+
try {
|
|
346
|
+
const updatedProcess = process_manager_js_1.processManager.monit(id);
|
|
347
|
+
process.stdout.write('\x1Bc'); // Clear screen
|
|
348
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} Process Monitor (Live):`));
|
|
349
|
+
console.log(chalk_1.default.blue(`\nID: ${updatedProcess.id}`));
|
|
350
|
+
console.log(`Name: ${updatedProcess.name}`);
|
|
351
|
+
console.log(`Status: ${updatedProcess.status}`);
|
|
352
|
+
console.log(`PID: ${updatedProcess.pid}`);
|
|
353
|
+
console.log(`Uptime: ${Math.floor(updatedProcess.uptime)}s`);
|
|
354
|
+
console.log(`Memory: ${updatedProcess.memory.toFixed(2)}MB`);
|
|
355
|
+
console.log(`Restarts: ${updatedProcess.restarts}/${updatedProcess.maxRestarts}`);
|
|
356
|
+
if (updatedProcess.lastError) {
|
|
357
|
+
console.log(`Last Error: ${chalk_1.default.red(updatedProcess.lastError)}`);
|
|
358
|
+
}
|
|
359
|
+
console.log(chalk_1.default.blue(`\nRecent Logs:`));
|
|
360
|
+
updatedProcess.logs.forEach(log => {
|
|
361
|
+
if (log.includes('error') || log.includes('Error')) {
|
|
362
|
+
console.log(chalk_1.default.red(log));
|
|
363
|
+
}
|
|
364
|
+
else if (log.includes('warn') || log.includes('Warn')) {
|
|
365
|
+
console.log(chalk_1.default.yellow(log));
|
|
366
|
+
}
|
|
367
|
+
else {
|
|
368
|
+
console.log(log);
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
catch (error) {
|
|
373
|
+
clearInterval(interval);
|
|
374
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} Error monitoring process: ${error}`));
|
|
375
|
+
process.exit(1);
|
|
376
|
+
}
|
|
377
|
+
}, parseInt(options.interval));
|
|
378
|
+
// Handle cleanup
|
|
379
|
+
process.on('SIGINT', () => {
|
|
380
|
+
clearInterval(interval);
|
|
381
|
+
process.exit(0);
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
catch (error) {
|
|
385
|
+
if (error instanceof Error) {
|
|
386
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} Error: ${error.message}`));
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} An unknown error occurred`));
|
|
390
|
+
}
|
|
391
|
+
process.exit(1);
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
program
|
|
395
|
+
.command('log <id>')
|
|
396
|
+
.description('View process logs')
|
|
397
|
+
.option('-l, --lines <number>', 'Number of lines to show', '100')
|
|
398
|
+
.option('-f, --follow', 'Follow log output')
|
|
399
|
+
.option('-e, --error', 'Show only error logs')
|
|
400
|
+
.option('-w, --warn', 'Show only warning logs')
|
|
401
|
+
.action((id, options) => {
|
|
402
|
+
try {
|
|
403
|
+
const logs = process_manager_js_1.processManager.log(id, parseInt(options.lines));
|
|
404
|
+
if (options.error) {
|
|
405
|
+
const errorLogs = logs.filter(log => log.toLowerCase().includes('error') ||
|
|
406
|
+
log.toLowerCase().includes('exception'));
|
|
407
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} Error Logs:`));
|
|
408
|
+
errorLogs.forEach(log => console.log(chalk_1.default.red(log)));
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
if (options.warn) {
|
|
412
|
+
const warnLogs = logs.filter(log => log.toLowerCase().includes('warn') ||
|
|
413
|
+
log.toLowerCase().includes('warning'));
|
|
414
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} Warning Logs:`));
|
|
415
|
+
warnLogs.forEach(log => console.log(chalk_1.default.yellow(log)));
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} Process Logs:`));
|
|
419
|
+
logs.forEach(log => {
|
|
420
|
+
if (log.includes('error') || log.includes('Error')) {
|
|
421
|
+
console.log(chalk_1.default.red(log));
|
|
422
|
+
}
|
|
423
|
+
else if (log.includes('warn') || log.includes('Warn')) {
|
|
424
|
+
console.log(chalk_1.default.yellow(log));
|
|
425
|
+
}
|
|
426
|
+
else {
|
|
427
|
+
console.log(log);
|
|
428
|
+
}
|
|
429
|
+
});
|
|
430
|
+
if (options.follow) {
|
|
431
|
+
const watcher = (0, chokidar_1.watch)(process_manager_js_1.processManager.getLogPath(id), {
|
|
432
|
+
persistent: true
|
|
433
|
+
});
|
|
434
|
+
watcher.on('change', () => {
|
|
435
|
+
const newLogs = process_manager_js_1.processManager.log(id, 1);
|
|
436
|
+
if (newLogs.length > 0) {
|
|
437
|
+
const log = newLogs[0];
|
|
438
|
+
if (log.includes('error') || log.includes('Error')) {
|
|
439
|
+
console.log(chalk_1.default.red(log));
|
|
440
|
+
}
|
|
441
|
+
else if (log.includes('warn') || log.includes('Warn')) {
|
|
442
|
+
console.log(chalk_1.default.yellow(log));
|
|
443
|
+
}
|
|
444
|
+
else {
|
|
445
|
+
console.log(log);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
});
|
|
449
|
+
process.on('SIGINT', () => {
|
|
450
|
+
watcher.close();
|
|
451
|
+
process.exit(0);
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
catch (error) {
|
|
456
|
+
if (error instanceof Error) {
|
|
457
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} Error: ${error.message}`));
|
|
458
|
+
}
|
|
459
|
+
else {
|
|
460
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} An unknown error occurred`));
|
|
461
|
+
}
|
|
462
|
+
process.exit(1);
|
|
463
|
+
}
|
|
464
|
+
});
|
|
27
465
|
program.parse(process.argv);
|
|
28
466
|
// Show help if no commands specified
|
|
29
467
|
if (program.args.length === 0) {
|
|
30
468
|
program.help();
|
|
31
469
|
}
|
|
32
470
|
// Graceful shutdown handling
|
|
33
|
-
const handleSignal =
|
|
471
|
+
const handleSignal = (signal) => {
|
|
34
472
|
console.log(`\n${chalk_1.default.yellow(`${figures_1.default.warning} Received ${signal}. Cleaning up...`)}`);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
try {
|
|
38
|
-
await cleanup();
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
console.error(`Cleanup error:`, error);
|
|
42
|
-
}
|
|
473
|
+
if (cleanupRunner) {
|
|
474
|
+
cleanupRunner();
|
|
43
475
|
}
|
|
476
|
+
// Give cleanup a moment, then exit
|
|
44
477
|
setTimeout(() => process.exit(0), 500);
|
|
45
478
|
};
|
|
46
|
-
process.on('SIGINT', () => handleSignal('SIGINT')
|
|
47
|
-
process.on('SIGTERM', () => handleSignal('SIGTERM')
|
|
48
|
-
process.on('SIGQUIT', () => handleSignal('SIGQUIT')
|
|
479
|
+
process.on('SIGINT', () => handleSignal('SIGINT')); // Ctrl+C
|
|
480
|
+
process.on('SIGTERM', () => handleSignal('SIGTERM'));
|
|
481
|
+
process.on('SIGQUIT', () => handleSignal('SIGQUIT'));
|
|
49
482
|
}
|
|
50
483
|
exports.default = cli;
|
package/dist/src/index.js
CHANGED
|
@@ -23,9 +23,7 @@ async function run(commands, options) {
|
|
|
23
23
|
stopOnError: (_f = options === null || options === void 0 ? void 0 : options.stopOnError) !== null && _f !== void 0 ? _f : false,
|
|
24
24
|
minimalOutput: (_g = options === null || options === void 0 ? void 0 : options.minimalOutput) !== null && _g !== void 0 ? _g : false,
|
|
25
25
|
groupOutput: (_h = options === null || options === void 0 ? void 0 : options.groupOutput) !== null && _h !== void 0 ? _h : false,
|
|
26
|
-
isServerMode: (_j = options === null || options === void 0 ? void 0 : options.isServerMode) !== null && _j !== void 0 ? _j : false
|
|
27
|
-
retry: options === null || options === void 0 ? void 0 : options.retry,
|
|
28
|
-
retryDelay: options === null || options === void 0 ? void 0 : options.retryDelay
|
|
26
|
+
isServerMode: (_j = options === null || options === void 0 ? void 0 : options.isServerMode) !== null && _j !== void 0 ? _j : false
|
|
29
27
|
};
|
|
30
28
|
const runner = new runner_1.Runner(runOptions);
|
|
31
29
|
if (options === null || options === void 0 ? void 0 : options.registerCleanup) {
|
package/dist/src/logger.js
CHANGED
|
@@ -7,7 +7,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
8
|
const figures_1 = __importDefault(require("figures"));
|
|
9
9
|
const string_width_1 = __importDefault(require("string-width"));
|
|
10
|
-
const utils_1 = require("./utils");
|
|
11
10
|
class Logger {
|
|
12
11
|
constructor() {
|
|
13
12
|
this.prefixLength = 0;
|
|
@@ -121,9 +120,6 @@ class Logger {
|
|
|
121
120
|
// Clear buffer after printing
|
|
122
121
|
this.outputBuffer.set(command, []);
|
|
123
122
|
}
|
|
124
|
-
clearBuffer(command) {
|
|
125
|
-
this.outputBuffer.set(command, []);
|
|
126
|
-
}
|
|
127
123
|
printLine(message, level = 'info') {
|
|
128
124
|
if (level === 'error') {
|
|
129
125
|
console.error(chalk_1.default.red(`${figures_1.default.cross} ${message}`));
|
|
@@ -140,12 +136,6 @@ class Logger {
|
|
|
140
136
|
this.startTimes.set(command, new Date());
|
|
141
137
|
const prefix = this.formatPrefix(command);
|
|
142
138
|
const color = this.commandColors.get(command) || chalk_1.default.white;
|
|
143
|
-
// Stop any previous spinner for this command (e.g. if retrying)
|
|
144
|
-
this.stopSpinner(command);
|
|
145
|
-
// Clear the line before printing "Starting..."
|
|
146
|
-
if (this.isSpinnerActive) { // Check if any spinner was active to avoid clearing unnecessarily
|
|
147
|
-
process.stdout.write('\r' + ' '.repeat(process.stdout.columns || 80) + '\r');
|
|
148
|
-
}
|
|
149
139
|
console.log(`${prefix} ${color('Starting...')}`);
|
|
150
140
|
// Start spinner for this command
|
|
151
141
|
this.startSpinner(command);
|
|
@@ -207,32 +197,6 @@ class Logger {
|
|
|
207
197
|
console.error(`${prefix} ${chalk_1.default.red(error.message)}`);
|
|
208
198
|
}
|
|
209
199
|
}
|
|
210
|
-
printEnd(result, minimalOutput) {
|
|
211
|
-
this.stopSpinner(result.command);
|
|
212
|
-
const prefix = this.formatPrefix(result.command); // Corrected to formatPrefix
|
|
213
|
-
let durationDisplay = '';
|
|
214
|
-
if (result.duration !== null) {
|
|
215
|
-
// Ensure result.duration is treated as a number here
|
|
216
|
-
durationDisplay = `(${(0, utils_1.formatDuration)(result.duration)})`;
|
|
217
|
-
}
|
|
218
|
-
const duration = durationDisplay;
|
|
219
|
-
if (minimalOutput) {
|
|
220
|
-
if (!result.success) {
|
|
221
|
-
const status = result.code !== null ? `failed (code ${result.code})` : 'failed';
|
|
222
|
-
this.printLine(`${prefix} ${chalk_1.default.red(figures_1.default.cross)} ${result.command} ${status} ${duration}`, 'error');
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
else {
|
|
226
|
-
if (result.success) {
|
|
227
|
-
this.printLine(`${prefix} ${chalk_1.default.green(figures_1.default.tick)} Command "${result.command}" finished successfully ${duration}`, 'info');
|
|
228
|
-
}
|
|
229
|
-
else {
|
|
230
|
-
const errorCode = result.code !== null ? ` (code ${result.code})` : '';
|
|
231
|
-
const errorMessage = result.error ? `: ${result.error.message}` : '';
|
|
232
|
-
this.printLine(`${prefix} ${chalk_1.default.red(figures_1.default.cross)} Command "${result.command}" failed${errorCode}${errorMessage} ${duration}`, 'error');
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
200
|
printSummary(results) {
|
|
237
201
|
// Stop any remaining spinners
|
|
238
202
|
this.stopAllSpinners();
|