nsgm-cli 2.1.23 → 2.1.25

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.
@@ -32,10 +32,11 @@
32
32
 
33
33
  ### 代码生成命令
34
34
 
35
- | 命令 | 说明 |
36
- | ---------------- | ------------ |
37
- | `npm run create` | 创建模板页面 |
38
- | `npm run delete` | 删除模板页面 |
35
+ | 命令 | 说明 |
36
+ | ----------------------- | --------------------- |
37
+ | `npm run create` | 创建模板页面 |
38
+ | `npm run delete` | 删除模板页面 |
39
+ | `npm run create-config` | 从配置文件批量创建模块 |
39
40
 
40
41
  ### 项目维护命令
41
42
 
@@ -188,6 +189,98 @@ module.exports = {
188
189
  - 不要将 `.env` 文件提交到版本控制系统
189
190
  - 定期更换登录密码
190
191
 
192
+ ## 配置文件批量创建模块
193
+
194
+ 项目支持从 JSON 配置文件批量创建模块,提高开发效率。
195
+
196
+ ### 配置文件位置
197
+
198
+ 配置文件应放置在 `config/` 目录下,例如 `config/modules.json`。
199
+
200
+ ### 配置文件格式
201
+
202
+ #### 单模块配置
203
+
204
+ ```json
205
+ {
206
+ "controller": "product",
207
+ "action": "manage",
208
+ "dictionary": ".",
209
+ "fields": [
210
+ {
211
+ "name": "name",
212
+ "type": "varchar",
213
+ "length": 255,
214
+ "required": true,
215
+ "comment": "商品名称",
216
+ "showInList": true,
217
+ "showInForm": true,
218
+ "searchable": true
219
+ }
220
+ ]
221
+ }
222
+ ```
223
+
224
+ #### 多模块配置
225
+
226
+ ```json
227
+ [
228
+ {
229
+ "controller": "category",
230
+ "action": "manage",
231
+ "dictionary": ".",
232
+ "fields": [...]
233
+ },
234
+ {
235
+ "controller": "product",
236
+ "action": "manage",
237
+ "dictionary": ".",
238
+ "fields": [...]
239
+ }
240
+ ]
241
+ ```
242
+
243
+ 项目已提供示例配置文件 `config/modules.json`,包含 `category` 和 `product` 两个模块。
244
+
245
+ ### 使用方法
246
+
247
+ ```bash
248
+ # 创建所有模块
249
+ npm run create-config config/modules.json
250
+
251
+ # 创建指定模块
252
+ npm run create-config config/modules.json --module category
253
+
254
+ # 预览模式(不实际创建)
255
+ npm run create-config config/modules.json --dry-run
256
+ ```
257
+
258
+ ### 字段命名规范
259
+
260
+ **始终使用蛇形命名(snake_case)**:
261
+
262
+ ```json
263
+ {
264
+ "name": "user_id", // ✅ 正确
265
+ "name": "category_id", // ✅ 正确
266
+ "name": "total_amount", // ✅ 正确
267
+ "name": "create_date", // ✅ 正确
268
+ "name": "update_date" // ✅ 正确
269
+ }
270
+ ```
271
+
272
+ 避免驼峰命名:
273
+
274
+ ```json
275
+ {
276
+ "name": "userId", // ❌ 不推荐
277
+ "name": "categoryId", // ❌ 不推荐
278
+ "name": "totalAmount", // ❌ 不推荐
279
+ }
280
+ ```
281
+
282
+ 更多详细信息,请参考项目中的示例配置文件 `config/modules.json`。
283
+
191
284
  ## 开发指南
192
285
 
193
286
  1. **创建新页面**:使用 `npm run create [controller] [action]` 命令
@@ -0,0 +1,163 @@
1
+ [
2
+ {
3
+ "controller": "category",
4
+ "action": "manage",
5
+ "dictionary": ".",
6
+ "fields": [
7
+ {
8
+ "name": "id",
9
+ "type": "integer",
10
+ "required": true,
11
+ "comment": "主键",
12
+ "isPrimaryKey": true,
13
+ "isAutoIncrement": true
14
+ },
15
+ {
16
+ "name": "name",
17
+ "type": "varchar",
18
+ "length": 100,
19
+ "required": true,
20
+ "comment": "分类名称",
21
+ "showInList": true,
22
+ "showInForm": true,
23
+ "searchable": true
24
+ },
25
+ {
26
+ "name": "description",
27
+ "type": "text",
28
+ "required": false,
29
+ "comment": "分类描述",
30
+ "showInList": false,
31
+ "showInForm": true
32
+ },
33
+ {
34
+ "name": "parent_id",
35
+ "type": "integer",
36
+ "required": false,
37
+ "comment": "父分类ID",
38
+ "showInList": true,
39
+ "showInForm": true
40
+ },
41
+ {
42
+ "name": "sort_order",
43
+ "type": "integer",
44
+ "required": true,
45
+ "comment": "排序",
46
+ "showInList": true,
47
+ "showInForm": true
48
+ },
49
+ {
50
+ "name": "status",
51
+ "type": "varchar",
52
+ "length": 20,
53
+ "required": true,
54
+ "comment": "状态",
55
+ "showInList": true,
56
+ "showInForm": true
57
+ },
58
+ {
59
+ "name": "create_date",
60
+ "type": "timestamp",
61
+ "required": true,
62
+ "comment": "创建时间",
63
+ "isSystemField": true
64
+ },
65
+ {
66
+ "name": "update_date",
67
+ "type": "timestamp",
68
+ "required": true,
69
+ "comment": "更新时间",
70
+ "isSystemField": true
71
+ }
72
+ ]
73
+ },
74
+ {
75
+ "controller": "product",
76
+ "action": "manage",
77
+ "dictionary": ".",
78
+ "fields": [
79
+ {
80
+ "name": "id",
81
+ "type": "integer",
82
+ "required": true,
83
+ "comment": "主键",
84
+ "isPrimaryKey": true,
85
+ "isAutoIncrement": true
86
+ },
87
+ {
88
+ "name": "name",
89
+ "type": "varchar",
90
+ "length": 255,
91
+ "required": true,
92
+ "comment": "商品名称",
93
+ "showInList": true,
94
+ "showInForm": true,
95
+ "searchable": true
96
+ },
97
+ {
98
+ "name": "description",
99
+ "type": "text",
100
+ "required": false,
101
+ "comment": "商品描述",
102
+ "showInList": false,
103
+ "showInForm": true
104
+ },
105
+ {
106
+ "name": "price",
107
+ "type": "decimal",
108
+ "required": true,
109
+ "comment": "商品价格",
110
+ "showInList": true,
111
+ "showInForm": true
112
+ },
113
+ {
114
+ "name": "category_id",
115
+ "type": "integer",
116
+ "required": false,
117
+ "comment": "分类ID",
118
+ "showInList": true,
119
+ "showInForm": true
120
+ },
121
+ {
122
+ "name": "stock",
123
+ "type": "integer",
124
+ "required": true,
125
+ "comment": "库存数量",
126
+ "showInList": true,
127
+ "showInForm": true
128
+ },
129
+ {
130
+ "name": "image_url",
131
+ "type": "varchar",
132
+ "length": 500,
133
+ "required": false,
134
+ "comment": "商品图片URL",
135
+ "showInList": true,
136
+ "showInForm": true
137
+ },
138
+ {
139
+ "name": "status",
140
+ "type": "varchar",
141
+ "length": 20,
142
+ "required": true,
143
+ "comment": "状态",
144
+ "showInList": true,
145
+ "showInForm": true
146
+ },
147
+ {
148
+ "name": "create_date",
149
+ "type": "timestamp",
150
+ "required": true,
151
+ "comment": "创建时间",
152
+ "isSystemField": true
153
+ },
154
+ {
155
+ "name": "update_date",
156
+ "type": "timestamp",
157
+ "required": true,
158
+ "comment": "更新时间",
159
+ "isSystemField": true
160
+ }
161
+ ]
162
+ }
163
+ ]
@@ -13,6 +13,7 @@
13
13
  "create": "nsgm create",
14
14
  "delete": "nsgm delete",
15
15
  "deletedb": "nsgm deletedb",
16
+ "create-config": "nsgm create-config",
16
17
  "generate-password": "node scripts/generate-password-hash.js",
17
18
  "postversion": "git push && git push --tags",
18
19
  "test": "jest",
@@ -0,0 +1,5 @@
1
+ import { Command } from "../types";
2
+ /**
3
+ * 从配置文件创建命令
4
+ */
5
+ export declare const createConfigCommand: Command;
@@ -0,0 +1,166 @@
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
+ exports.createConfigCommand = void 0;
7
+ const utils_1 = require("../utils");
8
+ const generate_1 = require("../../generate");
9
+ const fs_1 = __importDefault(require("fs"));
10
+ /**
11
+ * 从配置文件创建命令
12
+ */
13
+ exports.createConfigCommand = {
14
+ name: "create-config",
15
+ aliases: ["-cc", "--create-config"],
16
+ description: "从配置文件创建模块",
17
+ usage: "nsgm create-config <config-file> [options]",
18
+ examples: [
19
+ "nsgm create-config config/modules.json",
20
+ "nsgm create-config config/modules.json --module product",
21
+ "nsgm create-config config/modules.json --all",
22
+ ],
23
+ options: [
24
+ {
25
+ name: "module",
26
+ description: "指定要创建的模块名称(如果不指定则创建所有)",
27
+ required: false,
28
+ type: "string",
29
+ },
30
+ {
31
+ name: "all",
32
+ description: "创建配置文件中的所有模块",
33
+ required: false,
34
+ type: "boolean",
35
+ },
36
+ {
37
+ name: "dry-run",
38
+ description: "预览模式,只显示将要创建的模块而不实际创建",
39
+ required: false,
40
+ type: "boolean",
41
+ },
42
+ ],
43
+ execute: async (options) => {
44
+ try {
45
+ // 获取配置文件路径
46
+ const args = process.argv.slice(2);
47
+ if (args.length === 0 || args[0].startsWith("-")) {
48
+ utils_1.Console.error("请指定配置文件路径");
49
+ utils_1.Console.info("使用方法:");
50
+ utils_1.Console.info(" nsgm create-config <config-file> [--module <name>]");
51
+ utils_1.Console.info(" nsgm create-config <config-file> [--all]");
52
+ utils_1.Console.info("");
53
+ utils_1.Console.info("示例:");
54
+ utils_1.Console.info(" nsgm create-config config/modules.json");
55
+ utils_1.Console.info(" nsgm create-config config/modules.json --module category");
56
+ utils_1.Console.info(" nsgm create-config config/modules.json --all");
57
+ process.exit(1);
58
+ }
59
+ const configPath = args[0];
60
+ // 检查配置文件是否存在
61
+ if (!fs_1.default.existsSync(configPath)) {
62
+ utils_1.Console.error(`配置文件不存在: ${configPath}`);
63
+ process.exit(1);
64
+ }
65
+ // 读取配置文件
66
+ const configContent = fs_1.default.readFileSync(configPath, "utf8");
67
+ const config = JSON.parse(configContent);
68
+ // 验证配置格式
69
+ if (!Array.isArray(config)) {
70
+ utils_1.Console.error("配置文件格式错误:必须是一个数组");
71
+ process.exit(1);
72
+ }
73
+ // 解析目标模块
74
+ let targetModules = [];
75
+ if (options.module && typeof options.module === "string") {
76
+ // 创建指定模块
77
+ const targetModule = config.find((m) => m.controller === options.module);
78
+ if (!targetModule) {
79
+ utils_1.Console.error(`未找到模块: ${options.module}`);
80
+ utils_1.Console.info(`可用的模块: ${config.map((m) => m.controller).join(", ")}`);
81
+ process.exit(1);
82
+ }
83
+ targetModules = [targetModule];
84
+ }
85
+ else {
86
+ // 创建所有模块
87
+ targetModules = config;
88
+ }
89
+ // 预览模式
90
+ if (options.dryRun) {
91
+ utils_1.Console.title("📋 预览模式");
92
+ utils_1.Console.newLine();
93
+ utils_1.Console.info("将要创建的模块:");
94
+ utils_1.Console.newLine();
95
+ targetModules.forEach((module, index) => {
96
+ utils_1.Console.highlight(`${index + 1}. ${module.controller}`);
97
+ utils_1.Console.info(` 操作: ${module.action || "manage"}`);
98
+ utils_1.Console.info(` 目录: ${module.dictionary || "./"}`);
99
+ utils_1.Console.info(` 字段数: ${module.fields.length}`);
100
+ utils_1.Console.info(` 字段: ${module.fields.map((f) => f.name).join(", ")}`);
101
+ utils_1.Console.newLine();
102
+ });
103
+ utils_1.Console.separator();
104
+ utils_1.Console.info(`总计: ${targetModules.length} 个模块`);
105
+ utils_1.Console.newLine();
106
+ utils_1.Console.info("移除 --dry-run 参数以实际创建模块");
107
+ return;
108
+ }
109
+ // 确认创建
110
+ utils_1.Console.title(`📦 准备创建 ${targetModules.length} 个模块`);
111
+ utils_1.Console.newLine();
112
+ targetModules.forEach((module, index) => {
113
+ utils_1.Console.info(`${index + 1}. ${module.controller}`);
114
+ });
115
+ utils_1.Console.newLine();
116
+ const confirmed = await utils_1.Prompt.confirm("确认创建这些模块?", true);
117
+ if (!confirmed) {
118
+ utils_1.Console.warning("创建已取消");
119
+ process.exit(0);
120
+ }
121
+ // 逐个创建模块
122
+ let successCount = 0;
123
+ let failureCount = 0;
124
+ const failures = [];
125
+ for (const module of targetModules) {
126
+ utils_1.Console.separator();
127
+ utils_1.Console.highlight(`📦 创建模块 ${successCount + failureCount + 1}/${targetModules.length}: ${module.controller}`);
128
+ try {
129
+ const spinner = utils_1.Console.spinner("正在创建文件...", "green");
130
+ spinner.start();
131
+ // 调用核心创建函数
132
+ (0, generate_1.createFiles)(module.controller, module.action || "manage", module.dictionary || ".", module.fields);
133
+ spinner.succeed("控制器创建完成!");
134
+ successCount++;
135
+ utils_1.Console.newLine();
136
+ }
137
+ catch (error) {
138
+ const errorMessage = error instanceof Error ? error.message : String(error);
139
+ utils_1.Console.error(`错误: ${errorMessage}`);
140
+ failures.push({ module: module.controller, error: errorMessage });
141
+ failureCount++;
142
+ utils_1.Console.newLine();
143
+ }
144
+ }
145
+ // 显示总结
146
+ utils_1.Console.separator();
147
+ utils_1.Console.title("🎉 创建完成");
148
+ utils_1.Console.newLine();
149
+ utils_1.Console.highlight(`✅ 成功: ${successCount} 个`);
150
+ utils_1.Console.highlight(`❌ 失败: ${failureCount} 个`);
151
+ if (failures.length > 0) {
152
+ utils_1.Console.newLine();
153
+ utils_1.Console.error("失败的模块:");
154
+ failures.forEach(({ module, error }) => {
155
+ utils_1.Console.error(` - ${module}: ${error}`);
156
+ });
157
+ }
158
+ utils_1.Console.newLine();
159
+ utils_1.Console.box("创建已完成,请检查生成的文件!", "success");
160
+ }
161
+ catch (error) {
162
+ utils_1.Console.error(`执行失败: ${error}`);
163
+ process.exit(1);
164
+ }
165
+ },
166
+ };
@@ -7,6 +7,7 @@ export * from "./registry";
7
7
  export * from "./app";
8
8
  export * from "./commands/build";
9
9
  export * from "./commands/create";
10
+ export * from "./commands/create-config";
10
11
  export * from "./commands/delete";
11
12
  export * from "./commands/export";
12
13
  export * from "./commands/help";
package/lib/cli/index.js CHANGED
@@ -24,6 +24,7 @@ __exportStar(require("./app"), exports);
24
24
  // 命令导出
25
25
  __exportStar(require("./commands/build"), exports);
26
26
  __exportStar(require("./commands/create"), exports);
27
+ __exportStar(require("./commands/create-config"), exports);
27
28
  __exportStar(require("./commands/delete"), exports);
28
29
  __exportStar(require("./commands/export"), exports);
29
30
  __exportStar(require("./commands/help"), exports);
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CommandRegistry = void 0;
4
4
  const build_1 = require("./commands/build");
5
5
  const create_1 = require("./commands/create");
6
+ const create_config_1 = require("./commands/create-config");
6
7
  const delete_1 = require("./commands/delete");
7
8
  const export_1 = require("./commands/export");
8
9
  const help_1 = require("./commands/help");
@@ -26,6 +27,7 @@ class CommandRegistry {
26
27
  const commands = [
27
28
  build_1.buildCommand,
28
29
  create_1.createCommand,
30
+ create_config_1.createConfigCommand,
29
31
  delete_1.deleteCommand,
30
32
  delete_1.deleteDbCommand,
31
33
  export_1.exportCommand,
@@ -15,6 +15,7 @@ declare const scriptsPathSource = "../scripts";
15
15
  declare const scriptsPath = "./scripts";
16
16
  declare const typesPathSource = "../types";
17
17
  declare const typesPath = "./types";
18
+ declare const configPath = "./config";
18
19
  declare const reduxPath = "/redux";
19
20
  declare const servicePath = "/service";
20
21
  declare const styledPath = "/styled";
@@ -39,6 +40,7 @@ declare const sourcePagesPath: string;
39
40
  declare const sourcePublicPath: string;
40
41
  declare const sourceScriptsPath: string;
41
42
  declare const sourceTypesPath: string;
43
+ declare const sourceConfigPath: string;
42
44
  declare const destClientPath: string;
43
45
  declare const destClientReduxPath: string;
44
46
  declare const destClientServicePath: string;
@@ -55,9 +57,10 @@ declare const destPagesPath: string;
55
57
  declare const destPublicPath: string;
56
58
  declare const destScriptsPath: string;
57
59
  declare const destTypesPath: string;
60
+ declare const destConfigPath: string;
58
61
  declare const destClientUtilsMenuPath: string;
59
62
  declare const destClientReduxReducersAllPath: string;
60
63
  declare const destPublicHealthCheckPath: string;
61
64
  declare const destPackagePath: string;
62
65
  declare const destServerRestPath: string;
63
- export { sourceFolder, destFolder, isLocal, generationPath, clientPathSource, clientPath, serverPathSource, serverPath, pagesPathSource, pagesPath, publicPathSource, publicPath, scriptsPathSource, scriptsPath, typesPathSource, typesPath, reduxPath, servicePath, styledPath, styledLayoutPath, utilsPath, layoutPath, componentsPath, modulesPath, apisPath, sqlPath, utilsMenuPath, reduxReducersPath, slbHealthCheckPath, packagePath, restPath, sourceGenerationPath, sourceClientPath, sourceClientPathGeneration, sourceServerPath, sourceServerPathGeneration, sourcePagesPath, sourcePublicPath, sourceScriptsPath, sourceTypesPath, destClientPath, destClientReduxPath, destClientServicePath, destClientStyledPath, destClientStyledLayoutPath, destClientUtilsPath, destClientLayoutPath, destServerPath, destServerModulesPath, destServerApisPath, destServerSqlPath, destServerUtilsPath, destPagesPath, destPublicPath, destScriptsPath, destTypesPath, destClientUtilsMenuPath, destClientReduxReducersAllPath, destPublicHealthCheckPath, destPackagePath, destServerRestPath, mysqlUser, mysqlPassword, mysqlHost, mysqlPort, mysqlDatabase, };
66
+ export { sourceFolder, destFolder, isLocal, generationPath, clientPathSource, clientPath, serverPathSource, serverPath, pagesPathSource, pagesPath, publicPathSource, publicPath, scriptsPathSource, scriptsPath, typesPathSource, typesPath, configPath, reduxPath, servicePath, styledPath, styledLayoutPath, utilsPath, layoutPath, componentsPath, modulesPath, apisPath, sqlPath, utilsMenuPath, reduxReducersPath, slbHealthCheckPath, packagePath, restPath, sourceGenerationPath, sourceClientPath, sourceClientPathGeneration, sourceServerPath, sourceServerPathGeneration, sourcePagesPath, sourcePublicPath, sourceScriptsPath, sourceTypesPath, sourceConfigPath, destClientPath, destClientReduxPath, destClientServicePath, destClientStyledPath, destClientStyledLayoutPath, destClientUtilsPath, destClientLayoutPath, destServerPath, destServerModulesPath, destServerApisPath, destServerSqlPath, destServerUtilsPath, destPagesPath, destPublicPath, destScriptsPath, destTypesPath, destConfigPath, destClientUtilsMenuPath, destClientReduxReducersAllPath, destPublicHealthCheckPath, destPackagePath, destServerRestPath, mysqlUser, mysqlPassword, mysqlHost, mysqlPort, mysqlDatabase, };
package/lib/constants.js CHANGED
@@ -36,8 +36,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.destServerApisPath = exports.destServerModulesPath = exports.destServerPath = exports.destClientLayoutPath = exports.destClientUtilsPath = exports.destClientStyledLayoutPath = exports.destClientStyledPath = exports.destClientServicePath = exports.destClientReduxPath = exports.destClientPath = exports.sourceTypesPath = exports.sourceScriptsPath = exports.sourcePublicPath = exports.sourcePagesPath = exports.sourceServerPathGeneration = exports.sourceServerPath = exports.sourceClientPathGeneration = exports.sourceClientPath = exports.sourceGenerationPath = exports.restPath = exports.packagePath = exports.slbHealthCheckPath = exports.reduxReducersPath = exports.utilsMenuPath = exports.sqlPath = exports.apisPath = exports.modulesPath = exports.componentsPath = exports.layoutPath = exports.utilsPath = exports.styledLayoutPath = exports.styledPath = exports.servicePath = exports.reduxPath = exports.typesPath = exports.typesPathSource = exports.scriptsPath = exports.scriptsPathSource = exports.publicPath = exports.publicPathSource = exports.pagesPath = exports.pagesPathSource = exports.serverPath = exports.serverPathSource = exports.clientPath = exports.clientPathSource = exports.generationPath = exports.isLocal = exports.destFolder = exports.sourceFolder = void 0;
40
- exports.mysqlDatabase = exports.mysqlPort = exports.mysqlHost = exports.mysqlPassword = exports.mysqlUser = exports.destServerRestPath = exports.destPackagePath = exports.destPublicHealthCheckPath = exports.destClientReduxReducersAllPath = exports.destClientUtilsMenuPath = exports.destTypesPath = exports.destScriptsPath = exports.destPublicPath = exports.destPagesPath = exports.destServerUtilsPath = exports.destServerSqlPath = void 0;
39
+ exports.destServerPath = exports.destClientLayoutPath = exports.destClientUtilsPath = exports.destClientStyledLayoutPath = exports.destClientStyledPath = exports.destClientServicePath = exports.destClientReduxPath = exports.destClientPath = exports.sourceConfigPath = exports.sourceTypesPath = exports.sourceScriptsPath = exports.sourcePublicPath = exports.sourcePagesPath = exports.sourceServerPathGeneration = exports.sourceServerPath = exports.sourceClientPathGeneration = exports.sourceClientPath = exports.sourceGenerationPath = exports.restPath = exports.packagePath = exports.slbHealthCheckPath = exports.reduxReducersPath = exports.utilsMenuPath = exports.sqlPath = exports.apisPath = exports.modulesPath = exports.componentsPath = exports.layoutPath = exports.utilsPath = exports.styledLayoutPath = exports.styledPath = exports.servicePath = exports.reduxPath = exports.configPath = exports.typesPath = exports.typesPathSource = exports.scriptsPath = exports.scriptsPathSource = exports.publicPath = exports.publicPathSource = exports.pagesPath = exports.pagesPathSource = exports.serverPath = exports.serverPathSource = exports.clientPath = exports.clientPathSource = exports.generationPath = exports.isLocal = exports.destFolder = exports.sourceFolder = void 0;
40
+ exports.mysqlDatabase = exports.mysqlPort = exports.mysqlHost = exports.mysqlPassword = exports.mysqlUser = exports.destServerRestPath = exports.destPackagePath = exports.destPublicHealthCheckPath = exports.destClientReduxReducersAllPath = exports.destClientUtilsMenuPath = exports.destConfigPath = exports.destTypesPath = exports.destScriptsPath = exports.destPublicPath = exports.destPagesPath = exports.destServerUtilsPath = exports.destServerSqlPath = exports.destServerApisPath = exports.destServerModulesPath = void 0;
41
41
  const path_1 = __importStar(require("path"));
42
42
  const db_1 = __importDefault(require("./server/db"));
43
43
  const sourceFolder = __dirname;
@@ -80,6 +80,8 @@ const typesPathSource = "../types";
80
80
  exports.typesPathSource = typesPathSource;
81
81
  const typesPath = "./types";
82
82
  exports.typesPath = typesPath;
83
+ const configPath = "./config";
84
+ exports.configPath = configPath;
83
85
  const reduxPath = "/redux";
84
86
  exports.reduxPath = reduxPath;
85
87
  const servicePath = "/service";
@@ -128,6 +130,8 @@ const sourceScriptsPath = path_1.default.join(sourceFolder, scriptsPathSource);
128
130
  exports.sourceScriptsPath = sourceScriptsPath;
129
131
  const sourceTypesPath = path_1.default.join(sourceFolder, typesPathSource);
130
132
  exports.sourceTypesPath = sourceTypesPath;
133
+ const sourceConfigPath = path_1.default.join(sourceGenerationPath, configPath);
134
+ exports.sourceConfigPath = sourceConfigPath;
131
135
  const destClientPath = path_1.default.join(destFolder, clientPath);
132
136
  exports.destClientPath = destClientPath;
133
137
  const destClientReduxPath = (0, path_1.resolve)(destClientPath + reduxPath);
@@ -160,6 +164,8 @@ const destScriptsPath = path_1.default.join(destFolder, scriptsPath);
160
164
  exports.destScriptsPath = destScriptsPath;
161
165
  const destTypesPath = path_1.default.join(destFolder, typesPath);
162
166
  exports.destTypesPath = destTypesPath;
167
+ const destConfigPath = path_1.default.join(destFolder, configPath);
168
+ exports.destConfigPath = destConfigPath;
163
169
  const destClientUtilsMenuPath = (0, path_1.resolve)(destClientUtilsPath + utilsMenuPath);
164
170
  exports.destClientUtilsMenuPath = destClientUtilsMenuPath;
165
171
  const destClientReduxReducersAllPath = (0, path_1.resolve)(destClientReduxPath + reduxReducersPath);
package/lib/generate.js CHANGED
@@ -74,6 +74,7 @@ const initFiles = (dictionary, upgradeFlag = false, projectConfig) => {
74
74
  const { destPackagePath } = (0, generate_init_1.initRootFiles)(normalizedDictionary, newDestFolder);
75
75
  (0, generate_init_1.initTestFiles)(normalizedDictionary, newDestFolder);
76
76
  (0, generate_init_1.initTypesFiles)(normalizedDictionary, newDestFolder);
77
+ (0, generate_init_1.initConfigFiles)(normalizedDictionary, newDestFolder);
77
78
  // 如果提供了项目配置,应用到生成的文件中
78
79
  if (projectConfig) {
79
80
  console.log("应用项目配置...");
@@ -53,4 +53,10 @@ export declare const initTypesFiles: (dictionary: string, newDestFolder: string)
53
53
  * @param newDestFolder 新的目标文件夹路径
54
54
  */
55
55
  export declare const initTestFiles: (dictionary: string, newDestFolder: string) => void;
56
+ /**
57
+ * 初始化配置文件和目录
58
+ * @param dictionary 目标目录名称
59
+ * @param newDestFolder 新的目标文件夹路径
60
+ */
61
+ export declare const initConfigFiles: (dictionary: string, newDestFolder: string) => void;
56
62
  export {};
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.initTestFiles = exports.initTypesFiles = exports.initRootFiles = exports.initScriptsFiles = exports.initPublicFiles = exports.initServerFiles = exports.initPagesFiles = exports.initClientFiles = void 0;
36
+ exports.initConfigFiles = exports.initTestFiles = exports.initTypesFiles = exports.initRootFiles = exports.initScriptsFiles = exports.initPublicFiles = exports.initServerFiles = exports.initPagesFiles = exports.initClientFiles = void 0;
37
37
  const path_1 = __importStar(require("path"));
38
38
  const constants_1 = require("./constants");
39
39
  const utils_1 = require("./utils");
@@ -616,3 +616,43 @@ const initTestFiles = (dictionary, newDestFolder) => {
616
616
  }
617
617
  };
618
618
  exports.initTestFiles = initTestFiles;
619
+ /**
620
+ * 初始化配置文件和目录
621
+ * @param dictionary 目标目录名称
622
+ * @param newDestFolder 新的目标文件夹路径
623
+ */
624
+ const initConfigFiles = (dictionary, newDestFolder) => {
625
+ console.log("Initializing config files...");
626
+ try {
627
+ // 1. 确定目标路径
628
+ const baseDestPath = dictionary === "" ? constants_1.destFolder : newDestFolder;
629
+ const configDestPath = path_1.default.join(baseDestPath, constants_1.configPath);
630
+ // 2. 创建配置目录
631
+ createDirectoryStructure([configDestPath]);
632
+ // 3. 复制 config 目录下的所有文件
633
+ const sourceConfigDir = (0, path_1.resolve)(constants_1.sourceConfigPath);
634
+ if ((0, fs_1.existsSync)(sourceConfigDir)) {
635
+ const copyConfigRecursive = (sourceDir, destDir) => {
636
+ const items = (0, fs_1.readdirSync)(sourceDir, { withFileTypes: true });
637
+ items.forEach((item) => {
638
+ const sourcePath = (0, path_1.resolve)(sourceDir, item.name);
639
+ const destPath = (0, path_1.resolve)(destDir, item.name);
640
+ if (item.isDirectory()) {
641
+ (0, utils_1.mkdirSync)(destPath);
642
+ copyConfigRecursive(sourcePath, destPath);
643
+ }
644
+ else {
645
+ (0, utils_1.copyFileSync)(sourcePath, destPath, false);
646
+ }
647
+ });
648
+ };
649
+ copyConfigRecursive(sourceConfigDir, configDestPath);
650
+ }
651
+ console.log("Config files initialization completed");
652
+ }
653
+ catch (error) {
654
+ console.error("Failed to initialize config files:", error);
655
+ throw error;
656
+ }
657
+ };
658
+ exports.initConfigFiles = initConfigFiles;