nexpgen 1.0.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/.gitattributes +2 -0
- package/README.md +517 -0
- package/bin/cli.js +58 -0
- package/package.json +44 -0
- package/src/commands/generate.js +205 -0
- package/src/commands/init.js +191 -0
- package/src/templates/controller.template +127 -0
- package/src/templates/error.template +24 -0
- package/src/templates/helpers/imageUpload.template +191 -0
- package/src/templates/helpers/timeConverter.template +171 -0
- package/src/templates/middleware.template +302 -0
- package/src/templates/route.template +56 -0
- package/src/templates/servers/clean-arrow.template +42 -0
- package/src/templates/servers/clean-class.template +46 -0
- package/src/templates/servers/layered-arrow.template +42 -0
- package/src/templates/servers/layered-class.template +46 -0
- package/src/templates/servers/microservices-arrow.template +41 -0
- package/src/templates/servers/microservices-class.template +45 -0
- package/src/templates/servers/mvc-arrow.template +44 -0
- package/src/templates/servers/mvc-class.template +48 -0
- package/src/templates/servers/simple-arrow.template +42 -0
- package/src/templates/servers/simple-class.template +46 -0
- package/src/templates/service.template +121 -0
- package/src/templates/util.template +39 -0
- package/src/utils/architectureGenerator.js +925 -0
- package/src/utils/fileGenerator.js +617 -0
package/.gitattributes
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
# nexpgen
|
|
2
|
+
|
|
3
|
+
A powerful CLI tool for generating code files from templates with support for multiple architectures and function styles. Built by **CodevNexus**.
|
|
4
|
+
|
|
5
|
+
## 📋 Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Features](#features)
|
|
8
|
+
- [Installation](#installation)
|
|
9
|
+
- [Quick Start](#quick-start)
|
|
10
|
+
- [Usage Guide](#usage-guide)
|
|
11
|
+
- [Architecture Options](#architecture-options)
|
|
12
|
+
- [Function Styles](#function-styles)
|
|
13
|
+
- [Helper Files](#helper-files)
|
|
14
|
+
- [Configuration](#configuration)
|
|
15
|
+
- [Examples](#examples)
|
|
16
|
+
- [Project Structure](#project-structure)
|
|
17
|
+
- [Contributing](#contributing)
|
|
18
|
+
- [License](#license)
|
|
19
|
+
|
|
20
|
+
## ✨ Features
|
|
21
|
+
|
|
22
|
+
- 🏗️ **Multiple Architecture Support**: MVC, Microservices, Layered, Clean Architecture, and Simple Structure
|
|
23
|
+
- 🎨 **Function Style Options**: Class-based or Arrow function styles
|
|
24
|
+
- 📦 **Package Integration**: Automatically integrates dotenv, helmet, multer, and custom helpers
|
|
25
|
+
- 📁 **Smart File Generation**: Generate multiple files at once with nested directory support
|
|
26
|
+
- 🔧 **Template-Based**: Easy to customize templates for your needs
|
|
27
|
+
- 🛡️ **Production-Ready**: Comprehensive error handling and input validation
|
|
28
|
+
- 📝 **CamelCase Variables**: Automatic variable naming conversion
|
|
29
|
+
- ⚙️ **Configuration-Driven**: Remembers your preferences
|
|
30
|
+
- 🚀 **CRUD Generator**: Generate complete CRUD operations in one command ⭐ **NEW!**
|
|
31
|
+
- 🛣️ **Route Generation**: Auto-generate REST API routes ⭐ **NEW!**
|
|
32
|
+
- 🛡️ **Middleware Generation**: Generate auth, validation, error handling middleware ⭐ **NEW!**
|
|
33
|
+
|
|
34
|
+
## 🚀 Installation
|
|
35
|
+
|
|
36
|
+
### Global Installation (Recommended)
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npm install -g nexpgen
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Local Installation
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npm install nexpgen --save-dev
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Verify Installation
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
nexpgen --version
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## 🎯 Quick Start
|
|
55
|
+
|
|
56
|
+
### 1. Initialize a New Project
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
nexpgen init
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
This will prompt you with interactive questions:
|
|
63
|
+
- Package name
|
|
64
|
+
- Architecture type
|
|
65
|
+
- Function style preference
|
|
66
|
+
- Additional packages to include
|
|
67
|
+
|
|
68
|
+
### 2. Generate Files
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
nexpgen generate controller user
|
|
72
|
+
nexpgen generate service product
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## 📖 Usage Guide
|
|
76
|
+
|
|
77
|
+
### Initialize Command
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
nexpgen init
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
**What it does:**
|
|
84
|
+
- Creates project directory structure based on selected architecture
|
|
85
|
+
- Generates `server.js` entry point file
|
|
86
|
+
- Creates `package.json` with dependencies
|
|
87
|
+
- Sets up helper files (if selected)
|
|
88
|
+
- Creates `.env.example` (if dotenv selected)
|
|
89
|
+
- Saves configuration to `.nexpgenrc`
|
|
90
|
+
|
|
91
|
+
**Example:**
|
|
92
|
+
```bash
|
|
93
|
+
$ nexpgen init
|
|
94
|
+
🚀 Initializing project...
|
|
95
|
+
|
|
96
|
+
? What is your package name? my-awesome-app
|
|
97
|
+
? Which architecture do you want to use? MVC (Model-View-Controller)
|
|
98
|
+
? What function style do you prefer? Arrow functions with module.exports
|
|
99
|
+
? Select additional packages you want to include: dotenv, helmet, imageUpload
|
|
100
|
+
|
|
101
|
+
✅ Configuration saved to .nexpgenrc
|
|
102
|
+
📁 Created directory: src/controllers
|
|
103
|
+
📁 Created directory: src/services
|
|
104
|
+
...
|
|
105
|
+
✨ Project initialized successfully!
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Generate Command
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
nexpgen generate <type> <name> [options]
|
|
112
|
+
# or shorthand
|
|
113
|
+
nexpgen g <type> <name> [options]
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
**Types:**
|
|
117
|
+
- `controller` - Generate controller files (with full CRUD methods)
|
|
118
|
+
- `service` - Generate service files (with full CRUD methods)
|
|
119
|
+
- `util` - Generate utility files
|
|
120
|
+
- `error` - Generate error class files
|
|
121
|
+
- `route` - Generate route files (REST API routes)
|
|
122
|
+
- `middleware` - Generate middleware files (auth, validation, errorHandler, rateLimit)
|
|
123
|
+
- `crud` - Generate complete CRUD (controller + service + routes) ⭐ **NEW!**
|
|
124
|
+
|
|
125
|
+
**Options:**
|
|
126
|
+
- `-d, --directory <dir>` - Output directory (default: `src`)
|
|
127
|
+
|
|
128
|
+
**Examples:**
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
# Generate single file
|
|
132
|
+
nexpgen generate controller user
|
|
133
|
+
|
|
134
|
+
# Generate multiple files
|
|
135
|
+
nexpgen generate controller user,product,category
|
|
136
|
+
|
|
137
|
+
# Generate complete CRUD (controller + service + routes) ⭐ NEW!
|
|
138
|
+
nexpgen generate crud user
|
|
139
|
+
|
|
140
|
+
# Generate routes
|
|
141
|
+
nexpgen generate route product
|
|
142
|
+
|
|
143
|
+
# Generate middleware
|
|
144
|
+
nexpgen generate middleware auth
|
|
145
|
+
nexpgen generate middleware validation
|
|
146
|
+
nexpgen generate middleware errorHandler
|
|
147
|
+
|
|
148
|
+
# Generate with nested paths
|
|
149
|
+
nexpgen generate controller admin/user
|
|
150
|
+
nexpgen generate controller admin/front/dashboard
|
|
151
|
+
|
|
152
|
+
# Generate in custom directory
|
|
153
|
+
nexpgen generate service auth -d app/services
|
|
154
|
+
|
|
155
|
+
# Generate multiple files with nested paths
|
|
156
|
+
nexpgen generate service admin/auth,admin/users,front/products
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## 🏛️ Architecture Options
|
|
160
|
+
|
|
161
|
+
### MVC (Model-View-Controller)
|
|
162
|
+
```
|
|
163
|
+
src/
|
|
164
|
+
├── controllers/
|
|
165
|
+
├── models/
|
|
166
|
+
├── views/
|
|
167
|
+
├── routes/
|
|
168
|
+
├── middleware/
|
|
169
|
+
├── config/
|
|
170
|
+
└── utils/
|
|
171
|
+
public/
|
|
172
|
+
├── css/
|
|
173
|
+
├── js/
|
|
174
|
+
└── images/
|
|
175
|
+
config/
|
|
176
|
+
└── uploads/
|
|
177
|
+
└── images/
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Microservices
|
|
181
|
+
```
|
|
182
|
+
services/
|
|
183
|
+
├── api-gateway/
|
|
184
|
+
│ ├── src/
|
|
185
|
+
│ ├── public/
|
|
186
|
+
│ └── config/
|
|
187
|
+
├── user-service/
|
|
188
|
+
│ ├── src/
|
|
189
|
+
│ └── config/
|
|
190
|
+
└── shared/
|
|
191
|
+
public/
|
|
192
|
+
config/
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Layered Architecture
|
|
196
|
+
```
|
|
197
|
+
src/
|
|
198
|
+
├── presentation/
|
|
199
|
+
├── business/
|
|
200
|
+
├── data/
|
|
201
|
+
└── infrastructure/
|
|
202
|
+
public/
|
|
203
|
+
config/
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Clean Architecture
|
|
207
|
+
```
|
|
208
|
+
src/
|
|
209
|
+
├── domain/
|
|
210
|
+
├── application/
|
|
211
|
+
├── infrastructure/
|
|
212
|
+
└── presentation/
|
|
213
|
+
public/
|
|
214
|
+
config/
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Simple Structure
|
|
218
|
+
```
|
|
219
|
+
src/
|
|
220
|
+
├── controllers/
|
|
221
|
+
├── services/
|
|
222
|
+
├── routes/
|
|
223
|
+
├── utils/
|
|
224
|
+
└── config/
|
|
225
|
+
public/
|
|
226
|
+
config/
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## 💻 Function Styles
|
|
230
|
+
|
|
231
|
+
### Class-Based Style
|
|
232
|
+
|
|
233
|
+
```javascript
|
|
234
|
+
class UserController {
|
|
235
|
+
constructor() {
|
|
236
|
+
this.name = 'user';
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
async handle(req, res, next) {
|
|
240
|
+
try {
|
|
241
|
+
// Controller logic
|
|
242
|
+
res.json({ message: 'Success' });
|
|
243
|
+
} catch (error) {
|
|
244
|
+
next(error);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
module.exports = UserController;
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### Arrow Function Style
|
|
253
|
+
|
|
254
|
+
```javascript
|
|
255
|
+
const handle = async (req, res, next) => {
|
|
256
|
+
try {
|
|
257
|
+
// Controller logic
|
|
258
|
+
res.json({ message: 'Success' });
|
|
259
|
+
} catch (error) {
|
|
260
|
+
next(error);
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
const getById = async (req, res, next) => {
|
|
265
|
+
// Get by ID logic
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
module.exports = {
|
|
269
|
+
handle,
|
|
270
|
+
getById
|
|
271
|
+
};
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
## 🛠️ Helper Files
|
|
275
|
+
|
|
276
|
+
### Image Upload Helper
|
|
277
|
+
|
|
278
|
+
If selected during initialization, creates `src/utils/imageUploadHelper.js`:
|
|
279
|
+
|
|
280
|
+
**Usage:**
|
|
281
|
+
```javascript
|
|
282
|
+
const imageUpload = require('./src/utils/imageUploadHelper');
|
|
283
|
+
|
|
284
|
+
// Single file upload
|
|
285
|
+
router.post('/upload', imageUpload.getSingleUpload('image'), (req, res) => {
|
|
286
|
+
if (req.file) {
|
|
287
|
+
res.json({
|
|
288
|
+
message: 'File uploaded successfully',
|
|
289
|
+
file: req.file.filename,
|
|
290
|
+
path: req.file.path
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
// Multiple files upload
|
|
296
|
+
router.post('/upload-multiple', imageUpload.getMultipleUpload('images', 5), (req, res) => {
|
|
297
|
+
res.json({ files: req.files });
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
// Delete file
|
|
301
|
+
imageUpload.deleteFile('config/uploads/images/file-123456789.jpg');
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
**Features:**
|
|
305
|
+
- Stores uploaded images in `config/uploads/images/`
|
|
306
|
+
- Validates file types (jpeg, jpg, png, gif, webp)
|
|
307
|
+
- 5MB file size limit
|
|
308
|
+
- Automatic directory creation
|
|
309
|
+
|
|
310
|
+
### Time Converter Helper
|
|
311
|
+
|
|
312
|
+
If selected during initialization, creates `src/utils/customHelp.js`:
|
|
313
|
+
|
|
314
|
+
**Usage:**
|
|
315
|
+
```javascript
|
|
316
|
+
const timeConverter = require('./src/utils/customHelp');
|
|
317
|
+
|
|
318
|
+
// Format date
|
|
319
|
+
const formatted = timeConverter.format(new Date(), 'YYYY-MM-DD HH:mm:ss');
|
|
320
|
+
|
|
321
|
+
// Add time
|
|
322
|
+
const futureDate = timeConverter.addDays(new Date(), 7);
|
|
323
|
+
const futureHour = timeConverter.addHours(new Date(), 2);
|
|
324
|
+
|
|
325
|
+
// Calculate difference
|
|
326
|
+
const daysDiff = timeConverter.differenceInDays(date1, date2);
|
|
327
|
+
const hoursDiff = timeConverter.differenceInHours(date1, date2);
|
|
328
|
+
|
|
329
|
+
// Compare dates
|
|
330
|
+
const isBefore = timeConverter.isBefore(date1, date2);
|
|
331
|
+
const isSameDay = timeConverter.isSameDay(date1, date2);
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
## ⚙️ Configuration
|
|
335
|
+
|
|
336
|
+
Your preferences are saved in `.nexpgenrc`:
|
|
337
|
+
|
|
338
|
+
```json
|
|
339
|
+
{
|
|
340
|
+
"packageName": "my-app",
|
|
341
|
+
"architecture": "mvc",
|
|
342
|
+
"functionStyle": "arrow",
|
|
343
|
+
"packages": ["dotenv", "helmet", "imageUpload"]
|
|
344
|
+
}
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
The generate command automatically uses these settings when creating files.
|
|
348
|
+
|
|
349
|
+
## 📚 Examples
|
|
350
|
+
|
|
351
|
+
### Example 1: Complete CRUD Setup ⭐ NEW!
|
|
352
|
+
|
|
353
|
+
```bash
|
|
354
|
+
# Initialize project
|
|
355
|
+
nexpgen init
|
|
356
|
+
# Select: MVC, Arrow functions, dotenv, helmet, imageUpload
|
|
357
|
+
|
|
358
|
+
# Generate complete CRUD for resources (creates controller + service + routes)
|
|
359
|
+
nexpgen generate crud user
|
|
360
|
+
nexpgen generate crud product
|
|
361
|
+
nexpgen generate crud order
|
|
362
|
+
|
|
363
|
+
# Generate middleware
|
|
364
|
+
nexpgen generate middleware auth
|
|
365
|
+
nexpgen generate middleware errorHandler
|
|
366
|
+
|
|
367
|
+
# Register routes in server.js (instructions provided after CRUD generation)
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
### Example 2: Complete MVC Project Setup
|
|
371
|
+
|
|
372
|
+
```bash
|
|
373
|
+
# Initialize project
|
|
374
|
+
nexpgen init
|
|
375
|
+
# Select: MVC, Arrow functions, dotenv, helmet, imageUpload
|
|
376
|
+
|
|
377
|
+
# Generate controllers
|
|
378
|
+
nexpgen generate controller user,product,order
|
|
379
|
+
|
|
380
|
+
# Generate services
|
|
381
|
+
nexpgen generate service user,product,order
|
|
382
|
+
|
|
383
|
+
# Generate nested admin controllers
|
|
384
|
+
nexpgen generate controller admin/users,admin/products
|
|
385
|
+
|
|
386
|
+
# Generate utilities
|
|
387
|
+
nexpgen generate util validation,helpers
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
### Example 2: Microservices Setup
|
|
391
|
+
|
|
392
|
+
```bash
|
|
393
|
+
# Initialize microservices architecture
|
|
394
|
+
nexpgen init
|
|
395
|
+
# Select: Microservices, Class-based, all packages
|
|
396
|
+
|
|
397
|
+
# Generate service-specific files
|
|
398
|
+
cd services/user-service/src
|
|
399
|
+
nexpgen generate controller user
|
|
400
|
+
nexpgen generate service user
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
### Example 4: Using Generated Files
|
|
404
|
+
|
|
405
|
+
```javascript
|
|
406
|
+
// src/controllers/user.controller.js (Arrow function style)
|
|
407
|
+
const getById = async (req, res, next) => {
|
|
408
|
+
try {
|
|
409
|
+
const { id } = req.params;
|
|
410
|
+
const userData = await userService.getById(id);
|
|
411
|
+
res.json({ success: true, data: userData });
|
|
412
|
+
} catch (error) {
|
|
413
|
+
next(error);
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
module.exports = { getById };
|
|
418
|
+
|
|
419
|
+
// src/routes/userRoutes.js
|
|
420
|
+
const express = require('express');
|
|
421
|
+
const router = express.Router();
|
|
422
|
+
const userController = require('../controllers/user.controller');
|
|
423
|
+
|
|
424
|
+
router.get('/:id', userController.getById);
|
|
425
|
+
|
|
426
|
+
module.exports = router;
|
|
427
|
+
|
|
428
|
+
// server.js
|
|
429
|
+
const userRoutes = require('./src/routes/userRoutes');
|
|
430
|
+
app.use('/api/users', userRoutes);
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
## 📁 Project Structure
|
|
434
|
+
|
|
435
|
+
```
|
|
436
|
+
nexpgen/
|
|
437
|
+
├── bin/
|
|
438
|
+
│ └── cli.js # CLI entry point
|
|
439
|
+
├── src/
|
|
440
|
+
│ ├── commands/
|
|
441
|
+
│ │ ├── generate.js # Generate command
|
|
442
|
+
│ │ └── init.js # Init command
|
|
443
|
+
│ ├── templates/
|
|
444
|
+
│ │ ├── servers/ # Server templates
|
|
445
|
+
│ │ ├── helpers/ # Helper templates
|
|
446
|
+
│ │ ├── controller.template
|
|
447
|
+
│ │ ├── service.template
|
|
448
|
+
│ │ ├── util.template
|
|
449
|
+
│ │ └── error.template
|
|
450
|
+
│ └── utils/
|
|
451
|
+
│ ├── fileGenerator.js # File generation utility
|
|
452
|
+
│ └── architectureGenerator.js # Architecture setup
|
|
453
|
+
├── package.json
|
|
454
|
+
└── README.md
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
## 🔧 Advanced Usage
|
|
458
|
+
|
|
459
|
+
### Custom Templates
|
|
460
|
+
|
|
461
|
+
You can customize templates by modifying files in `node_modules/nexpgen/src/templates/` or by copying them to your project.
|
|
462
|
+
|
|
463
|
+
### Environment Variables
|
|
464
|
+
|
|
465
|
+
If dotenv is selected, create a `.env` file:
|
|
466
|
+
|
|
467
|
+
```env
|
|
468
|
+
PORT=3000
|
|
469
|
+
NODE_ENV=development
|
|
470
|
+
DATABASE_URL=your_database_url
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
### Static Files
|
|
474
|
+
|
|
475
|
+
Place static files in the `public/` directory:
|
|
476
|
+
- CSS files → `public/css/`
|
|
477
|
+
- JavaScript files → `public/js/`
|
|
478
|
+
- Images → `public/images/`
|
|
479
|
+
|
|
480
|
+
The server automatically serves these files.
|
|
481
|
+
|
|
482
|
+
### Uploaded Files
|
|
483
|
+
|
|
484
|
+
Uploaded images are stored in `config/uploads/images/`. Make sure this directory is:
|
|
485
|
+
- Included in `.gitignore` (for production)
|
|
486
|
+
- Has proper write permissions
|
|
487
|
+
- Backed up regularly (if needed)
|
|
488
|
+
|
|
489
|
+
## 🐛 Troubleshooting
|
|
490
|
+
|
|
491
|
+
### Issue: Template not found
|
|
492
|
+
**Solution:** Ensure nexpgen is properly installed: `npm install -g nexpgen`
|
|
493
|
+
|
|
494
|
+
### Issue: Permission denied
|
|
495
|
+
**Solution:** Check file/directory permissions. On Linux/Mac, you may need `sudo` for global installation.
|
|
496
|
+
|
|
497
|
+
### Issue: Invalid package name
|
|
498
|
+
**Solution:** Package names must follow npm naming conventions. Use lowercase letters, numbers, hyphens, and underscores only.
|
|
499
|
+
|
|
500
|
+
### Issue: File already exists
|
|
501
|
+
**Solution:** The tool won't overwrite existing files. Rename or delete the existing file first.
|
|
502
|
+
|
|
503
|
+
## 🤝 Contributing
|
|
504
|
+
|
|
505
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
506
|
+
|
|
507
|
+
## 📄 License
|
|
508
|
+
|
|
509
|
+
ISC
|
|
510
|
+
|
|
511
|
+
## 👨💻 Author
|
|
512
|
+
|
|
513
|
+
**CodevNexus**
|
|
514
|
+
|
|
515
|
+
---
|
|
516
|
+
|
|
517
|
+
Made with ❤️ by CodevNexus
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
const { program } = require('commander');
|
|
2
|
+
const generateCommand = require('../src/commands/generate');
|
|
3
|
+
const initCommand = require('../src/commands/init');
|
|
4
|
+
|
|
5
|
+
process.on('uncaughtException', (error) => {
|
|
6
|
+
console.error('❌ Uncaught Exception:', error.message);
|
|
7
|
+
process.exit(1);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
process.on('unhandledRejection', (reason, promise) => {
|
|
11
|
+
console.error('❌ Unhandled Rejection at:', promise, 'reason:', reason);
|
|
12
|
+
process.exit(1);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
program
|
|
16
|
+
.name('nexpgen')
|
|
17
|
+
.description('A CLI tool for generating code files from templates')
|
|
18
|
+
.version('1.0.0');
|
|
19
|
+
|
|
20
|
+
program
|
|
21
|
+
.command('init')
|
|
22
|
+
.description('Initialize a new project')
|
|
23
|
+
.action(async () => {
|
|
24
|
+
try {
|
|
25
|
+
await initCommand();
|
|
26
|
+
} catch (error) {
|
|
27
|
+
console.error(`❌ Init command failed: ${error.message}`);
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
program
|
|
33
|
+
.command('generate')
|
|
34
|
+
.alias('g')
|
|
35
|
+
.description('Generate code files from templates')
|
|
36
|
+
.argument('<type>', 'Type of file to generate (controller, service, util, error, route, middleware, crud)')
|
|
37
|
+
.argument('<name>', 'Name of the file to generate')
|
|
38
|
+
.option('-d, --directory <dir>', 'Output directory', 'src')
|
|
39
|
+
.action(async (type, name, options) => {
|
|
40
|
+
try {
|
|
41
|
+
if (!type || !name) {
|
|
42
|
+
console.error('❌ Error: Type and name are required');
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
await generateCommand(type, name, options);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.error(`❌ Generate command failed: ${error.message}`);
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
program.on('command:*', () => {
|
|
53
|
+
console.error(`❌ Invalid command: ${program.args.join(' ')}`);
|
|
54
|
+
console.error('See --help for a list of available commands.');
|
|
55
|
+
process.exit(1);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
program.parse();
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nexpgen",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A powerful CLI tool for generating code files from templates with support for multiple architectures (MVC, Microservices, Clean Architecture) and function styles. Built by CodevNexus.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"nexpgen": "./bin/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"cli",
|
|
14
|
+
"generator",
|
|
15
|
+
"template",
|
|
16
|
+
"code-generator",
|
|
17
|
+
"scaffold",
|
|
18
|
+
"boilerplate",
|
|
19
|
+
"mvc",
|
|
20
|
+
"microservices",
|
|
21
|
+
"clean-architecture",
|
|
22
|
+
"layered-architecture",
|
|
23
|
+
"express",
|
|
24
|
+
"nodejs",
|
|
25
|
+
"codevnexus"
|
|
26
|
+
],
|
|
27
|
+
"author": "CodevNexus",
|
|
28
|
+
"license": "ISC",
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/9Bit-Dark-knight/nexpgen.git"
|
|
32
|
+
},
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/9Bit-Dark-knight/nexpgen/issues"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://github.com/9Bit-Dark-knight/nexpgen#readme",
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"commander": "^11.0.0",
|
|
39
|
+
"inquirer": "^9.2.12"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=14.0.0"
|
|
43
|
+
}
|
|
44
|
+
}
|