nsgm-cli 2.1.25 → 2.1.26
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 +108 -8
- package/generation/README.md +10 -4
- package/generation/package.json +1 -1
- package/lib/cli/commands/create-config.js +8 -2
- package/lib/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -39,6 +39,7 @@ NSGM CLI is a comprehensive full-stack development framework that combines the p
|
|
|
39
39
|
### ⚡ **Rapid Development**
|
|
40
40
|
|
|
41
41
|
- **Code Generation**: Automatic CRUD operations, API endpoints, and database schemas
|
|
42
|
+
- **Config-Based Generation**: Batch create multiple modules from JSON configuration files
|
|
42
43
|
- **Hot Reload**: Instant development feedback
|
|
43
44
|
- **Type Safety**: Full TypeScript support throughout the stack
|
|
44
45
|
|
|
@@ -139,14 +140,15 @@ Your application will be available at `http://localhost:3000` with:
|
|
|
139
140
|
|
|
140
141
|
### Core Commands
|
|
141
142
|
|
|
142
|
-
| Command
|
|
143
|
-
|
|
|
144
|
-
| `nsgm init`
|
|
145
|
-
| `nsgm create`
|
|
146
|
-
| `nsgm delete`
|
|
147
|
-
| `nsgm
|
|
148
|
-
| `nsgm
|
|
149
|
-
| `nsgm
|
|
143
|
+
| Command | Description | Mode | Example |
|
|
144
|
+
| ---------------- | ------------------------------- | --------------- | ----------------------------- |
|
|
145
|
+
| `nsgm init` | Initialize new project | Interactive/CLI | `nsgm init blog-app` |
|
|
146
|
+
| `nsgm create` | Generate controller with CRUD | Interactive/CLI | `nsgm create user` |
|
|
147
|
+
| `nsgm delete` | Remove controller and files | Interactive/CLI | `nsgm delete product` |
|
|
148
|
+
| `nsgm create-config` | Batch create from config file | CLI | `nsgm create-config config/modules.json` |
|
|
149
|
+
| `nsgm dev` | Start development server | CLI | `nsgm dev` |
|
|
150
|
+
| `nsgm build` | Build for production | CLI | `nsgm build` |
|
|
151
|
+
| `nsgm start` | Start production server | CLI | `nsgm start` |
|
|
150
152
|
|
|
151
153
|
### Advanced Commands
|
|
152
154
|
|
|
@@ -154,6 +156,11 @@ Your application will be available at `http://localhost:3000` with:
|
|
|
154
156
|
# Database operations
|
|
155
157
|
nsgm deletedb user # Delete controller + database table
|
|
156
158
|
|
|
159
|
+
# Batch module creation
|
|
160
|
+
nsgm create-config config/modules.json # Create all modules from config
|
|
161
|
+
nsgm create-config config/modules.json --module category # Create specific module
|
|
162
|
+
nsgm create-config config/modules.json --dry-run # Preview without creating
|
|
163
|
+
|
|
157
164
|
# Project maintenance
|
|
158
165
|
nsgm upgrade # Upgrade project base files
|
|
159
166
|
nsgm export # Export static pages
|
|
@@ -455,10 +462,103 @@ npm run tsbuild
|
|
|
455
462
|
## 📖 Documentation
|
|
456
463
|
|
|
457
464
|
- [Security Guide](SECURITY.md) - Security best practices
|
|
465
|
+
- [Config-Based Generation Guide](docs/CONFIG-CMD-IMPLEMENTATION.md) - Batch module creation from config files
|
|
458
466
|
- [API Reference](docs/api.md) - Complete API documentation
|
|
459
467
|
- [Migration Guide](docs/migration.md) - Upgrade instructions
|
|
460
468
|
- [Troubleshooting](docs/troubleshooting.md) - Common issues and solutions
|
|
461
469
|
|
|
470
|
+
## 📋 Configuration File-Based Generation
|
|
471
|
+
|
|
472
|
+
NSGM CLI supports batch module creation from JSON configuration files, making it easy to generate multiple modules at once.
|
|
473
|
+
|
|
474
|
+
### Configuration File Format
|
|
475
|
+
|
|
476
|
+
Create a JSON file (e.g., `config/modules.json`) with your module definitions:
|
|
477
|
+
|
|
478
|
+
```json
|
|
479
|
+
[
|
|
480
|
+
{
|
|
481
|
+
"controller": "category",
|
|
482
|
+
"action": "manage",
|
|
483
|
+
"dictionary": ".",
|
|
484
|
+
"fields": [
|
|
485
|
+
{
|
|
486
|
+
"name": "id",
|
|
487
|
+
"type": "integer",
|
|
488
|
+
"required": true,
|
|
489
|
+
"comment": "Primary key",
|
|
490
|
+
"isPrimaryKey": true,
|
|
491
|
+
"isAutoIncrement": true
|
|
492
|
+
},
|
|
493
|
+
{
|
|
494
|
+
"name": "name",
|
|
495
|
+
"type": "varchar",
|
|
496
|
+
"length": 100,
|
|
497
|
+
"required": true,
|
|
498
|
+
"comment": "Category name",
|
|
499
|
+
"showInList": true,
|
|
500
|
+
"showInForm": true,
|
|
501
|
+
"searchable": true
|
|
502
|
+
}
|
|
503
|
+
]
|
|
504
|
+
}
|
|
505
|
+
]
|
|
506
|
+
```
|
|
507
|
+
|
|
508
|
+
### Usage Examples
|
|
509
|
+
|
|
510
|
+
```bash
|
|
511
|
+
# Create all modules from config
|
|
512
|
+
nsgm create-config config/modules.json
|
|
513
|
+
|
|
514
|
+
# Or use npm script with default config
|
|
515
|
+
npm run create-config
|
|
516
|
+
|
|
517
|
+
# Create specific module
|
|
518
|
+
nsgm create-config config/modules.json --module category
|
|
519
|
+
|
|
520
|
+
# Preview mode (dry-run)
|
|
521
|
+
nsgm create-config config/modules.json --dry-run
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
### Field Naming Convention
|
|
525
|
+
|
|
526
|
+
**Always use snake_case for field names:**
|
|
527
|
+
|
|
528
|
+
```json
|
|
529
|
+
{
|
|
530
|
+
"name": "user_id", // ✅ Correct
|
|
531
|
+
"name": "category_id", // ✅ Correct
|
|
532
|
+
"name": "total_amount", // ✅ Correct
|
|
533
|
+
"name": "create_date", // ✅ Correct
|
|
534
|
+
"name": "update_date" // ✅ Correct
|
|
535
|
+
}
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
Avoid camelCase:
|
|
539
|
+
|
|
540
|
+
```json
|
|
541
|
+
{
|
|
542
|
+
"name": "userId", // ❌ Not recommended
|
|
543
|
+
"name": "categoryId", // ❌ Not recommended
|
|
544
|
+
"name": "totalAmount", // ❌ Not recommended
|
|
545
|
+
}
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
### Configuration File Location
|
|
549
|
+
|
|
550
|
+
Generated projects include a `config/` directory with example configuration files:
|
|
551
|
+
|
|
552
|
+
```
|
|
553
|
+
project/
|
|
554
|
+
├── config/
|
|
555
|
+
│ ├── modules.json # Default module configuration
|
|
556
|
+
└── your-custom-config.json # Your custom configurations
|
|
557
|
+
├── server/
|
|
558
|
+
├── client/
|
|
559
|
+
└── ...
|
|
560
|
+
```
|
|
561
|
+
|
|
462
562
|
## 🐛 Troubleshooting
|
|
463
563
|
|
|
464
564
|
### Common Issues
|
package/generation/README.md
CHANGED
|
@@ -245,14 +245,20 @@ module.exports = {
|
|
|
245
245
|
### 使用方法
|
|
246
246
|
|
|
247
247
|
```bash
|
|
248
|
-
#
|
|
249
|
-
npm run create-config
|
|
248
|
+
# 创建所有模块(使用默认配置文件 config/modules.json)
|
|
249
|
+
npm run create-config
|
|
250
|
+
|
|
251
|
+
# 或指定配置文件路径
|
|
252
|
+
nsgm create-config config/modules.json
|
|
250
253
|
|
|
251
254
|
# 创建指定模块
|
|
252
|
-
npm run create-config
|
|
255
|
+
npm run create-config --module category
|
|
253
256
|
|
|
254
257
|
# 预览模式(不实际创建)
|
|
255
|
-
npm run create-config
|
|
258
|
+
npm run create-config --dry-run
|
|
259
|
+
|
|
260
|
+
# 使用自定义配置文件
|
|
261
|
+
nsgm create-config path/to/your-config.json
|
|
256
262
|
```
|
|
257
263
|
|
|
258
264
|
### 字段命名规范
|
package/generation/package.json
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"create": "nsgm create",
|
|
14
14
|
"delete": "nsgm delete",
|
|
15
15
|
"deletedb": "nsgm deletedb",
|
|
16
|
-
"create-config": "nsgm create-config",
|
|
16
|
+
"create-config": "nsgm create-config config/modules.json",
|
|
17
17
|
"generate-password": "node scripts/generate-password-hash.js",
|
|
18
18
|
"postversion": "git push && git push --tags",
|
|
19
19
|
"test": "jest",
|
|
@@ -44,7 +44,13 @@ exports.createConfigCommand = {
|
|
|
44
44
|
try {
|
|
45
45
|
// 获取配置文件路径
|
|
46
46
|
const args = process.argv.slice(2);
|
|
47
|
-
|
|
47
|
+
// 跳过命令名和别名
|
|
48
|
+
let configPathIndex = 0;
|
|
49
|
+
const commandNames = ["create-config", "-cc", "--create-config"];
|
|
50
|
+
while (configPathIndex < args.length && commandNames.includes(args[configPathIndex])) {
|
|
51
|
+
configPathIndex++;
|
|
52
|
+
}
|
|
53
|
+
if (configPathIndex >= args.length || args[configPathIndex].startsWith("-")) {
|
|
48
54
|
utils_1.Console.error("请指定配置文件路径");
|
|
49
55
|
utils_1.Console.info("使用方法:");
|
|
50
56
|
utils_1.Console.info(" nsgm create-config <config-file> [--module <name>]");
|
|
@@ -56,7 +62,7 @@ exports.createConfigCommand = {
|
|
|
56
62
|
utils_1.Console.info(" nsgm create-config config/modules.json --all");
|
|
57
63
|
process.exit(1);
|
|
58
64
|
}
|
|
59
|
-
const configPath = args[
|
|
65
|
+
const configPath = args[configPathIndex];
|
|
60
66
|
// 检查配置文件是否存在
|
|
61
67
|
if (!fs_1.default.existsSync(configPath)) {
|
|
62
68
|
utils_1.Console.error(`配置文件不存在: ${configPath}`);
|