neex 0.4.4 → 0.5.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.
Files changed (65) hide show
  1. package/README.md +227 -70
  2. package/dist/bin/neex.js +4 -0
  3. package/dist/src/cli.js +50 -0
  4. package/dist/src/commands/dev-commands.js +190 -0
  5. package/dist/src/commands/index.js +21 -0
  6. package/dist/src/commands/process-commands.js +679 -0
  7. package/dist/src/commands/run-commands.js +94 -0
  8. package/dist/src/commands/server-commands.js +50 -0
  9. package/dist/src/dev-runner.js +209 -0
  10. package/dist/src/index.js +72 -0
  11. package/dist/{logger.js → src/logger.js} +36 -1
  12. package/dist/src/process-manager.js +669 -0
  13. package/dist/{runner.js → src/runner.js} +112 -79
  14. package/dist/{types.js → src/types.js} +0 -1
  15. package/dist/src/utils.js +10 -0
  16. package/dist/src/watcher.js +245 -0
  17. package/feet.txt +16 -0
  18. package/package.json +5 -19
  19. package/.env +0 -2
  20. package/Screenshot 1404-03-20 at 17.20.45.png +0 -0
  21. package/Screenshot 1404-03-20 at 17.20.56.png +0 -0
  22. package/Screenshot 1404-03-20 at 17.21.04.png +0 -0
  23. package/bun.lock +0 -939
  24. package/dist/cli.d.ts +0 -1
  25. package/dist/cli.js +0 -49
  26. package/dist/cli.js.map +0 -1
  27. package/dist/commands/process-command/process.d.ts +0 -2
  28. package/dist/commands/process-command/process.js +0 -150
  29. package/dist/commands/process-command/process.js.map +0 -1
  30. package/dist/commands/project-command/build.d.ts +0 -3
  31. package/dist/commands/project-command/build.js +0 -42
  32. package/dist/commands/project-command/build.js.map +0 -1
  33. package/dist/commands/project-command/cache.d.ts +0 -3
  34. package/dist/commands/project-command/cache.js +0 -57
  35. package/dist/commands/project-command/cache.js.map +0 -1
  36. package/dist/commands/project-command/dev.d.ts +0 -3
  37. package/dist/commands/project-command/dev.js +0 -52
  38. package/dist/commands/project-command/dev.js.map +0 -1
  39. package/dist/commands/project-command/start.d.ts +0 -3
  40. package/dist/commands/project-command/start.js +0 -46
  41. package/dist/commands/project-command/start.js.map +0 -1
  42. package/dist/commands/run-commands/run.d.ts +0 -2
  43. package/dist/commands/run-commands/run.js +0 -82
  44. package/dist/commands/run-commands/run.js.map +0 -1
  45. package/dist/index.d.ts +0 -30
  46. package/dist/index.js +0 -66
  47. package/dist/index.js.map +0 -1
  48. package/dist/logger.d.ts +0 -31
  49. package/dist/logger.js.map +0 -1
  50. package/dist/process-manager.d.ts +0 -60
  51. package/dist/process-manager.js +0 -277
  52. package/dist/process-manager.js.map +0 -1
  53. package/dist/project-manager.d.ts +0 -64
  54. package/dist/project-manager.js +0 -467
  55. package/dist/project-manager.js.map +0 -1
  56. package/dist/runner.d.ts +0 -17
  57. package/dist/runner.js.map +0 -1
  58. package/dist/server.d.ts +0 -2
  59. package/dist/server.js +0 -67
  60. package/dist/server.js.map +0 -1
  61. package/dist/types.d.ts +0 -37
  62. package/dist/types.js.map +0 -1
  63. package/dist/typescript-runner.d.ts +0 -12
  64. package/dist/typescript-runner.js +0 -162
  65. package/dist/typescript-runner.js.map +0 -1
package/README.md CHANGED
@@ -6,26 +6,26 @@
6
6
  </picture>
7
7
  </a>
8
8
 
9
- # Neex v0.4.1
9
+ # Neex v0.5.0
10
+
10
11
  ### 🚀 Neex: The Modern Build System for Polyrepo-in-Monorepo Architecture
11
12
 
