nsgm-cli 2.1.12 → 2.1.14

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 (113) hide show
  1. package/README.md +369 -163
  2. package/client/components/Button.tsx +3 -5
  3. package/client/components/__tests__/Button.test.tsx +10 -10
  4. package/client/layout/index.tsx +149 -137
  5. package/client/redux/reducers.ts +1 -1
  6. package/client/redux/store.ts +2 -1
  7. package/client/redux/template/manage/actions.ts +77 -88
  8. package/client/redux/template/manage/reducers.ts +25 -37
  9. package/client/redux/template/manage/types.ts +1 -1
  10. package/client/service/template/manage.ts +20 -21
  11. package/client/styled/common.ts +12 -13
  12. package/client/styled/layout/index.ts +19 -19
  13. package/client/styled/template/manage.ts +14 -13
  14. package/client/utils/common.ts +23 -21
  15. package/client/utils/cookie.ts +18 -19
  16. package/client/utils/fetch.ts +64 -100
  17. package/client/utils/menu.tsx +16 -3
  18. package/client/utils/sso.ts +74 -84
  19. package/eslint.config.js +38 -1
  20. package/generation/README.md +25 -18
  21. package/generation/__tests__/example.test.js +41 -0
  22. package/generation/client/utils/menu.tsx +9 -2
  23. package/generation/env.example +3 -0
  24. package/generation/eslint.config.js +112 -0
  25. package/generation/gitignore +6 -1
  26. package/generation/jest.config.js +40 -0
  27. package/generation/package.json +25 -4
  28. package/jest.config.js +23 -6
  29. package/lib/args.js +9 -1
  30. package/lib/cli/app.d.ts +28 -0
  31. package/lib/cli/app.js +99 -0
  32. package/lib/cli/commands/build.d.ts +2 -0
  33. package/lib/cli/commands/build.js +29 -0
  34. package/lib/cli/commands/create.d.ts +2 -0
  35. package/lib/cli/commands/create.js +113 -0
  36. package/lib/cli/commands/delete.d.ts +3 -0
  37. package/lib/cli/commands/delete.js +151 -0
  38. package/lib/cli/commands/export.d.ts +2 -0
  39. package/lib/cli/commands/export.js +42 -0
  40. package/lib/cli/commands/help.d.ts +2 -0
  41. package/lib/cli/commands/help.js +42 -0
  42. package/lib/cli/commands/init.d.ts +2 -0
  43. package/lib/cli/commands/init.js +115 -0
  44. package/lib/cli/commands/server.d.ts +3 -0
  45. package/lib/cli/commands/server.js +26 -0
  46. package/lib/cli/commands/upgrade.d.ts +2 -0
  47. package/lib/cli/commands/upgrade.js +38 -0
  48. package/lib/cli/commands/version.d.ts +2 -0
  49. package/lib/cli/commands/version.js +24 -0
  50. package/lib/cli/index.d.ts +16 -0
  51. package/lib/cli/index.js +33 -0
  52. package/lib/cli/parser.d.ts +22 -0
  53. package/lib/cli/parser.js +115 -0
  54. package/lib/cli/registry.d.ts +33 -0
  55. package/lib/cli/registry.js +81 -0
  56. package/lib/cli/types/project.d.ts +10 -0
  57. package/lib/cli/types/project.js +2 -0
  58. package/lib/cli/types.d.ts +31 -0
  59. package/lib/cli/types.js +20 -0
  60. package/lib/cli/utils/console.d.ts +62 -0
  61. package/lib/cli/utils/console.js +148 -0
  62. package/lib/cli/utils/index.d.ts +2 -0
  63. package/lib/cli/utils/index.js +7 -0
  64. package/lib/cli/utils/prompt.d.ts +83 -0
  65. package/lib/cli/utils/prompt.js +368 -0
  66. package/lib/constants.d.ts +58 -0
  67. package/lib/constants.js +162 -0
  68. package/lib/generate.d.ts +25 -3
  69. package/lib/generate.js +97 -621
  70. package/lib/generate_create.d.ts +9 -0
  71. package/lib/generate_create.js +326 -0
  72. package/lib/generate_delete.d.ts +8 -0
  73. package/lib/generate_delete.js +156 -0
  74. package/lib/generate_init.d.ts +50 -0
  75. package/lib/generate_init.js +492 -0
  76. package/lib/generators/base-generator.d.ts +47 -0
  77. package/lib/generators/base-generator.js +92 -0
  78. package/lib/generators/generator-factory.d.ts +20 -0
  79. package/lib/generators/generator-factory.js +25 -0
  80. package/lib/generators/page-generator.d.ts +41 -0
  81. package/lib/generators/page-generator.js +552 -0
  82. package/lib/generators/resolver-generator.d.ts +12 -0
  83. package/lib/generators/resolver-generator.js +303 -0
  84. package/lib/generators/schema-generator.d.ts +7 -0
  85. package/lib/generators/schema-generator.js +57 -0
  86. package/lib/generators/service-generator.d.ts +7 -0
  87. package/lib/generators/service-generator.js +119 -0
  88. package/lib/generators/sql-generator.d.ts +8 -0
  89. package/lib/generators/sql-generator.js +52 -0
  90. package/lib/index.d.ts +1 -1
  91. package/lib/index.js +14 -193
  92. package/lib/server/csrf.js +9 -16
  93. package/lib/server/db.js +6 -7
  94. package/lib/server/graphql.js +5 -6
  95. package/lib/server/plugins/date.js +1 -1
  96. package/lib/server/utils/graphql-cache.js +3 -3
  97. package/lib/tsconfig.build.tsbuildinfo +1 -1
  98. package/lib/utils/project-config.d.ts +5 -0
  99. package/lib/utils/project-config.js +145 -0
  100. package/lib/utils.js +1 -1
  101. package/next.config.js +12 -8
  102. package/package.json +10 -7
  103. package/pages/_app.tsx +23 -28
  104. package/pages/_document.tsx +39 -19
  105. package/pages/index.tsx +84 -39
  106. package/pages/login.tsx +21 -21
  107. package/pages/template/manage.tsx +114 -89
  108. package/public/fonts/font-awesome.min.css +4 -0
  109. package/public/fonts/fontawesome-webfont.woff +0 -0
  110. package/public/fonts/fontawesome-webfont.woff2 +0 -0
  111. package/public/slbhealthcheck.html +1 -1
  112. package/server/apis/template.js +0 -2
  113. package/generation/eslintrc.js +0 -16
