neex 0.5.7 → 0.6.0
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/README.md +1 -1
- package/dist/src/commands/dev-commands.js +95 -114
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -32,141 +32,111 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
32
32
|
const figures_1 = __importDefault(require("figures"));
|
|
33
33
|
const path = __importStar(require("path"));
|
|
34
34
|
const fs = __importStar(require("fs/promises"));
|
|
35
|
-
// Helper function to
|
|
36
|
-
async function
|
|
37
|
-
var _a, _b;
|
|
35
|
+
// Helper function to check if file exists
|
|
36
|
+
async function fileExists(filePath) {
|
|
38
37
|
try {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const packageJsonContent = await fs.readFile(packageJsonPath, 'utf-8');
|
|
42
|
-
const packageJson = JSON.parse(packageJsonContent);
|
|
43
|
-
if ((_a = packageJson.scripts) === null || _a === void 0 ? void 0 : _a.dev) {
|
|
44
|
-
if (verbose) {
|
|
45
|
-
console.log(chalk_1.default.blue(`${figures_1.default.info} Using "dev" script from package.json: npm run dev`));
|
|
46
|
-
}
|
|
47
|
-
return 'npm run dev';
|
|
48
|
-
}
|
|
49
|
-
if ((_b = packageJson.scripts) === null || _b === void 0 ? void 0 : _b.start) {
|
|
50
|
-
if (verbose) {
|
|
51
|
-
console.log(chalk_1.default.blue(`${figures_1.default.info} Using "start" script from package.json: npm run start`));
|
|
52
|
-
}
|
|
53
|
-
return 'npm run start';
|
|
54
|
-
}
|
|
55
|
-
if (packageJson.main) {
|
|
56
|
-
const mainFile = packageJson.main;
|
|
57
|
-
const mainFilePath = path.resolve(process.cwd(), mainFile);
|
|
58
|
-
try {
|
|
59
|
-
await fs.access(mainFilePath);
|
|
60
|
-
if (mainFile.endsWith('.ts') || mainFile.endsWith('.mts') || mainFile.endsWith('.cts')) {
|
|
61
|
-
if (verbose) {
|
|
62
|
-
console.log(chalk_1.default.blue(`${figures_1.default.info} Using "main" field (TypeScript): neex dev ${mainFile}`));
|
|
63
|
-
}
|
|
64
|
-
return `neex dev ${mainFile}`;
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
if (verbose) {
|
|
68
|
-
console.log(chalk_1.default.blue(`${figures_1.default.info} Using "main" field (JavaScript): node ${mainFile}`));
|
|
69
|
-
}
|
|
70
|
-
return `node ${mainFile}`;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
catch (e) {
|
|
74
|
-
// Main file doesn't exist, do nothing
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return null;
|
|
38
|
+
await fs.access(filePath);
|
|
39
|
+
return true;
|
|
78
40
|
}
|
|
79
|
-
catch (
|
|
80
|
-
|
|
81
|
-
|
|
41
|
+
catch (_a) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// Helper function to determine the best command to run the file
|
|
46
|
+
async function getBestCommand(filePath) {
|
|
47
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
48
|
+
const absolutePath = path.resolve(process.cwd(), filePath);
|
|
49
|
+
// Check if file exists
|
|
50
|
+
if (!(await fileExists(absolutePath))) {
|
|
51
|
+
throw new Error(`File not found: ${filePath}`);
|
|
52
|
+
}
|
|
53
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} neex dev: Analyzing file type for ${chalk_1.default.cyan(filePath)}`));
|
|
54
|
+
switch (ext) {
|
|
55
|
+
case '.ts':
|
|
56
|
+
case '.mts':
|
|
57
|
+
case '.cts':
|
|
58
|
+
console.log(chalk_1.default.green(`${figures_1.default.tick} neex dev: Detected TypeScript file, using ts-node for execution`));
|
|
59
|
+
return `npx ts-node ${filePath}`;
|
|
60
|
+
case '.js':
|
|
61
|
+
case '.mjs':
|
|
62
|
+
case '.cjs':
|
|
63
|
+
console.log(chalk_1.default.green(`${figures_1.default.tick} neex dev: Detected JavaScript file, using node for execution`));
|
|
64
|
+
return `node ${filePath}`;
|
|
65
|
+
default:
|
|
66
|
+
console.log(chalk_1.default.yellow(`${figures_1.default.warning} neex dev: Unknown file extension ${ext}, attempting to run with node`));
|
|
67
|
+
return `node ${filePath}`;
|
|
82
68
|
}
|
|
83
69
|
}
|
|
84
70
|
function addDevCommands(program) {
|
|
85
71
|
let devRunner = null;
|
|
86
|
-
// Dev command
|
|
72
|
+
// Dev command - file watching and auto-restart like nodemon/ts-node-dev
|
|
87
73
|
program
|
|
88
|
-
.command('dev
|
|
74
|
+
.command('dev <file>') // Made file mandatory
|
|
89
75
|
.alias('d')
|
|
90
|
-
.description('Run
|
|
76
|
+
.description('Run TypeScript/JavaScript files with file watching and auto-restart (like nodemon/ts-node-dev but better)')
|
|
91
77
|
.option('-c, --no-color', 'Disable colored output')
|
|
92
78
|
.option('-t, --no-timing', 'Hide timing information')
|
|
93
79
|
.option('-p, --no-prefix', 'Hide command prefix')
|
|
94
80
|
.option('-s, --stop-on-error', 'Stop on first error')
|
|
95
81
|
.option('-o, --no-output', 'Hide command output')
|
|
96
82
|
.option('-m, --minimal', 'Use minimal output format')
|
|
97
|
-
.option('-w, --watch <paths...>', '
|
|
83
|
+
.option('-w, --watch <paths...>', 'Additional paths to watch (default: current directory)')
|
|
98
84
|
.option('-i, --ignore <patterns...>', 'Patterns to ignore')
|
|
99
85
|
.option('-e, --ext <extensions...>', 'File extensions to watch (default: js,mjs,json,ts,tsx,jsx)')
|
|
100
86
|
.option('-d, --delay <ms>', 'Delay before restart in milliseconds', parseInt)
|
|
101
87
|
.option('--clear', 'Clear console on restart')
|
|
102
|
-
.option('--
|
|
88
|
+
.option('--verbose', 'Verbose output')
|
|
103
89
|
.option('--signal <signal>', 'Signal to send to processes on restart', 'SIGTERM')
|
|
104
|
-
.action(async (
|
|
90
|
+
.action(async (file, options) => {
|
|
105
91
|
try {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
console.error(chalk_1.default.red(`${figures_1.default.cross} No command specified and no default script found.`));
|
|
118
|
-
console.error(chalk_1.default.yellow(`${figures_1.default.pointer} Add a "dev" or "start" script to package.json or specify a command.`));
|
|
119
|
-
process.exit(1);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
else { // At least one command/argument is provided
|
|
123
|
-
const firstArg = effectiveCommands[0];
|
|
124
|
-
const remainingArgs = effectiveCommands.slice(1);
|
|
125
|
-
const isLikelyCommandOrScript = firstArg.includes(' ') || firstArg.startsWith('npm') || firstArg.startsWith('yarn') || firstArg.startsWith('pnpm');
|
|
126
|
-
if (!isLikelyCommandOrScript) {
|
|
127
|
-
const filePath = path.resolve(process.cwd(), firstArg);
|
|
128
|
-
try {
|
|
129
|
-
await fs.access(filePath); // Check if file exists
|
|
130
|
-
let commandToExecute = '';
|
|
131
|
-
if (firstArg.endsWith('.js') || firstArg.endsWith('.mjs') || firstArg.endsWith('.cjs')) {
|
|
132
|
-
commandToExecute = `node ${firstArg}`;
|
|
133
|
-
if (verbose) {
|
|
134
|
-
console.log(chalk_1.default.blue(`${figures_1.default.info} Detected .js file, using node.`));
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
else if (firstArg.endsWith('.ts') || firstArg.endsWith('.mts') || firstArg.endsWith('.cts')) {
|
|
138
|
-
commandToExecute = `node --loader ts-node/esm ${firstArg}`;
|
|
139
|
-
if (verbose) {
|
|
140
|
-
console.log(chalk_1.default.blue(`${figures_1.default.info} Detected .ts file, using node with ts-node loader.`));
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
if (commandToExecute) {
|
|
144
|
-
effectiveCommands = [commandToExecute, ...remainingArgs];
|
|
145
|
-
}
|
|
146
|
-
else if (verbose) {
|
|
147
|
-
console.log(chalk_1.default.yellow(`${figures_1.default.warning} Running "${firstArg}" as command.`));
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
catch (e) {
|
|
151
|
-
if (verbose) {
|
|
152
|
-
console.log(chalk_1.default.yellow(`${figures_1.default.warning} File "${firstArg}" not found, running as command.`));
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
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);
|
|
156
100
|
}
|
|
157
|
-
//
|
|
158
|
-
|
|
159
|
-
|
|
101
|
+
// Get the best command to run the file
|
|
102
|
+
let commandToExecute;
|
|
103
|
+
try {
|
|
104
|
+
commandToExecute = await getBestCommand(file);
|
|
160
105
|
}
|
|
161
|
-
|
|
162
|
-
console.
|
|
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);
|
|
163
109
|
}
|
|
164
|
-
|
|
110
|
+
// Setup watch configuration
|
|
111
|
+
const watchPaths = options.watch ? [...options.watch, './'] : ['./'];
|
|
165
112
|
const ignorePatterns = options.ignore || [
|
|
166
|
-
'node_modules/**',
|
|
167
|
-
'
|
|
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'
|
|
168
124
|
];
|
|
169
|
-
const extensions = options.ext || ['js', 'mjs', 'json', 'ts', 'tsx', 'jsx'];
|
|
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
|
|
170
140
|
devRunner = new dev_runner_js_1.DevRunner({
|
|
171
141
|
runnerName: 'neex dev',
|
|
172
142
|
parallel: false,
|
|
@@ -181,21 +151,30 @@ function addDevCommands(program) {
|
|
|
181
151
|
ext: extensions,
|
|
182
152
|
delay: options.delay || 1000,
|
|
183
153
|
clearConsole: options.clear,
|
|
184
|
-
verbose: verbose,
|
|
154
|
+
verbose: options.verbose,
|
|
185
155
|
signal: options.signal,
|
|
186
156
|
restartOnChange: true,
|
|
187
157
|
groupOutput: false,
|
|
188
158
|
isServerMode: false
|
|
189
159
|
});
|
|
190
|
-
|
|
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]);
|
|
191
165
|
}
|
|
192
166
|
catch (error) {
|
|
167
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} neex dev: Fatal error occurred`));
|
|
193
168
|
if (error instanceof Error) {
|
|
194
|
-
console.error(chalk_1.default.red(`${figures_1.default.cross}
|
|
169
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} Details: ${error.message}`));
|
|
170
|
+
if (options.verbose && error.stack) {
|
|
171
|
+
console.error(chalk_1.default.gray(`Stack trace:\n${error.stack}`));
|
|
172
|
+
}
|
|
195
173
|
}
|
|
196
174
|
else {
|
|
197
|
-
console.error(chalk_1.default.red(`${figures_1.default.cross}
|
|
175
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} Unknown error occurred`));
|
|
198
176
|
}
|
|
177
|
+
console.error(chalk_1.default.yellow(`${figures_1.default.pointer} Try running with --verbose flag for more details`));
|
|
199
178
|
process.exit(1);
|
|
200
179
|
}
|
|
201
180
|
});
|
|
@@ -204,7 +183,9 @@ function addDevCommands(program) {
|
|
|
204
183
|
getDevRunner: () => devRunner,
|
|
205
184
|
cleanupDev: () => {
|
|
206
185
|
if (devRunner && devRunner.isActive()) {
|
|
186
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} neex dev: Stopping development server...`));
|
|
207
187
|
devRunner.stop();
|
|
188
|
+
console.log(chalk_1.default.green(`${figures_1.default.tick} neex dev: Development server stopped successfully`));
|
|
208
189
|
}
|
|
209
190
|
}
|
|
210
191
|
};
|