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
|
@@ -17,5 +17,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
// src/commands/index.ts - Export all commands
|
|
18
18
|
__exportStar(require("./run-commands.js"), exports);
|
|
19
19
|
__exportStar(require("./dev-commands.js"), exports);
|
|
20
|
-
__exportStar(require("./process-commands.js"), exports);
|
|
21
20
|
__exportStar(require("./server-commands.js"), exports);
|
|
21
|
+
__exportStar(require("./start-commands.js"), exports);
|
|
22
|
+
__exportStar(require("./build-commands"), exports);
|
|
@@ -0,0 +1,178 @@
|
|
|
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.addStartCommands = void 0;
|
|
30
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
31
|
+
const figures_1 = __importDefault(require("figures"));
|
|
32
|
+
const path = __importStar(require("path"));
|
|
33
|
+
const fs = __importStar(require("fs/promises"));
|
|
34
|
+
// Helper function to check if file exists
|
|
35
|
+
async function fileExists(filePath) {
|
|
36
|
+
try {
|
|
37
|
+
await fs.access(filePath);
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
catch (_a) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// Helper function to determine the best command to start the application
|
|
45
|
+
async function getStartCommand(filePath, showInfo) {
|
|
46
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
47
|
+
const absolutePath = path.resolve(process.cwd(), filePath);
|
|
48
|
+
const fileName = path.basename(filePath, ext);
|
|
49
|
+
// Check if file exists
|
|
50
|
+
if (!(await fileExists(absolutePath))) {
|
|
51
|
+
throw new Error(`File not found: ${filePath}`);
|
|
52
|
+
}
|
|
53
|
+
if (showInfo) {
|
|
54
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} neex start: Analyzing ${chalk_1.default.cyan(path.basename(filePath))}`));
|
|
55
|
+
}
|
|
56
|
+
switch (ext) {
|
|
57
|
+
case '.js':
|
|
58
|
+
case '.mjs':
|
|
59
|
+
case '.cjs':
|
|
60
|
+
if (showInfo) {
|
|
61
|
+
console.log(chalk_1.default.green(`${figures_1.default.tick} neex start: JavaScript detected, using Node.js runtime`));
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
command: `node ${filePath}`,
|
|
65
|
+
runtime: 'Node.js',
|
|
66
|
+
processName: fileName
|
|
67
|
+
};
|
|
68
|
+
case '.ts':
|
|
69
|
+
case '.mts':
|
|
70
|
+
case '.cts':
|
|
71
|
+
if (showInfo) {
|
|
72
|
+
console.log(chalk_1.default.yellow(`${figures_1.default.warning} neex start: TypeScript detected, consider building first`));
|
|
73
|
+
console.log(chalk_1.default.yellow(`${figures_1.default.pointer} Tip: Run 'neex build ${filePath}' first, then start the built .js file`));
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
command: `npx ts-node ${filePath}`,
|
|
77
|
+
runtime: 'TypeScript (ts-node)',
|
|
78
|
+
processName: fileName
|
|
79
|
+
};
|
|
80
|
+
default:
|
|
81
|
+
if (showInfo) {
|
|
82
|
+
console.log(chalk_1.default.yellow(`${figures_1.default.warning} neex start: Unknown file type, using Node.js`));
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
command: `node ${filePath}`,
|
|
86
|
+
runtime: 'Node.js',
|
|
87
|
+
processName: fileName
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function addStartCommands(program) {
|
|
92
|
+
let startManager = null;
|
|
93
|
+
const cleanupStart = () => {
|
|
94
|
+
if (startManager) {
|
|
95
|
+
startManager.stop();
|
|
96
|
+
startManager = null;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
program
|
|
100
|
+
.command('start <file>')
|
|
101
|
+
.alias('s')
|
|
102
|
+
.description('Start JavaScript/TypeScript applications in production mode')
|
|
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('-o, --no-output', 'Hide command output')
|
|
107
|
+
.option('-m, --minimal', 'Use minimal output format')
|
|
108
|
+
.option('-w, --watch', 'Watch for changes and restart (production hot-reload)')
|
|
109
|
+
.option('-i, --ignore <patterns...>', 'Patterns to ignore when watching')
|
|
110
|
+
.option('-e, --ext <extensions...>', 'File extensions to watch (default: js,mjs,json)')
|
|
111
|
+
.option('-d, --delay <ms>', 'Delay before restart in milliseconds', parseInt)
|
|
112
|
+
.option('--max-restarts <number>', 'Maximum number of restarts', parseInt)
|
|
113
|
+
.option('--restart-delay <ms>', 'Delay between restarts in milliseconds', parseInt)
|
|
114
|
+
.option('--verbose', 'Verbose output')
|
|
115
|
+
.option('--info', 'Show detailed information during startup')
|
|
116
|
+
.option('--signal <signal>', 'Signal to send to processes on restart', 'SIGTERM')
|
|
117
|
+
.option('--env <env>', 'Environment mode', 'production')
|
|
118
|
+
.option('--cluster', 'Enable cluster mode (spawn multiple processes)')
|
|
119
|
+
.option('--cluster-instances <number>', 'Number of cluster instances', parseInt)
|
|
120
|
+
.option('--memory-limit <mb>', 'Memory limit in MB', parseInt)
|
|
121
|
+
.option('--cpu-limit <percent>', 'CPU limit percentage', parseInt)
|
|
122
|
+
.action(async (file, options) => {
|
|
123
|
+
try {
|
|
124
|
+
const showInfo = options.info || false;
|
|
125
|
+
if (showInfo) {
|
|
126
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} neex start: Starting production application server...`));
|
|
127
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} neex start: Target file: ${chalk_1.default.cyan(file)}`));
|
|
128
|
+
}
|
|
129
|
+
// Validate file parameter
|
|
130
|
+
if (!file || file.trim() === '') {
|
|
131
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} neex start: Error - No file specified!`));
|
|
132
|
+
console.error(chalk_1.default.yellow(`${figures_1.default.pointer} Usage: neex start <file>`));
|
|
133
|
+
console.error(chalk_1.default.yellow(`${figures_1.default.pointer} Example: neex start dist/server.js`));
|
|
134
|
+
process.exit(1);
|
|
135
|
+
}
|
|
136
|
+
// Get the start command configuration
|
|
137
|
+
let startConfig;
|
|
138
|
+
try {
|
|
139
|
+
startConfig = await getStartCommand(file, showInfo);
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} neex start: ${error instanceof Error ? error.message : 'Unknown error occurred'}`));
|
|
143
|
+
process.exit(1);
|
|
144
|
+
}
|
|
145
|
+
// Setup watch configuration if enabled
|
|
146
|
+
const watchPaths = options.watch ? [path.dirname(file)] : [];
|
|
147
|
+
const ignorePatterns = options.ignore || [
|
|
148
|
+
'node_modules/**',
|
|
149
|
+
'.git/**',
|
|
150
|
+
'*.log',
|
|
151
|
+
'src/**',
|
|
152
|
+
'test/**',
|
|
153
|
+
'tests/**',
|
|
154
|
+
'coverage/**',
|
|
155
|
+
'.nyc_output/**',
|
|
156
|
+
'*.tmp',
|
|
157
|
+
'*.temp',
|
|
158
|
+
'.DS_Store',
|
|
159
|
+
'Thumbs.db'
|
|
160
|
+
];
|
|
161
|
+
const extensions = options.ext || ['js', 'mjs', 'json'];
|
|
162
|
+
// Log configuration only if --info flag is set
|
|
163
|
+
if (showInfo) {
|
|
164
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} neex start: Configuration:`));
|
|
165
|
+
console;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} neex start: ${error instanceof Error ? error.message : 'Unknown error occurred'}`));
|
|
170
|
+
process.exit(1);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
return {
|
|
174
|
+
getStartManager: () => startManager,
|
|
175
|
+
cleanupStart
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
exports.addStartCommands = addStartCommands;
|
package/dist/src/dev-runner.js
CHANGED
|
@@ -44,7 +44,8 @@ class DevRunner {
|
|
|
44
44
|
ext: ['js', 'mjs', 'json', 'ts', 'tsx', 'jsx'],
|
|
45
45
|
delay: 1000,
|
|
46
46
|
verbose: false,
|
|
47
|
-
|
|
47
|
+
showInfo: false,
|
|
48
|
+
runnerName: 'neex dev',
|
|
48
49
|
};
|
|
49
50
|
this.options = {
|
|
50
51
|
...defaultOptions,
|
|
@@ -57,7 +58,7 @@ class DevRunner {
|
|
|
57
58
|
ignore: this.options.ignore,
|
|
58
59
|
ext: this.options.ext,
|
|
59
60
|
delay: this.options.delay,
|
|
60
|
-
verbose: this.options.verbose
|
|
61
|
+
verbose: this.options.verbose && this.options.showInfo // Only show verbose watcher logs if both verbose and showInfo are true
|
|
61
62
|
};
|
|
62
63
|
this.fileWatcher = new watcher_1.FileWatcher(watchOptions);
|
|
63
64
|
this.fileWatcher.on('change', (event) => {
|
|
@@ -68,7 +69,9 @@ class DevRunner {
|
|
|
68
69
|
}
|
|
69
70
|
async handleFileChange(event) {
|
|
70
71
|
const prefix = chalk_1.default.cyan(`[${this.options.runnerName}]`);
|
|
71
|
-
|
|
72
|
+
if (this.options.showInfo) {
|
|
73
|
+
logger_1.default.printLine(`${prefix} File changed: ${chalk_1.default.yellow(event.relativePath)}`, 'info');
|
|
74
|
+
}
|
|
72
75
|
if (this.options.clearConsole) {
|
|
73
76
|
console.clear();
|
|
74
77
|
}
|
|
@@ -78,18 +81,38 @@ class DevRunner {
|
|
|
78
81
|
if (this.commands.length === 0) {
|
|
79
82
|
return [];
|
|
80
83
|
}
|
|
81
|
-
|
|
84
|
+
// Create a modified options object for the runner to clean up output
|
|
85
|
+
const runnerOptions = {
|
|
86
|
+
...this.options,
|
|
87
|
+
// Override prefix behavior to show clean command name
|
|
88
|
+
customPrefix: (command) => {
|
|
89
|
+
// Extract just the filename from the command
|
|
90
|
+
const match = command.match(/(?:npx ts-node|node)\s+(.+)/);
|
|
91
|
+
if (match) {
|
|
92
|
+
const filePath = match[1];
|
|
93
|
+
const fileName = filePath.split('/').pop() || filePath;
|
|
94
|
+
return `${fileName}`;
|
|
95
|
+
}
|
|
96
|
+
return command;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
this.runner = new runner_1.Runner(runnerOptions);
|
|
82
100
|
try {
|
|
83
101
|
const results = await this.runner.run(this.commands);
|
|
84
102
|
return results;
|
|
85
103
|
}
|
|
86
104
|
catch (error) {
|
|
87
|
-
|
|
105
|
+
if (this.options.showInfo) {
|
|
106
|
+
logger_1.default.printLine(`Execution failed: ${error.message}`, 'error');
|
|
107
|
+
}
|
|
88
108
|
return [];
|
|
89
109
|
}
|
|
90
110
|
}
|
|
91
111
|
printDevBanner() {
|
|
92
112
|
var _a, _b;
|
|
113
|
+
if (!this.options.showInfo) {
|
|
114
|
+
return; // Don't show banner if showInfo is false
|
|
115
|
+
}
|
|
93
116
|
const prefix = chalk_1.default.cyan(`[${this.options.runnerName}]`);
|
|
94
117
|
const uptime = Math.floor((Date.now() - this.startTime.getTime()) / 1000);
|
|
95
118
|
const uptimeStr = this.formatUptime(uptime);
|
|
@@ -125,7 +148,7 @@ class DevRunner {
|
|
|
125
148
|
this.startTime = new Date();
|
|
126
149
|
// Setup file watcher
|
|
127
150
|
this.setupFileWatcher();
|
|
128
|
-
// Print development banner
|
|
151
|
+
// Print development banner only if showInfo is true
|
|
129
152
|
this.printDevBanner();
|
|
130
153
|
// Start file watcher
|
|
131
154
|
if (this.fileWatcher) {
|
|
@@ -133,19 +156,25 @@ class DevRunner {
|
|
|
133
156
|
}
|
|
134
157
|
// Run initial commands
|
|
135
158
|
const prefix = chalk_1.default.cyan(`[${this.options.runnerName}]`);
|
|
136
|
-
|
|
159
|
+
if (this.options.showInfo) {
|
|
160
|
+
logger_1.default.printLine(`${prefix} Starting development server...`, 'info');
|
|
161
|
+
}
|
|
137
162
|
await this.runCommands();
|
|
138
163
|
// Set up graceful shutdown
|
|
139
164
|
this.setupGracefulShutdown();
|
|
140
|
-
|
|
141
|
-
|
|
165
|
+
if (this.options.showInfo) {
|
|
166
|
+
logger_1.default.printLine(`${prefix} Development server started. Watching for changes...`, 'info');
|
|
167
|
+
logger_1.default.printLine(`${prefix} Press ${chalk_1.default.cyan('Ctrl+C')} to stop`, 'info');
|
|
168
|
+
}
|
|
142
169
|
}
|
|
143
170
|
async restart() {
|
|
144
171
|
const prefix = chalk_1.default.cyan(`[${this.options.runnerName}]`);
|
|
145
172
|
if (!this.isRunning) {
|
|
146
173
|
return;
|
|
147
174
|
}
|
|
148
|
-
|
|
175
|
+
if (this.options.showInfo) {
|
|
176
|
+
logger_1.default.printLine(`${prefix} Restarting due to file changes...`, 'info');
|
|
177
|
+
}
|
|
149
178
|
this.restartCount++;
|
|
150
179
|
// Stop current processes
|
|
151
180
|
if (this.runner) {
|
|
@@ -153,18 +182,22 @@ class DevRunner {
|
|
|
153
182
|
}
|
|
154
183
|
// Wait a moment before restarting
|
|
155
184
|
await new Promise(resolve => setTimeout(resolve, 500));
|
|
156
|
-
// Print restart banner
|
|
185
|
+
// Print restart banner only if showInfo is true
|
|
157
186
|
this.printDevBanner();
|
|
158
187
|
// Run commands again
|
|
159
188
|
await this.runCommands();
|
|
160
|
-
|
|
189
|
+
if (this.options.showInfo) {
|
|
190
|
+
logger_1.default.printLine(`${prefix} Restart completed. Watching for changes...`, 'info');
|
|
191
|
+
}
|
|
161
192
|
}
|
|
162
193
|
async stop() {
|
|
163
194
|
const prefix = chalk_1.default.cyan(`[${this.options.runnerName}]`);
|
|
164
195
|
if (!this.isRunning) {
|
|
165
196
|
return;
|
|
166
197
|
}
|
|
167
|
-
|
|
198
|
+
if (this.options.showInfo) {
|
|
199
|
+
logger_1.default.printLine(`${prefix} Stopping development server...`, 'info');
|
|
200
|
+
}
|
|
168
201
|
this.isRunning = false;
|
|
169
202
|
// Stop file watcher
|
|
170
203
|
if (this.fileWatcher) {
|
|
@@ -176,14 +209,18 @@ class DevRunner {
|
|
|
176
209
|
}
|
|
177
210
|
const uptime = Math.floor((Date.now() - this.startTime.getTime()) / 1000);
|
|
178
211
|
const uptimeStr = this.formatUptime(uptime);
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
212
|
+
if (this.options.showInfo) {
|
|
213
|
+
logger_1.default.printLine(`${prefix} ${this.options.runnerName} development server stopped after ${uptimeStr}`, 'info');
|
|
214
|
+
if (this.restartCount > 0) {
|
|
215
|
+
logger_1.default.printLine(`${prefix} Total restarts: ${this.restartCount}`, 'info');
|
|
216
|
+
}
|
|
182
217
|
}
|
|
183
218
|
}
|
|
184
219
|
setupGracefulShutdown() {
|
|
185
220
|
const handleSignal = (signal) => {
|
|
186
|
-
|
|
221
|
+
if (this.options.showInfo) {
|
|
222
|
+
console.log(`\n${chalk_1.default.yellow(`${figures_1.default.warning} Received ${signal}. Shutting down development server...`)}`);
|
|
223
|
+
}
|
|
187
224
|
this.stop().then(() => {
|
|
188
225
|
process.exit(0);
|
|
189
226
|
});
|