@@ -0,0 +1,492 @@
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 () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.initTestFiles = exports.initRootFiles = exports.initScriptsFiles = exports.initPublicFiles = exports.initServerFiles = exports.initPagesFiles = exports.initClientFiles = void 0;
37
+ const path_1 = __importStar(require("path"));
38
+ const constants_1 = require("./constants");
39
+ const utils_1 = require("./utils");
40
+ // 常量定义
41
+ const CLIENT_FILES = {
42
+ reduxStore: '/store.ts',
43
+ styledCommon: '/common.ts',
44
+ styledLayoutIndex: '/index.ts',
45
+ utilsCommon: '/common.ts',
46
+ utilsFetch: '/fetch.ts',
47
+ utilsCookie: '/cookie.ts',
48
+ utilsSso: '/sso.ts',
49
+ layoutIndex: '/index.tsx',
50
+ };
51
+ const PAGES_FILES = {
52
+ index: '/index.tsx',
53
+ app: '/_app.tsx',
54
+ document: '/_document.tsx',
55
+ login: '/login.tsx',
56
+ };
57
+ const SERVER_FILES = {
58
+ apisSso: '/sso.js',
59
+ utilsCommon: '/common.js',
60
+ utilsDBPoolManager: '/db-pool-manager.js',
61
+ };
62
+ const PUBLIC_FILES = {
63
+ images: '/images',
64
+ zhizuotuImage: '/zhizuotu_1.png',
65
+ };
66
+ const SCRIPTS_FILES = {
67
+ startup: '/startup.sh',
68
+ shutdown: '/shutdown.sh',
69
+ password: '/generate-password-hash.js',
70
+ };
71
+ const ROOT_FILES = {
72
+ nextConfig: '/next.config.js',
73
+ mysqlConfig: '/mysql.config.js',
74
+ projectConfig: '/project.config.js',
75
+ tsconfig: '/tsconfig.json',
76
+ gitignoreSource: '/gitignore',
77
+ gitignore: '/.gitignore',
78
+ eslintrc: '/eslint.config.js',
79
+ nextEnvSource: '../next-env.d.ts',
80
+ nextEnv: '/next-env.d.ts',
81
+ readme: '/README.md',
82
+ appConfigSource: '../app.config.js',
83
+ appConfig: '/app.config.js',
84
+ app: '/app.js',
85
+ envExampleSource: '/env.example',
86
+ envExample: '/.env.example',
87
+ jestConfig: '/jest.config.js',
88
+ jestSetup: '/jest.setup.js',
89
+ jestSetupGlobals: '/jest.setup-globals.js',
90
+ };
91
+ // 辅助函数
92
+ const createDirectoryStructure = (directories) => {
93
+ directories.forEach((dir) => (0, utils_1.mkdirSync)(dir));
94
+ };
95
+ const copyMultipleFiles = (fileMappings) => {
96
+ fileMappings.forEach(({ source, dest, upgradeFlag }) => {
97
+ (0, utils_1.copyFileSync)(source, dest, upgradeFlag);
98
+ });
99
+ };
100
+ /**
101
+ * 初始化客户端文件
102
+ * @param dictionary 目标目录名称
103
+ * @param newDestFolder 新的目标文件夹路径
104
+ * @param upgradeFlag 是否为升级模式
105
+ */
106
+ const initClientFiles = (dictionary, newDestFolder, upgradeFlag) => {
107
+ console.log('Initializing client files...');
108
+ try {
109
+ // 1. 确定目标路径
110
+ const baseDestPath = dictionary === '' ? constants_1.destClientPath : path_1.default.join(newDestFolder, constants_1.clientPath);
111
+ const destPaths = {
112
+ client: baseDestPath,
113
+ redux: (0, path_1.resolve)(baseDestPath + constants_1.reduxPath),
114
+ styled: (0, path_1.resolve)(baseDestPath + constants_1.styledPath),
115
+ styledLayout: (0, path_1.resolve)(baseDestPath + constants_1.styledPath + constants_1.styledLayoutPath),
116
+ utils: (0, path_1.resolve)(baseDestPath + constants_1.utilsPath),
117
+ layout: (0, path_1.resolve)(baseDestPath + constants_1.layoutPath),
118
+ };
119
+ // 2. 创建目录结构
120
+ const directoriesToCreate = [
121
+ destPaths.client,
122
+ destPaths.redux,
123
+ destPaths.styled,
124
+ destPaths.styledLayout,
125
+ destPaths.utils,
126
+ destPaths.layout,
127
+ ];
128
+ createDirectoryStructure(directoriesToCreate);
129
+ // 3. 定义文件映射
130
+ const fileMappings = [
131
+ {
132
+ source: (0, path_1.resolve)(constants_1.sourceClientPath + constants_1.reduxPath + CLIENT_FILES.reduxStore),
133
+ dest: (0, path_1.resolve)(destPaths.redux + CLIENT_FILES.reduxStore),
134
+ upgradeFlag,
135
+ },
136
+ {
137
+ source: (0, path_1.resolve)(constants_1.sourceClientPath + constants_1.styledPath + CLIENT_FILES.styledCommon),
138
+ dest: (0, path_1.resolve)(destPaths.styled + CLIENT_FILES.styledCommon),
139
+ upgradeFlag,
140
+ },
141
+ {
142
+ source: (0, path_1.resolve)(constants_1.sourceClientPath + constants_1.styledPath + constants_1.styledLayoutPath + CLIENT_FILES.styledLayoutIndex),
143
+ dest: (0, path_1.resolve)(destPaths.styledLayout + CLIENT_FILES.styledLayoutIndex),
144
+ upgradeFlag,
145
+ },
146
+ {
147
+ source: (0, path_1.resolve)(constants_1.sourceClientPath + constants_1.utilsPath + CLIENT_FILES.utilsCookie),
148
+ dest: (0, path_1.resolve)(destPaths.utils + CLIENT_FILES.utilsCookie),
149
+ upgradeFlag,
150
+ },
151
+ {
152
+ source: (0, path_1.resolve)(constants_1.sourceClientPath + constants_1.utilsPath + CLIENT_FILES.utilsSso),
153
+ dest: (0, path_1.resolve)(destPaths.utils + CLIENT_FILES.utilsSso),
154
+ upgradeFlag,
155
+ },
156
+ {
157
+ source: (0, path_1.resolve)(constants_1.sourceClientPath + constants_1.utilsPath + CLIENT_FILES.utilsCommon),
158
+ dest: (0, path_1.resolve)(destPaths.utils + CLIENT_FILES.utilsCommon),
159
+ upgradeFlag,
160
+ },
161
+ {
162
+ source: (0, path_1.resolve)(constants_1.sourceClientPath + constants_1.utilsPath + CLIENT_FILES.utilsFetch),
163
+ dest: (0, path_1.resolve)(destPaths.utils + CLIENT_FILES.utilsFetch),
164
+ upgradeFlag,
165
+ },
166
+ {
167
+ source: (0, path_1.resolve)(constants_1.sourceClientPath + constants_1.layoutPath + CLIENT_FILES.layoutIndex),
168
+ dest: (0, path_1.resolve)(destPaths.layout + CLIENT_FILES.layoutIndex),
169
+ upgradeFlag,
170
+ },
171
+ // 这些文件不使用 upgradeFlag
172
+ {
173
+ source: (0, path_1.resolve)(constants_1.sourceClientPathGeneration + constants_1.reduxPath + constants_1.reduxReducersPath),
174
+ dest: (0, path_1.resolve)(destPaths.redux + constants_1.reduxReducersPath),
175
+ },
176
+ {
177
+ source: (0, path_1.resolve)(constants_1.sourceClientPathGeneration + constants_1.utilsPath + constants_1.utilsMenuPath),
178
+ dest: (0, path_1.resolve)(destPaths.utils + constants_1.utilsMenuPath),
179
+ },
180
+ ];
181
+ // 4. 复制文件
182
+ copyMultipleFiles(fileMappings);
183
+ console.log('Client files initialization completed');
184
+ return {
185
+ destClientUtilsMenuPath: (0, path_1.resolve)(destPaths.utils + constants_1.utilsMenuPath),
186
+ destClientReduxReducersAllPath: (0, path_1.resolve)(destPaths.redux + constants_1.reduxReducersPath),
187
+ };
188
+ }
189
+ catch (error) {
190
+ console.error('Failed to initialize client files:', error);
191
+ throw error;
192
+ }
193
+ };
194
+ exports.initClientFiles = initClientFiles;
195
+ /**
196
+ * 初始化页面文件
197
+ * @param dictionary 目标目录名称
198
+ * @param newDestFolder 新的目标文件夹路径
199
+ * @param upgradeFlag 是否为升级模式
200
+ */
201
+ const initPagesFiles = (dictionary, newDestFolder, upgradeFlag) => {
202
+ console.log('Initializing pages files...');
203
+ try {
204
+ // 1. 确定目标路径
205
+ const baseDestPath = dictionary === '' ? constants_1.destPagesPath : path_1.default.join(newDestFolder, constants_1.pagesPath);
206
+ // 2. 创建目录
207
+ createDirectoryStructure([baseDestPath]);
208
+ // 3. 定义文件映射
209
+ const fileMappings = [
210
+ {
211
+ source: (0, path_1.resolve)(constants_1.sourcePagesPath + PAGES_FILES.index),
212
+ dest: (0, path_1.resolve)(baseDestPath + PAGES_FILES.index),
213
+ upgradeFlag,
214
+ },
215
+ {
216
+ source: (0, path_1.resolve)(constants_1.sourcePagesPath + PAGES_FILES.app),
217
+ dest: (0, path_1.resolve)(baseDestPath + PAGES_FILES.app),
218
+ upgradeFlag,
219
+ },
220
+ {
221
+ source: (0, path_1.resolve)(constants_1.sourcePagesPath + PAGES_FILES.document),
222
+ dest: (0, path_1.resolve)(baseDestPath + PAGES_FILES.document),
223
+ upgradeFlag,
224
+ },
225
+ {
226
+ source: (0, path_1.resolve)(constants_1.sourcePagesPath + PAGES_FILES.login),
227
+ dest: (0, path_1.resolve)(baseDestPath + PAGES_FILES.login),
228
+ upgradeFlag,
229
+ },
230
+ ];
231
+ // 4. 复制文件
232
+ copyMultipleFiles(fileMappings);
233
+ console.log('Pages files initialization completed');
234
+ }
235
+ catch (error) {
236
+ console.error('Failed to initialize pages files:', error);
237
+ throw error;
238
+ }
239
+ };
240
+ exports.initPagesFiles = initPagesFiles;
241
+ /**
242
+ * 初始化服务器文件
243
+ * @param dictionary 目标目录名称
244
+ * @param newDestFolder 新的目标文件夹路径
245
+ * @param upgradeFlag 是否为升级模式
246
+ */
247
+ const initServerFiles = (dictionary, newDestFolder, upgradeFlag) => {
248
+ console.log('Initializing server files...');
249
+ try {
250
+ // 1. 确定目标路径
251
+ const baseDestPath = dictionary === '' ? constants_1.destServerPath : path_1.default.join(newDestFolder, constants_1.serverPath);
252
+ const destPaths = {
253
+ server: baseDestPath,
254
+ apis: (0, path_1.resolve)(baseDestPath + constants_1.apisPath),
255
+ utils: (0, path_1.resolve)(baseDestPath + constants_1.utilsPath),
256
+ };
257
+ // 2. 创建目录结构
258
+ const directoriesToCreate = [destPaths.server, destPaths.apis, destPaths.utils];
259
+ createDirectoryStructure(directoriesToCreate);
260
+ // 3. 定义文件映射
261
+ const fileMappings = [
262
+ {
263
+ source: (0, path_1.resolve)(constants_1.sourceServerPath + constants_1.apisPath + SERVER_FILES.apisSso),
264
+ dest: (0, path_1.resolve)(destPaths.apis + SERVER_FILES.apisSso),
265
+ upgradeFlag,
266
+ },
267
+ {
268
+ source: (0, path_1.resolve)(constants_1.sourceServerPathGeneration + constants_1.utilsPath + SERVER_FILES.utilsCommon),
269
+ dest: (0, path_1.resolve)(destPaths.utils + SERVER_FILES.utilsCommon),
270
+ upgradeFlag,
271
+ },
272
+ {
273
+ source: (0, path_1.resolve)(constants_1.sourceServerPathGeneration + constants_1.utilsPath + SERVER_FILES.utilsDBPoolManager),
274
+ dest: (0, path_1.resolve)(destPaths.utils + SERVER_FILES.utilsDBPoolManager),
275
+ upgradeFlag,
276
+ },
277
+ // REST 文件不使用 upgradeFlag
278
+ {
279
+ source: (0, path_1.resolve)(constants_1.sourceServerPathGeneration + constants_1.restPath),
280
+ dest: (0, path_1.resolve)(destPaths.server + constants_1.restPath),
281
+ },
282
+ ];
283
+ // 4. 复制文件
284
+ copyMultipleFiles(fileMappings);
285
+ console.log('Server files initialization completed');
286
+ return {
287
+ destServerRestPath: (0, path_1.resolve)(destPaths.server + constants_1.restPath),
288
+ };
289
+ }
290
+ catch (error) {
291
+ console.error('Failed to initialize server files:', error);
292
+ throw error;
293
+ }
294
+ };
295
+ exports.initServerFiles = initServerFiles;
296
+ /**
297
+ * 初始化公共文件
298
+ * @param dictionary 目标目录名称
299
+ * @param newDestFolder 新的目标文件夹路径
300
+ * @param upgradeFlag 是否为升级模式
301
+ */
302
+ const initPublicFiles = (dictionary, newDestFolder, upgradeFlag) => {
303
+ console.log('Initializing public files...');
304
+ try {
305
+ // 1. 确定目标路径
306
+ const baseDestPath = dictionary === '' ? constants_1.destPublicPath : path_1.default.join(newDestFolder, constants_1.publicPath);
307
+ const destPaths = {
308
+ public: baseDestPath,
309
+ images: (0, path_1.resolve)(baseDestPath + PUBLIC_FILES.images),
310
+ };
311
+ // 2. 创建目录结构
312
+ const directoriesToCreate = [destPaths.public, destPaths.images];
313
+ createDirectoryStructure(directoriesToCreate);
314
+ // 3. 定义文件映射
315
+ const fileMappings = [
316
+ {
317
+ source: (0, path_1.resolve)(constants_1.sourcePublicPath + constants_1.slbHealthCheckPath),
318
+ dest: (0, path_1.resolve)(destPaths.public + constants_1.slbHealthCheckPath),
319
+ upgradeFlag,
320
+ },
321
+ {
322
+ source: (0, path_1.resolve)(constants_1.sourcePublicPath + PUBLIC_FILES.images + PUBLIC_FILES.zhizuotuImage),
323
+ dest: (0, path_1.resolve)(destPaths.images + PUBLIC_FILES.zhizuotuImage),
324
+ upgradeFlag,
325
+ },
326
+ ];
327
+ // 4. 复制文件
328
+ copyMultipleFiles(fileMappings);
329
+ console.log('Public files initialization completed');
330
+ return {
331
+ destPublicHealthCheckPath: (0, path_1.resolve)(destPaths.public + constants_1.slbHealthCheckPath),
332
+ };
333
+ }
334
+ catch (error) {
335
+ console.error('Failed to initialize public files:', error);
336
+ throw error;
337
+ }
338
+ };
339
+ exports.initPublicFiles = initPublicFiles;
340
+ /**
341
+ * 初始化脚本文件
342
+ * @param dictionary 目标目录名称
343
+ * @param newDestFolder 新的目标文件夹路径
344
+ */
345
+ const initScriptsFiles = (dictionary, newDestFolder) => {
346
+ console.log('Initializing scripts files...');
347
+ try {
348
+ // 1. 确定目标路径
349
+ const baseDestPath = dictionary === '' ? constants_1.destScriptsPath : path_1.default.join(newDestFolder, constants_1.scriptsPath);
350
+ // 2. 创建目录
351
+ createDirectoryStructure([baseDestPath]);
352
+ // 3. 定义文件映射(脚本文件通常不使用 upgradeFlag)
353
+ const fileMappings = [
354
+ {
355
+ source: (0, path_1.resolve)(constants_1.sourceScriptsPath + SCRIPTS_FILES.startup),
356
+ dest: (0, path_1.resolve)(baseDestPath + SCRIPTS_FILES.startup),
357
+ },
358
+ {
359
+ source: (0, path_1.resolve)(constants_1.sourceScriptsPath + SCRIPTS_FILES.shutdown),
360
+ dest: (0, path_1.resolve)(baseDestPath + SCRIPTS_FILES.shutdown),
361
+ },
362
+ {
363
+ source: (0, path_1.resolve)(constants_1.sourceScriptsPath + SCRIPTS_FILES.password),
364
+ dest: (0, path_1.resolve)(baseDestPath + SCRIPTS_FILES.password),
365
+ },
366
+ ];
367
+ // 4. 复制文件
368
+ copyMultipleFiles(fileMappings);
369
+ console.log('Scripts files initialization completed');
370
+ }
371
+ catch (error) {
372
+ console.error('Failed to initialize scripts files:', error);
373
+ throw error;
374
+ }
375
+ };
376
+ exports.initScriptsFiles = initScriptsFiles;
377
+ /**
378
+ * 初始化根目录文件
379
+ * @param dictionary 目标目录名称
380
+ * @param newDestFolder 新的目标文件夹路径
381
+ */
382
+ const initRootFiles = (dictionary, newDestFolder) => {
383
+ console.log('Initializing root files...');
384
+ try {
385
+ // 1. 确定目标路径
386
+ const baseDestPath = dictionary === '' ? constants_1.destFolder : newDestFolder;
387
+ // 2. 定义文件映射(根文件通常不使用 upgradeFlag)
388
+ const fileMappings = [
389
+ {
390
+ source: (0, path_1.resolve)(constants_1.sourceGenerationPath + ROOT_FILES.nextConfig),
391
+ dest: (0, path_1.resolve)(baseDestPath + ROOT_FILES.nextConfig),
392
+ },
393
+ {
394
+ source: (0, path_1.resolve)(constants_1.sourceGenerationPath + ROOT_FILES.mysqlConfig),
395
+ dest: (0, path_1.resolve)(baseDestPath + ROOT_FILES.mysqlConfig),
396
+ },
397
+ {
398
+ source: (0, path_1.resolve)(constants_1.sourceGenerationPath + ROOT_FILES.projectConfig),
399
+ dest: (0, path_1.resolve)(baseDestPath + ROOT_FILES.projectConfig),
400
+ },
401
+ {
402
+ source: (0, path_1.resolve)(constants_1.sourceGenerationPath + constants_1.packagePath),
403
+ dest: (0, path_1.resolve)(baseDestPath + constants_1.packagePath),
404
+ },
405
+ {
406
+ source: (0, path_1.resolve)(constants_1.sourceGenerationPath + ROOT_FILES.tsconfig),
407
+ dest: (0, path_1.resolve)(baseDestPath + ROOT_FILES.tsconfig),
408
+ },
409
+ {
410
+ source: (0, path_1.resolve)(constants_1.sourceGenerationPath + ROOT_FILES.gitignoreSource),
411
+ dest: (0, path_1.resolve)(baseDestPath + ROOT_FILES.gitignore),
412
+ },
413
+ {
414
+ source: (0, path_1.resolve)(constants_1.sourceGenerationPath + ROOT_FILES.eslintrc),
415
+ dest: (0, path_1.resolve)(baseDestPath + ROOT_FILES.eslintrc),
416
+ },
417
+ {
418
+ source: path_1.default.join(constants_1.sourceFolder, ROOT_FILES.nextEnvSource),
419
+ dest: (0, path_1.resolve)(baseDestPath + ROOT_FILES.nextEnv),
420
+ },
421
+ {
422
+ source: (0, path_1.resolve)(constants_1.sourceGenerationPath + ROOT_FILES.readme),
423
+ dest: (0, path_1.resolve)(baseDestPath + ROOT_FILES.readme),
424
+ },
425
+ {
426
+ source: path_1.default.join(constants_1.sourceFolder, ROOT_FILES.appConfigSource),
427
+ dest: (0, path_1.resolve)(baseDestPath + ROOT_FILES.appConfig),
428
+ },
429
+ {
430
+ source: (0, path_1.resolve)(constants_1.sourceGenerationPath + ROOT_FILES.app),
431
+ dest: (0, path_1.resolve)(baseDestPath + ROOT_FILES.app),
432
+ },
433
+ {
434
+ source: (0, path_1.resolve)(constants_1.sourceGenerationPath + ROOT_FILES.envExampleSource),
435
+ dest: (0, path_1.resolve)(baseDestPath + ROOT_FILES.envExample),
436
+ },
437
+ {
438
+ source: (0, path_1.resolve)(constants_1.sourceGenerationPath + ROOT_FILES.jestConfig),
439
+ dest: (0, path_1.resolve)(baseDestPath + ROOT_FILES.jestConfig),
440
+ },
441
+ {
442
+ source: (0, path_1.resolve)(path_1.default.join(constants_1.sourceFolder, '..', ROOT_FILES.jestSetup)),
443
+ dest: (0, path_1.resolve)(baseDestPath + ROOT_FILES.jestSetup),
444
+ },
445
+ {
446
+ source: (0, path_1.resolve)(path_1.default.join(constants_1.sourceFolder, '..', ROOT_FILES.jestSetupGlobals)),
447
+ dest: (0, path_1.resolve)(baseDestPath + ROOT_FILES.jestSetupGlobals),
448
+ },
449
+ ];
450
+ // 3. 复制文件
451
+ copyMultipleFiles(fileMappings);
452
+ console.log('Root files initialization completed');
453
+ return {
454
+ destPackagePath: (0, path_1.resolve)(baseDestPath + constants_1.packagePath),
455
+ };
456
+ }
457
+ catch (error) {
458
+ console.error('Failed to initialize root files:', error);
459
+ throw error;
460
+ }
461
+ };
462
+ exports.initRootFiles = initRootFiles;
463
+ /**
464
+ * 初始化测试文件和目录
465
+ * @param dictionary 目标目录名称
466
+ * @param newDestFolder 新的目标文件夹路径
467
+ */
468
+ const initTestFiles = (dictionary, newDestFolder) => {
469
+ console.log('Initializing test files...');
470
+ try {
471
+ // 1. 确定目标路径
472
+ const baseDestPath = dictionary === '' ? constants_1.destFolder : newDestFolder;
473
+ const testDestPath = path_1.default.join(baseDestPath, '__tests__');
474
+ // 2. 创建测试目录
475
+ createDirectoryStructure([testDestPath]);
476
+ // 3. 定义文件映射
477
+ const fileMappings = [
478
+ {
479
+ source: path_1.default.join(constants_1.sourceGenerationPath, '__tests__', 'example.test.js'),
480
+ dest: path_1.default.join(testDestPath, 'example.test.js'),
481
+ },
482
+ ];
483
+ // 4. 复制文件
484
+ copyMultipleFiles(fileMappings);
485
+ console.log('Test files initialization completed');
486
+ }
487
+ catch (error) {
488
+ console.error('Failed to initialize test files:', error);
489
+ throw error;
490
+ }
491
+ };
492
+ exports.initTestFiles = initTestFiles;
@@ -0,0 +1,47 @@
1
+ import { FieldDefinition } from '../cli/utils/prompt';
2
+ /**
3
+ * 基础生成器抽象类
4
+ * 定义所有代码生成器的通用接口
5
+ */
6
+ export declare abstract class BaseGenerator {
7
+ protected controller: string;
8
+ protected action: string;
9
+ protected fields: FieldDefinition[];
10
+ constructor(controller: string, action: string, fields: FieldDefinition[]);
11
+ /**
12
+ * 生成代码的主方法
13
+ */
14
+ abstract generate(): string;
15
+ /**
16
+ * 获取首字母大写的控制器名
17
+ */
18
+ protected getCapitalizedController(): string;
19
+ /**
20
+ * 获取首字母大写的动作名
21
+ */
22
+ protected getCapitalizedAction(): string;
23
+ /**
24
+ * 获取显示字段
25
+ */
26
+ protected getDisplayFields(): FieldDefinition[];
27
+ /**
28
+ * 获取表单字段
29
+ */
30
+ protected getFormFields(): FieldDefinition[];
31
+ /**
32
+ * 获取可搜索字段
33
+ */
34
+ protected getSearchableFields(): FieldDefinition[];
35
+ /**
36
+ * 获取非系统字段
37
+ */
38
+ protected getNonSystemFields(): FieldDefinition[];
39
+ /**
40
+ * 将字段类型转换为GraphQL类型
41
+ */
42
+ protected getGraphQLType(fieldType: string): string;
43
+ /**
44
+ * 将字段类型转换为SQL类型
45
+ */
46
+ protected getSQLType(field: FieldDefinition): string;
47
+ }
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseGenerator = void 0;
4
+ /**
5
+ * 基础生成器抽象类
6
+ * 定义所有代码生成器的通用接口
7
+ */
8
+ class BaseGenerator {
9
+ constructor(controller, action, fields) {
10
+ this.controller = controller;
11
+ this.action = action;
12
+ this.fields = fields;
13
+ }
14
+ /**
15
+ * 获取首字母大写的控制器名
16
+ */
17
+ getCapitalizedController() {
18
+ return this.controller.charAt(0).toUpperCase() + this.controller.slice(1);
19
+ }
20
+ /**
21
+ * 获取首字母大写的动作名
22
+ */
23
+ getCapitalizedAction() {
24
+ return this.action.charAt(0).toUpperCase() + this.action.slice(1);
25
+ }
26
+ /**
27
+ * 获取显示字段
28
+ */
29
+ getDisplayFields() {
30
+ return this.fields.filter((f) => f.showInList && !f.isSystemField);
31
+ }
32
+ /**
33
+ * 获取表单字段
34
+ */
35
+ getFormFields() {
36
+ return this.fields.filter((f) => f.showInForm && !f.isPrimaryKey && !f.isSystemField);
37
+ }
38
+ /**
39
+ * 获取可搜索字段
40
+ */
41
+ getSearchableFields() {
42
+ return this.fields.filter((f) => f.searchable);
43
+ }
44
+ /**
45
+ * 获取非系统字段
46
+ */
47
+ getNonSystemFields() {
48
+ return this.fields.filter((f) => !f.isSystemField);
49
+ }
50
+ /**
51
+ * 将字段类型转换为GraphQL类型
52
+ */
53
+ getGraphQLType(fieldType) {
54
+ switch (fieldType) {
55
+ case 'integer':
56
+ return 'Int';
57
+ case 'decimal':
58
+ return 'Float';
59
+ case 'boolean':
60
+ return 'Boolean';
61
+ default:
62
+ return 'String';
63
+ }
64
+ }
65
+ /**
66
+ * 将字段类型转换为SQL类型
67
+ */
68
+ getSQLType(field) {
69
+ switch (field.type) {
70
+ case 'varchar':
71
+ return `varchar(${field.length || 255})`;
72
+ case 'text':
73
+ return 'text';
74
+ case 'integer':
75
+ return 'integer';
76
+ case 'decimal':
77
+ const [precision, scale] = (field.length || '10,2').toString().split(',');
78
+ return `decimal(${precision || 10},${scale || 2})`;
79
+ case 'boolean':
80
+ return 'boolean';
81
+ case 'date':
82
+ return 'date';
83
+ case 'datetime':
84
+ return 'datetime';
85
+ case 'timestamp':
86
+ return 'TIMESTAMP(3)';
87
+ default:
88
+ return 'varchar(255)';
89
+ }
90
+ }
91
+ }
92
+ exports.BaseGenerator = BaseGenerator;
@@ -0,0 +1,20 @@
1
+ import { SQLGenerator } from './sql-generator';
2
+ import { SchemaGenerator } from './schema-generator';
3
+ import { ResolverGenerator } from './resolver-generator';
4
+ import { ServiceGenerator } from './service-generator';
5
+ import { FieldDefinition } from '../cli/utils/prompt';
6
+ /**
7
+ * 代码生成器工厂
8
+ * 统一管理所有代码生成器
9
+ */
10
+ export declare class GeneratorFactory {
11
+ /**
12
+ * 创建所有必要的代码生成器
13
+ */
14
+ static createGenerators(controller: string, action: string, fields: FieldDefinition[]): {
15
+ sql: SQLGenerator;
16
+ schema: SchemaGenerator;
17
+ resolver: ResolverGenerator;
18
+ service: ServiceGenerator;
19
+ };
20
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GeneratorFactory = void 0;
4
+ const sql_generator_1 = require("./sql-generator");
5
+ const schema_generator_1 = require("./schema-generator");
6
+ const resolver_generator_1 = require("./resolver-generator");
7
+ const service_generator_1 = require("./service-generator");
8
+ /**
9
+ * 代码生成器工厂
10
+ * 统一管理所有代码生成器
11
+ */
12
+ class GeneratorFactory {
13
+ /**
14
+ * 创建所有必要的代码生成器
15
+ */
16
+ static createGenerators(controller, action, fields) {
17
+ return {
18
+ sql: new sql_generator_1.SQLGenerator(controller, action, fields),
19
+ schema: new schema_generator_1.SchemaGenerator(controller, action, fields),
20
+ resolver: new resolver_generator_1.ResolverGenerator(controller, action, fields),
21
+ service: new service_generator_1.ServiceGenerator(controller, action, fields),
22
+ };
23
+ }
24
+ }
25
+ exports.GeneratorFactory = GeneratorFactory;