neex 0.6.47 → 0.6.51
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 +69 -70
- package/dist/src/commands/build-commands.js +83 -13
- package/dist/src/commands/dev-commands.js +30 -134
- package/dist/src/commands/start-commands.js +219 -35
- package/dist/src/dev-manager.js +47 -151
- package/dist/src/start-manager.js +415 -80
- package/package.json +1 -1
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.BuildManager = void 0;
|
|
7
|
-
// src/build-manager.ts - Build manager for TypeScript projects using
|
|
7
|
+
// src/build-manager.ts - Build manager for TypeScript projects using tsc
|
|
8
8
|
const child_process_1 = require("child_process");
|
|
9
9
|
const chokidar_1 = require("chokidar");
|
|
10
10
|
const logger_manager_js_1 = require("./logger-manager.js");
|
|
@@ -19,7 +19,7 @@ class BuildManager {
|
|
|
19
19
|
this.buildProcess = null;
|
|
20
20
|
this.isBuilding = false;
|
|
21
21
|
this.buildCount = 0;
|
|
22
|
-
this.debouncedBuild = this.debounce(this.runBuild.bind(this),
|
|
22
|
+
this.debouncedBuild = this.debounce(this.runBuild.bind(this), 300);
|
|
23
23
|
this.options = options;
|
|
24
24
|
}
|
|
25
25
|
async cleanOutputDirectory() {
|
|
@@ -78,49 +78,28 @@ class BuildManager {
|
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
args.push('--sourcemap');
|
|
97
|
-
}
|
|
98
|
-
if (this.options.format === 'esm') {
|
|
99
|
-
args.push('--format', 'esm');
|
|
100
|
-
}
|
|
101
|
-
if (this.options.external.length > 0) {
|
|
102
|
-
args.push('--external', this.options.external.join(','));
|
|
103
|
-
}
|
|
104
|
-
return { command: 'tsx', args };
|
|
81
|
+
getTscCommand() {
|
|
82
|
+
const args = [
|
|
83
|
+
'--project',
|
|
84
|
+
this.options.tsconfig,
|
|
85
|
+
'--outDir',
|
|
86
|
+
this.options.output,
|
|
87
|
+
'--target',
|
|
88
|
+
this.options.target,
|
|
89
|
+
'--declaration'
|
|
90
|
+
];
|
|
91
|
+
if (this.options.sourcemap) {
|
|
92
|
+
args.push('--sourceMap');
|
|
93
|
+
}
|
|
94
|
+
if (this.options.format === 'esm') {
|
|
95
|
+
args.push('--module', 'es2020', '--moduleResolution', 'node');
|
|
105
96
|
}
|
|
106
97
|
else {
|
|
107
|
-
|
|
108
|
-
const args = [
|
|
109
|
-
'--project',
|
|
110
|
-
this.options.tsconfig,
|
|
111
|
-
'--outDir',
|
|
112
|
-
this.options.output,
|
|
113
|
-
'--target',
|
|
114
|
-
this.options.target
|
|
115
|
-
];
|
|
116
|
-
if (this.options.sourcemap) {
|
|
117
|
-
args.push('--sourceMap');
|
|
118
|
-
}
|
|
119
|
-
if (this.options.format === 'esm') {
|
|
120
|
-
args.push('--module', 'es2020');
|
|
121
|
-
}
|
|
122
|
-
return { command: 'tsc', args };
|
|
98
|
+
args.push('--module', 'commonjs');
|
|
123
99
|
}
|
|
100
|
+
// Always include these for better compatibility
|
|
101
|
+
args.push('--esModuleInterop', '--allowSyntheticDefaultImports', '--strict');
|
|
102
|
+
return { command: 'tsc', args };
|
|
124
103
|
}
|
|
125
104
|
async runBuild() {
|
|
126
105
|
if (this.isBuilding) {
|
|
@@ -135,31 +114,28 @@ class BuildManager {
|
|
|
135
114
|
}
|
|
136
115
|
try {
|
|
137
116
|
await this.ensureOutputDirectory();
|
|
138
|
-
const { command, args } = this.
|
|
117
|
+
const { command, args } = this.getTscCommand();
|
|
139
118
|
if (this.options.verbose) {
|
|
140
119
|
logger_manager_js_1.loggerManager.printLine(`Executing: ${command} ${args.join(' ')}`, 'info');
|
|
141
120
|
}
|
|
142
121
|
return new Promise((resolve, reject) => {
|
|
143
122
|
var _a, _b;
|
|
144
123
|
this.buildProcess = (0, child_process_1.spawn)(command, args, {
|
|
145
|
-
stdio:
|
|
124
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
146
125
|
shell: false,
|
|
147
126
|
env: {
|
|
148
127
|
...process.env,
|
|
149
|
-
FORCE_COLOR:
|
|
128
|
+
FORCE_COLOR: '0' // Disable TSC colors to avoid log pollution
|
|
150
129
|
}
|
|
151
130
|
});
|
|
131
|
+
let stdout = '';
|
|
152
132
|
let stderr = '';
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
133
|
+
// Capture all output but don't display TSC logs
|
|
134
|
+
(_a = this.buildProcess.stdout) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
|
|
135
|
+
stdout += data.toString();
|
|
136
|
+
});
|
|
158
137
|
(_b = this.buildProcess.stderr) === null || _b === void 0 ? void 0 : _b.on('data', (data) => {
|
|
159
138
|
stderr += data.toString();
|
|
160
|
-
if (this.options.verbose) {
|
|
161
|
-
process.stderr.write(data);
|
|
162
|
-
}
|
|
163
139
|
});
|
|
164
140
|
this.buildProcess.on('error', (error) => {
|
|
165
141
|
this.buildProcess = null;
|
|
@@ -182,11 +158,15 @@ class BuildManager {
|
|
|
182
158
|
resolve();
|
|
183
159
|
}
|
|
184
160
|
else {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
161
|
+
// Only show meaningful errors, filter out TSC verbosity
|
|
162
|
+
const meaningfulErrors = this.filterTscErrors(stderr);
|
|
163
|
+
if (meaningfulErrors) {
|
|
164
|
+
logger_manager_js_1.loggerManager.printLine(`Build failed:\n${meaningfulErrors}`, 'error');
|
|
188
165
|
}
|
|
189
|
-
|
|
166
|
+
else {
|
|
167
|
+
logger_manager_js_1.loggerManager.printLine(`Build failed with code ${code}`, 'error');
|
|
168
|
+
}
|
|
169
|
+
reject(new Error(`Build failed with code ${code}`));
|
|
190
170
|
}
|
|
191
171
|
});
|
|
192
172
|
});
|
|
@@ -196,14 +176,28 @@ class BuildManager {
|
|
|
196
176
|
throw error;
|
|
197
177
|
}
|
|
198
178
|
}
|
|
179
|
+
filterTscErrors(stderr) {
|
|
180
|
+
if (!stderr)
|
|
181
|
+
return '';
|
|
182
|
+
const lines = stderr.split('\n');
|
|
183
|
+
const meaningfulLines = lines.filter(line => {
|
|
184
|
+
const trimmed = line.trim();
|
|
185
|
+
// Filter out TSC verbose output, keep only actual errors
|
|
186
|
+
return trimmed &&
|
|
187
|
+
!trimmed.includes('message TS') &&
|
|
188
|
+
!trimmed.includes('Found 0 errors') &&
|
|
189
|
+
!trimmed.match(/^\s*\d+\s*$/) && // Filter line numbers
|
|
190
|
+
!trimmed.includes('Watching for file changes');
|
|
191
|
+
});
|
|
192
|
+
return meaningfulLines.join('\n').trim();
|
|
193
|
+
}
|
|
199
194
|
async analyzeBuild() {
|
|
200
195
|
try {
|
|
201
|
-
const stats = await promises_1.default.stat(this.options.output);
|
|
202
196
|
const files = await promises_1.default.readdir(this.options.output, { withFileTypes: true });
|
|
203
197
|
let totalSize = 0;
|
|
204
198
|
const fileStats = [];
|
|
205
199
|
for (const file of files) {
|
|
206
|
-
if (file.isFile()) {
|
|
200
|
+
if (file.isFile() && (file.name.endsWith('.js') || file.name.endsWith('.d.ts'))) {
|
|
207
201
|
const filePath = path_1.default.join(this.options.output, file.name);
|
|
208
202
|
const stat = await promises_1.default.stat(filePath);
|
|
209
203
|
totalSize += stat.size;
|
|
@@ -211,11 +205,13 @@ class BuildManager {
|
|
|
211
205
|
}
|
|
212
206
|
}
|
|
213
207
|
fileStats.sort((a, b) => b.size - a.size);
|
|
214
|
-
logger_manager_js_1.loggerManager.printLine(`${chalk_1.default.blue(figures_1.default.info)}
|
|
208
|
+
logger_manager_js_1.loggerManager.printLine(`${chalk_1.default.blue(figures_1.default.info)} Build Analysis:`, 'info');
|
|
215
209
|
logger_manager_js_1.loggerManager.printLine(`Total size: ${chalk_1.default.cyan(this.formatBytes(totalSize))}`, 'info');
|
|
216
|
-
logger_manager_js_1.loggerManager.printLine(`
|
|
217
|
-
if (this.options.verbose) {
|
|
218
|
-
fileStats.slice(0,
|
|
210
|
+
logger_manager_js_1.loggerManager.printLine(`Generated files: ${fileStats.length}`, 'info');
|
|
211
|
+
if (this.options.verbose && fileStats.length > 0) {
|
|
212
|
+
const topFiles = fileStats.slice(0, 5);
|
|
213
|
+
logger_manager_js_1.loggerManager.printLine('Largest files:', 'info');
|
|
214
|
+
topFiles.forEach(file => {
|
|
219
215
|
logger_manager_js_1.loggerManager.printLine(` ${file.name}: ${this.formatBytes(file.size)}`, 'info');
|
|
220
216
|
});
|
|
221
217
|
}
|
|
@@ -237,7 +233,7 @@ class BuildManager {
|
|
|
237
233
|
this.buildProcess = null;
|
|
238
234
|
const cleanup = () => {
|
|
239
235
|
if (!this.options.quiet) {
|
|
240
|
-
logger_manager_js_1.loggerManager.printLine(`${chalk_1.default.yellow(figures_1.default.square)}
|
|
236
|
+
logger_manager_js_1.loggerManager.printLine(`${chalk_1.default.yellow(figures_1.default.square)} Build process stopped`, 'info');
|
|
241
237
|
}
|
|
242
238
|
resolve();
|
|
243
239
|
};
|
|
@@ -257,7 +253,7 @@ class BuildManager {
|
|
|
257
253
|
// Ignore
|
|
258
254
|
}
|
|
259
255
|
}
|
|
260
|
-
},
|
|
256
|
+
}, 3000);
|
|
261
257
|
}
|
|
262
258
|
}
|
|
263
259
|
catch (error) {
|
|
@@ -286,12 +282,13 @@ class BuildManager {
|
|
|
286
282
|
ignoreInitial: true,
|
|
287
283
|
followSymlinks: false,
|
|
288
284
|
usePolling: false,
|
|
289
|
-
atomic:
|
|
285
|
+
atomic: 200,
|
|
290
286
|
ignored: [
|
|
291
287
|
'**/node_modules/**',
|
|
292
288
|
'**/.git/**',
|
|
293
289
|
`**/${this.options.output}/**`,
|
|
294
|
-
'**/*.log'
|
|
290
|
+
'**/*.log',
|
|
291
|
+
'**/*.map'
|
|
295
292
|
]
|
|
296
293
|
});
|
|
297
294
|
this.watcher.on('change', (filePath) => {
|
|
@@ -342,7 +339,7 @@ class BuildManager {
|
|
|
342
339
|
if (this.options.watch) {
|
|
343
340
|
this.setupWatcher();
|
|
344
341
|
if (!this.options.quiet) {
|
|
345
|
-
logger_manager_js_1.loggerManager.printLine(
|
|
342
|
+
logger_manager_js_1.loggerManager.printLine(`${chalk_1.default.blue(figures_1.default.info)} Watching for changes...`, 'info');
|
|
346
343
|
}
|
|
347
344
|
}
|
|
348
345
|
}
|
|
@@ -354,13 +351,15 @@ class BuildManager {
|
|
|
354
351
|
}
|
|
355
352
|
}
|
|
356
353
|
async stop() {
|
|
357
|
-
|
|
354
|
+
if (!this.options.quiet) {
|
|
355
|
+
logger_manager_js_1.loggerManager.printLine(`${chalk_1.default.yellow(figures_1.default.warning)} Stopping build process...`, 'info');
|
|
356
|
+
}
|
|
358
357
|
if (this.watcher) {
|
|
359
358
|
await this.watcher.close();
|
|
360
359
|
this.watcher = null;
|
|
361
360
|
}
|
|
362
361
|
await this.stopProcess();
|
|
363
|
-
if (this.buildCount > 0) {
|
|
362
|
+
if (this.buildCount > 0 && !this.options.quiet) {
|
|
364
363
|
logger_manager_js_1.loggerManager.printLine(`${chalk_1.default.blue(figures_1.default.info)} Build process stopped after ${this.buildCount} build(s)`, 'info');
|
|
365
364
|
}
|
|
366
365
|
}
|
|
@@ -7,6 +7,7 @@ exports.addBuildCommands = void 0;
|
|
|
7
7
|
const build_manager_js_1 = require("../build-manager.js");
|
|
8
8
|
const logger_manager_js_1 = require("../logger-manager.js");
|
|
9
9
|
const chalk_1 = __importDefault(require("chalk"));
|
|
10
|
+
const figures_1 = __importDefault(require("figures"));
|
|
10
11
|
function addBuildCommands(program) {
|
|
11
12
|
let buildManager = null;
|
|
12
13
|
// Build command for TypeScript projects
|
|
@@ -15,13 +16,10 @@ function addBuildCommands(program) {
|
|
|
15
16
|
.description('Build TypeScript project for production (default: src)')
|
|
16
17
|
.option('-o, --output <dir>', 'Output directory', 'dist')
|
|
17
18
|
.option('-w, --watch', 'Watch mode for continuous building')
|
|
18
|
-
.option('-c, --clean', 'Clean output directory before build')
|
|
19
|
-
.option('-m, --minify', 'Minify output')
|
|
19
|
+
.option('-c, --clean', 'Clean output directory before build', true)
|
|
20
20
|
.option('-s, --sourcemap', 'Generate source maps')
|
|
21
21
|
.option('-t, --target <target>', 'TypeScript target (es2020, es2022, etc.)', 'es2020')
|
|
22
22
|
.option('-f, --format <format>', 'Output format (cjs, esm)', 'cjs')
|
|
23
|
-
.option('--no-bundle', 'Don\'t bundle, just compile')
|
|
24
|
-
.option('--external <packages>', 'External packages (comma-separated)')
|
|
25
23
|
.option('--tsconfig <file>', 'TypeScript config file', 'tsconfig.json')
|
|
26
24
|
.option('-v, --verbose', 'Verbose output')
|
|
27
25
|
.option('-q, --quiet', 'Quiet output')
|
|
@@ -30,18 +28,20 @@ function addBuildCommands(program) {
|
|
|
30
28
|
.action(async (source, options) => {
|
|
31
29
|
try {
|
|
32
30
|
const sourceDir = source || 'src';
|
|
33
|
-
|
|
31
|
+
if (!options.quiet) {
|
|
32
|
+
logger_manager_js_1.loggerManager.printLine(`${chalk_1.default.blue(figures_1.default.info)} Building TypeScript project from ${chalk_1.default.cyan(sourceDir)}`, 'info');
|
|
33
|
+
}
|
|
34
34
|
buildManager = new build_manager_js_1.BuildManager({
|
|
35
35
|
source: sourceDir,
|
|
36
36
|
output: options.output,
|
|
37
37
|
watch: options.watch,
|
|
38
38
|
clean: options.clean,
|
|
39
|
-
minify:
|
|
39
|
+
minify: false,
|
|
40
40
|
sourcemap: options.sourcemap,
|
|
41
41
|
target: options.target,
|
|
42
42
|
format: options.format,
|
|
43
|
-
bundle:
|
|
44
|
-
external:
|
|
43
|
+
bundle: false,
|
|
44
|
+
external: [],
|
|
45
45
|
tsconfig: options.tsconfig,
|
|
46
46
|
verbose: options.verbose,
|
|
47
47
|
quiet: options.quiet,
|
|
@@ -49,24 +49,94 @@ function addBuildCommands(program) {
|
|
|
49
49
|
analyze: options.analyze
|
|
50
50
|
});
|
|
51
51
|
await buildManager.build();
|
|
52
|
+
// If not in watch mode, show completion message
|
|
53
|
+
if (!options.watch && !options.quiet) {
|
|
54
|
+
logger_manager_js_1.loggerManager.printLine(`${chalk_1.default.green(figures_1.default.tick)} Build completed successfully`, 'info');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
if (error instanceof Error) {
|
|
59
|
+
logger_manager_js_1.loggerManager.printLine(`${chalk_1.default.red(figures_1.default.cross)} Build failed: ${error.message}`, 'error');
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
logger_manager_js_1.loggerManager.printLine(`${chalk_1.default.red(figures_1.default.cross)} An unknown build error occurred`, 'error');
|
|
63
|
+
}
|
|
64
|
+
process.exit(1);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
// Add a quick build command without options
|
|
68
|
+
program
|
|
69
|
+
.command('compile [source]')
|
|
70
|
+
.alias('tsc')
|
|
71
|
+
.description('Quick TypeScript compilation (alias for build)')
|
|
72
|
+
.action(async (source) => {
|
|
73
|
+
try {
|
|
74
|
+
const sourceDir = source || 'src';
|
|
75
|
+
logger_manager_js_1.loggerManager.printLine(`${chalk_1.default.blue(figures_1.default.info)} Compiling TypeScript...`, 'info');
|
|
76
|
+
buildManager = new build_manager_js_1.BuildManager({
|
|
77
|
+
source: sourceDir,
|
|
78
|
+
output: 'dist',
|
|
79
|
+
watch: false,
|
|
80
|
+
clean: true,
|
|
81
|
+
minify: false,
|
|
82
|
+
sourcemap: false,
|
|
83
|
+
target: 'es2020',
|
|
84
|
+
format: 'cjs',
|
|
85
|
+
bundle: false,
|
|
86
|
+
external: [],
|
|
87
|
+
tsconfig: 'tsconfig.json',
|
|
88
|
+
verbose: false,
|
|
89
|
+
quiet: false,
|
|
90
|
+
color: true,
|
|
91
|
+
analyze: false
|
|
92
|
+
});
|
|
93
|
+
await buildManager.build();
|
|
94
|
+
logger_manager_js_1.loggerManager.printLine(`${chalk_1.default.green(figures_1.default.tick)} Compilation completed`, 'info');
|
|
52
95
|
}
|
|
53
96
|
catch (error) {
|
|
54
97
|
if (error instanceof Error) {
|
|
55
|
-
logger_manager_js_1.loggerManager.printLine(
|
|
98
|
+
logger_manager_js_1.loggerManager.printLine(`${chalk_1.default.red(figures_1.default.cross)} Compilation failed: ${error.message}`, 'error');
|
|
56
99
|
}
|
|
57
100
|
else {
|
|
58
|
-
logger_manager_js_1.loggerManager.printLine(
|
|
101
|
+
logger_manager_js_1.loggerManager.printLine(`${chalk_1.default.red(figures_1.default.cross)} An unknown compilation error occurred`, 'error');
|
|
59
102
|
}
|
|
60
103
|
process.exit(1);
|
|
61
104
|
}
|
|
62
105
|
});
|
|
63
106
|
// Cleanup function
|
|
64
|
-
const cleanupBuild = () => {
|
|
107
|
+
const cleanupBuild = async () => {
|
|
108
|
+
if (buildManager) {
|
|
109
|
+
try {
|
|
110
|
+
await buildManager.stop();
|
|
111
|
+
buildManager = null;
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
// Ignore cleanup errors
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
// Handle process termination
|
|
119
|
+
const handleExit = (signal) => {
|
|
65
120
|
if (buildManager) {
|
|
66
|
-
|
|
67
|
-
|
|
121
|
+
logger_manager_js_1.loggerManager.printLine(`\n${chalk_1.default.yellow(figures_1.default.warning)} Received ${signal}, stopping build process...`, 'info');
|
|
122
|
+
cleanupBuild().then(() => {
|
|
123
|
+
process.exit(0);
|
|
124
|
+
}).catch(() => {
|
|
125
|
+
process.exit(1);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
process.exit(0);
|
|
68
130
|
}
|
|
69
131
|
};
|
|
132
|
+
// Register signal handlers
|
|
133
|
+
process.on('SIGINT', () => handleExit('SIGINT'));
|
|
134
|
+
process.on('SIGTERM', () => handleExit('SIGTERM'));
|
|
135
|
+
process.on('exit', () => {
|
|
136
|
+
if (buildManager) {
|
|
137
|
+
cleanupBuild();
|
|
138
|
+
}
|
|
139
|
+
});
|
|
70
140
|
return { cleanupBuild };
|
|
71
141
|
}
|
|
72
142
|
exports.addBuildCommands = addBuildCommands;
|
|
@@ -1,27 +1,4 @@
|
|
|
1
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
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
4
|
};
|
|
@@ -30,86 +7,6 @@ exports.addDevCommands = void 0;
|
|
|
30
7
|
const dev_manager_js_1 = require("../dev-manager.js");
|
|
31
8
|
const logger_manager_js_1 = require("../logger-manager.js");
|
|
32
9
|
const chalk_1 = __importDefault(require("chalk"));
|
|
33
|
-
// Helper function to run the development server
|
|
34
|
-
async function runDevServer(file, options) {
|
|
35
|
-
try {
|
|
36
|
-
let targetFile = file || 'src/index.ts';
|
|
37
|
-
logger_manager_js_1.loggerManager.printLine(`Starting development server for ${chalk_1.default.cyan(targetFile)}`, 'info');
|
|
38
|
-
// Check if file exists and suggest alternatives
|
|
39
|
-
const fs = await Promise.resolve().then(() => __importStar(require('fs')));
|
|
40
|
-
if (!fs.existsSync(targetFile)) {
|
|
41
|
-
// Try common alternatives
|
|
42
|
-
const alternatives = [
|
|
43
|
-
'src/index.js',
|
|
44
|
-
'src/app.ts',
|
|
45
|
-
'src/app.js',
|
|
46
|
-
'src/server.ts',
|
|
47
|
-
'src/server.js',
|
|
48
|
-
'index.ts',
|
|
49
|
-
'index.js',
|
|
50
|
-
'app.ts',
|
|
51
|
-
'app.js',
|
|
52
|
-
'server.ts',
|
|
53
|
-
'server.js'
|
|
54
|
-
];
|
|
55
|
-
let found = false;
|
|
56
|
-
for (const alt of alternatives) {
|
|
57
|
-
if (fs.existsSync(alt)) {
|
|
58
|
-
logger_manager_js_1.loggerManager.printLine(`File ${targetFile} not found. Using ${alt} instead.`, 'warn');
|
|
59
|
-
targetFile = alt;
|
|
60
|
-
found = true;
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
if (!found) {
|
|
65
|
-
logger_manager_js_1.loggerManager.printLine(`File ${targetFile} not found. Common alternatives also not found.`, 'error');
|
|
66
|
-
logger_manager_js_1.loggerManager.printLine(`Please specify the correct file path or create ${targetFile}`, 'error');
|
|
67
|
-
process.exit(1);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
const devManager = new dev_manager_js_1.DevManager({
|
|
71
|
-
file: targetFile,
|
|
72
|
-
watch: options.watch.split(',').map((p) => p.trim()),
|
|
73
|
-
ignore: options.ignore.split(',').map((p) => p.trim()),
|
|
74
|
-
extensions: options.ext.split(',').map((e) => e.trim()),
|
|
75
|
-
delay: options.delay,
|
|
76
|
-
color: options.color,
|
|
77
|
-
quiet: options.quiet,
|
|
78
|
-
verbose: options.verbose,
|
|
79
|
-
clearConsole: options.clear,
|
|
80
|
-
inspect: options.inspect,
|
|
81
|
-
inspectBrk: options.inspectBrk,
|
|
82
|
-
envFile: options.env,
|
|
83
|
-
execCommand: options.exec,
|
|
84
|
-
useTypeScript: options.typescript
|
|
85
|
-
});
|
|
86
|
-
await devManager.start();
|
|
87
|
-
return devManager; // Return for cleanup
|
|
88
|
-
}
|
|
89
|
-
catch (error) {
|
|
90
|
-
if (error instanceof Error) {
|
|
91
|
-
logger_manager_js_1.loggerManager.printLine(`Development server error: ${error.message}`, 'error');
|
|
92
|
-
// Provide helpful suggestions based on error type
|
|
93
|
-
if (error.message.includes('TypeScript execution not available')) {
|
|
94
|
-
logger_manager_js_1.loggerManager.printLine('', 'info');
|
|
95
|
-
logger_manager_js_1.loggerManager.printLine('To run TypeScript files, install one of the following:', 'info');
|
|
96
|
-
logger_manager_js_1.loggerManager.printLine(' npm install --save-dev tsx', 'info');
|
|
97
|
-
logger_manager_js_1.loggerManager.printLine(' npm install --save-dev ts-node', 'info');
|
|
98
|
-
logger_manager_js_1.loggerManager.printLine('', 'info');
|
|
99
|
-
logger_manager_js_1.loggerManager.printLine('Or use --exec to specify a custom command:', 'info');
|
|
100
|
-
logger_manager_js_1.loggerManager.printLine(' neex dev --exec "bun run" src/server.ts', 'info');
|
|
101
|
-
}
|
|
102
|
-
else if (error.message.includes('ENOENT')) {
|
|
103
|
-
logger_manager_js_1.loggerManager.printLine('', 'info');
|
|
104
|
-
logger_manager_js_1.loggerManager.printLine('Make sure the required runtime is installed and in PATH', 'info');
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
logger_manager_js_1.loggerManager.printLine('An unknown development server error occurred', 'error');
|
|
109
|
-
}
|
|
110
|
-
process.exit(1);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
10
|
function addDevCommands(program) {
|
|
114
11
|
let devManager = null;
|
|
115
12
|
// Dev command for hot reloading development
|
|
@@ -127,38 +24,37 @@ function addDevCommands(program) {
|
|
|
127
24
|
.option('--inspect', 'Enable Node.js inspector')
|
|
128
25
|
.option('--inspect-brk', 'Enable Node.js inspector with break')
|
|
129
26
|
.option('--env <file>', 'Load environment variables from file', '.env')
|
|
130
|
-
.option('--exec <command>', 'Command to execute instead of
|
|
131
|
-
.option('--typescript', 'Force TypeScript mode')
|
|
132
|
-
.action(async (file, options) => {
|
|
133
|
-
devManager = await runDevServer(file, options);
|
|
134
|
-
});
|
|
135
|
-
// Add a convenience command for TypeScript projects
|
|
136
|
-
program
|
|
137
|
-
.command('dev:ts [file]')
|
|
138
|
-
.description('Start development server with TypeScript support')
|
|
139
|
-
.option('-w, --watch <patterns>', 'Watch additional patterns (comma-separated)', 'src/**/*')
|
|
140
|
-
.option('-i, --ignore <patterns>', 'Ignore patterns (comma-separated)', 'node_modules,dist,build,.git')
|
|
141
|
-
.option('-d, --delay <ms>', 'Delay before restart (ms)', parseInt, 1000)
|
|
142
|
-
.option('-q, --quiet', 'Reduce output verbosity')
|
|
143
|
-
.option('-v, --verbose', 'Verbose output')
|
|
144
|
-
.option('--env <file>', 'Load environment variables from file', '.env')
|
|
27
|
+
.option('--exec <command>', 'Command to execute instead of tsx')
|
|
145
28
|
.action(async (file, options) => {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
29
|
+
try {
|
|
30
|
+
const targetFile = file || 'src/index.ts';
|
|
31
|
+
logger_manager_js_1.loggerManager.printLine(`Starting development server for ${chalk_1.default.cyan(targetFile)}`, 'info');
|
|
32
|
+
devManager = new dev_manager_js_1.DevManager({
|
|
33
|
+
file: targetFile,
|
|
34
|
+
watch: options.watch.split(',').map((p) => p.trim()),
|
|
35
|
+
ignore: options.ignore.split(',').map((p) => p.trim()),
|
|
36
|
+
extensions: options.ext.split(',').map((e) => e.trim()),
|
|
37
|
+
delay: options.delay,
|
|
38
|
+
color: options.color,
|
|
39
|
+
quiet: options.quiet,
|
|
40
|
+
verbose: options.verbose,
|
|
41
|
+
clearConsole: options.clear,
|
|
42
|
+
inspect: options.inspect,
|
|
43
|
+
inspectBrk: options.inspectBrk,
|
|
44
|
+
envFile: options.env,
|
|
45
|
+
execCommand: options.exec
|
|
46
|
+
});
|
|
47
|
+
await devManager.start();
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
if (error instanceof Error) {
|
|
51
|
+
logger_manager_js_1.loggerManager.printLine(`Development server error: ${error.message}`, 'error');
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
logger_manager_js_1.loggerManager.printLine('An unknown development server error occurred', 'error');
|
|
55
|
+
}
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
162
58
|
});
|
|
163
59
|
// Cleanup function
|
|
164
60
|
const cleanupDev = () => {
|