neex 0.6.17 → 0.6.20
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/dist/src/build-manager.js +340 -0
- package/dist/src/cli.js +4 -2
- package/dist/src/commands/build-commands.js +227 -0
- package/dist/src/commands/dev-commands.js +26 -20
- package/dist/src/commands/index.js +2 -1
- package/dist/src/commands/start-commands.js +178 -0
- package/dist/src/dev-runner.js +54 -17
- package/dist/src/start-manager.js +384 -0
- package/package.json +1 -1
|
@@ -0,0 +1,340 @@
|
|
|
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.BuildManager = void 0;
|
|
30
|
+
// src/build-manager.ts - Build manager with file watching and compilation
|
|
31
|
+
const watcher_1 = require("./watcher");
|
|
32
|
+
const runner_1 = require("./runner");
|
|
33
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
34
|
+
const figures_1 = __importDefault(require("figures"));
|
|
35
|
+
const logger_1 = __importDefault(require("./logger"));
|
|
36
|
+
const path = __importStar(require("path"));
|
|
37
|
+
const fs = __importStar(require("fs/promises"));
|
|
38
|
+
class BuildManager {
|
|
39
|
+
constructor(options) {
|
|
40
|
+
this.isBuilding = false;
|
|
41
|
+
this.buildCount = 0;
|
|
42
|
+
this.startTime = new Date();
|
|
43
|
+
const defaultOptions = {
|
|
44
|
+
parallel: false,
|
|
45
|
+
printOutput: true,
|
|
46
|
+
color: true,
|
|
47
|
+
showTiming: true,
|
|
48
|
+
prefix: true,
|
|
49
|
+
stopOnError: false,
|
|
50
|
+
minimalOutput: false,
|
|
51
|
+
groupOutput: false,
|
|
52
|
+
isServerMode: false,
|
|
53
|
+
watch: false,
|
|
54
|
+
ignore: [
|
|
55
|
+
'node_modules/**',
|
|
56
|
+
'.git/**',
|
|
57
|
+
'*.log',
|
|
58
|
+
'dist/**',
|
|
59
|
+
'build/**',
|
|
60
|
+
'coverage/**',
|
|
61
|
+
'.nyc_output/**',
|
|
62
|
+
'*.tmp',
|
|
63
|
+
'*.temp'
|
|
64
|
+
],
|
|
65
|
+
delay: 1000,
|
|
66
|
+
verbose: false,
|
|
67
|
+
showInfo: false,
|
|
68
|
+
runnerName: 'neex build',
|
|
69
|
+
clean: false,
|
|
70
|
+
sourceMap: false,
|
|
71
|
+
target: 'es2020',
|
|
72
|
+
module: 'commonjs'
|
|
73
|
+
};
|
|
74
|
+
this.options = {
|
|
75
|
+
...defaultOptions,
|
|
76
|
+
...options
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
setupFileWatcher() {
|
|
80
|
+
if (!this.options.watch) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const inputDir = path.dirname(this.options.inputFile);
|
|
84
|
+
const watchOptions = {
|
|
85
|
+
watch: [inputDir],
|
|
86
|
+
ignore: this.options.ignore,
|
|
87
|
+
ext: this.options.buildType === 'typescript' ? ['ts', 'tsx'] : ['js', 'jsx', 'mjs', 'cjs'],
|
|
88
|
+
delay: this.options.delay,
|
|
89
|
+
verbose: this.options.verbose && this.options.showInfo
|
|
90
|
+
};
|
|
91
|
+
this.fileWatcher = new watcher_1.FileWatcher(watchOptions);
|
|
92
|
+
this.fileWatcher.on('change', (event) => {
|
|
93
|
+
if (this.options.watch && !this.isBuilding) {
|
|
94
|
+
this.handleFileChange(event);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
async handleFileChange(event) {
|
|
99
|
+
const prefix = chalk_1.default.cyan(`[${this.options.runnerName}]`);
|
|
100
|
+
if (this.options.showInfo) {
|
|
101
|
+
logger_1.default.printLine(`${prefix} File changed: ${chalk_1.default.yellow(event.relativePath)}`, 'info');
|
|
102
|
+
}
|
|
103
|
+
await this.rebuild();
|
|
104
|
+
}
|
|
105
|
+
async ensureOutputDirectory() {
|
|
106
|
+
try {
|
|
107
|
+
await fs.mkdir(this.options.outputDir, { recursive: true });
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
if (this.options.showInfo) {
|
|
111
|
+
logger_1.default.printLine(`Failed to create output directory: ${error.message}`, 'error');
|
|
112
|
+
}
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async cleanOutputDirectory() {
|
|
117
|
+
if (!this.options.clean) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
await fs.rm(this.options.outputDir, { recursive: true, force: true });
|
|
122
|
+
if (this.options.showInfo) {
|
|
123
|
+
const prefix = chalk_1.default.cyan(`[${this.options.runnerName}]`);
|
|
124
|
+
logger_1.default.printLine(`${prefix} Cleaned output directory: ${chalk_1.default.yellow(this.options.outputDir)}`, 'info');
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
if (this.options.showInfo) {
|
|
129
|
+
logger_1.default.printLine(`Failed to clean output directory: ${error.message}`, 'error');
|
|
130
|
+
}
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
generateBuildCommand() {
|
|
135
|
+
const { inputFile, outputDir, buildType, sourceMap, target, module } = this.options;
|
|
136
|
+
switch (buildType) {
|
|
137
|
+
case 'typescript':
|
|
138
|
+
let tsCommand = `npx tsc ${inputFile} --outDir ${outputDir} --target ${target} --module ${module} --moduleResolution node --esModuleInterop --allowSyntheticDefaultImports --strict --skipLibCheck`;
|
|
139
|
+
if (sourceMap) {
|
|
140
|
+
tsCommand += ' --sourceMap';
|
|
141
|
+
}
|
|
142
|
+
return tsCommand;
|
|
143
|
+
case 'javascript':
|
|
144
|
+
case 'copy':
|
|
145
|
+
return `cp ${inputFile} ${path.join(outputDir, path.basename(inputFile))}`;
|
|
146
|
+
default:
|
|
147
|
+
return `cp ${inputFile} ${path.join(outputDir, path.basename(inputFile))}`;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
async runBuild() {
|
|
151
|
+
const buildCommand = this.generateBuildCommand();
|
|
152
|
+
// Create a modified options object for the runner
|
|
153
|
+
const runnerOptions = {
|
|
154
|
+
...this.options,
|
|
155
|
+
customPrefix: () => `build`
|
|
156
|
+
};
|
|
157
|
+
this.runner = new runner_1.Runner(runnerOptions);
|
|
158
|
+
try {
|
|
159
|
+
this.isBuilding = true;
|
|
160
|
+
this.buildCount++;
|
|
161
|
+
this.lastBuildTime = new Date();
|
|
162
|
+
// Ensure output directory exists
|
|
163
|
+
await this.ensureOutputDirectory();
|
|
164
|
+
// Clean if requested
|
|
165
|
+
if (this.options.clean && this.buildCount === 1) {
|
|
166
|
+
await this.cleanOutputDirectory();
|
|
167
|
+
await this.ensureOutputDirectory();
|
|
168
|
+
}
|
|
169
|
+
const results = await this.runner.run([buildCommand]);
|
|
170
|
+
// Handle build results
|
|
171
|
+
const success = results.every(result => result.success);
|
|
172
|
+
const prefix = chalk_1.default.cyan(`[${this.options.runnerName}]`);
|
|
173
|
+
if (success) {
|
|
174
|
+
if (this.options.showInfo) {
|
|
175
|
+
logger_1.default.printLine(`${prefix} ${chalk_1.default.green(`${figures_1.default.tick} Build completed successfully`)}`, 'info');
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
if (this.options.showInfo) {
|
|
180
|
+
logger_1.default.printLine(`${prefix} ${chalk_1.default.red(`${figures_1.default.cross} Build failed`)}`, 'error');
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return results;
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
if (this.options.showInfo) {
|
|
187
|
+
logger_1.default.printLine(`Build failed: ${error.message}`, 'error');
|
|
188
|
+
}
|
|
189
|
+
return [];
|
|
190
|
+
}
|
|
191
|
+
finally {
|
|
192
|
+
this.isBuilding = false;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
printBuildBanner() {
|
|
196
|
+
var _a;
|
|
197
|
+
if (!this.options.showInfo) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const prefix = chalk_1.default.cyan(`[${this.options.runnerName}]`);
|
|
201
|
+
const uptime = Math.floor((Date.now() - this.startTime.getTime()) / 1000);
|
|
202
|
+
const uptimeStr = this.formatUptime(uptime);
|
|
203
|
+
console.log('\n' + chalk_1.default.bgBlue.black(` ${(_a = this.options.runnerName) === null || _a === void 0 ? void 0 : _a.toUpperCase()} MODE `) + '\n');
|
|
204
|
+
if (this.buildCount > 0) {
|
|
205
|
+
console.log(`${prefix} ${chalk_1.default.green(`${figures_1.default.tick} Build #${this.buildCount}`)}`);
|
|
206
|
+
}
|
|
207
|
+
console.log(`${prefix} ${chalk_1.default.blue(`${figures_1.default.info} Uptime: ${uptimeStr}`)}`);
|
|
208
|
+
console.log(`${prefix} ${chalk_1.default.blue(`${figures_1.default.info} Input: ${this.options.inputFile}`)}`);
|
|
209
|
+
console.log(`${prefix} ${chalk_1.default.blue(`${figures_1.default.info} Output: ${this.options.outputDir}`)}`);
|
|
210
|
+
console.log(`${prefix} ${chalk_1.default.blue(`${figures_1.default.info} Build type: ${this.options.buildType}`)}`);
|
|
211
|
+
if (this.options.watch) {
|
|
212
|
+
console.log(`${prefix} ${chalk_1.default.blue(`${figures_1.default.info} Watching for changes...`)}`);
|
|
213
|
+
}
|
|
214
|
+
console.log('');
|
|
215
|
+
}
|
|
216
|
+
formatUptime(seconds) {
|
|
217
|
+
if (seconds < 60) {
|
|
218
|
+
return `${seconds}s`;
|
|
219
|
+
}
|
|
220
|
+
else if (seconds < 3600) {
|
|
221
|
+
const minutes = Math.floor(seconds / 60);
|
|
222
|
+
const remainingSeconds = seconds % 60;
|
|
223
|
+
return `${minutes}m ${remainingSeconds}s`;
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
const hours = Math.floor(seconds / 3600);
|
|
227
|
+
const minutes = Math.floor((seconds % 3600) / 60);
|
|
228
|
+
return `${hours}h ${minutes}m`;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
async start() {
|
|
232
|
+
this.startTime = new Date();
|
|
233
|
+
// Setup file watcher if watch mode is enabled
|
|
234
|
+
if (this.options.watch) {
|
|
235
|
+
this.setupFileWatcher();
|
|
236
|
+
}
|
|
237
|
+
// Print build banner only if showInfo is true
|
|
238
|
+
this.printBuildBanner();
|
|
239
|
+
// Start file watcher if enabled
|
|
240
|
+
if (this.fileWatcher) {
|
|
241
|
+
await this.fileWatcher.start();
|
|
242
|
+
}
|
|
243
|
+
// Run initial build
|
|
244
|
+
const prefix = chalk_1.default.cyan(`[${this.options.runnerName}]`);
|
|
245
|
+
if (this.options.showInfo) {
|
|
246
|
+
logger_1.default.printLine(`${prefix} Starting build process...`, 'info');
|
|
247
|
+
}
|
|
248
|
+
await this.runBuild();
|
|
249
|
+
// Set up graceful shutdown
|
|
250
|
+
this.setupGracefulShutdown();
|
|
251
|
+
if (this.options.watch) {
|
|
252
|
+
if (this.options.showInfo) {
|
|
253
|
+
logger_1.default.printLine(`${prefix} Build completed. Watching for changes...`, 'info');
|
|
254
|
+
logger_1.default.printLine(`${prefix} Press ${chalk_1.default.cyan('Ctrl+C')} to stop`, 'info');
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
if (this.options.showInfo) {
|
|
259
|
+
logger_1.default.printLine(`${prefix} Build process completed`, 'info');
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
async rebuild() {
|
|
264
|
+
const prefix = chalk_1.default.cyan(`[${this.options.runnerName}]`);
|
|
265
|
+
if (this.isBuilding) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
if (this.options.showInfo) {
|
|
269
|
+
logger_1.default.printLine(`${prefix} Rebuilding due to file changes...`, 'info');
|
|
270
|
+
}
|
|
271
|
+
// Stop current processes
|
|
272
|
+
if (this.runner) {
|
|
273
|
+
this.runner.cleanup('SIGTERM');
|
|
274
|
+
}
|
|
275
|
+
// Wait a moment before rebuilding
|
|
276
|
+
await new Promise(resolve => setTimeout(resolve, 500));
|
|
277
|
+
// Print rebuild banner only if showInfo is true
|
|
278
|
+
this.printBuildBanner();
|
|
279
|
+
// Run build again
|
|
280
|
+
await this.runBuild();
|
|
281
|
+
if (this.options.showInfo) {
|
|
282
|
+
logger_1.default.printLine(`${prefix} Rebuild completed. Watching for changes...`, 'info');
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
async stop() {
|
|
286
|
+
const prefix = chalk_1.default.cyan(`[${this.options.runnerName}]`);
|
|
287
|
+
if (!this.isBuilding && !this.options.watch) {
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
if (this.options.showInfo) {
|
|
291
|
+
logger_1.default.printLine(`${prefix} Stopping build process...`, 'info');
|
|
292
|
+
}
|
|
293
|
+
// Stop file watcher
|
|
294
|
+
if (this.fileWatcher) {
|
|
295
|
+
this.fileWatcher.stop();
|
|
296
|
+
}
|
|
297
|
+
// Stop current processes
|
|
298
|
+
if (this.runner) {
|
|
299
|
+
this.runner.cleanup('SIGTERM');
|
|
300
|
+
}
|
|
301
|
+
const uptime = Math.floor((Date.now() - this.startTime.getTime()) / 1000);
|
|
302
|
+
const uptimeStr = this.formatUptime(uptime);
|
|
303
|
+
if (this.options.showInfo) {
|
|
304
|
+
logger_1.default.printLine(`${prefix} Build process stopped after ${uptimeStr}`, 'info');
|
|
305
|
+
if (this.buildCount > 0) {
|
|
306
|
+
logger_1.default.printLine(`${prefix} Total builds: ${this.buildCount}`, 'info');
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
setupGracefulShutdown() {
|
|
311
|
+
const handleSignal = (signal) => {
|
|
312
|
+
if (this.options.showInfo) {
|
|
313
|
+
console.log(`\n${chalk_1.default.yellow(`${figures_1.default.warning} Received ${signal}. Shutting down build process...`)}`);
|
|
314
|
+
}
|
|
315
|
+
this.stop().then(() => {
|
|
316
|
+
process.exit(0);
|
|
317
|
+
});
|
|
318
|
+
};
|
|
319
|
+
process.on('SIGINT', () => handleSignal('SIGINT'));
|
|
320
|
+
process.on('SIGTERM', () => handleSignal('SIGTERM'));
|
|
321
|
+
process.on('SIGQUIT', () => handleSignal('SIGQUIT'));
|
|
322
|
+
}
|
|
323
|
+
isActive() {
|
|
324
|
+
return this.isBuilding || (this.options.watch || false);
|
|
325
|
+
}
|
|
326
|
+
getUptime() {
|
|
327
|
+
return Math.floor((Date.now() - this.startTime.getTime()) / 1000);
|
|
328
|
+
}
|
|
329
|
+
getBuildCount() {
|
|
330
|
+
return this.buildCount;
|
|
331
|
+
}
|
|
332
|
+
getLastBuildTime() {
|
|
333
|
+
return this.lastBuildTime;
|
|
334
|
+
}
|
|
335
|
+
getWatchedFiles() {
|
|
336
|
+
var _a;
|
|
337
|
+
return ((_a = this.fileWatcher) === null || _a === void 0 ? void 0 : _a.getWatchedFiles()) || [];
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
exports.BuildManager = BuildManager;
|
package/dist/src/cli.js
CHANGED
|
@@ -22,8 +22,10 @@ function cli() {
|
|
|
22
22
|
(0, index_js_1.addServerCommands)(program);
|
|
23
23
|
const devCommands = (0, index_js_1.addDevCommands)(program);
|
|
24
24
|
cleanupHandlers.push(devCommands.cleanupDev);
|
|
25
|
-
const
|
|
26
|
-
cleanupHandlers.push(
|
|
25
|
+
const buildCommands = (0, index_js_1.addBuildCommands)(program);
|
|
26
|
+
cleanupHandlers.push(buildCommands.cleanupBuild);
|
|
27
|
+
const startCommands = (0, index_js_1.addStartCommands)(program);
|
|
28
|
+
cleanupHandlers.push(startCommands.cleanupStart);
|
|
27
29
|
program.parse(process.argv);
|
|
28
30
|
// Show help if no commands specified
|
|
29
31
|
if (program.args.length === 0) {
|
|
@@ -0,0 +1,227 @@
|
|
|
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.addBuildCommands = void 0;
|
|
30
|
+
const build_manager_js_1 = require("../build-manager.js");
|
|
31
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
32
|
+
const figures_1 = __importDefault(require("figures"));
|
|
33
|
+
const path = __importStar(require("path"));
|
|
34
|
+
const fs = __importStar(require("fs/promises"));
|
|
35
|
+
// Helper function to check if file exists
|
|
36
|
+
async function fileExists(filePath) {
|
|
37
|
+
try {
|
|
38
|
+
await fs.access(filePath);
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
catch (_a) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// Helper function to determine build configuration
|
|
46
|
+
async function getBuildConfig(filePath, outputDir, showInfo) {
|
|
47
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
48
|
+
const absolutePath = path.resolve(process.cwd(), filePath);
|
|
49
|
+
const fileName = path.basename(filePath, ext);
|
|
50
|
+
const outputPath = path.resolve(process.cwd(), outputDir);
|
|
51
|
+
// Check if file exists
|
|
52
|
+
if (!(await fileExists(absolutePath))) {
|
|
53
|
+
throw new Error(`File not found: ${filePath}`);
|
|
54
|
+
}
|
|
55
|
+
if (showInfo) {
|
|
56
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} neex build: Analyzing ${chalk_1.default.cyan(path.basename(filePath))}`));
|
|
57
|
+
}
|
|
58
|
+
switch (ext) {
|
|
59
|
+
case '.ts':
|
|
60
|
+
case '.mts':
|
|
61
|
+
case '.cts':
|
|
62
|
+
if (showInfo) {
|
|
63
|
+
console.log(chalk_1.default.green(`${figures_1.default.tick} neex build: TypeScript detected, compiling to JavaScript`));
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
inputFile: absolutePath,
|
|
67
|
+
outputFile: path.join(outputPath, `${fileName}.js`),
|
|
68
|
+
buildCommand: `npx tsc ${filePath} --outDir ${outputDir} --target es2020 --module commonjs --moduleResolution node --esModuleInterop --allowSyntheticDefaultImports --strict --skipLibCheck`,
|
|
69
|
+
buildType: 'typescript'
|
|
70
|
+
};
|
|
71
|
+
case '.js':
|
|
72
|
+
case '.mjs':
|
|
73
|
+
case '.cjs':
|
|
74
|
+
if (showInfo) {
|
|
75
|
+
console.log(chalk_1.default.green(`${figures_1.default.tick} neex build: JavaScript detected, copying to output directory`));
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
inputFile: absolutePath,
|
|
79
|
+
outputFile: path.join(outputPath, path.basename(filePath)),
|
|
80
|
+
buildCommand: `cp ${filePath} ${path.join(outputDir, path.basename(filePath))}`,
|
|
81
|
+
buildType: 'copy'
|
|
82
|
+
};
|
|
83
|
+
default:
|
|
84
|
+
if (showInfo) {
|
|
85
|
+
console.log(chalk_1.default.yellow(`${figures_1.default.warning} neex build: Unknown file type, copying as-is`));
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
inputFile: absolutePath,
|
|
89
|
+
outputFile: path.join(outputPath, path.basename(filePath)),
|
|
90
|
+
buildCommand: `cp ${filePath} ${path.join(outputDir, path.basename(filePath))}`,
|
|
91
|
+
buildType: 'copy'
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function addBuildCommands(program) {
|
|
96
|
+
let buildManager = null;
|
|
97
|
+
// Build command - compile TypeScript/JavaScript projects
|
|
98
|
+
program
|
|
99
|
+
.command('build <file>') // Made file mandatory
|
|
100
|
+
.alias('b')
|
|
101
|
+
.description('Build TypeScript/JavaScript files for production')
|
|
102
|
+
.option('-o, --output <dir>', 'Output directory', 'dist')
|
|
103
|
+
.option('-c, --no-color', 'Disable colored output')
|
|
104
|
+
.option('-t, --no-timing', 'Hide timing information')
|
|
105
|
+
.option('-p, --no-prefix', 'Hide command prefix')
|
|
106
|
+
.option('-s, --stop-on-error', 'Stop on first error')
|
|
107
|
+
.option('-m, --minimal', 'Use minimal output format')
|
|
108
|
+
.option('-w, --watch', 'Watch for changes and rebuild')
|
|
109
|
+
.option('-i, --ignore <patterns...>', 'Patterns to ignore when watching')
|
|
110
|
+
.option('-d, --delay <ms>', 'Delay before rebuild in milliseconds', parseInt)
|
|
111
|
+
.option('--clean', 'Clean output directory before build')
|
|
112
|
+
.option('--verbose', 'Verbose output')
|
|
113
|
+
.option('--info', 'Show detailed information during build')
|
|
114
|
+
.option('--source-map', 'Generate source maps')
|
|
115
|
+
.option('--target <target>', 'Target ECMAScript version', 'es2020')
|
|
116
|
+
.option('--module <module>', 'Module system', 'commonjs')
|
|
117
|
+
.action(async (file, options) => {
|
|
118
|
+
try {
|
|
119
|
+
const showInfo = options.info || false;
|
|
120
|
+
if (showInfo) {
|
|
121
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} neex build: Starting build process...`));
|
|
122
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} neex build: Target file: ${chalk_1.default.cyan(file)}`));
|
|
123
|
+
}
|
|
124
|
+
// Validate file parameter
|
|
125
|
+
if (!file || file.trim() === '') {
|
|
126
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} neex build: Error - No file specified!`));
|
|
127
|
+
console.error(chalk_1.default.yellow(`${figures_1.default.pointer} Usage: neex build <file>`));
|
|
128
|
+
console.error(chalk_1.default.yellow(`${figures_1.default.pointer} Example: neex build src/server.ts`));
|
|
129
|
+
process.exit(1);
|
|
130
|
+
}
|
|
131
|
+
// Get build configuration
|
|
132
|
+
let buildConfig;
|
|
133
|
+
try {
|
|
134
|
+
buildConfig = await getBuildConfig(file, options.output, showInfo);
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} neex build: ${error instanceof Error ? error.message : 'Unknown error occurred'}`));
|
|
138
|
+
process.exit(1);
|
|
139
|
+
}
|
|
140
|
+
// Setup ignore patterns for watch mode
|
|
141
|
+
const ignorePatterns = options.ignore || [
|
|
142
|
+
'node_modules/**',
|
|
143
|
+
'.git/**',
|
|
144
|
+
'*.log',
|
|
145
|
+
'dist/**',
|
|
146
|
+
'build/**',
|
|
147
|
+
'coverage/**',
|
|
148
|
+
'.nyc_output/**',
|
|
149
|
+
'*.tmp',
|
|
150
|
+
'*.temp',
|
|
151
|
+
'.DS_Store',
|
|
152
|
+
'Thumbs.db'
|
|
153
|
+
];
|
|
154
|
+
// Log configuration only if --info flag is set
|
|
155
|
+
if (showInfo) {
|
|
156
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} neex build: Configuration:`));
|
|
157
|
+
console.log(chalk_1.default.blue(` ${figures_1.default.arrowRight} Input: ${chalk_1.default.cyan(file)}`));
|
|
158
|
+
console.log(chalk_1.default.blue(` ${figures_1.default.arrowRight} Output: ${chalk_1.default.cyan(options.output)}`));
|
|
159
|
+
console.log(chalk_1.default.blue(` ${figures_1.default.arrowRight} Build type: ${chalk_1.default.cyan(buildConfig.buildType)}`));
|
|
160
|
+
console.log(chalk_1.default.blue(` ${figures_1.default.arrowRight} Target: ${chalk_1.default.cyan(options.target)}`));
|
|
161
|
+
console.log(chalk_1.default.blue(` ${figures_1.default.arrowRight} Module: ${chalk_1.default.cyan(options.module)}`));
|
|
162
|
+
console.log(chalk_1.default.blue(` ${figures_1.default.arrowRight} Watch mode: ${chalk_1.default.cyan(options.watch ? 'Yes' : 'No')}`));
|
|
163
|
+
console.log(chalk_1.default.blue(` ${figures_1.default.arrowRight} Clean before build: ${chalk_1.default.cyan(options.clean ? 'Yes' : 'No')}`));
|
|
164
|
+
console.log(chalk_1.default.blue(` ${figures_1.default.arrowRight} Source maps: ${chalk_1.default.cyan(options.sourceMap ? 'Yes' : 'No')}`));
|
|
165
|
+
if (options.verbose) {
|
|
166
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} neex build: Verbose mode enabled - showing detailed logs`));
|
|
167
|
+
}
|
|
168
|
+
console.log(chalk_1.default.green(`${figures_1.default.tick} neex build: Starting build process...`));
|
|
169
|
+
console.log(chalk_1.default.gray(`${'='.repeat(60)}`));
|
|
170
|
+
}
|
|
171
|
+
// Create BuildManager instance
|
|
172
|
+
buildManager = new build_manager_js_1.BuildManager({
|
|
173
|
+
runnerName: 'neex build',
|
|
174
|
+
inputFile: file,
|
|
175
|
+
outputDir: options.output,
|
|
176
|
+
buildType: buildConfig.buildType,
|
|
177
|
+
buildCommand: buildConfig.buildCommand,
|
|
178
|
+
color: options.color,
|
|
179
|
+
showTiming: options.timing,
|
|
180
|
+
prefix: options.prefix,
|
|
181
|
+
stopOnError: options.stopOnError,
|
|
182
|
+
printOutput: true,
|
|
183
|
+
minimalOutput: options.minimal,
|
|
184
|
+
watch: options.watch,
|
|
185
|
+
ignore: ignorePatterns,
|
|
186
|
+
delay: options.delay || 1000,
|
|
187
|
+
verbose: options.verbose,
|
|
188
|
+
showInfo: showInfo,
|
|
189
|
+
clean: options.clean,
|
|
190
|
+
sourceMap: options.sourceMap,
|
|
191
|
+
target: options.target,
|
|
192
|
+
module: options.module,
|
|
193
|
+
parallel: false,
|
|
194
|
+
groupOutput: false,
|
|
195
|
+
isServerMode: false
|
|
196
|
+
});
|
|
197
|
+
// Start the build process
|
|
198
|
+
await buildManager.start();
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} neex build: Fatal error occurred`));
|
|
202
|
+
if (error instanceof Error) {
|
|
203
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} Details: ${error.message}`));
|
|
204
|
+
if (options.verbose && error.stack) {
|
|
205
|
+
console.error(chalk_1.default.gray(`Stack trace:\n${error.stack}`));
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} Unknown error occurred`));
|
|
210
|
+
}
|
|
211
|
+
console.error(chalk_1.default.yellow(`${figures_1.default.pointer} Try running with --verbose flag for more details`));
|
|
212
|
+
process.exit(1);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
// Return cleanup function for build manager
|
|
216
|
+
return {
|
|
217
|
+
getBuildManager: () => buildManager,
|
|
218
|
+
cleanupBuild: () => {
|
|
219
|
+
if (buildManager && buildManager.isActive()) {
|
|
220
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} neex build: Stopping build process...`));
|
|
221
|
+
buildManager.stop();
|
|
222
|
+
console.log(chalk_1.default.green(`${figures_1.default.tick} neex build: Build process stopped successfully`));
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
exports.addBuildCommands = addBuildCommands;
|
|
@@ -43,7 +43,7 @@ async function fileExists(filePath) {
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
// Helper function to determine the best command to run the file
|
|
46
|
-
async function getBestCommand(filePath, showInfo
|
|
46
|
+
async function getBestCommand(filePath, showInfo) {
|
|
47
47
|
const ext = path.extname(filePath).toLowerCase();
|
|
48
48
|
const absolutePath = path.resolve(process.cwd(), filePath);
|
|
49
49
|
// Check if file exists
|
|
@@ -94,12 +94,15 @@ function addDevCommands(program) {
|
|
|
94
94
|
.option('-d, --delay <ms>', 'Delay before restart in milliseconds', parseInt)
|
|
95
95
|
.option('--clear', 'Clear console on restart')
|
|
96
96
|
.option('--verbose', 'Verbose output')
|
|
97
|
-
.option('--info', 'Show detailed information
|
|
97
|
+
.option('--info', 'Show detailed information during startup')
|
|
98
98
|
.option('--signal <signal>', 'Signal to send to processes on restart', 'SIGTERM')
|
|
99
99
|
.action(async (file, options) => {
|
|
100
100
|
try {
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
const showInfo = options.info || false;
|
|
102
|
+
if (showInfo) {
|
|
103
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} neex dev: Starting enhanced development server...`));
|
|
104
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} neex dev: Target file: ${chalk_1.default.cyan(file)}`));
|
|
105
|
+
}
|
|
103
106
|
// Validate file parameter
|
|
104
107
|
if (!file || file.trim() === '') {
|
|
105
108
|
console.error(chalk_1.default.red(`${figures_1.default.cross} neex dev: Error - No file specified!`));
|
|
@@ -111,7 +114,7 @@ function addDevCommands(program) {
|
|
|
111
114
|
let commandToExecute;
|
|
112
115
|
let fileExtension;
|
|
113
116
|
try {
|
|
114
|
-
commandToExecute = await getBestCommand(file);
|
|
117
|
+
commandToExecute = await getBestCommand(file, showInfo);
|
|
115
118
|
fileExtension = path.extname(file).toLowerCase();
|
|
116
119
|
}
|
|
117
120
|
catch (error) {
|
|
@@ -134,19 +137,24 @@ function addDevCommands(program) {
|
|
|
134
137
|
'Thumbs.db'
|
|
135
138
|
];
|
|
136
139
|
const extensions = options.ext || ['js', 'mjs', 'json', 'ts', 'tsx', 'jsx', 'vue', 'svelte'];
|
|
137
|
-
// Log configuration
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
140
|
+
// Log configuration only if --info flag is set
|
|
141
|
+
if (showInfo) {
|
|
142
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} neex dev: Configuration:`));
|
|
143
|
+
console.log(chalk_1.default.blue(` ${figures_1.default.arrowRight} Target: ${chalk_1.default.cyan(file)}`));
|
|
144
|
+
console.log(chalk_1.default.blue(` ${figures_1.default.arrowRight} Runtime: ${chalk_1.default.cyan(fileExtension === '.ts' || fileExtension === '.mts' || fileExtension === '.cts' ? 'TypeScript' : 'JavaScript')}`));
|
|
145
|
+
console.log(chalk_1.default.blue(` ${figures_1.default.arrowRight} Watch paths: ${chalk_1.default.cyan(watchPaths.join(', '))}`));
|
|
146
|
+
console.log(chalk_1.default.blue(` ${figures_1.default.arrowRight} Extensions: ${chalk_1.default.cyan(extensions.join(', '))}`));
|
|
147
|
+
console.log(chalk_1.default.blue(` ${figures_1.default.arrowRight} Restart delay: ${chalk_1.default.cyan(options.delay || 1000)}ms`));
|
|
148
|
+
console.log(chalk_1.default.blue(` ${figures_1.default.arrowRight} Clear console: ${chalk_1.default.cyan(options.clear ? 'Yes' : 'No')}`));
|
|
149
|
+
if (options.verbose) {
|
|
150
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} neex dev: Verbose mode enabled - showing detailed logs`));
|
|
151
|
+
}
|
|
152
|
+
console.log(chalk_1.default.green(`${figures_1.default.tick} neex dev: Starting file watcher and process manager...`));
|
|
153
|
+
console.log(chalk_1.default.green(`${figures_1.default.tick} neex dev: Launching ${chalk_1.default.cyan(path.basename(file))} with auto-restart capability...`));
|
|
154
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} neex dev: Press Ctrl+C to stop the development server`));
|
|
155
|
+
console.log(chalk_1.default.gray(`${'='.repeat(60)}`));
|
|
147
156
|
}
|
|
148
|
-
|
|
149
|
-
// Create DevRunner instance - remove customPrefix since it doesn't exist
|
|
157
|
+
// Create DevRunner instance
|
|
150
158
|
devRunner = new dev_runner_js_1.DevRunner({
|
|
151
159
|
runnerName: 'neex dev',
|
|
152
160
|
parallel: false,
|
|
@@ -162,15 +170,13 @@ function addDevCommands(program) {
|
|
|
162
170
|
delay: options.delay || 1000,
|
|
163
171
|
clearConsole: options.clear,
|
|
164
172
|
verbose: options.verbose,
|
|
173
|
+
showInfo: showInfo,
|
|
165
174
|
signal: options.signal,
|
|
166
175
|
restartOnChange: true,
|
|
167
176
|
groupOutput: false,
|
|
168
177
|
isServerMode: false
|
|
169
178
|
});
|
|
170
179
|
// Start the development server
|
|
171
|
-
console.log(chalk_1.default.green(`${figures_1.default.tick} neex dev: Launching ${chalk_1.default.cyan(path.basename(file))} with auto-restart capability...`));
|
|
172
|
-
console.log(chalk_1.default.blue(`${figures_1.default.info} neex dev: Press Ctrl+C to stop the development server`));
|
|
173
|
-
console.log(chalk_1.default.gray(`${'='.repeat(60)}`));
|
|
174
180
|
await devRunner.start([commandToExecute]);
|
|
175
181
|
}
|
|
176
182
|
catch (error) {
|