neex 0.3.7 → 0.3.8

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.
@@ -1,320 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.Runner = void 0;
30
- // src/runner.ts - Updated version
31
- const child_process_1 = require("child_process");
32
- const fsPromises = __importStar(require("fs/promises"));
33
- const path = __importStar(require("path"));
34
- const chalk_1 = __importDefault(require("chalk"));
35
- const logger_1 = __importDefault(require("./logger"));
36
- const p_map_1 = __importDefault(require("p-map"));
37
- const npm_run_path_1 = __importDefault(require("npm-run-path"));
38
- class Runner {
39
- constructor(options) {
40
- this.activeProcesses = new Map();
41
- this.serverInfo = new Map();
42
- this.portRegex = /listening on (?:port |http:\/\/localhost:|https:\/\/localhost:)(\d+)/i;
43
- this.urlRegex = /(https?:\/\/localhost:[0-9]+(?:\/[^\s]*)?)/i;
44
- this.options = options;
45
- this.activeProcesses = new Map();
46
- }
47
- async resolveScriptAndCwd(scriptNameOrCommand, baseDir) {
48
- try {
49
- const packageJsonPath = path.join(baseDir, 'package.json');
50
- const packageJsonContent = await fsPromises.readFile(packageJsonPath, 'utf-8');
51
- const packageJson = JSON.parse(packageJsonContent);
52
- if (packageJson.scripts && packageJson.scripts[scriptNameOrCommand]) {
53
- const scriptValue = packageJson.scripts[scriptNameOrCommand];
54
- const cdMatch = scriptValue.match(/^cd\s+([^&]+)\s+&&\s+(.*)$/);
55
- if (cdMatch) {
56
- const dir = cdMatch[1];
57
- const commandToExecute = cdMatch[2];
58
- const targetCwd = path.resolve(baseDir, dir);
59
- return { executableCommand: commandToExecute, executionCwd: targetCwd };
60
- }
61
- else {
62
- // It's a script from package.json, but no 'cd ... && ...' pattern
63
- return { executableCommand: scriptValue, executionCwd: baseDir };
64
- }
65
- }
66
- }
67
- catch (error) {
68
- // Errors like package.json not found, or script not in package.json
69
- // Will treat as direct command
70
- }
71
- return { executableCommand: scriptNameOrCommand, executionCwd: undefined };
72
- }
73
- detectServerInfo(command, data) {
74
- if (!this.options.isServerMode)
75
- return;
76
- // Get or create server info
77
- let serverInfo = this.serverInfo.get(command);
78
- if (!serverInfo) {
79
- serverInfo = {
80
- name: command,
81
- status: 'starting'
82
- };
83
- this.serverInfo.set(command, serverInfo);
84
- }
85
- // Try to detect port from output
86
- const portMatch = data.match(this.portRegex);
87
- if (portMatch && portMatch[1]) {
88
- serverInfo.port = parseInt(portMatch[1], 10);
89
- serverInfo.status = 'running';
90
- // Only log if we just discovered the port
91
- if (!serverInfo.url) {
92
- logger_1.default.printLine(`Server ${command} running on port ${serverInfo.port}`, 'info');
93
- }
94
- }
95
- // Try to detect full URL from output
96
- const urlMatch = data.match(this.urlRegex);
97
- if (urlMatch && urlMatch[1]) {
98
- serverInfo.url = urlMatch[1];
99
- serverInfo.status = 'running';
100
- // Log the full URL once we detect it
101
- logger_1.default.printLine(`Server ${command} available at ${chalk_1.default.cyan(serverInfo.url)}`, 'info');
102
- }
103
- // Update server info
104
- this.serverInfo.set(command, serverInfo);
105
- }
106
- async runCommand(originalCommand) {
107
- const { executableCommand: command, executionCwd: cwd } = await this.resolveScriptAndCwd(originalCommand, process.cwd());
108
- const startTime = new Date();
109
- const result = {
110
- command: originalCommand,
111
- success: false,
112
- code: null,
113
- startTime,
114
- endTime: null,
115
- output: []
116
- };
117
- if (this.options.printOutput) {
118
- logger_1.default.printStart(originalCommand);
119
- }
120
- return new Promise((resolve) => {
121
- const [cmd, ...args] = command.split(' ');
122
- const env = {
123
- ...process.env,
124
- ...npm_run_path_1.default.env(),
125
- FORCE_COLOR: this.options.color ? '1' : '0'
126
- };
127
- const proc = (0, child_process_1.spawn)(cmd, args, {
128
- stdio: ['ignore', 'pipe', 'pipe'],
129
- shell: true,
130
- env,
131
- detached: true,
132
- cwd
133
- });
134
- this.activeProcesses.set(originalCommand, proc);
135
- if (this.options.isServerMode) {
136
- this.serverInfo.set(originalCommand, {
137
- name: originalCommand,
138
- status: 'starting',
139
- pid: proc.pid,
140
- startTime: new Date()
141
- });
142
- }
143
- // Capture and display output
144
- if (this.options.printOutput) {
145
- proc.stdout.on('data', (data) => {
146
- const output = {
147
- command: originalCommand,
148
- type: 'stdout',
149
- data: data.toString(),
150
- timestamp: new Date()
151
- };
152
- if (this.options.isServerMode) {
153
- this.detectServerInfo(originalCommand, data.toString());
154
- }
155
- // Store output for logging
156
- if (result.output)
157
- result.output.push(output);
158
- logger_1.default.bufferOutput(output);
159
- // Print immediately unless we're in group mode
160
- if (!this.options.groupOutput) {
161
- logger_1.default.printBuffer(originalCommand);
162
- }
163
- });
164
- proc.stderr.on('data', (data) => {
165
- const output = {
166
- command: originalCommand,
167
- type: 'stderr',
168
- data: data.toString(),
169
- timestamp: new Date()
170
- };
171
- // Store output for logging
172
- if (result.output)
173
- result.output.push(output);
174
- logger_1.default.bufferOutput(output);
175
- // Print immediately unless we're in group mode
176
- if (!this.options.groupOutput) {
177
- logger_1.default.printBuffer(originalCommand);
178
- }
179
- });
180
- }
181
- proc.on('close', (code) => {
182
- const endTime = new Date();
183
- const duration = endTime.getTime() - startTime.getTime();
184
- result.endTime = endTime;
185
- result.duration = duration;
186
- result.code = code;
187
- result.success = code === 0;
188
- this.activeProcesses.delete(originalCommand);
189
- if (this.options.isServerMode) {
190
- const serverInfo = this.serverInfo.get(originalCommand);
191
- if (serverInfo) {
192
- serverInfo.status = code === 0 ? 'stopped' : 'error';
193
- this.serverInfo.set(originalCommand, serverInfo);
194
- }
195
- // If this is server mode and a server failed, print prominent error
196
- if (code !== 0) {
197
- logger_1.default.printLine(`Server ${originalCommand} crashed with code ${code}`, 'error');
198
- }
199
- }
200
- // Print grouped output at the end if enabled
201
- if (this.options.groupOutput && result.output && result.output.length > 0) {
202
- logger_1.default.printBuffer(originalCommand);
203
- }
204
- if (this.options.printOutput) {
205
- if (result.success) {
206
- logger_1.default.printSuccess(result);
207
- }
208
- else {
209
- logger_1.default.printError(result);
210
- }
211
- }
212
- resolve(result);
213
- });
214
- proc.on('error', (error) => {
215
- const endTime = new Date();
216
- const duration = endTime.getTime() - startTime.getTime();
217
- result.endTime = endTime;
218
- result.duration = duration;
219
- result.error = error;
220
- result.success = false;
221
- this.activeProcesses.delete(originalCommand);
222
- if (this.options.isServerMode) {
223
- const serverInfo = this.serverInfo.get(originalCommand);
224
- if (serverInfo) {
225
- serverInfo.status = 'error';
226
- this.serverInfo.set(originalCommand, serverInfo);
227
- }
228
- }
229
- if (this.options.printOutput) {
230
- logger_1.default.printError(result);
231
- }
232
- resolve(result);
233
- });
234
- });
235
- }
236
- async runSequential(commands) {
237
- const results = [];
238
- for (const cmd of commands) {
239
- const result = await this.runCommand(cmd);
240
- results.push(result);
241
- // Stop on error if enabled
242
- if (!result.success && this.options.stopOnError) {
243
- break;
244
- }
245
- }
246
- return results;
247
- }
248
- async runParallel(commands) {
249
- const concurrency = this.options.maxParallel || commands.length;
250
- const mapper = async (cmd) => {
251
- return this.runCommand(cmd);
252
- };
253
- try {
254
- return await (0, p_map_1.default)(commands, mapper, {
255
- concurrency,
256
- stopOnError: this.options.stopOnError
257
- });
258
- }
259
- catch (error) {
260
- // If pMap stops due to stopOnError
261
- if (this.options.isServerMode) {
262
- logger_1.default.printLine('One or more servers failed to start. Stopping all servers.', 'error');
263
- }
264
- return [];
265
- }
266
- }
267
- async run(commands) {
268
- if (commands.length === 0) {
269
- return [];
270
- }
271
- // Set up logger with commands
272
- logger_1.default.setCommands(commands);
273
- // Run in parallel or sequential mode
274
- if (this.options.parallel) {
275
- if (this.options.isServerMode) {
276
- logger_1.default.printLine('Starting servers in parallel mode', 'info');
277
- }
278
- return this.runParallel(commands);
279
- }
280
- else {
281
- if (this.options.isServerMode) {
282
- logger_1.default.printLine('Starting servers in sequential mode', 'info');
283
- }
284
- return this.runSequential(commands);
285
- }
286
- }
287
- cleanup(signal = 'SIGTERM') {
288
- logger_1.default.printLine('Cleaning up child processes...', 'warn');
289
- this.activeProcesses.forEach((proc, command) => {
290
- if (proc.pid && !proc.killed) {
291
- try {
292
- // Kill process group
293
- process.kill(-proc.pid, signal);
294
- logger_1.default.printLine(`Sent ${signal} to process group ${proc.pid} (${command})`, 'info');
295
- }
296
- catch (e) {
297
- // Fallback if killing group failed
298
- try {
299
- proc.kill(signal);
300
- logger_1.default.printLine(`Sent ${signal} to process ${proc.pid} (${command})`, 'info');
301
- }
302
- catch (errInner) {
303
- logger_1.default.printLine(`Failed to kill process ${proc.pid} (${command}): ${errInner.message}`, 'error');
304
- }
305
- }
306
- }
307
- });
308
- this.activeProcesses.clear();
309
- // Print server status summary if in server mode
310
- if (this.options.isServerMode && this.serverInfo.size > 0) {
311
- logger_1.default.printLine('Server shutdown summary:', 'info');
312
- this.serverInfo.forEach((info, command) => {
313
- const statusColor = info.status === 'running' ? chalk_1.default.green :
314
- info.status === 'error' ? chalk_1.default.red : chalk_1.default.yellow;
315
- logger_1.default.printLine(` ${command}: ${statusColor(info.status)}`, 'info');
316
- });
317
- }
318
- }
319
- }
320
- exports.Runner = Runner;
package/dist/src/types.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });