neex 0.4.6 → 0.5.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 +366 -39
- package/dist/src/cli.js +24 -13
- package/dist/src/commands/dev-commands.js +190 -0
- package/dist/src/commands/index.js +21 -0
- package/dist/src/commands/process-commands.js +679 -0
- package/dist/src/commands/run-commands.js +94 -0
- package/dist/src/commands/server-commands.js +50 -0
- package/dist/src/dev-runner.js +209 -0
- package/dist/src/index.js +3 -1
- package/dist/src/logger.js +36 -0
- package/dist/src/process-manager.js +669 -0
- package/dist/src/runner.js +112 -78
- package/dist/src/utils.js +10 -0
- package/dist/src/watcher.js +245 -0
- package/feet.txt +16 -0
- package/package.json +4 -4
- package/bun.lock +0 -621
- package/dist/src/commands/run-commands/run.js +0 -81
- package/dist/src/project-manager.js +0 -208
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
</picture>
|
|
7
7
|
</a>
|
|
8
8
|
|
|
9
|
-
# Neex v0.1
|
|
9
|
+
# Neex v0.5.1
|
|
10
10
|
|
|
11
11
|
### 🚀 Neex: The Modern Build System for Polyrepo-in-Monorepo Architecture
|
|
12
12
|
|
|
@@ -20,12 +20,12 @@
|
|
|
20
20
|
|
|
21
21
|
next + express = neex 🌱
|
|
22
22
|
|
|
23
|
-
Neex is a modern build system designed
|
|
23
|
+
Neex is a modern build system and script runner designed for **Polyrepo-in-Monorepo** architectures, but powerful enough for any project. It simplifies managing and running multiple scripts across your project, whether they are microservices, frontend applications, or build tasks. Neex offers robust features like parallel and sequential execution, live-reloading for development (`watch`), optimized server running (`servers`), and even basic process management (`pm2`-like commands), all aimed at making your development workflow more efficient, organized, and visually clear.
|
|
24
24
|
|
|
25
25
|
## ✨ Key Features
|
|
26
26
|
|
|
27
27
|
- 🎨 **Colored Output** - Distinguish commands with unique colors
|
|
28
|
-
- ⚡ **Dual Execution Modes** - Run commands in parallel (`
|
|
28
|
+
- ⚡ **Dual Execution Modes** - Run commands in parallel (`px`) or sequence (`s`, `run`)
|
|
29
29
|
- ⏱️ **Smart Timing** - Track execution time for each command
|
|
30
30
|
- 🛑 **Error Control** - Stop on first error (perfect for CI/CD)
|
|
31
31
|
- 🔢 **Parallel Control** - Limit concurrent processes with `--max-parallel`
|
|
@@ -34,7 +34,24 @@ Neex is a modern build system designed to bridge the gap between polyrepo and mo
|
|
|
34
34
|
- 🤫 **Flexible Display** - Control prefixes, timing, and output visibility
|
|
35
35
|
- 🧰 **Node.js API** - Programmatic usage in your applications
|
|
36
36
|
|
|
37
|
-
##
|
|
37
|
+
## 🚀 Installation
|
|
38
|
+
|
|
39
|
+
Install Neex globally to use it anywhere, or locally in your project.
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
# Global install
|
|
43
|
+
npm install -g neex
|
|
44
|
+
|
|
45
|
+
# Local install
|
|
46
|
+
npm install --save-dev neex # npm
|
|
47
|
+
yarn add --dev neex # yarn
|
|
48
|
+
pnpm add --save-dev neex # pnpm
|
|
49
|
+
bun add --dev neex # bun
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
When installed locally, you can run Neex commands using `npx neex ...` or by adding them to your `package.json` scripts.
|
|
53
|
+
|
|
54
|
+
## 🖥️ Usage
|
|
38
55
|
|
|
39
56
|
```bash
|
|
40
57
|
# Global install
|
|
@@ -49,36 +66,288 @@ bun add -D neex # bun
|
|
|
49
66
|
|
|
50
67
|
## 🖥️ Usage
|
|
51
68
|
|
|
52
|
-
### Commands
|
|
69
|
+
### Core Commands
|
|
70
|
+
|
|
71
|
+
Neex provides several commands to manage and run your scripts:
|
|
72
|
+
|
|
73
|
+
- **`px <commands...>`** (*default command*)
|
|
74
|
+
- Runs specified commands in **parallel** by default.
|
|
75
|
+
- Use the `-q` or `--sequential` flag to run them sequentially.
|
|
76
|
+
- Ideal for build steps, tests, or any tasks that can run concurrently.
|
|
77
|
+
|
|
78
|
+
- **`run <commands...>`** (alias: `s`)
|
|
79
|
+
- Runs specified commands **sequentially**.
|
|
80
|
+
- Useful for tasks that depend on the completion of previous ones (e.g., build then deploy).
|
|
81
|
+
|
|
82
|
+
- **`servers <commands...>`** (alias: `srv`)
|
|
83
|
+
- Optimized for running multiple development **servers** (e.g., backend API, frontend app) in parallel.
|
|
84
|
+
- Provides grouped and clear output for each server, making it easy to monitor logs.
|
|
85
|
+
- Detects and displays server ports and URLs.
|
|
86
|
+
|
|
87
|
+
- **`watch <commands...>`** (alias: `w`)
|
|
88
|
+
- Runs commands and **watches for file changes** to automatically restart them (Nodemon-like functionality).
|
|
89
|
+
- Highly configurable with options for watched paths, ignored patterns, extensions, and restart delays.
|
|
90
|
+
- Perfect for development workflows where you need instant feedback on code changes.
|
|
53
91
|
|
|
54
|
-
-
|
|
55
|
-
-
|
|
92
|
+
- **Process Management Commands**
|
|
93
|
+
- Neex provides built-in process management capabilities, similar to PM2, for long-running applications. These commands operate directly under `neex`:
|
|
94
|
+
- **`start <script_path_or_command> [--name <name>] [--watch] [-- <args...>]`**: Start a new process.
|
|
95
|
+
- **`stop <name_or_id>`**: Stop a running process.
|
|
96
|
+
- **`restart <name_or_id>`**: Restart a running process.
|
|
97
|
+
- **`delete <name_or_id>`**: Stop and delete a process from the list.
|
|
98
|
+
- **`list`** (aliases: `ls`, `status`): List all managed processes.
|
|
99
|
+
- **`logs [name_or_id] [--lines <number>] [--follow]`**: Display logs for a specific process or all if no ID is given.
|
|
100
|
+
- **`monit`**: Launch a monitoring interface for all managed processes.
|
|
101
|
+
- **`save`**: Save the current list of running processes.
|
|
102
|
+
- **`resurrect`**: Restart processes that were previously saved.
|
|
103
|
+
- **`startup`**: Generate a sample startup script (e.g., for systemd).
|
|
56
104
|
|
|
57
|
-
### Examples
|
|
105
|
+
### General Command Examples
|
|
58
106
|
|
|
59
107
|
```bash
|
|
60
|
-
# Parallel execution (default)
|
|
61
|
-
neex
|
|
108
|
+
# Parallel execution (default behavior for px)
|
|
109
|
+
neex px "npm run build:api" "npm run build:frontend" "npm run lint"
|
|
110
|
+
# px is the command for parallel execution
|
|
111
|
+
neex px "npm run test:unit" "npm run test:integration"
|
|
62
112
|
|
|
63
113
|
# Sequential execution
|
|
64
|
-
neex
|
|
114
|
+
neex run "npm run clean" "npm run build" "npm run deploy"
|
|
115
|
+
# Alias for sequential
|
|
116
|
+
neex s "echo First" "echo Second" "echo Third"
|
|
117
|
+
|
|
118
|
+
# Run 'px' commands sequentially using the -q flag
|
|
119
|
+
neex px -q "npm run step1" "npm run step2"
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### `servers` Command Examples
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
# Start frontend and backend development servers
|
|
126
|
+
neex servers "cd frontend && npm start" "cd backend && npm start"
|
|
127
|
+
|
|
128
|
+
# Group output for better readability
|
|
129
|
+
neex servers --group-output "npm run dev:service-a" "npm run dev:service-b"
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### `watch` Command Examples
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
# Watch for changes in './src' and restart 'npm run build'
|
|
136
|
+
neex watch "npm run build" -w ./src
|
|
137
|
+
|
|
138
|
+
# Watch for .ts file changes in 'services/' and restart two commands, ignoring 'node_modules'
|
|
139
|
+
neex watch "npm run start:service1" "npm run start:service2" -w services/ -e ts,tsx -i node_modules/**
|
|
140
|
+
|
|
141
|
+
# Clear console on restart and set a delay
|
|
142
|
+
neex watch "node server.js" --clear --delay 1500
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Process Management Command Examples
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
# Start a Node.js app and give it a name
|
|
149
|
+
neex start server.js --name my-app
|
|
150
|
+
|
|
151
|
+
# Start an app and watch for file changes
|
|
152
|
+
neex start api/index.js --name my-api --watch
|
|
153
|
+
|
|
154
|
+
# List all running processes managed by neex
|
|
155
|
+
neex list
|
|
156
|
+
|
|
157
|
+
# View logs for 'my-app'
|
|
158
|
+
neex logs my-app
|
|
159
|
+
|
|
160
|
+
# Stop 'my-api'
|
|
161
|
+
neex stop my-api
|
|
162
|
+
|
|
163
|
+
# Restart 'my-app'
|
|
164
|
+
neex restart my-app
|
|
165
|
+
|
|
166
|
+
# Delete 'my-api' from neex management
|
|
167
|
+
neex delete my-api
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### `dev` Command Examples
|
|
171
|
+
|
|
172
|
+
The `dev` command is designed for development environments, providing automatic file watching and restart functionality. Here are various ways to use it:
|
|
173
|
+
|
|
174
|
+
#### 1. Automatic Usage
|
|
175
|
+
|
|
176
|
+
When no arguments are provided, neex dev will automatically:
|
|
177
|
+
|
|
178
|
+
- If `package.json` has a `"dev"` script:
|
|
179
|
+
```bash
|
|
180
|
+
neex dev # runs: npm run dev
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
- If only a `"start"` script exists:
|
|
184
|
+
```bash
|
|
185
|
+
neex dev # runs: npm run start
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
- If only a `"main"` field exists:
|
|
189
|
+
```bash
|
|
190
|
+
neex dev # runs: node main.js (for JavaScript)
|
|
191
|
+
neex dev # runs: npx ts-node main.ts (for TypeScript)
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
#### 2. Direct File Execution
|
|
195
|
+
|
|
196
|
+
Run JavaScript or TypeScript files directly:
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
# JavaScript file
|
|
200
|
+
neex dev app.js # runs: node app.js
|
|
201
|
+
|
|
202
|
+
# TypeScript file
|
|
203
|
+
neex dev server.ts # runs: npx ts-node server.ts
|
|
204
|
+
|
|
205
|
+
# ES modules
|
|
206
|
+
neex dev index.mjs
|
|
207
|
+
|
|
208
|
+
# CommonJS TypeScript
|
|
209
|
+
neex dev main.cts
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
#### 3. Package Manager Scripts
|
|
213
|
+
|
|
214
|
+
Run npm/yarn/pnpm scripts:
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
# npm scripts
|
|
218
|
+
neex dev "npm run dev"
|
|
219
|
+
neex dev "npm run start"
|
|
220
|
+
neex dev "npm run build"
|
|
221
|
+
|
|
222
|
+
# yarn scripts
|
|
223
|
+
neex dev "yarn dev"
|
|
224
|
+
neex dev "yarn start"
|
|
225
|
+
|
|
226
|
+
# pnpm scripts
|
|
227
|
+
neex dev "pnpm dev"
|
|
228
|
+
neex dev "pnpm start"
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
#### 4. System Commands
|
|
65
232
|
|
|
66
|
-
|
|
67
|
-
|
|
233
|
+
Execute various system commands:
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
neex dev "python app.py"
|
|
237
|
+
neex dev "php server.php"
|
|
238
|
+
neex dev "go run main.go"
|
|
239
|
+
neex dev "cargo run"
|
|
240
|
+
neex dev "dotnet run"
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
#### 5. Configuration Options
|
|
244
|
+
|
|
245
|
+
Customize the development experience with these options:
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
# Watch specific directories
|
|
249
|
+
neex dev --watch src --watch public "npm run dev"
|
|
250
|
+
|
|
251
|
+
# Ignore certain files/directories
|
|
252
|
+
neex dev --ignore "*.log" --ignore "temp/**" "node server.js"
|
|
253
|
+
|
|
254
|
+
# Specify file extensions
|
|
255
|
+
neex dev --ext js,ts,vue,jsx "npm run dev"
|
|
256
|
+
|
|
257
|
+
# Set restart delay
|
|
258
|
+
neex dev --delay 2000 "npm run dev"
|
|
259
|
+
|
|
260
|
+
# Clear console on restart
|
|
261
|
+
neex dev --clear "node app.js"
|
|
262
|
+
|
|
263
|
+
# Minimal output
|
|
264
|
+
neex dev --minimal "npm run dev"
|
|
265
|
+
|
|
266
|
+
# Disable colors
|
|
267
|
+
neex dev --no-color "npm run dev"
|
|
268
|
+
|
|
269
|
+
# Disable timing display
|
|
270
|
+
neex dev --no-timing "npm run dev"
|
|
271
|
+
|
|
272
|
+
# Stop on first error
|
|
273
|
+
neex dev --stop-on-error "npm run test"
|
|
68
274
|
```
|
|
69
275
|
|
|
70
|
-
|
|
276
|
+
#### 6. Framework-Specific Examples
|
|
71
277
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
278
|
+
```bash
|
|
279
|
+
# Express.js
|
|
280
|
+
neex dev server.js
|
|
281
|
+
|
|
282
|
+
# Fastify
|
|
283
|
+
neex dev --watch src "npm run dev"
|
|
284
|
+
|
|
285
|
+
# Nest.js
|
|
286
|
+
neex dev --watch src --ext ts "npm run start:dev"
|
|
287
|
+
|
|
288
|
+
# Koa.js
|
|
289
|
+
neex dev --watch app --ext js "node app.js"
|
|
81
290
|
|
|
291
|
+
# Electron
|
|
292
|
+
neex dev --watch src --ext js,html "npm run electron"
|
|
293
|
+
|
|
294
|
+
# Webpack Dev Server
|
|
295
|
+
neex dev --watch src --ext js,css,html "npm run dev"
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
#### 7. Error Handling
|
|
299
|
+
|
|
300
|
+
```bash
|
|
301
|
+
# No command specified and no default script
|
|
302
|
+
neex dev
|
|
303
|
+
# Error: No command specified for 'neex dev' and no default script
|
|
304
|
+
|
|
305
|
+
# Non-existent file
|
|
306
|
+
neex dev nonexistent.js
|
|
307
|
+
# Warning: File "nonexistent.js" not found. Attempting to run as command.
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
### 📚 Examples
|
|
311
|
+
|
|
312
|
+
### Parallel Execution
|
|
313
|
+
|
|
314
|
+
```bash
|
|
315
|
+
# Parallel execution (default behavior for p)
|
|
316
|
+
neex p "npm run build:api" "npm run build:frontend" "npm run lint"
|
|
317
|
+
neex par "npm run test:unit" "npm run test:integration"
|
|
318
|
+
neex parallel "npm run test:frontend" "npm run test:backend"
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
### Sequential Execution
|
|
322
|
+
|
|
323
|
+
```bash
|
|
324
|
+
# Sequential execution using s command
|
|
325
|
+
neex s "npm run clean" "npm run build" "npm run deploy"
|
|
326
|
+
neex seq "echo First" "echo Second" "echo Third"
|
|
327
|
+
neex sequential "npm run step1" "npm run step2" "npm run step3"
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
### Parallel with Sequential Flag
|
|
331
|
+
|
|
332
|
+
```bash
|
|
333
|
+
# Run parallel commands sequentially using the -q flag
|
|
334
|
+
neex p -q "npm run step1" "npm run step2"
|
|
335
|
+
neex par -q "npm run build" "npm run test"
|
|
336
|
+
neex parallel -q "npm run lint" "npm run format"
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
### Advanced Options
|
|
340
|
+
|
|
341
|
+
```bash
|
|
342
|
+
# With retry options
|
|
343
|
+
neex p --retry 3 --retry-delay 1000 "npm run test"
|
|
344
|
+
|
|
345
|
+
# With output control
|
|
346
|
+
neex s --no-color --no-timing --no-output "npm run build"
|
|
347
|
+
|
|
348
|
+
# With parallel limits
|
|
349
|
+
neex p --max-parallel 2 "npm run build:frontend" "npm run build:backend" "npm run build:api"
|
|
350
|
+
```
|
|
82
351
|
|
|
83
352
|
### Advanced Example
|
|
84
353
|
|
|
@@ -115,17 +384,38 @@ async function main() {
|
|
|
115
384
|
}
|
|
116
385
|
```
|
|
117
386
|
|
|
118
|
-
### API Options
|
|
387
|
+
### API Options (`RunOptions`)
|
|
388
|
+
|
|
389
|
+
When using Neex programmatically, you can pass an options object to the `run` function:
|
|
119
390
|
|
|
120
391
|
```typescript
|
|
121
|
-
interface RunOptions {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
printOutput
|
|
128
|
-
|
|
392
|
+
export interface RunOptions {
|
|
393
|
+
// Run in parallel or sequentially
|
|
394
|
+
parallel: boolean;
|
|
395
|
+
// Maximum number of parallel processes (default: CPU count)
|
|
396
|
+
maxParallel?: number;
|
|
397
|
+
// Show command output (default: true)
|
|
398
|
+
printOutput: boolean;
|
|
399
|
+
// Color output (default: true)
|
|
400
|
+
color: boolean;
|
|
401
|
+
// Show timing information (default: true)
|
|
402
|
+
showTiming: boolean;
|
|
403
|
+
// Show command prefix (default: true)
|
|
404
|
+
prefix: boolean;
|
|
405
|
+
// Stop on error (default: false)
|
|
406
|
+
stopOnError: boolean;
|
|
407
|
+
// Use minimal output format (default: false)
|
|
408
|
+
minimalOutput: boolean;
|
|
409
|
+
// Group output by command (default: false, mainly for server mode)
|
|
410
|
+
groupOutput: boolean;
|
|
411
|
+
// Use server mode formatting (default: false)
|
|
412
|
+
isServerMode: boolean;
|
|
413
|
+
// Number of times to retry a failed command (default: 0)
|
|
414
|
+
retry?: number;
|
|
415
|
+
// Delay in milliseconds between retries (default: 1000)
|
|
416
|
+
retryDelay?: number;
|
|
417
|
+
// Callback to register a cleanup function, called on SIGINT/SIGTERM
|
|
418
|
+
registerCleanup?: (cleanupFn: () => void) => void;
|
|
129
419
|
}
|
|
130
420
|
```
|
|
131
421
|
|
|
@@ -141,17 +431,54 @@ steps:
|
|
|
141
431
|
run: neex p -s -m 4 "npm run lint" "npm test" "npm run e2e"
|
|
142
432
|
```
|
|
143
433
|
|
|
144
|
-
## 💡 Real-world
|
|
434
|
+
## 💡 Real-world Scenarios & `package.json` Integration
|
|
435
|
+
|
|
436
|
+
Neex shines when integrated into your `package.json` scripts.
|
|
437
|
+
|
|
438
|
+
**Example `package.json` scripts:**
|
|
439
|
+
|
|
440
|
+
```json
|
|
441
|
+
{
|
|
442
|
+
"scripts": {
|
|
443
|
+
"dev:frontend": "cd packages/frontend && npm run dev",
|
|
444
|
+
"dev:backend": "cd packages/api && npm run dev",
|
|
445
|
+
"dev": "neex servers \"npm run dev:frontend\" \"npm run dev:backend\" --group-output",
|
|
446
|
+
|
|
447
|
+
"build:ui": "cd packages/ui-library && npm run build",
|
|
448
|
+
"build:app": "cd packages/main-app && npm run build",
|
|
449
|
+
"build": "neex runx \"npm run build:ui\" \"npm run build:app\"",
|
|
450
|
+
|
|
451
|
+
"test": "neex runx -s \"npm run test:unit\" \"npm run test:e2e\"",
|
|
452
|
+
"test:unit": "jest",
|
|
453
|
+
"test:e2e": "playwright test",
|
|
454
|
+
|
|
455
|
+
"lint": "eslint .",
|
|
456
|
+
"format": "prettier --write .",
|
|
457
|
+
"check-all": "neex p \"npm run lint\" \"npm run format -- --check\" \"npm run test\"",
|
|
458
|
+
|
|
459
|
+
"start:prod": "neex pm2 start dist/server.js --name my-prod-app",
|
|
460
|
+
"watch:build": "neex watch \"npm run build:app\" -w packages/main-app/src -e ts,tsx"
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
**Running these scripts:**
|
|
145
466
|
|
|
146
467
|
```bash
|
|
147
|
-
#
|
|
148
|
-
|
|
468
|
+
# Start all development servers with grouped output
|
|
469
|
+
npm run dev
|
|
470
|
+
|
|
471
|
+
# Build UI library and main application in parallel
|
|
472
|
+
npm run build
|
|
473
|
+
|
|
474
|
+
# Run linters, format check, and all tests in parallel
|
|
475
|
+
npm run check-all
|
|
149
476
|
|
|
150
|
-
#
|
|
151
|
-
|
|
477
|
+
# Start the production application using neex's pm2
|
|
478
|
+
npm run start:prod
|
|
152
479
|
|
|
153
|
-
#
|
|
154
|
-
|
|
480
|
+
# Watch for changes in the main app's src and rebuild it
|
|
481
|
+
npm run watch:build
|
|
155
482
|
```
|
|
156
483
|
|
|
157
484
|
## 🤝 Contributing
|
package/dist/src/cli.js
CHANGED
|
@@ -3,37 +3,48 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
// src/cli.ts -
|
|
6
|
+
// src/cli.ts - Main CLI file (refactored)
|
|
7
7
|
const commander_1 = require("commander");
|
|
8
|
+
const index_js_1 = require("./commands/index.js");
|
|
8
9
|
const chalk_1 = __importDefault(require("chalk"));
|
|
9
10
|
const figures_1 = __importDefault(require("figures"));
|
|
10
|
-
const project_manager_js_1 = require("./project-manager.js");
|
|
11
11
|
const { version } = require('../../package.json');
|
|
12
12
|
function cli() {
|
|
13
13
|
const program = new commander_1.Command();
|
|
14
|
-
|
|
14
|
+
// Initialize cleanup handlers
|
|
15
|
+
const cleanupHandlers = [];
|
|
15
16
|
program
|
|
16
17
|
.name('neex')
|
|
17
|
-
.description('Professional
|
|
18
|
+
.description('Professional script runner with nodemon and PM2 functionality')
|
|
18
19
|
.version(version);
|
|
19
|
-
//
|
|
20
|
-
|
|
20
|
+
// Add all command groups
|
|
21
|
+
(0, index_js_1.addRunCommands)(program);
|
|
22
|
+
(0, index_js_1.addServerCommands)(program);
|
|
23
|
+
const devCommands = (0, index_js_1.addDevCommands)(program);
|
|
24
|
+
cleanupHandlers.push(devCommands.cleanupDev);
|
|
25
|
+
const processCommands = (0, index_js_1.addProcessCommands)(program);
|
|
26
|
+
cleanupHandlers.push(processCommands.cleanupProcess);
|
|
21
27
|
program.parse(process.argv);
|
|
22
28
|
// Show help if no commands specified
|
|
23
29
|
if (program.args.length === 0) {
|
|
24
30
|
program.help();
|
|
25
31
|
}
|
|
26
32
|
// Graceful shutdown handling
|
|
27
|
-
const handleSignal = (signal) => {
|
|
33
|
+
const handleSignal = async (signal) => {
|
|
28
34
|
console.log(`\n${chalk_1.default.yellow(`${figures_1.default.warning} Received ${signal}. Cleaning up...`)}`);
|
|
29
|
-
|
|
30
|
-
|
|
35
|
+
// Run all cleanup handlers
|
|
36
|
+
for (const cleanup of cleanupHandlers) {
|
|
37
|
+
try {
|
|
38
|
+
await cleanup();
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
console.error(`Cleanup error:`, error);
|
|
42
|
+
}
|
|
31
43
|
}
|
|
32
|
-
// Give cleanup a moment, then exit
|
|
33
44
|
setTimeout(() => process.exit(0), 500);
|
|
34
45
|
};
|
|
35
|
-
process.on('SIGINT', () => handleSignal('SIGINT'));
|
|
36
|
-
process.on('SIGTERM', () => handleSignal('SIGTERM'));
|
|
37
|
-
process.on('SIGQUIT', () => handleSignal('SIGQUIT'));
|
|
46
|
+
process.on('SIGINT', () => handleSignal('SIGINT').catch(err => console.error('SIGINT handler error:', err)));
|
|
47
|
+
process.on('SIGTERM', () => handleSignal('SIGTERM').catch(err => console.error('SIGTERM handler error:', err)));
|
|
48
|
+
process.on('SIGQUIT', () => handleSignal('SIGQUIT').catch(err => console.error('SIGQUIT handler error:', err)));
|
|
38
49
|
}
|
|
39
50
|
exports.default = cli;
|