neex 0.6.14 → 0.6.15
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/commands/dev-commands.js +74 -29
- package/dist/src/dev-runner.js +28 -62
- package/package.json +1 -1
|
@@ -43,35 +43,27 @@ 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
|
|
46
|
+
async function getBestCommand(filePath) {
|
|
47
47
|
const ext = path.extname(filePath).toLowerCase();
|
|
48
48
|
const absolutePath = path.resolve(process.cwd(), filePath);
|
|
49
49
|
// Check if file exists
|
|
50
50
|
if (!(await fileExists(absolutePath))) {
|
|
51
51
|
throw new Error(`File not found: ${filePath}`);
|
|
52
52
|
}
|
|
53
|
-
|
|
54
|
-
console.log(chalk_1.default.blue(`${figures_1.default.info} neex dev: Analyzing ${chalk_1.default.cyan(path.basename(filePath))}`));
|
|
55
|
-
}
|
|
53
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} neex dev: Analyzing file type for ${chalk_1.default.cyan(filePath)}`));
|
|
56
54
|
switch (ext) {
|
|
57
55
|
case '.ts':
|
|
58
56
|
case '.mts':
|
|
59
57
|
case '.cts':
|
|
60
|
-
|
|
61
|
-
console.log(chalk_1.default.green(`${figures_1.default.tick} neex dev: TypeScript detected, ready to run`));
|
|
62
|
-
}
|
|
58
|
+
console.log(chalk_1.default.green(`${figures_1.default.tick} neex dev: Detected TypeScript file, using ts-node for execution`));
|
|
63
59
|
return `npx ts-node ${filePath}`;
|
|
64
60
|
case '.js':
|
|
65
61
|
case '.mjs':
|
|
66
62
|
case '.cjs':
|
|
67
|
-
|
|
68
|
-
console.log(chalk_1.default.green(`${figures_1.default.tick} neex dev: JavaScript detected, ready to run`));
|
|
69
|
-
}
|
|
63
|
+
console.log(chalk_1.default.green(`${figures_1.default.tick} neex dev: Detected JavaScript file, using node for execution`));
|
|
70
64
|
return `node ${filePath}`;
|
|
71
65
|
default:
|
|
72
|
-
|
|
73
|
-
console.log(chalk_1.default.yellow(`${figures_1.default.warning} neex dev: Unknown file type, using Node.js`));
|
|
74
|
-
}
|
|
66
|
+
console.log(chalk_1.default.yellow(`${figures_1.default.warning} neex dev: Unknown file extension ${ext}, attempting to run with node`));
|
|
75
67
|
return `node ${filePath}`;
|
|
76
68
|
}
|
|
77
69
|
}
|
|
@@ -93,30 +85,83 @@ function addDevCommands(program) {
|
|
|
93
85
|
.option('-e, --ext <extensions...>', 'File extensions to watch (default: js,mjs,json,ts,tsx,jsx)')
|
|
94
86
|
.option('-d, --delay <ms>', 'Delay before restart in milliseconds', parseInt)
|
|
95
87
|
.option('--clear', 'Clear console on restart')
|
|
88
|
+
.option('--verbose', 'Verbose output')
|
|
96
89
|
.option('--signal <signal>', 'Signal to send to processes on restart', 'SIGTERM')
|
|
97
90
|
.action(async (file, options) => {
|
|
98
91
|
try {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
92
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} neex dev: Starting enhanced development server...`));
|
|
93
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} neex dev: Target file: ${chalk_1.default.cyan(file)}`));
|
|
94
|
+
// Validate file parameter
|
|
95
|
+
if (!file || file.trim() === '') {
|
|
96
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} neex dev: Error - No file specified!`));
|
|
97
|
+
console.error(chalk_1.default.yellow(`${figures_1.default.pointer} Usage: neex dev <file>`));
|
|
98
|
+
console.error(chalk_1.default.yellow(`${figures_1.default.pointer} Example: neex dev src/server.ts`));
|
|
99
|
+
process.exit(1);
|
|
100
|
+
}
|
|
101
|
+
// Get the best command to run the file
|
|
102
|
+
let commandToExecute;
|
|
103
|
+
try {
|
|
104
|
+
commandToExecute = await getBestCommand(file);
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} neex dev: ${error instanceof Error ? error.message : 'Unknown error occurred'}`));
|
|
108
|
+
process.exit(1);
|
|
109
|
+
}
|
|
110
|
+
// Setup watch configuration
|
|
111
|
+
const watchPaths = options.watch ? [...options.watch, './'] : ['./'];
|
|
112
|
+
const ignorePatterns = options.ignore || [
|
|
113
|
+
'node_modules/**',
|
|
114
|
+
'.git/**',
|
|
115
|
+
'*.log',
|
|
116
|
+
'dist/**',
|
|
117
|
+
'build/**',
|
|
118
|
+
'coverage/**',
|
|
119
|
+
'.nyc_output/**',
|
|
120
|
+
'*.tmp',
|
|
121
|
+
'*.temp',
|
|
122
|
+
'.DS_Store',
|
|
123
|
+
'Thumbs.db'
|
|
124
|
+
];
|
|
125
|
+
const extensions = options.ext || ['js', 'mjs', 'json', 'ts', 'tsx', 'jsx', 'vue', 'svelte'];
|
|
126
|
+
// Log configuration
|
|
127
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} neex dev: Configuration:`));
|
|
128
|
+
console.log(chalk_1.default.blue(` ${figures_1.default.arrowRight} Command: ${chalk_1.default.cyan(commandToExecute)}`));
|
|
129
|
+
console.log(chalk_1.default.blue(` ${figures_1.default.arrowRight} Watch paths: ${chalk_1.default.cyan(watchPaths.join(', '))}`));
|
|
130
|
+
console.log(chalk_1.default.blue(` ${figures_1.default.arrowRight} Extensions: ${chalk_1.default.cyan(extensions.join(', '))}`));
|
|
131
|
+
console.log(chalk_1.default.blue(` ${figures_1.default.arrowRight} Ignore patterns: ${chalk_1.default.cyan(ignorePatterns.length)} patterns`));
|
|
132
|
+
console.log(chalk_1.default.blue(` ${figures_1.default.arrowRight} Restart delay: ${chalk_1.default.cyan(options.delay || 1000)}ms`));
|
|
133
|
+
console.log(chalk_1.default.blue(` ${figures_1.default.arrowRight} Clear console: ${chalk_1.default.cyan(options.clear ? 'Yes' : 'No')}`));
|
|
134
|
+
console.log(chalk_1.default.blue(` ${figures_1.default.arrowRight} Signal: ${chalk_1.default.cyan(options.signal)}`));
|
|
135
|
+
if (options.verbose) {
|
|
136
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} neex dev: Verbose mode enabled - showing detailed logs`));
|
|
137
|
+
}
|
|
138
|
+
console.log(chalk_1.default.green(`${figures_1.default.tick} neex dev: Starting file watcher and process manager...`));
|
|
139
|
+
// Create DevRunner instance
|
|
140
|
+
devRunner = new dev_runner_js_1.DevRunner({
|
|
106
141
|
runnerName: 'neex dev',
|
|
107
142
|
parallel: false,
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
143
|
+
color: options.color,
|
|
144
|
+
showTiming: options.timing,
|
|
145
|
+
prefix: options.prefix,
|
|
146
|
+
stopOnError: options.stopOnError,
|
|
147
|
+
printOutput: options.output,
|
|
113
148
|
minimalOutput: options.minimal,
|
|
114
|
-
|
|
115
|
-
|
|
149
|
+
watch: watchPaths,
|
|
150
|
+
ignore: ignorePatterns,
|
|
151
|
+
ext: extensions,
|
|
152
|
+
delay: options.delay || 1000,
|
|
153
|
+
clearConsole: options.clear,
|
|
154
|
+
verbose: options.verbose,
|
|
155
|
+
signal: options.signal,
|
|
116
156
|
restartOnChange: true,
|
|
117
|
-
|
|
157
|
+
groupOutput: false,
|
|
158
|
+
isServerMode: false
|
|
118
159
|
});
|
|
119
|
-
|
|
160
|
+
// Start the development server
|
|
161
|
+
console.log(chalk_1.default.green(`${figures_1.default.tick} neex dev: Launching ${chalk_1.default.cyan(path.basename(file))} with auto-restart capability...`));
|
|
162
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} neex dev: Press Ctrl+C to stop the development server`));
|
|
163
|
+
console.log(chalk_1.default.gray(`${'='.repeat(60)}`));
|
|
164
|
+
await devRunner.start([commandToExecute]);
|
|
120
165
|
}
|
|
121
166
|
catch (error) {
|
|
122
167
|
console.error(chalk_1.default.red(`${figures_1.default.cross} neex dev: Fatal error occurred`));
|
package/dist/src/dev-runner.js
CHANGED
|
@@ -44,8 +44,7 @@ class DevRunner {
|
|
|
44
44
|
ext: ['js', 'mjs', 'json', 'ts', 'tsx', 'jsx'],
|
|
45
45
|
delay: 1000,
|
|
46
46
|
verbose: false,
|
|
47
|
-
|
|
48
|
-
runnerName: 'neex dev',
|
|
47
|
+
runnerName: 'watch', // Default runner name if not specified
|
|
49
48
|
};
|
|
50
49
|
this.options = {
|
|
51
50
|
...defaultOptions,
|
|
@@ -58,7 +57,7 @@ class DevRunner {
|
|
|
58
57
|
ignore: this.options.ignore,
|
|
59
58
|
ext: this.options.ext,
|
|
60
59
|
delay: this.options.delay,
|
|
61
|
-
verbose:
|
|
60
|
+
verbose: this.options.verbose
|
|
62
61
|
};
|
|
63
62
|
this.fileWatcher = new watcher_1.FileWatcher(watchOptions);
|
|
64
63
|
this.fileWatcher.on('change', (event) => {
|
|
@@ -68,6 +67,8 @@ class DevRunner {
|
|
|
68
67
|
});
|
|
69
68
|
}
|
|
70
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');
|
|
71
72
|
if (this.options.clearConsole) {
|
|
72
73
|
console.clear();
|
|
73
74
|
}
|
|
@@ -77,52 +78,31 @@ class DevRunner {
|
|
|
77
78
|
if (this.commands.length === 0) {
|
|
78
79
|
return [];
|
|
79
80
|
}
|
|
80
|
-
|
|
81
|
-
const runnerOptions = {
|
|
82
|
-
...this.options,
|
|
83
|
-
// Override prefix behavior to show clean command name
|
|
84
|
-
customPrefix: (command) => {
|
|
85
|
-
// Extract just the filename from the command
|
|
86
|
-
const match = command.match(/(?:npx ts-node|node)\s+(.+)/);
|
|
87
|
-
if (match) {
|
|
88
|
-
const filePath = match[1];
|
|
89
|
-
const fileName = filePath.split('/').pop() || filePath;
|
|
90
|
-
return `${fileName}`;
|
|
91
|
-
}
|
|
92
|
-
return command;
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
this.runner = new runner_1.Runner(runnerOptions);
|
|
81
|
+
this.runner = new runner_1.Runner(this.options);
|
|
96
82
|
try {
|
|
97
83
|
const results = await this.runner.run(this.commands);
|
|
98
84
|
return results;
|
|
99
85
|
}
|
|
100
86
|
catch (error) {
|
|
101
|
-
|
|
102
|
-
logger_1.default.printLine(`Execution failed: ${error.message}`, 'error');
|
|
103
|
-
}
|
|
87
|
+
logger_1.default.printLine(`Execution failed: ${error.message}`, 'error');
|
|
104
88
|
return [];
|
|
105
89
|
}
|
|
106
90
|
}
|
|
107
91
|
printDevBanner() {
|
|
108
|
-
var _a, _b
|
|
109
|
-
if (!this.options.showInfo) {
|
|
110
|
-
return; // Don't show banner if showInfo is false
|
|
111
|
-
}
|
|
92
|
+
var _a, _b;
|
|
112
93
|
const prefix = chalk_1.default.cyan(`[${this.options.runnerName}]`);
|
|
113
94
|
const uptime = Math.floor((Date.now() - this.startTime.getTime()) / 1000);
|
|
114
95
|
const uptimeStr = this.formatUptime(uptime);
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
console.log(chalk_1.default.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
console.log('');
|
|
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(', ')}`)}`);
|
|
125
104
|
}
|
|
105
|
+
console.log('');
|
|
126
106
|
}
|
|
127
107
|
formatUptime(seconds) {
|
|
128
108
|
if (seconds < 60) {
|
|
@@ -145,7 +125,7 @@ class DevRunner {
|
|
|
145
125
|
this.startTime = new Date();
|
|
146
126
|
// Setup file watcher
|
|
147
127
|
this.setupFileWatcher();
|
|
148
|
-
// Print development banner
|
|
128
|
+
// Print development banner
|
|
149
129
|
this.printDevBanner();
|
|
150
130
|
// Start file watcher
|
|
151
131
|
if (this.fileWatcher) {
|
|
@@ -153,25 +133,19 @@ class DevRunner {
|
|
|
153
133
|
}
|
|
154
134
|
// Run initial commands
|
|
155
135
|
const prefix = chalk_1.default.cyan(`[${this.options.runnerName}]`);
|
|
156
|
-
|
|
157
|
-
logger_1.default.printLine(`${prefix} Starting development server...`, 'info');
|
|
158
|
-
}
|
|
136
|
+
logger_1.default.printLine(`${prefix} Starting development server...`, 'info');
|
|
159
137
|
await this.runCommands();
|
|
160
138
|
// Set up graceful shutdown
|
|
161
139
|
this.setupGracefulShutdown();
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
logger_1.default.printLine(`${prefix} Press ${chalk_1.default.cyan('Ctrl+C')} to stop`, 'info');
|
|
165
|
-
}
|
|
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');
|
|
166
142
|
}
|
|
167
143
|
async restart() {
|
|
168
144
|
const prefix = chalk_1.default.cyan(`[${this.options.runnerName}]`);
|
|
169
145
|
if (!this.isRunning) {
|
|
170
146
|
return;
|
|
171
147
|
}
|
|
172
|
-
|
|
173
|
-
logger_1.default.printLine(`${prefix} Restarting due to file changes...`, 'info');
|
|
174
|
-
}
|
|
148
|
+
logger_1.default.printLine(`${prefix} Restarting due to file changes...`, 'info');
|
|
175
149
|
this.restartCount++;
|
|
176
150
|
// Stop current processes
|
|
177
151
|
if (this.runner) {
|
|
@@ -179,22 +153,18 @@ class DevRunner {
|
|
|
179
153
|
}
|
|
180
154
|
// Wait a moment before restarting
|
|
181
155
|
await new Promise(resolve => setTimeout(resolve, 500));
|
|
182
|
-
// Print restart banner
|
|
156
|
+
// Print restart banner
|
|
183
157
|
this.printDevBanner();
|
|
184
158
|
// Run commands again
|
|
185
159
|
await this.runCommands();
|
|
186
|
-
|
|
187
|
-
logger_1.default.printLine(`${prefix} Restart completed. Watching for changes...`, 'info');
|
|
188
|
-
}
|
|
160
|
+
logger_1.default.printLine(`${prefix} Restart completed. Watching for changes...`, 'info');
|
|
189
161
|
}
|
|
190
162
|
async stop() {
|
|
191
163
|
const prefix = chalk_1.default.cyan(`[${this.options.runnerName}]`);
|
|
192
164
|
if (!this.isRunning) {
|
|
193
165
|
return;
|
|
194
166
|
}
|
|
195
|
-
|
|
196
|
-
logger_1.default.printLine(`${prefix} Stopping development server...`, 'info');
|
|
197
|
-
}
|
|
167
|
+
logger_1.default.printLine(`${prefix} Stopping development server...`, 'info');
|
|
198
168
|
this.isRunning = false;
|
|
199
169
|
// Stop file watcher
|
|
200
170
|
if (this.fileWatcher) {
|
|
@@ -206,18 +176,14 @@ class DevRunner {
|
|
|
206
176
|
}
|
|
207
177
|
const uptime = Math.floor((Date.now() - this.startTime.getTime()) / 1000);
|
|
208
178
|
const uptimeStr = this.formatUptime(uptime);
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
logger_1.default.printLine(`${prefix} Total restarts: ${this.restartCount}`, 'info');
|
|
213
|
-
}
|
|
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');
|
|
214
182
|
}
|
|
215
183
|
}
|
|
216
184
|
setupGracefulShutdown() {
|
|
217
185
|
const handleSignal = (signal) => {
|
|
218
|
-
|
|
219
|
-
console.log(`\n${chalk_1.default.yellow(`${figures_1.default.warning} Received ${signal}. Shutting down development server...`)}`);
|
|
220
|
-
}
|
|
186
|
+
console.log(`\n${chalk_1.default.yellow(`${figures_1.default.warning} Received ${signal}. Shutting down development server...`)}`);
|
|
221
187
|
this.stop().then(() => {
|
|
222
188
|
process.exit(0);
|
|
223
189
|
});
|