12
13
  [![NPM version](https://img.shields.io/npm/v/neex.svg?style=for-the-badge&labelColor=000000&color=0066FF&borderRadius=8)](https://www.npmjs.com/package/neex)
13
14
  [![Download Count](https://img.shields.io/npm/dt/neex.svg?style=for-the-badge&labelColor=000000&color=0066FF&borderRadius=8)](https://www.npmjs.com/package/neex)
14
15
  [![MIT License](https://img.shields.io/badge/license-MIT-0066FF.svg?style=for-the-badge&labelColor=000000&borderRadius=8)](https://github.com/neexjs/blob/main/LICENSE)
15
16
  [![GitHub](https://img.shields.io/badge/GitHub-Neex-0066FF.svg?style=for-the-badge&logo=github&labelColor=000000&logoWidth=20&borderRadius=8)](https://github.com/Neexjs)
16
-
17
17
  </div>
18
18
 
19
19
  ## 🎯 Overview
20
20
 
21
21
  next + express = neex 🌱
22
22
 
23
- Neex is a modern build system designed to bridge the gap between polyrepo and monorepo architectures. It provides powerful script execution capabilities with features like parallel processing, colored output, and intelligent build orchestration. Whether you're managing a complex monorepo or coordinating multiple repositories, neex makes your development workflow more efficient and visually organized.
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 (`p`) or sequence (`s`)
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
- ## Quick Start
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,58 +66,155 @@ bun add -D neex # bun
49
66
 
50
67
  ## 🖥️ Usage
51
68
 
52
- ### Process Management 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.
91
+
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).
104
+
105
+ ### General Command Examples
53
106
 
54
107
  ```bash
55
- # Start a process
56
- neex startx app.js -n "my-app" -w
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"
57
112
 
58
- # startx options
59
- -n, --name <name> Process name
60
- -w, --watch Watch for file changes
61
- -r, --max-restarts <number> Maximum restart attempts
62
- -d, --restart-delay <ms> Delay between restarts
113
+ # Sequential execution
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
63
133
 
64
- # Stop a process
65
- neex stopx <process-id>
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 -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
66
146
 
67
- # List processes
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
68
155
  neex list
69
- neex list -a # Show all processes
70
- neex list -j # JSON output
71
156
 
72
- # Monitor process
73
- neex monit <process-id>
74
- neex monit <process-id> -i 1000 # Set update interval
157
+ # View logs for 'my-app'
158
+ neex logs my-app
159
+
160
+ # Stop 'my-api'
161
+ neex stop my-api
75
162
 
76
- # View logs
77
- neex log <process-id>
78
- neex log <process-id> -f # Follow logs
79
- neex log <process-id> -e # Show only errors
80
- neex log <process-id> -w # Show only warnings
163
+ # Restart 'my-app'
164
+ neex restart my-app
165
+
166
+ # Delete 'my-api' from neex management
167
+ neex delete my-api
81
168
  ```
82
169
 
83
- ### Script Execution Commands
170
+ ### 📚 Examples
171
+
172
+ ### Parallel Execution
84
173
 
85
174
  ```bash
86
- # Sequential execution
87
- neex s "npm install" "npm run build"
175
+ # Parallel execution (default behavior for p)
176
+ neex p "npm run build:api" "npm run build:frontend" "npm run lint"
177
+ neex par "npm run test:unit" "npm run test:integration"
178
+ neex parallel "npm run test:frontend" "npm run test:backend"
179
+ ```
180
+
181
+ ### Sequential Execution
182
+
183
+ ```bash
184
+ # Sequential execution using s command
185
+ neex s "npm run clean" "npm run build" "npm run deploy"
186
+ neex seq "echo First" "echo Second" "echo Third"
187
+ neex sequential "npm run step1" "npm run step2" "npm run step3"
188
+ ```
189
+
190
+ ### Parallel with Sequential Flag
88
191
 
89
- # Parallel execution
90
- neex p "npm run dev" "npm run watch"
192
+ ```bash
193
+ # Run parallel commands sequentially using the -q flag
194
+ neex p -q "npm run step1" "npm run step2"
195
+ neex par -q "npm run build" "npm run test"
196
+ neex parallel -q "npm run lint" "npm run format"
91
197
  ```
92
198
 
93
- ### 🛠️ Options
199
+ ### Advanced Options
200
+
201
+ ```bash
202
+ # With retry options
203
+ neex p --retry 3 --retry-delay 1000 "npm run test"
94
204
 
95
- | Flag | Alias | Description | Default |
96
- |------|-------|-------------|----------|
97
- | `--no-color` | `-c` | Disable colors | `false` |
98
- | `--no-timing` | `-t` | Hide timing | `false` |
99
- | `--no-prefix` | `-p` | Hide prefixes | `false` |
100
- | `--stop-on-error` | `-s` | Stop on failure | `false` |
101
- | `--no-output` | `-o` | Hide all output | `false` |
102
- | `--max-parallel` | `-m` | Max parallel tasks | CPU count |
103
- | `--sequential` | `-q` | Force sequential | `false` |
205
+ # With output control
206
+ neex s --no-color --no-timing --no-output "npm run build"
207
+
208
+ # With parallel limits
209
+ neex p --max-parallel 2 "npm run build:frontend" "npm run build:backend" "npm run build:api"
210
+ ```
211
+
212
+ ### Advanced Example
213
+
214
+ ```bash
215
+ # Run tests & build with max 2 parallel tasks, stop on error
216
+ neex p -s -m 2 -t "npm test" "npm run build" "npm run lint"
217
+ ```
104
218
 
105
219
  ## 📦 Node.js API
106
220
 
@@ -130,6 +244,41 @@ async function main() {
130
244
  }
131
245
  ```
132
246
 
247
+ ### API Options (`RunOptions`)
248
+
249
+ When using Neex programmatically, you can pass an options object to the `run` function:
250
+
251
+ ```typescript
252
+ export interface RunOptions {
253
+ // Run in parallel or sequentially
254
+ parallel: boolean;
255
+ // Maximum number of parallel processes (default: CPU count)
256
+ maxParallel?: number;
257
+ // Show command output (default: true)
258
+ printOutput: boolean;
259
+ // Color output (default: true)
260
+ color: boolean;
261
+ // Show timing information (default: true)
262
+ showTiming: boolean;
263
+ // Show command prefix (default: true)
264
+ prefix: boolean;
265
+ // Stop on error (default: false)
266
+ stopOnError: boolean;
267
+ // Use minimal output format (default: false)
268
+ minimalOutput: boolean;
269
+ // Group output by command (default: false, mainly for server mode)
270
+ groupOutput: boolean;
271
+ // Use server mode formatting (default: false)
272
+ isServerMode: boolean;
273
+ // Number of times to retry a failed command (default: 0)
274
+ retry?: number;
275
+ // Delay in milliseconds between retries (default: 1000)
276
+ retryDelay?: number;
277
+ // Callback to register a cleanup function, called on SIGINT/SIGTERM
278
+ registerCleanup?: (cleanupFn: () => void) => void;
279
+ }
280
+ ```
281
+
133
282
  ## 🔄 CI/CD Integration
134
283
 
135
284
  ```yaml
@@ -142,47 +291,55 @@ steps:
142
291
  run: neex p -s -m 4 "npm run lint" "npm test" "npm run e2e"
143
292
  ```
144
293
 
145
- ## 💡 Real-world Examples
294
+ ## 💡 Real-world Scenarios & `package.json` Integration
146
295
 
147
- ### Multi-part Project Execution
296
+ Neex shines when integrated into your `package.json` scripts.
297
+
298
+ **Example `package.json` scripts:**
148
299
 
149
300
  ```json
150
301
  {
151
302
  "scripts": {
152
- "dev": "neex p dev:client dev:server",
153
- "dev:client": "cd apps/client && npm run dev",
154
- "dev:server": "cd apps/server && npm run dev",
155
- "build": "neex s build:client build:server",
156
- "build:client": "cd apps/client && npm run build",
157
- "build:server": "cd apps/server && npm run build",
158
- "start": "neex p start:client start:server",
159
- "start:client": "cd apps/client && npm run start",
160
- "start:server": "cd apps/server && npm run start"
161
- }
162
- }
163
- ```
303
+ "dev:frontend": "cd packages/frontend && npm run dev",
304
+ "dev:backend": "cd packages/api && npm run dev",
305
+ "dev": "neex servers \"npm run dev:frontend\" \"npm run dev:backend\" --group-output",
164
306
 
165
- ### Production Project Management
307
+ "build:ui": "cd packages/ui-library && npm run build",
308
+ "build:app": "cd packages/main-app && npm run build",
309
+ "build": "neex runx \"npm run build:ui\" \"npm run build:app\"",
166
310
 
167
- ```json
168
- {
169
- "scripts": {
170
- "startx": "neex startx:client && neex startx:server",
171
- "startx:client": "neex startx apps/client/index.js -n client -w",
172
- "startx:server": "neex startx apps/server/index.js -n server -w",
173
- "stopx": "neex stopx:client && neex stopx:server",
174
- "stopx:client": "neex stopx client",
175
- "stopx:server": "neex stopx server"
311
+ "test": "neex runx -s \"npm run test:unit\" \"npm run test:e2e\"",
312
+ "test:unit": "jest",
313
+ "test:e2e": "playwright test",
314
+
315
+ "lint": "eslint .",
316
+ "format": "prettier --write .",
317
+ "check-all": "neex p \"npm run lint\" \"npm run format -- --check\" \"npm run test\"",
318
+
319
+ "start:prod": "neex pm2 start dist/server.js --name my-prod-app",
320
+ "watch:build": "neex watch \"npm run build:app\" -w packages/main-app/src -e ts,tsx"
176
321
  }
177
322
  }
178
323
  ```
179
324
 
180
- ## Important Notes
325
+ **Running these scripts:**
326
+
327
+ ```bash
328
+ # Start all development servers with grouped output
329
+ npm run dev
181
330
 
182
- - Logs are stored in the `.neex-logs` directory
183
- - Configuration is stored in `.neex-config.json`
184
- - Use `Ctrl+C` to stop live monitoring
185
- - Use `neex stopx -f` for force stop when needed
331
+ # Build UI library and main application in parallel
332
+ npm run build
333
+
334
+ # Run linters, format check, and all tests in parallel
335
+ npm run check-all
336
+
337
+ # Start the production application using neex's pm2
338
+ npm run start:prod
339
+
340
+ # Watch for changes in the main app's src and rebuild it
341
+ npm run watch:build
342
+ ```
186
343
 
187
344
  ## 🤝 Contributing
188
345
 
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ require('../src/cli').default();
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ // src/cli.ts - Main CLI file (refactored)
7
+ const commander_1 = require("commander");
8
+ const index_js_1 = require("./commands/index.js");
9
+ const chalk_1 = __importDefault(require("chalk"));
10
+ const figures_1 = __importDefault(require("figures"));
11
+ const { version } = require('../../package.json');
12
+ function cli() {
13
+ const program = new commander_1.Command();
14
+ // Initialize cleanup handlers
15
+ const cleanupHandlers = [];
16
+ program
17
+ .name('neex')
18
+ .description('Professional script runner with nodemon and PM2 functionality')
19
+ .version(version);
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);
27
+ program.parse(process.argv);
28
+ // Show help if no commands specified
29
+ if (program.args.length === 0) {
30
+ program.help();
31
+ }
32
+ // Graceful shutdown handling
33
+ const handleSignal = async (signal) => {
34
+ console.log(`\n${chalk_1.default.yellow(`${figures_1.default.warning} Received ${signal}. Cleaning up...`)}`);
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
+ }
43
+ }
44
+ setTimeout(() => process.exit(0), 500);
45
+ };
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)));
49
+ }
50
+ exports.default = cli;
@@ -0,0 +1,190 @@
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.addDevCommands = void 0;
30
+ const dev_runner_js_1 = require("../dev-runner.js");
31
+ const chalk_1 = __importDefault(require("chalk"));
32
+ const figures_1 = __importDefault(require("figures"));
33
+ const path = __importStar(require("path"));
34
+ const fs = __importStar(require("fs/promises"));
35
+ // Helper function to find default command from package.json
36
+ async function findDefaultCommand() {
37
+ var _a, _b;
38
+ try {
39
+ const packageJsonPath = path.join(process.cwd(), 'package.json');
40
+ await fs.access(packageJsonPath);
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
+ 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): npx ts-node ${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;
70
+ }
71
+ catch (error) {
72
+ // package.json doesn't exist or other error, do nothing
73
+ return null;
74
+ }
75
+ }
76
+ function addDevCommands(program) {
77
+ let devRunner = null;
78
+ // Dev command (Nodemon functionality - formerly watch)
79
+ program
80
+ .command('dev [commands...]') // Made commands optional
81
+ .alias('d')
82
+ .description('Run commands with file watching and auto-restart (nodemon functionality)')
83
+ .option('-c, --no-color', 'Disable colored output')
84
+ .option('-t, --no-timing', 'Hide timing information')
85
+ .option('-p, --no-prefix', 'Hide command prefix')
86
+ .option('-s, --stop-on-error', 'Stop on first error')
87
+ .option('-o, --no-output', 'Hide command output')
88
+ .option('-m, --minimal', 'Use minimal output format')
89
+ .option('-w, --watch <paths...>', 'Paths to watch (default: current directory)')
90
+ .option('-i, --ignore <patterns...>', 'Patterns to ignore')
91
+ .option('-e, --ext <extensions...>', 'File extensions to watch (default: js,mjs,json,ts,tsx,jsx)')
92
+ .option('-d, --delay <ms>', 'Delay before restart in milliseconds', parseInt)
93
+ .option('--clear', 'Clear console on restart')
94
+ .option('--verbose', 'Verbose output')
95
+ .option('--signal <signal>', 'Signal to send to processes on restart', 'SIGTERM')
96
+ .action(async (commands, options) => {
97
+ try {
98
+ let effectiveCommands = commands;
99
+ if (!effectiveCommands || effectiveCommands.length === 0) {
100
+ const foundCommand = await findDefaultCommand();
101
+ if (foundCommand) {
102
+ effectiveCommands = [foundCommand];
103
+ console.log(chalk_1.default.blue(`${figures_1.default.info} No command specified for 'neex dev', using default: "${foundCommand}"`));
104
+ }
105
+ else {
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
+ }
110
+ }
111
+ else { // At least one command/argument is provided
112
+ const firstArg = effectiveCommands[0];
113
+ const remainingArgs = effectiveCommands.slice(1);
114
+ const isLikelyCommandOrScript = firstArg.includes(' ') || firstArg.startsWith('npm') || firstArg.startsWith('yarn') || firstArg.startsWith('pnpm');
115
+ if (!isLikelyCommandOrScript) {
116
+ const filePath = path.resolve(process.cwd(), firstArg);
117
+ try {
118
+ await fs.access(filePath); // Check if file exists
119
+ let commandToExecute = '';
120
+ if (firstArg.endsWith('.js') || firstArg.endsWith('.mjs') || firstArg.endsWith('.cjs')) {
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 = `npx ts-node ${firstArg}`;
126
+ console.log(chalk_1.default.blue(`${figures_1.default.info} Detected .ts file, prepending with npx ts-node.`));
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
+ }
140
+ }
141
+ console.log(chalk_1.default.blue(`${figures_1.default.info} Starting development server with file watching (neex dev) for command(s): ${effectiveCommands.map(cmd => `"${cmd}"`).join(' && ')}...`));
142
+ const watchPaths = options.watch || ['./'];
143
+ const ignorePatterns = options.ignore || [
144
+ 'node_modules/**', '.git/**', '*.log', 'dist/**', 'build/**',
145
+ 'coverage/**', '.nyc_output/**', '*.tmp', '*.temp'
146
+ ];
147
+ const extensions = options.ext || ['js', 'mjs', 'json', 'ts', 'tsx', 'jsx'];
148
+ devRunner = new dev_runner_js_1.DevRunner({
149
+ runnerName: 'neex dev',
150
+ parallel: false,
151
+ color: options.color,
152
+ showTiming: options.timing,
153
+ prefix: options.prefix,
154
+ stopOnError: options.stopOnError,
155
+ printOutput: options.output,
156
+ minimalOutput: options.minimal,
157
+ watch: watchPaths,
158
+ ignore: ignorePatterns,
159
+ ext: extensions,
160
+ delay: options.delay || 1000,
161
+ clearConsole: options.clear,
162
+ verbose: options.verbose,
163
+ signal: options.signal,
164
+ restartOnChange: true,
165
+ groupOutput: false,
166
+ isServerMode: false
167
+ });
168
+ await devRunner.start(effectiveCommands);
169
+ }
170
+ catch (error) {
171
+ if (error instanceof Error) {
172
+ console.error(chalk_1.default.red(`${figures_1.default.cross} Dev Error: ${error.message}`));
173
+ }
174
+ else {
175
+ console.error(chalk_1.default.red(`${figures_1.default.cross} An unknown dev error occurred`));
176
+ }
177
+ process.exit(1);
178
+ }
179
+ });
180
+ // Return cleanup function for dev runner
181
+ return {
182
+ getDevRunner: () => devRunner,
183
+ cleanupDev: () => {
184
+ if (devRunner && devRunner.isActive()) {
185
+ devRunner.stop();
186
+ }
187
+ }
188
+ };
189
+ }
190
+ exports.addDevCommands = addDevCommands;
@@ -0,0 +1,21 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ // src/commands/index.ts - Export all commands
18
+ __exportStar(require("./run-commands.js"), exports);
19
+ __exportStar(require("./dev-commands.js"), exports);
20
+ __exportStar(require("./process-commands.js"), exports);
21
+ __exportStar(require("./server-commands.js"), exports);