neex 0.4.4 → 0.5.0
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 +227 -70
- package/dist/bin/neex.js +4 -0
- package/dist/src/cli.js +50 -0
- package/dist/src/commands/dev-commands.js +190 -0
- package/dist/src/commands/index.js +21 -0
- package/dist/src/commands/process-commands.js +679 -0
- package/dist/src/commands/run-commands.js +94 -0
- package/dist/src/commands/server-commands.js +50 -0
- package/dist/src/dev-runner.js +209 -0
- package/dist/src/index.js +72 -0
- package/dist/{logger.js → src/logger.js} +36 -1
- package/dist/src/process-manager.js +669 -0
- package/dist/{runner.js → src/runner.js} +112 -79
- package/dist/{types.js → src/types.js} +0 -1
- package/dist/src/utils.js +10 -0
- package/dist/src/watcher.js +245 -0
- package/feet.txt +16 -0
- package/package.json +5 -19
- package/.env +0 -2
- package/Screenshot 1404-03-20 at 17.20.45.png +0 -0
- package/Screenshot 1404-03-20 at 17.20.56.png +0 -0
- package/Screenshot 1404-03-20 at 17.21.04.png +0 -0
- package/bun.lock +0 -939
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +0 -49
- package/dist/cli.js.map +0 -1
- package/dist/commands/process-command/process.d.ts +0 -2
- package/dist/commands/process-command/process.js +0 -150
- package/dist/commands/process-command/process.js.map +0 -1
- package/dist/commands/project-command/build.d.ts +0 -3
- package/dist/commands/project-command/build.js +0 -42
- package/dist/commands/project-command/build.js.map +0 -1
- package/dist/commands/project-command/cache.d.ts +0 -3
- package/dist/commands/project-command/cache.js +0 -57
- package/dist/commands/project-command/cache.js.map +0 -1
- package/dist/commands/project-command/dev.d.ts +0 -3
- package/dist/commands/project-command/dev.js +0 -52
- package/dist/commands/project-command/dev.js.map +0 -1
- package/dist/commands/project-command/start.d.ts +0 -3
- package/dist/commands/project-command/start.js +0 -46
- package/dist/commands/project-command/start.js.map +0 -1
- package/dist/commands/run-commands/run.d.ts +0 -2
- package/dist/commands/run-commands/run.js +0 -82
- package/dist/commands/run-commands/run.js.map +0 -1
- package/dist/index.d.ts +0 -30
- package/dist/index.js +0 -66
- package/dist/index.js.map +0 -1
- package/dist/logger.d.ts +0 -31
- package/dist/logger.js.map +0 -1
- package/dist/process-manager.d.ts +0 -60
- package/dist/process-manager.js +0 -277
- package/dist/process-manager.js.map +0 -1
- package/dist/project-manager.d.ts +0 -64
- package/dist/project-manager.js +0 -467
- package/dist/project-manager.js.map +0 -1
- package/dist/runner.d.ts +0 -17
- package/dist/runner.js.map +0 -1
- package/dist/server.d.ts +0 -2
- package/dist/server.js +0 -67
- package/dist/server.js.map +0 -1
- package/dist/types.d.ts +0 -37
- package/dist/types.js.map +0 -1
- package/dist/typescript-runner.d.ts +0 -12
- package/dist/typescript-runner.js +0 -162
- package/dist/typescript-runner.js.map +0 -1
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.addRunCommands = void 0;
|
|
7
|
+
const index_js_1 = require("../index.js");
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const figures_1 = __importDefault(require("figures"));
|
|
10
|
+
function addRunCommands(program) {
|
|
11
|
+
let cleanupRunner = null;
|
|
12
|
+
// Main command for sequential execution (similar to run-s)
|
|
13
|
+
program
|
|
14
|
+
.command("s <commands...>")
|
|
15
|
+
.alias("seq")
|
|
16
|
+
.alias("sequential")
|
|
17
|
+
.description("Run commands sequentially")
|
|
18
|
+
.option("-c, --no-color", "Disable colored output")
|
|
19
|
+
.option("-t, --no-timing", "Hide timing information")
|
|
20
|
+
.option("-p, --no-prefix", "Hide command prefix")
|
|
21
|
+
.option("-s, --stop-on-error", "Stop on first error")
|
|
22
|
+
.option("-o, --no-output", "Hide command output")
|
|
23
|
+
.option("-m, --minimal", "Use minimal output format")
|
|
24
|
+
.action(async (commands, options) => {
|
|
25
|
+
try {
|
|
26
|
+
await (0, index_js_1.run)(commands, {
|
|
27
|
+
parallel: false,
|
|
28
|
+
color: options.color,
|
|
29
|
+
showTiming: options.timing,
|
|
30
|
+
prefix: options.prefix,
|
|
31
|
+
stopOnError: options.stopOnError,
|
|
32
|
+
printOutput: options.output,
|
|
33
|
+
minimalOutput: options.minimal,
|
|
34
|
+
registerCleanup: (cleanup) => {
|
|
35
|
+
cleanupRunner = cleanup;
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
if (error instanceof Error) {
|
|
41
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} Error: ${error.message}`));
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} An unknown error occurred`));
|
|
45
|
+
}
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
// runx command: parallel execution by default (with alias 'p'), can run sequentially with -q
|
|
50
|
+
program
|
|
51
|
+
.command("p <commands...>", { isDefault: true })
|
|
52
|
+
.alias("par")
|
|
53
|
+
.alias("parallel")
|
|
54
|
+
.description("Run commands in parallel (default) or sequentially with -q. This is the default command.")
|
|
55
|
+
.option("-c, --no-color", "Disable colored output")
|
|
56
|
+
.option("-t, --no-timing", "Hide timing information")
|
|
57
|
+
.option("-p, --no-prefix", "Hide command prefix")
|
|
58
|
+
.option("-s, --stop-on-error", "Stop on first error")
|
|
59
|
+
.option("-o, --no-output", "Hide command output")
|
|
60
|
+
.option("-m, --minimal", "Use minimal output format")
|
|
61
|
+
.option("-x, --max-parallel <number>", "Maximum number of parallel processes", parseInt)
|
|
62
|
+
.option("-q, --sequential", "Run commands sequentially instead of in parallel")
|
|
63
|
+
.option("--retry <count>", "Number of times to retry a failed command", parseInt)
|
|
64
|
+
.option("--retry-delay <ms>", "Delay in milliseconds between retries", parseInt)
|
|
65
|
+
.action(async (commands, options) => {
|
|
66
|
+
try {
|
|
67
|
+
await (0, index_js_1.run)(commands, {
|
|
68
|
+
parallel: !options.sequential,
|
|
69
|
+
maxParallel: options.maxParallel,
|
|
70
|
+
color: options.color,
|
|
71
|
+
showTiming: options.timing,
|
|
72
|
+
prefix: options.prefix,
|
|
73
|
+
stopOnError: options.stopOnError,
|
|
74
|
+
printOutput: options.output,
|
|
75
|
+
minimalOutput: options.minimal,
|
|
76
|
+
retry: options.retry,
|
|
77
|
+
retryDelay: options.retryDelay,
|
|
78
|
+
registerCleanup: (cleanup) => {
|
|
79
|
+
cleanupRunner = cleanup;
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
if (error instanceof Error) {
|
|
85
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} Error: ${error.message}`));
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} An unknown error occurred`));
|
|
89
|
+
}
|
|
90
|
+
process.exit(1);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
exports.addRunCommands = addRunCommands;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.addServerCommands = void 0;
|
|
7
|
+
const index_js_1 = require("../index.js");
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const figures_1 = __importDefault(require("figures"));
|
|
10
|
+
function addServerCommands(program) {
|
|
11
|
+
let cleanupRunner = null;
|
|
12
|
+
// Servers command specifically optimized for running web servers
|
|
13
|
+
program
|
|
14
|
+
.command('servers <commands...>')
|
|
15
|
+
.alias('srv')
|
|
16
|
+
.description('Run multiple servers with optimized output for API, frontend, etc.')
|
|
17
|
+
.option('-c, --no-color', 'Disable colored output')
|
|
18
|
+
.option('-t, --no-timing', 'Hide timing information')
|
|
19
|
+
.option('-p, --no-prefix', 'Hide command prefix')
|
|
20
|
+
.option('-s, --stop-on-error', 'Stop when any server crashes')
|
|
21
|
+
.option('-x, --max-parallel <number>', 'Maximum number of parallel servers', parseInt)
|
|
22
|
+
.option('-g, --group-output', 'Group outputs by server')
|
|
23
|
+
.action(async (commands, options) => {
|
|
24
|
+
try {
|
|
25
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} Starting servers in parallel mode...`));
|
|
26
|
+
await (0, index_js_1.run)(commands, {
|
|
27
|
+
parallel: true,
|
|
28
|
+
maxParallel: options.maxParallel,
|
|
29
|
+
color: options.color,
|
|
30
|
+
showTiming: options.timing,
|
|
31
|
+
prefix: options.prefix,
|
|
32
|
+
stopOnError: options.stopOnError,
|
|
33
|
+
printOutput: true,
|
|
34
|
+
registerCleanup: (cleanup) => { cleanupRunner = cleanup; },
|
|
35
|
+
groupOutput: options.groupOutput,
|
|
36
|
+
isServerMode: true
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
if (error instanceof Error) {
|
|
41
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} Server Error: ${error.message}`));
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} An unknown server error occurred`));
|
|
45
|
+
}
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
exports.addServerCommands = addServerCommands;
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DevRunner = void 0;
|
|
7
|
+
// src/dev-runner.ts - Development runner with file watching (nodemon functionality)
|
|
8
|
+
const watcher_1 = require("./watcher");
|
|
9
|
+
const runner_1 = require("./runner");
|
|
10
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
11
|
+
const figures_1 = __importDefault(require("figures"));
|
|
12
|
+
const logger_1 = __importDefault(require("./logger"));
|
|
13
|
+
class DevRunner {
|
|
14
|
+
constructor(options) {
|
|
15
|
+
this.commands = [];
|
|
16
|
+
this.isRunning = false;
|
|
17
|
+
this.restartCount = 0;
|
|
18
|
+
this.startTime = new Date();
|
|
19
|
+
const defaultOptions = {
|
|
20
|
+
parallel: false,
|
|
21
|
+
printOutput: true,
|
|
22
|
+
color: true,
|
|
23
|
+
showTiming: true,
|
|
24
|
+
prefix: true,
|
|
25
|
+
stopOnError: false,
|
|
26
|
+
minimalOutput: false,
|
|
27
|
+
groupOutput: false,
|
|
28
|
+
isServerMode: false,
|
|
29
|
+
restartOnChange: true,
|
|
30
|
+
clearConsole: false,
|
|
31
|
+
signal: 'SIGTERM',
|
|
32
|
+
watch: ['./'],
|
|
33
|
+
ignore: [
|
|
34
|
+
'node_modules/**',
|
|
35
|
+
'.git/**',
|
|
36
|
+
'*.log',
|
|
37
|
+
'dist/**',
|
|
38
|
+
'build/**',
|
|
39
|
+
'coverage/**',
|
|
40
|
+
'.nyc_output/**',
|
|
41
|
+
'*.tmp',
|
|
42
|
+
'*.temp'
|
|
43
|
+
],
|
|
44
|
+
ext: ['js', 'mjs', 'json', 'ts', 'tsx', 'jsx'],
|
|
45
|
+
delay: 1000,
|
|
46
|
+
verbose: false,
|
|
47
|
+
runnerName: 'watch', // Default runner name if not specified
|
|
48
|
+
};
|
|
49
|
+
this.options = {
|
|
50
|
+
...defaultOptions,
|
|
51
|
+
...options
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
setupFileWatcher() {
|
|
55
|
+
const watchOptions = {
|
|
56
|
+
watch: this.options.watch || ['./'],
|
|
57
|
+
ignore: this.options.ignore,
|
|
58
|
+
ext: this.options.ext,
|
|
59
|
+
delay: this.options.delay,
|
|
60
|
+
verbose: this.options.verbose
|
|
61
|
+
};
|
|
62
|
+
this.fileWatcher = new watcher_1.FileWatcher(watchOptions);
|
|
63
|
+
this.fileWatcher.on('change', (event) => {
|
|
64
|
+
if (this.options.restartOnChange && this.isRunning) {
|
|
65
|
+
this.handleFileChange(event);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
async handleFileChange(event) {
|
|
70
|
+
const prefix = chalk_1.default.cyan(`[${this.options.runnerName}]`);
|
|
71
|
+
logger_1.default.printLine(`${prefix} File changed: ${chalk_1.default.yellow(event.relativePath)}`, 'info');
|
|
72
|
+
if (this.options.clearConsole) {
|
|
73
|
+
console.clear();
|
|
74
|
+
}
|
|
75
|
+
await this.restart();
|
|
76
|
+
}
|
|
77
|
+
async runCommands() {
|
|
78
|
+
if (this.commands.length === 0) {
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
81
|
+
this.runner = new runner_1.Runner(this.options);
|
|
82
|
+
try {
|
|
83
|
+
const results = await this.runner.run(this.commands);
|
|
84
|
+
return results;
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
logger_1.default.printLine(`Execution failed: ${error.message}`, 'error');
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
printDevBanner() {
|
|
92
|
+
var _a, _b;
|
|
93
|
+
const prefix = chalk_1.default.cyan(`[${this.options.runnerName}]`);
|
|
94
|
+
const uptime = Math.floor((Date.now() - this.startTime.getTime()) / 1000);
|
|
95
|
+
const uptimeStr = this.formatUptime(uptime);
|
|
96
|
+
console.log('\n' + chalk_1.default.bgGreen.black(` ${(_a = this.options.runnerName) === null || _a === void 0 ? void 0 : _a.toUpperCase()} MODE `) + '\n');
|
|
97
|
+
if (this.restartCount > 0) {
|
|
98
|
+
console.log(`${prefix} ${chalk_1.default.green(`${figures_1.default.arrowUp} Restarted ${this.restartCount} times`)}`);
|
|
99
|
+
}
|
|
100
|
+
console.log(`${prefix} ${chalk_1.default.blue(`${figures_1.default.info} Uptime: ${uptimeStr}`)}`);
|
|
101
|
+
console.log(`${prefix} ${chalk_1.default.blue(`${figures_1.default.info} Watching: ${((_b = this.options.watch) === null || _b === void 0 ? void 0 : _b.join(', ')) || 'current directory'}`)}`);
|
|
102
|
+
if (this.options.ext && this.options.ext.length > 0) {
|
|
103
|
+
console.log(`${prefix} ${chalk_1.default.blue(`${figures_1.default.info} Extensions: ${this.options.ext.join(', ')}`)}`);
|
|
104
|
+
}
|
|
105
|
+
console.log('');
|
|
106
|
+
}
|
|
107
|
+
formatUptime(seconds) {
|
|
108
|
+
if (seconds < 60) {
|
|
109
|
+
return `${seconds}s`;
|
|
110
|
+
}
|
|
111
|
+
else if (seconds < 3600) {
|
|
112
|
+
const minutes = Math.floor(seconds / 60);
|
|
113
|
+
const remainingSeconds = seconds % 60;
|
|
114
|
+
return `${minutes}m ${remainingSeconds}s`;
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
const hours = Math.floor(seconds / 3600);
|
|
118
|
+
const minutes = Math.floor((seconds % 3600) / 60);
|
|
119
|
+
return `${hours}h ${minutes}m`;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
async start(commands) {
|
|
123
|
+
this.commands = commands;
|
|
124
|
+
this.isRunning = true;
|
|
125
|
+
this.startTime = new Date();
|
|
126
|
+
// Setup file watcher
|
|
127
|
+
this.setupFileWatcher();
|
|
128
|
+
// Print development banner
|
|
129
|
+
this.printDevBanner();
|
|
130
|
+
// Start file watcher
|
|
131
|
+
if (this.fileWatcher) {
|
|
132
|
+
await this.fileWatcher.start();
|
|
133
|
+
}
|
|
134
|
+
// Run initial commands
|
|
135
|
+
const prefix = chalk_1.default.cyan(`[${this.options.runnerName}]`);
|
|
136
|
+
logger_1.default.printLine(`${prefix} Starting development server...`, 'info');
|
|
137
|
+
await this.runCommands();
|
|
138
|
+
// Set up graceful shutdown
|
|
139
|
+
this.setupGracefulShutdown();
|
|
140
|
+
logger_1.default.printLine(`${prefix} Development server started. Watching for changes...`, 'info');
|
|
141
|
+
logger_1.default.printLine(`${prefix} Press ${chalk_1.default.cyan('Ctrl+C')} to stop`, 'info');
|
|
142
|
+
}
|
|
143
|
+
async restart() {
|
|
144
|
+
const prefix = chalk_1.default.cyan(`[${this.options.runnerName}]`);
|
|
145
|
+
if (!this.isRunning) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
logger_1.default.printLine(`${prefix} Restarting due to file changes...`, 'info');
|
|
149
|
+
this.restartCount++;
|
|
150
|
+
// Stop current processes
|
|
151
|
+
if (this.runner) {
|
|
152
|
+
this.runner.cleanup(this.options.signal);
|
|
153
|
+
}
|
|
154
|
+
// Wait a moment before restarting
|
|
155
|
+
await new Promise(resolve => setTimeout(resolve, 500));
|
|
156
|
+
// Print restart banner
|
|
157
|
+
this.printDevBanner();
|
|
158
|
+
// Run commands again
|
|
159
|
+
await this.runCommands();
|
|
160
|
+
logger_1.default.printLine(`${prefix} Restart completed. Watching for changes...`, 'info');
|
|
161
|
+
}
|
|
162
|
+
async stop() {
|
|
163
|
+
const prefix = chalk_1.default.cyan(`[${this.options.runnerName}]`);
|
|
164
|
+
if (!this.isRunning) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
logger_1.default.printLine(`${prefix} Stopping development server...`, 'info');
|
|
168
|
+
this.isRunning = false;
|
|
169
|
+
// Stop file watcher
|
|
170
|
+
if (this.fileWatcher) {
|
|
171
|
+
this.fileWatcher.stop();
|
|
172
|
+
}
|
|
173
|
+
// Stop current processes
|
|
174
|
+
if (this.runner) {
|
|
175
|
+
this.runner.cleanup(this.options.signal);
|
|
176
|
+
}
|
|
177
|
+
const uptime = Math.floor((Date.now() - this.startTime.getTime()) / 1000);
|
|
178
|
+
const uptimeStr = this.formatUptime(uptime);
|
|
179
|
+
logger_1.default.printLine(`${prefix} ${this.options.runnerName} development server stopped after ${uptimeStr}`, 'info');
|
|
180
|
+
if (this.restartCount > 0) {
|
|
181
|
+
logger_1.default.printLine(`${prefix} Total restarts: ${this.restartCount}`, 'info');
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
setupGracefulShutdown() {
|
|
185
|
+
const handleSignal = (signal) => {
|
|
186
|
+
console.log(`\n${chalk_1.default.yellow(`${figures_1.default.warning} Received ${signal}. Shutting down development server...`)}`);
|
|
187
|
+
this.stop().then(() => {
|
|
188
|
+
process.exit(0);
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
process.on('SIGINT', () => handleSignal('SIGINT'));
|
|
192
|
+
process.on('SIGTERM', () => handleSignal('SIGTERM'));
|
|
193
|
+
process.on('SIGQUIT', () => handleSignal('SIGQUIT'));
|
|
194
|
+
}
|
|
195
|
+
isActive() {
|
|
196
|
+
return this.isRunning;
|
|
197
|
+
}
|
|
198
|
+
getUptime() {
|
|
199
|
+
return Math.floor((Date.now() - this.startTime.getTime()) / 1000);
|
|
200
|
+
}
|
|
201
|
+
getRestartCount() {
|
|
202
|
+
return this.restartCount;
|
|
203
|
+
}
|
|
204
|
+
getWatchedFiles() {
|
|
205
|
+
var _a;
|
|
206
|
+
return ((_a = this.fileWatcher) === null || _a === void 0 ? void 0 : _a.getWatchedFiles()) || [];
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
exports.DevRunner = DevRunner;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.runServers = exports.runSequential = exports.runParallel = exports.run = void 0;
|
|
7
|
+
// src/index.ts - Updated version
|
|
8
|
+
const runner_1 = require("./runner");
|
|
9
|
+
const logger_1 = __importDefault(require("./logger"));
|
|
10
|
+
/**
|
|
11
|
+
* Run one or more commands in parallel or sequentially
|
|
12
|
+
*/
|
|
13
|
+
async function run(commands, options) {
|
|
14
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
15
|
+
const cmdArray = Array.isArray(commands) ? commands : [commands];
|
|
16
|
+
const runOptions = {
|
|
17
|
+
parallel: (_a = options === null || options === void 0 ? void 0 : options.parallel) !== null && _a !== void 0 ? _a : false,
|
|
18
|
+
maxParallel: options === null || options === void 0 ? void 0 : options.maxParallel,
|
|
19
|
+
printOutput: (_b = options === null || options === void 0 ? void 0 : options.printOutput) !== null && _b !== void 0 ? _b : true,
|
|
20
|
+
color: (_c = options === null || options === void 0 ? void 0 : options.color) !== null && _c !== void 0 ? _c : true,
|
|
21
|
+
showTiming: (_d = options === null || options === void 0 ? void 0 : options.showTiming) !== null && _d !== void 0 ? _d : true,
|
|
22
|
+
prefix: (_e = options === null || options === void 0 ? void 0 : options.prefix) !== null && _e !== void 0 ? _e : true,
|
|
23
|
+
stopOnError: (_f = options === null || options === void 0 ? void 0 : options.stopOnError) !== null && _f !== void 0 ? _f : false,
|
|
24
|
+
minimalOutput: (_g = options === null || options === void 0 ? void 0 : options.minimalOutput) !== null && _g !== void 0 ? _g : false,
|
|
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
|
|
29
|
+
};
|
|
30
|
+
const runner = new runner_1.Runner(runOptions);
|
|
31
|
+
if (options === null || options === void 0 ? void 0 : options.registerCleanup) {
|
|
32
|
+
options.registerCleanup(() => runner.cleanup());
|
|
33
|
+
}
|
|
34
|
+
const results = await runner.run(cmdArray);
|
|
35
|
+
if (runOptions.printOutput && cmdArray.length > 1) {
|
|
36
|
+
logger_1.default.printSummary(results);
|
|
37
|
+
}
|
|
38
|
+
return results;
|
|
39
|
+
}
|
|
40
|
+
exports.run = run;
|
|
41
|
+
/**
|
|
42
|
+
* Run multiple commands in parallel
|
|
43
|
+
*/
|
|
44
|
+
async function runParallel(commands, options) {
|
|
45
|
+
return run(commands, { ...options, parallel: true });
|
|
46
|
+
}
|
|
47
|
+
exports.runParallel = runParallel;
|
|
48
|
+
/**
|
|
49
|
+
* Run multiple commands sequentially
|
|
50
|
+
*/
|
|
51
|
+
async function runSequential(commands, options) {
|
|
52
|
+
return run(commands, { ...options, parallel: false });
|
|
53
|
+
}
|
|
54
|
+
exports.runSequential = runSequential;
|
|
55
|
+
/**
|
|
56
|
+
* Run multiple servers with optimized output
|
|
57
|
+
*/
|
|
58
|
+
async function runServers(commands, options) {
|
|
59
|
+
return run(commands, {
|
|
60
|
+
...options,
|
|
61
|
+
parallel: true,
|
|
62
|
+
isServerMode: true,
|
|
63
|
+
printOutput: true
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
exports.runServers = runServers;
|
|
67
|
+
exports.default = {
|
|
68
|
+
run,
|
|
69
|
+
runParallel,
|
|
70
|
+
runSequential,
|
|
71
|
+
runServers
|
|
72
|
+
};
|
|
@@ -7,6 +7,7 @@ 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");
|
|
10
11
|
class Logger {
|
|
11
12
|
constructor() {
|
|
12
13
|
this.prefixLength = 0;
|
|
@@ -120,6 +121,9 @@ class Logger {
|
|
|
120
121
|
// Clear buffer after printing
|
|
121
122
|
this.outputBuffer.set(command, []);
|
|
122
123
|
}
|
|
124
|
+
clearBuffer(command) {
|
|
125
|
+
this.outputBuffer.set(command, []);
|
|
126
|
+
}
|
|
123
127
|
printLine(message, level = 'info') {
|
|
124
128
|
if (level === 'error') {
|
|
125
129
|
console.error(chalk_1.default.red(`${figures_1.default.cross} ${message}`));
|
|
@@ -136,6 +140,12 @@ class Logger {
|
|
|
136
140
|
this.startTimes.set(command, new Date());
|
|
137
141
|
const prefix = this.formatPrefix(command);
|
|
138
142
|
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
|
+
}
|
|
139
149
|
console.log(`${prefix} ${color('Starting...')}`);
|
|
140
150
|
// Start spinner for this command
|
|
141
151
|
this.startSpinner(command);
|
|
@@ -197,6 +207,32 @@ class Logger {
|
|
|
197
207
|
console.error(`${prefix} ${chalk_1.default.red(error.message)}`);
|
|
198
208
|
}
|
|
199
209
|
}
|
|
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
|
+
}
|
|
200
236
|
printSummary(results) {
|
|
201
237
|
// Stop any remaining spinners
|
|
202
238
|
this.stopAllSpinners();
|
|
@@ -235,4 +271,3 @@ class Logger {
|
|
|
235
271
|
}
|
|
236
272
|
}
|
|
237
273
|
exports.default = Logger.getInstance();
|
|
238
|
-
//# sourceMappingURL=logger.js.map
|