neex 0.5.9 → 0.6.1
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 -91
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -32,119 +32,112 @@ 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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
console.log(chalk_1.default.blue(`${figures_1.default.info} No command provided. Using "dev" script from package.json: npm run dev`));
|
|
45
|
-
return 'npm run dev';
|
|
46
|
-
}
|
|
47
|
-
if ((_b = packageJson.scripts) === null || _b === void 0 ? void 0 : _b.start) {
|
|
48
|
-
console.log(chalk_1.default.blue(`${figures_1.default.info} No command provided. Using "start" script from package.json: npm run start`));
|
|
49
|
-
return 'npm run start';
|
|
50
|
-
}
|
|
51
|
-
if (packageJson.main) {
|
|
52
|
-
const mainFile = packageJson.main;
|
|
53
|
-
const mainFilePath = path.resolve(process.cwd(), mainFile);
|
|
54
|
-
try {
|
|
55
|
-
await fs.access(mainFilePath);
|
|
56
|
-
if (mainFile.endsWith('.ts') || mainFile.endsWith('.mts') || mainFile.endsWith('.cts')) {
|
|
57
|
-
console.log(chalk_1.default.blue(`${figures_1.default.info} No command or script found. Using "main" field (TypeScript): neex dev ${mainFile}`));
|
|
58
|
-
return `npx ts-node ${mainFile}`;
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
console.log(chalk_1.default.blue(`${figures_1.default.info} No command or script found. Using "main" field (JavaScript): node ${mainFile}`));
|
|
62
|
-
return `node ${mainFile}`;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
catch (e) {
|
|
66
|
-
// Main file doesn't exist, do nothing, will fall through to return null
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return null;
|
|
38
|
+
await fs.access(filePath);
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
catch (_a) {
|
|
42
|
+
return false;
|
|
70
43
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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 ${chalk_1.default.cyan(path.basename(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: TypeScript detected, ready to run`));
|
|
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: JavaScript detected, ready to run`));
|
|
64
|
+
return `node ${filePath}`;
|
|
65
|
+
default:
|
|
66
|
+
console.log(chalk_1.default.yellow(`${figures_1.default.warning} neex dev: Unknown file type, using Node.js`));
|
|
67
|
+
return `node ${filePath}`;
|
|
74
68
|
}
|
|
75
69
|
}
|
|
76
70
|
function addDevCommands(program) {
|
|
77
71
|
let devRunner = null;
|
|
78
|
-
// Dev command
|
|
72
|
+
// Dev command - file watching and auto-restart like nodemon/ts-node-dev
|
|
79
73
|
program
|
|
80
|
-
.command('dev
|
|
74
|
+
.command('dev <file>') // Made file mandatory
|
|
81
75
|
.alias('d')
|
|
82
|
-
.description('Run
|
|
76
|
+
.description('Run TypeScript/JavaScript files with file watching and auto-restart (like nodemon/ts-node-dev but better)')
|
|
83
77
|
.option('-c, --no-color', 'Disable colored output')
|
|
84
78
|
.option('-t, --no-timing', 'Hide timing information')
|
|
85
79
|
.option('-p, --no-prefix', 'Hide command prefix')
|
|
86
80
|
.option('-s, --stop-on-error', 'Stop on first error')
|
|
87
81
|
.option('-o, --no-output', 'Hide command output')
|
|
88
82
|
.option('-m, --minimal', 'Use minimal output format')
|
|
89
|
-
.option('-w, --watch <paths...>', '
|
|
83
|
+
.option('-w, --watch <paths...>', 'Additional paths to watch (default: current directory)')
|
|
90
84
|
.option('-i, --ignore <patterns...>', 'Patterns to ignore')
|
|
91
85
|
.option('-e, --ext <extensions...>', 'File extensions to watch (default: js,mjs,json,ts,tsx,jsx)')
|
|
92
86
|
.option('-d, --delay <ms>', 'Delay before restart in milliseconds', parseInt)
|
|
93
87
|
.option('--clear', 'Clear console on restart')
|
|
94
88
|
.option('--verbose', 'Verbose output')
|
|
95
89
|
.option('--signal <signal>', 'Signal to send to processes on restart', 'SIGTERM')
|
|
96
|
-
.action(async (
|
|
90
|
+
.action(async (file, options) => {
|
|
97
91
|
try {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
console.error(chalk_1.default.red(`${figures_1.default.cross} No command specified for 'neex dev' and no default script (dev, start) or main file found in package.json.`));
|
|
107
|
-
console.error(chalk_1.default.yellow(`${figures_1.default.pointer} Please specify a command to run (e.g., neex dev "npm run dev") or define a "dev" or "start" script in your package.json.`));
|
|
108
|
-
process.exit(1);
|
|
109
|
-
}
|
|
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);
|
|
110
100
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
commandToExecute = `node ${firstArg}`;
|
|
122
|
-
console.log(chalk_1.default.blue(`${figures_1.default.info} Detected .js file, prepending with node.`));
|
|
123
|
-
}
|
|
124
|
-
else if (firstArg.endsWith('.ts') || firstArg.endsWith('.mts') || firstArg.endsWith('.cts')) {
|
|
125
|
-
commandToExecute = `neex dev ${firstArg}`;
|
|
126
|
-
console.log(chalk_1.default.blue(`${figures_1.default.info} Detected .ts file, prepending with neex dev.`));
|
|
127
|
-
}
|
|
128
|
-
if (commandToExecute) {
|
|
129
|
-
effectiveCommands = [commandToExecute, ...remainingArgs];
|
|
130
|
-
console.log(chalk_1.default.cyan(`${figures_1.default.pointer} Executing: ${effectiveCommands.join(' ')}`));
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
console.log(chalk_1.default.yellow(`${figures_1.default.warning} First argument "${firstArg}" is not a recognized .js/.ts file and doesn't look like a script. Attempting to run as is.`));
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
catch (e) {
|
|
137
|
-
console.log(chalk_1.default.yellow(`${figures_1.default.warning} File "${firstArg}" not found. Attempting to run as command.`));
|
|
138
|
-
}
|
|
139
|
-
}
|
|
101
|
+
// Get the best command to run the file
|
|
102
|
+
let commandToExecute;
|
|
103
|
+
let fileExtension;
|
|
104
|
+
try {
|
|
105
|
+
commandToExecute = await getBestCommand(file);
|
|
106
|
+
fileExtension = path.extname(file).toLowerCase();
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} neex dev: ${error instanceof Error ? error.message : 'Unknown error occurred'}`));
|
|
110
|
+
process.exit(1);
|
|
140
111
|
}
|
|
141
|
-
|
|
142
|
-
const watchPaths = options.watch
|
|
112
|
+
// Setup watch configuration
|
|
113
|
+
const watchPaths = options.watch ? [...options.watch, './'] : ['./'];
|
|
143
114
|
const ignorePatterns = options.ignore || [
|
|
144
|
-
'node_modules/**',
|
|
145
|
-
'
|
|
115
|
+
'node_modules/**',
|
|
116
|
+
'.git/**',
|
|
117
|
+
'*.log',
|
|
118
|
+
'dist/**',
|
|
119
|
+
'build/**',
|
|
120
|
+
'coverage/**',
|
|
121
|
+
'.nyc_output/**',
|
|
122
|
+
'*.tmp',
|
|
123
|
+
'*.temp',
|
|
124
|
+
'.DS_Store',
|
|
125
|
+
'Thumbs.db'
|
|
146
126
|
];
|
|
147
|
-
const extensions = options.ext || ['js', 'mjs', 'json', 'ts', 'tsx', 'jsx'];
|
|
127
|
+
const extensions = options.ext || ['js', 'mjs', 'json', 'ts', 'tsx', 'jsx', 'vue', 'svelte'];
|
|
128
|
+
// Log configuration
|
|
129
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} neex dev: Configuration:`));
|
|
130
|
+
console.log(chalk_1.default.blue(` ${figures_1.default.arrowRight} Target: ${chalk_1.default.cyan(file)}`));
|
|
131
|
+
console.log(chalk_1.default.blue(` ${figures_1.default.arrowRight} Runtime: ${chalk_1.default.cyan(fileExtension === '.ts' || fileExtension === '.mts' || fileExtension === '.cts' ? 'TypeScript' : 'JavaScript')}`));
|
|
132
|
+
console.log(chalk_1.default.blue(` ${figures_1.default.arrowRight} Watch paths: ${chalk_1.default.cyan(watchPaths.join(', '))}`));
|
|
133
|
+
console.log(chalk_1.default.blue(` ${figures_1.default.arrowRight} Extensions: ${chalk_1.default.cyan(extensions.join(', '))}`));
|
|
134
|
+
console.log(chalk_1.default.blue(` ${figures_1.default.arrowRight} Restart delay: ${chalk_1.default.cyan(options.delay || 1000)}ms`));
|
|
135
|
+
console.log(chalk_1.default.blue(` ${figures_1.default.arrowRight} Clear console: ${chalk_1.default.cyan(options.clear ? 'Yes' : 'No')}`));
|
|
136
|
+
if (options.verbose) {
|
|
137
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} neex dev: Verbose mode enabled - showing detailed logs`));
|
|
138
|
+
}
|
|
139
|
+
console.log(chalk_1.default.green(`${figures_1.default.tick} neex dev: Starting file watcher and process manager...`));
|
|
140
|
+
// Create DevRunner instance - remove customPrefix since it doesn't exist
|
|
148
141
|
devRunner = new dev_runner_js_1.DevRunner({
|
|
149
142
|
runnerName: 'neex dev',
|
|
150
143
|
parallel: false,
|
|
@@ -165,15 +158,24 @@ function addDevCommands(program) {
|
|
|
165
158
|
groupOutput: false,
|
|
166
159
|
isServerMode: false
|
|
167
160
|
});
|
|
168
|
-
|
|
161
|
+
// Start the development server
|
|
162
|
+
console.log(chalk_1.default.green(`${figures_1.default.tick} neex dev: Launching ${chalk_1.default.cyan(path.basename(file))} with auto-restart capability...`));
|
|
163
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} neex dev: Press Ctrl+C to stop the development server`));
|
|
164
|
+
console.log(chalk_1.default.gray(`${'='.repeat(60)}`));
|
|
165
|
+
await devRunner.start([commandToExecute]);
|
|
169
166
|
}
|
|
170
167
|
catch (error) {
|
|
168
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} neex dev: Fatal error occurred`));
|
|
171
169
|
if (error instanceof Error) {
|
|
172
|
-
console.error(chalk_1.default.red(`${figures_1.default.cross}
|
|
170
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} Details: ${error.message}`));
|
|
171
|
+
if (options.verbose && error.stack) {
|
|
172
|
+
console.error(chalk_1.default.gray(`Stack trace:\n${error.stack}`));
|
|
173
|
+
}
|
|
173
174
|
}
|
|
174
175
|
else {
|
|
175
|
-
console.error(chalk_1.default.red(`${figures_1.default.cross}
|
|
176
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} Unknown error occurred`));
|
|
176
177
|
}
|
|
178
|
+
console.error(chalk_1.default.yellow(`${figures_1.default.pointer} Try running with --verbose flag for more details`));
|
|
177
179
|
process.exit(1);
|
|
178
180
|
}
|
|
179
181
|
});
|
|
@@ -182,7 +184,9 @@ function addDevCommands(program) {
|
|
|
182
184
|
getDevRunner: () => devRunner,
|
|
183
185
|
cleanupDev: () => {
|
|
184
186
|
if (devRunner && devRunner.isActive()) {
|
|
187
|
+
console.log(chalk_1.default.blue(`${figures_1.default.info} neex dev: Stopping development server...`));
|
|
185
188
|
devRunner.stop();
|
|
189
|
+
console.log(chalk_1.default.green(`${figures_1.default.tick} neex dev: Development server stopped successfully`));
|
|
186
190
|
}
|
|
187
191
|
}
|
|
188
192
|
};
|