nsgm-cli 2.1.19 → 2.1.21
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/client/components/Button.tsx +3 -3
- package/client/components/ClientProviders.tsx +12 -12
- package/client/components/LanguageSwitcher.tsx +26 -26
- package/client/components/SSRSafeAntdProvider.tsx +7 -7
- package/client/components/SuppressHydrationWarnings.tsx +30 -30
- package/client/components/__tests__/Button.test.tsx +12 -12
- package/client/layout/index.tsx +124 -124
- package/client/redux/reducers.ts +2 -2
- package/client/redux/store.ts +24 -24
- package/client/redux/template/manage/actions.ts +40 -40
- package/client/redux/template/manage/reducers.ts +32 -32
- package/client/redux/template/manage/types.ts +19 -19
- package/client/service/template/manage.ts +29 -29
- package/client/styled/common.ts +6 -6
- package/client/styled/layout/index.ts +17 -17
- package/client/styled/template/manage.ts +19 -19
- package/client/utils/common.ts +54 -54
- package/client/utils/cookie.ts +30 -30
- package/client/utils/fetch.ts +111 -111
- package/client/utils/i18n.ts +41 -41
- package/client/utils/menu.tsx +12 -12
- package/client/utils/navigation.ts +22 -22
- package/client/utils/sso.ts +124 -124
- package/client/utils/suppressWarnings.ts +17 -17
- package/generation/prettierrc +6 -0
- package/lib/args.js +19 -19
- package/lib/cli/app.d.ts +1 -1
- package/lib/cli/app.js +2 -2
- package/lib/cli/commands/build.d.ts +1 -1
- package/lib/cli/commands/build.js +9 -9
- package/lib/cli/commands/create.d.ts +1 -1
- package/lib/cli/commands/create.js +36 -36
- package/lib/cli/commands/delete.d.ts +1 -1
- package/lib/cli/commands/delete.js +55 -55
- package/lib/cli/commands/export.d.ts +1 -1
- package/lib/cli/commands/export.js +12 -12
- package/lib/cli/commands/help.d.ts +1 -1
- package/lib/cli/commands/help.js +29 -29
- package/lib/cli/commands/init.d.ts +1 -1
- package/lib/cli/commands/init.js +31 -31
- package/lib/cli/commands/server.d.ts +1 -1
- package/lib/cli/commands/server.js +12 -12
- package/lib/cli/commands/upgrade.d.ts +1 -1
- package/lib/cli/commands/upgrade.js +13 -13
- package/lib/cli/commands/version.d.ts +1 -1
- package/lib/cli/commands/version.js +7 -7
- package/lib/cli/index.d.ts +13 -13
- package/lib/cli/parser.d.ts +1 -1
- package/lib/cli/parser.js +12 -12
- package/lib/cli/registry.d.ts +1 -1
- package/lib/cli/types.d.ts +2 -2
- package/lib/cli/utils/console.d.ts +2 -2
- package/lib/cli/utils/console.js +22 -22
- package/lib/cli/utils/index.d.ts +2 -2
- package/lib/cli/utils/prompt.d.ts +1 -1
- package/lib/cli/utils/prompt.js +98 -98
- package/lib/constants.js +28 -28
- package/lib/generate.d.ts +2 -2
- package/lib/generate.js +19 -19
- package/lib/generate_create.d.ts +1 -1
- package/lib/generate_create.js +38 -38
- package/lib/generate_delete.js +63 -63
- package/lib/generate_init.js +94 -94
- package/lib/generators/base-generator.d.ts +1 -1
- package/lib/generators/base-generator.js +23 -23
- package/lib/generators/file-generator.js +15 -15
- package/lib/generators/generator-factory.d.ts +5 -5
- package/lib/generators/i18n-generator.d.ts +1 -1
- package/lib/generators/i18n-generator.js +127 -127
- package/lib/generators/page-generator.d.ts +1 -1
- package/lib/generators/page-generator.js +25 -25
- package/lib/generators/resolver-generator.d.ts +1 -1
- package/lib/generators/resolver-generator.js +27 -27
- package/lib/generators/schema-generator.d.ts +1 -1
- package/lib/generators/schema-generator.js +4 -4
- package/lib/generators/service-generator.d.ts +1 -1
- package/lib/generators/service-generator.js +29 -29
- package/lib/generators/sql-generator.d.ts +1 -1
- package/lib/generators/sql-generator.js +10 -10
- package/lib/index.js +23 -23
- package/lib/server/csrf.d.ts +3 -3
- package/lib/server/csrf.js +20 -20
- package/lib/server/db.d.ts +1 -1
- package/lib/server/db.js +21 -21
- package/lib/server/graphql.js +26 -26
- package/lib/server/plugins/date.d.ts +1 -1
- package/lib/server/plugins/date.js +6 -6
- package/lib/server/utils/graphql-cache.js +5 -5
- package/lib/tsconfig.build.tsbuildinfo +1 -1
- package/lib/utils/project-config.d.ts +1 -1
- package/lib/utils/project-config.js +20 -20
- package/lib/utils.js +3 -3
- package/package.json +1 -1
- package/pages/_app.tsx +62 -62
- package/pages/_document.tsx +15 -15
- package/pages/_error.tsx +26 -26
- package/pages/index.tsx +48 -48
- package/pages/login.tsx +64 -64
- package/pages/template/manage.tsx +175 -175
package/lib/generate_init.js
CHANGED
|
@@ -40,69 +40,69 @@ const utils_1 = require("./utils");
|
|
|
40
40
|
const fs_1 = require("fs");
|
|
41
41
|
// 常量定义
|
|
42
42
|
const CLIENT_FILES = {
|
|
43
|
-
reduxStore:
|
|
44
|
-
styledCommon:
|
|
45
|
-
styledLayoutIndex:
|
|
46
|
-
utilsCommon:
|
|
47
|
-
utilsFetch:
|
|
48
|
-
utilsCookie:
|
|
49
|
-
utilsSso:
|
|
50
|
-
utilsI18n:
|
|
51
|
-
utilsNavigation:
|
|
52
|
-
utilsSuppressWarnings:
|
|
53
|
-
layoutIndex:
|
|
54
|
-
languageSwitcher:
|
|
55
|
-
clientProviders:
|
|
56
|
-
ssrSafeAntdProvider:
|
|
57
|
-
suppressHydrationWarnings:
|
|
43
|
+
reduxStore: "/store.ts",
|
|
44
|
+
styledCommon: "/common.ts",
|
|
45
|
+
styledLayoutIndex: "/index.ts",
|
|
46
|
+
utilsCommon: "/common.ts",
|
|
47
|
+
utilsFetch: "/fetch.ts",
|
|
48
|
+
utilsCookie: "/cookie.ts",
|
|
49
|
+
utilsSso: "/sso.ts",
|
|
50
|
+
utilsI18n: "/i18n.ts",
|
|
51
|
+
utilsNavigation: "/navigation.ts",
|
|
52
|
+
utilsSuppressWarnings: "/suppressWarnings.ts",
|
|
53
|
+
layoutIndex: "/index.tsx",
|
|
54
|
+
languageSwitcher: "/LanguageSwitcher.tsx",
|
|
55
|
+
clientProviders: "/ClientProviders.tsx",
|
|
56
|
+
ssrSafeAntdProvider: "/SSRSafeAntdProvider.tsx",
|
|
57
|
+
suppressHydrationWarnings: "/SuppressHydrationWarnings.tsx",
|
|
58
58
|
};
|
|
59
59
|
const PAGES_FILES = {
|
|
60
|
-
index:
|
|
61
|
-
app:
|
|
62
|
-
document:
|
|
63
|
-
login:
|
|
60
|
+
index: "/index.tsx",
|
|
61
|
+
app: "/_app.tsx",
|
|
62
|
+
document: "/_document.tsx",
|
|
63
|
+
login: "/login.tsx",
|
|
64
64
|
};
|
|
65
65
|
const SERVER_FILES = {
|
|
66
|
-
apisSso:
|
|
67
|
-
utilsCommon:
|
|
68
|
-
utilsDBPoolManager:
|
|
69
|
-
utilsValidation:
|
|
66
|
+
apisSso: "/sso.js",
|
|
67
|
+
utilsCommon: "/common.js",
|
|
68
|
+
utilsDBPoolManager: "/db-pool-manager.js",
|
|
69
|
+
utilsValidation: "/validation.js",
|
|
70
70
|
};
|
|
71
71
|
const PUBLIC_FILES = {
|
|
72
|
-
images:
|
|
73
|
-
fonts:
|
|
74
|
-
favicon:
|
|
75
|
-
locales:
|
|
72
|
+
images: "/images",
|
|
73
|
+
fonts: "/fonts",
|
|
74
|
+
favicon: "/favicon.ico",
|
|
75
|
+
locales: "/locales",
|
|
76
76
|
};
|
|
77
77
|
const SCRIPTS_FILES = {
|
|
78
|
-
startup:
|
|
79
|
-
shutdown:
|
|
80
|
-
password:
|
|
78
|
+
startup: "/startup.sh",
|
|
79
|
+
shutdown: "/shutdown.sh",
|
|
80
|
+
password: "/generate-password-hash.js",
|
|
81
81
|
};
|
|
82
82
|
const ROOT_FILES = {
|
|
83
|
-
nextConfig:
|
|
84
|
-
nextI18nConfig:
|
|
85
|
-
mysqlConfig:
|
|
86
|
-
projectConfig:
|
|
87
|
-
tsconfig:
|
|
88
|
-
gitignoreSource:
|
|
89
|
-
gitignore:
|
|
90
|
-
eslintrc:
|
|
91
|
-
prettierrcSource:
|
|
92
|
-
prettierrc:
|
|
93
|
-
nextEnvSource:
|
|
94
|
-
nextEnv:
|
|
95
|
-
readme:
|
|
96
|
-
appConfigSource:
|
|
97
|
-
appConfig:
|
|
98
|
-
app:
|
|
99
|
-
envExampleSource:
|
|
100
|
-
envExample:
|
|
101
|
-
envSource:
|
|
102
|
-
env:
|
|
103
|
-
jestConfig:
|
|
104
|
-
jestSetup:
|
|
105
|
-
jestSetupGlobals:
|
|
83
|
+
nextConfig: "/next.config.js",
|
|
84
|
+
nextI18nConfig: "/next-i18next.config.js",
|
|
85
|
+
mysqlConfig: "/mysql.config.js",
|
|
86
|
+
projectConfig: "/project.config.js",
|
|
87
|
+
tsconfig: "/tsconfig.json",
|
|
88
|
+
gitignoreSource: "/gitignore",
|
|
89
|
+
gitignore: "/.gitignore",
|
|
90
|
+
eslintrc: "/eslint.config.js",
|
|
91
|
+
prettierrcSource: "/prettierrc",
|
|
92
|
+
prettierrc: "/.prettierrc",
|
|
93
|
+
nextEnvSource: "../next-env.d.ts",
|
|
94
|
+
nextEnv: "/next-env.d.ts",
|
|
95
|
+
readme: "/README.md",
|
|
96
|
+
appConfigSource: "../app.config.js",
|
|
97
|
+
appConfig: "/app.config.js",
|
|
98
|
+
app: "/app.js",
|
|
99
|
+
envExampleSource: "/env.example",
|
|
100
|
+
envExample: "/.env.example",
|
|
101
|
+
envSource: "/env",
|
|
102
|
+
env: "/.env",
|
|
103
|
+
jestConfig: "/jest.config.js",
|
|
104
|
+
jestSetup: "/jest.setup.js",
|
|
105
|
+
jestSetupGlobals: "/jest.setup-globals.js",
|
|
106
106
|
};
|
|
107
107
|
// 辅助函数
|
|
108
108
|
const createDirectoryStructure = (directories) => {
|
|
@@ -120,10 +120,10 @@ const copyMultipleFiles = (fileMappings) => {
|
|
|
120
120
|
* @param upgradeFlag 是否为升级模式
|
|
121
121
|
*/
|
|
122
122
|
const initClientFiles = (dictionary, newDestFolder, upgradeFlag) => {
|
|
123
|
-
console.log(
|
|
123
|
+
console.log("Initializing client files...");
|
|
124
124
|
try {
|
|
125
125
|
// 1. 确定目标路径
|
|
126
|
-
const baseDestPath = dictionary ===
|
|
126
|
+
const baseDestPath = dictionary === "" ? constants_1.destClientPath : path_1.default.join(newDestFolder, constants_1.clientPath);
|
|
127
127
|
const destPaths = {
|
|
128
128
|
client: baseDestPath,
|
|
129
129
|
redux: (0, path_1.resolve)(baseDestPath + constants_1.reduxPath),
|
|
@@ -232,14 +232,14 @@ const initClientFiles = (dictionary, newDestFolder, upgradeFlag) => {
|
|
|
232
232
|
];
|
|
233
233
|
// 4. 复制文件
|
|
234
234
|
copyMultipleFiles(fileMappings);
|
|
235
|
-
console.log(
|
|
235
|
+
console.log("Client files initialization completed");
|
|
236
236
|
return {
|
|
237
237
|
destClientUtilsMenuPath: (0, path_1.resolve)(destPaths.utils + constants_1.utilsMenuPath),
|
|
238
238
|
destClientReduxReducersAllPath: (0, path_1.resolve)(destPaths.redux + constants_1.reduxReducersPath),
|
|
239
239
|
};
|
|
240
240
|
}
|
|
241
241
|
catch (error) {
|
|
242
|
-
console.error(
|
|
242
|
+
console.error("Failed to initialize client files:", error);
|
|
243
243
|
throw error;
|
|
244
244
|
}
|
|
245
245
|
};
|
|
@@ -251,10 +251,10 @@ exports.initClientFiles = initClientFiles;
|
|
|
251
251
|
* @param upgradeFlag 是否为升级模式
|
|
252
252
|
*/
|
|
253
253
|
const initPagesFiles = (dictionary, newDestFolder, upgradeFlag) => {
|
|
254
|
-
console.log(
|
|
254
|
+
console.log("Initializing pages files...");
|
|
255
255
|
try {
|
|
256
256
|
// 1. 确定目标路径
|
|
257
|
-
const baseDestPath = dictionary ===
|
|
257
|
+
const baseDestPath = dictionary === "" ? constants_1.destPagesPath : path_1.default.join(newDestFolder, constants_1.pagesPath);
|
|
258
258
|
// 2. 创建目录
|
|
259
259
|
createDirectoryStructure([baseDestPath]);
|
|
260
260
|
// 3. 定义文件映射
|
|
@@ -282,10 +282,10 @@ const initPagesFiles = (dictionary, newDestFolder, upgradeFlag) => {
|
|
|
282
282
|
];
|
|
283
283
|
// 4. 复制文件
|
|
284
284
|
copyMultipleFiles(fileMappings);
|
|
285
|
-
console.log(
|
|
285
|
+
console.log("Pages files initialization completed");
|
|
286
286
|
}
|
|
287
287
|
catch (error) {
|
|
288
|
-
console.error(
|
|
288
|
+
console.error("Failed to initialize pages files:", error);
|
|
289
289
|
throw error;
|
|
290
290
|
}
|
|
291
291
|
};
|
|
@@ -297,10 +297,10 @@ exports.initPagesFiles = initPagesFiles;
|
|
|
297
297
|
* @param upgradeFlag 是否为升级模式
|
|
298
298
|
*/
|
|
299
299
|
const initServerFiles = (dictionary, newDestFolder, upgradeFlag) => {
|
|
300
|
-
console.log(
|
|
300
|
+
console.log("Initializing server files...");
|
|
301
301
|
try {
|
|
302
302
|
// 1. 确定目标路径
|
|
303
|
-
const baseDestPath = dictionary ===
|
|
303
|
+
const baseDestPath = dictionary === "" ? constants_1.destServerPath : path_1.default.join(newDestFolder, constants_1.serverPath);
|
|
304
304
|
const destPaths = {
|
|
305
305
|
server: baseDestPath,
|
|
306
306
|
apis: (0, path_1.resolve)(baseDestPath + constants_1.apisPath),
|
|
@@ -339,13 +339,13 @@ const initServerFiles = (dictionary, newDestFolder, upgradeFlag) => {
|
|
|
339
339
|
];
|
|
340
340
|
// 4. 复制文件
|
|
341
341
|
copyMultipleFiles(fileMappings);
|
|
342
|
-
console.log(
|
|
342
|
+
console.log("Server files initialization completed");
|
|
343
343
|
return {
|
|
344
344
|
destServerRestPath: (0, path_1.resolve)(destPaths.server + constants_1.restPath),
|
|
345
345
|
};
|
|
346
346
|
}
|
|
347
347
|
catch (error) {
|
|
348
|
-
console.error(
|
|
348
|
+
console.error("Failed to initialize server files:", error);
|
|
349
349
|
throw error;
|
|
350
350
|
}
|
|
351
351
|
};
|
|
@@ -357,10 +357,10 @@ exports.initServerFiles = initServerFiles;
|
|
|
357
357
|
* @param upgradeFlag 是否为升级模式
|
|
358
358
|
*/
|
|
359
359
|
const initPublicFiles = (dictionary, newDestFolder, upgradeFlag) => {
|
|
360
|
-
console.log(
|
|
360
|
+
console.log("Initializing public files...");
|
|
361
361
|
try {
|
|
362
362
|
// 1. 确定目标路径
|
|
363
|
-
const baseDestPath = dictionary ===
|
|
363
|
+
const baseDestPath = dictionary === "" ? constants_1.destPublicPath : path_1.default.join(newDestFolder, constants_1.publicPath);
|
|
364
364
|
const destPaths = {
|
|
365
365
|
public: baseDestPath,
|
|
366
366
|
images: (0, path_1.resolve)(baseDestPath + PUBLIC_FILES.images),
|
|
@@ -414,13 +414,13 @@ const initPublicFiles = (dictionary, newDestFolder, upgradeFlag) => {
|
|
|
414
414
|
};
|
|
415
415
|
copyLocalesRecursive(sourceLocalesDir, destPaths.locales);
|
|
416
416
|
}
|
|
417
|
-
console.log(
|
|
417
|
+
console.log("Public files initialization completed");
|
|
418
418
|
return {
|
|
419
419
|
destPublicHealthCheckPath: (0, path_1.resolve)(destPaths.public + constants_1.slbHealthCheckPath),
|
|
420
420
|
};
|
|
421
421
|
}
|
|
422
422
|
catch (error) {
|
|
423
|
-
console.error(
|
|
423
|
+
console.error("Failed to initialize public files:", error);
|
|
424
424
|
throw error;
|
|
425
425
|
}
|
|
426
426
|
};
|
|
@@ -431,10 +431,10 @@ exports.initPublicFiles = initPublicFiles;
|
|
|
431
431
|
* @param newDestFolder 新的目标文件夹路径
|
|
432
432
|
*/
|
|
433
433
|
const initScriptsFiles = (dictionary, newDestFolder) => {
|
|
434
|
-
console.log(
|
|
434
|
+
console.log("Initializing scripts files...");
|
|
435
435
|
try {
|
|
436
436
|
// 1. 确定目标路径
|
|
437
|
-
const baseDestPath = dictionary ===
|
|
437
|
+
const baseDestPath = dictionary === "" ? constants_1.destScriptsPath : path_1.default.join(newDestFolder, constants_1.scriptsPath);
|
|
438
438
|
// 2. 创建目录
|
|
439
439
|
createDirectoryStructure([baseDestPath]);
|
|
440
440
|
// 3. 定义文件映射(脚本文件通常不使用 upgradeFlag)
|
|
@@ -454,10 +454,10 @@ const initScriptsFiles = (dictionary, newDestFolder) => {
|
|
|
454
454
|
];
|
|
455
455
|
// 4. 复制文件
|
|
456
456
|
copyMultipleFiles(fileMappings);
|
|
457
|
-
console.log(
|
|
457
|
+
console.log("Scripts files initialization completed");
|
|
458
458
|
}
|
|
459
459
|
catch (error) {
|
|
460
|
-
console.error(
|
|
460
|
+
console.error("Failed to initialize scripts files:", error);
|
|
461
461
|
throw error;
|
|
462
462
|
}
|
|
463
463
|
};
|
|
@@ -468,10 +468,10 @@ exports.initScriptsFiles = initScriptsFiles;
|
|
|
468
468
|
* @param newDestFolder 新的目标文件夹路径
|
|
469
469
|
*/
|
|
470
470
|
const initRootFiles = (dictionary, newDestFolder) => {
|
|
471
|
-
console.log(
|
|
471
|
+
console.log("Initializing root files...");
|
|
472
472
|
try {
|
|
473
473
|
// 1. 确定目标路径
|
|
474
|
-
const baseDestPath = dictionary ===
|
|
474
|
+
const baseDestPath = dictionary === "" ? constants_1.destFolder : newDestFolder;
|
|
475
475
|
// 2. 定义文件映射(根文件通常不使用 upgradeFlag)
|
|
476
476
|
const fileMappings = [
|
|
477
477
|
{
|
|
@@ -479,7 +479,7 @@ const initRootFiles = (dictionary, newDestFolder) => {
|
|
|
479
479
|
dest: (0, path_1.resolve)(baseDestPath + ROOT_FILES.nextConfig),
|
|
480
480
|
},
|
|
481
481
|
{
|
|
482
|
-
source: (0, path_1.resolve)(path_1.default.join(constants_1.sourceFolder,
|
|
482
|
+
source: (0, path_1.resolve)(path_1.default.join(constants_1.sourceFolder, "..", ROOT_FILES.nextI18nConfig)),
|
|
483
483
|
dest: (0, path_1.resolve)(baseDestPath + ROOT_FILES.nextI18nConfig),
|
|
484
484
|
},
|
|
485
485
|
{
|
|
@@ -507,7 +507,7 @@ const initRootFiles = (dictionary, newDestFolder) => {
|
|
|
507
507
|
dest: (0, path_1.resolve)(baseDestPath + ROOT_FILES.eslintrc),
|
|
508
508
|
},
|
|
509
509
|
{
|
|
510
|
-
source: path_1.
|
|
510
|
+
source: (0, path_1.resolve)(constants_1.sourceGenerationPath + ROOT_FILES.prettierrcSource),
|
|
511
511
|
dest: (0, path_1.resolve)(baseDestPath + ROOT_FILES.prettierrc),
|
|
512
512
|
},
|
|
513
513
|
{
|
|
@@ -539,23 +539,23 @@ const initRootFiles = (dictionary, newDestFolder) => {
|
|
|
539
539
|
dest: (0, path_1.resolve)(baseDestPath + ROOT_FILES.jestConfig),
|
|
540
540
|
},
|
|
541
541
|
{
|
|
542
|
-
source: (0, path_1.resolve)(path_1.default.join(constants_1.sourceFolder,
|
|
542
|
+
source: (0, path_1.resolve)(path_1.default.join(constants_1.sourceFolder, "..", ROOT_FILES.jestSetup)),
|
|
543
543
|
dest: (0, path_1.resolve)(baseDestPath + ROOT_FILES.jestSetup),
|
|
544
544
|
},
|
|
545
545
|
{
|
|
546
|
-
source: (0, path_1.resolve)(path_1.default.join(constants_1.sourceFolder,
|
|
546
|
+
source: (0, path_1.resolve)(path_1.default.join(constants_1.sourceFolder, "..", ROOT_FILES.jestSetupGlobals)),
|
|
547
547
|
dest: (0, path_1.resolve)(baseDestPath + ROOT_FILES.jestSetupGlobals),
|
|
548
548
|
},
|
|
549
549
|
];
|
|
550
550
|
// 3. 复制文件
|
|
551
551
|
copyMultipleFiles(fileMappings);
|
|
552
|
-
console.log(
|
|
552
|
+
console.log("Root files initialization completed");
|
|
553
553
|
return {
|
|
554
554
|
destPackagePath: (0, path_1.resolve)(baseDestPath + constants_1.packagePath),
|
|
555
555
|
};
|
|
556
556
|
}
|
|
557
557
|
catch (error) {
|
|
558
|
-
console.error(
|
|
558
|
+
console.error("Failed to initialize root files:", error);
|
|
559
559
|
throw error;
|
|
560
560
|
}
|
|
561
561
|
};
|
|
@@ -566,22 +566,22 @@ exports.initRootFiles = initRootFiles;
|
|
|
566
566
|
* @param newDestFolder 新的目标文件夹路径
|
|
567
567
|
*/
|
|
568
568
|
const initTypesFiles = (dictionary, newDestFolder) => {
|
|
569
|
-
console.log(
|
|
569
|
+
console.log("Initializing types files...");
|
|
570
570
|
try {
|
|
571
571
|
// 1. 确定目标路径
|
|
572
|
-
const baseDestPath = dictionary ===
|
|
572
|
+
const baseDestPath = dictionary === "" ? constants_1.destTypesPath : path_1.default.join(newDestFolder, constants_1.typesPath);
|
|
573
573
|
// 2. 创建目录
|
|
574
574
|
createDirectoryStructure([baseDestPath]);
|
|
575
575
|
// 3. 复制 i18next.d.ts 文件
|
|
576
|
-
const sourceI18nextFile = (0, path_1.resolve)(constants_1.destFolder,
|
|
577
|
-
const destI18nextFile = (0, path_1.resolve)(baseDestPath,
|
|
576
|
+
const sourceI18nextFile = (0, path_1.resolve)(constants_1.destFolder, "types", "i18next.d.ts");
|
|
577
|
+
const destI18nextFile = (0, path_1.resolve)(baseDestPath, "i18next.d.ts");
|
|
578
578
|
if ((0, fs_1.existsSync)(sourceI18nextFile)) {
|
|
579
579
|
(0, utils_1.copyFileSync)(sourceI18nextFile, destI18nextFile);
|
|
580
580
|
}
|
|
581
|
-
console.log(
|
|
581
|
+
console.log("Types files initialization completed");
|
|
582
582
|
}
|
|
583
583
|
catch (error) {
|
|
584
|
-
console.error(
|
|
584
|
+
console.error("Failed to initialize types files:", error);
|
|
585
585
|
throw error;
|
|
586
586
|
}
|
|
587
587
|
};
|
|
@@ -592,26 +592,26 @@ exports.initTypesFiles = initTypesFiles;
|
|
|
592
592
|
* @param newDestFolder 新的目标文件夹路径
|
|
593
593
|
*/
|
|
594
594
|
const initTestFiles = (dictionary, newDestFolder) => {
|
|
595
|
-
console.log(
|
|
595
|
+
console.log("Initializing test files...");
|
|
596
596
|
try {
|
|
597
597
|
// 1. 确定目标路径
|
|
598
|
-
const baseDestPath = dictionary ===
|
|
599
|
-
const testDestPath = path_1.default.join(baseDestPath,
|
|
598
|
+
const baseDestPath = dictionary === "" ? constants_1.destFolder : newDestFolder;
|
|
599
|
+
const testDestPath = path_1.default.join(baseDestPath, "__tests__");
|
|
600
600
|
// 2. 创建测试目录
|
|
601
601
|
createDirectoryStructure([testDestPath]);
|
|
602
602
|
// 3. 定义文件映射
|
|
603
603
|
const fileMappings = [
|
|
604
604
|
{
|
|
605
|
-
source: path_1.default.join(constants_1.sourceGenerationPath,
|
|
606
|
-
dest: path_1.default.join(testDestPath,
|
|
605
|
+
source: path_1.default.join(constants_1.sourceGenerationPath, "__tests__", "example.test.js"),
|
|
606
|
+
dest: path_1.default.join(testDestPath, "example.test.js"),
|
|
607
607
|
},
|
|
608
608
|
];
|
|
609
609
|
// 4. 复制文件
|
|
610
610
|
copyMultipleFiles(fileMappings);
|
|
611
|
-
console.log(
|
|
611
|
+
console.log("Test files initialization completed");
|
|
612
612
|
}
|
|
613
613
|
catch (error) {
|
|
614
|
-
console.error(
|
|
614
|
+
console.error("Failed to initialize test files:", error);
|
|
615
615
|
throw error;
|
|
616
616
|
}
|
|
617
617
|
};
|
|
@@ -52,14 +52,14 @@ class BaseGenerator {
|
|
|
52
52
|
*/
|
|
53
53
|
getGraphQLType(fieldType) {
|
|
54
54
|
switch (fieldType) {
|
|
55
|
-
case
|
|
56
|
-
return
|
|
57
|
-
case
|
|
58
|
-
return
|
|
59
|
-
case
|
|
60
|
-
return
|
|
55
|
+
case "integer":
|
|
56
|
+
return "Int";
|
|
57
|
+
case "decimal":
|
|
58
|
+
return "Float";
|
|
59
|
+
case "boolean":
|
|
60
|
+
return "Boolean";
|
|
61
61
|
default:
|
|
62
|
-
return
|
|
62
|
+
return "String";
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
@@ -67,25 +67,25 @@ class BaseGenerator {
|
|
|
67
67
|
*/
|
|
68
68
|
getSQLType(field) {
|
|
69
69
|
switch (field.type) {
|
|
70
|
-
case
|
|
70
|
+
case "varchar":
|
|
71
71
|
return `varchar(${field.length || 255})`;
|
|
72
|
-
case
|
|
73
|
-
return
|
|
74
|
-
case
|
|
75
|
-
return
|
|
76
|
-
case
|
|
77
|
-
const [precision, scale] = (field.length ||
|
|
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
78
|
return `decimal(${precision || 10},${scale || 2})`;
|
|
79
|
-
case
|
|
80
|
-
return
|
|
81
|
-
case
|
|
82
|
-
return
|
|
83
|
-
case
|
|
84
|
-
return
|
|
85
|
-
case
|
|
86
|
-
return
|
|
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
87
|
default:
|
|
88
|
-
return
|
|
88
|
+
return "varchar(255)";
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
}
|
|
@@ -42,7 +42,7 @@ const path = __importStar(require("path"));
|
|
|
42
42
|
* 负责将生成的内容写入到文件系统
|
|
43
43
|
*/
|
|
44
44
|
class FileGenerator {
|
|
45
|
-
constructor(projectPath =
|
|
45
|
+
constructor(projectPath = ".") {
|
|
46
46
|
this.projectPath = projectPath;
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
@@ -52,20 +52,20 @@ class FileGenerator {
|
|
|
52
52
|
const i18nGenerator = new i18n_generator_1.I18nGenerator(controller, action, fields);
|
|
53
53
|
// 定义支持的语言
|
|
54
54
|
const locales = [
|
|
55
|
-
{ code:
|
|
56
|
-
{ code:
|
|
57
|
-
{ code:
|
|
55
|
+
{ code: "zh-CN", generator: () => i18nGenerator.generateChineseTranslation() },
|
|
56
|
+
{ code: "en-US", generator: () => i18nGenerator.generateEnglishTranslation() },
|
|
57
|
+
{ code: "ja-JP", generator: () => i18nGenerator.generateJapaneseTranslation() },
|
|
58
58
|
];
|
|
59
59
|
// 为每种语言生成文件
|
|
60
60
|
locales.forEach((locale) => {
|
|
61
|
-
const localeDir = path.join(this.projectPath,
|
|
61
|
+
const localeDir = path.join(this.projectPath, "public", "locales", locale.code);
|
|
62
62
|
const filePath = path.join(localeDir, `${controller}.json`);
|
|
63
63
|
// 确保目录存在
|
|
64
64
|
this.ensureDirectoryExists(localeDir);
|
|
65
65
|
// 生成内容
|
|
66
66
|
const content = locale.generator();
|
|
67
67
|
// 写入文件
|
|
68
|
-
fs.writeFileSync(filePath, content,
|
|
68
|
+
fs.writeFileSync(filePath, content, "utf8");
|
|
69
69
|
console.log(`✅ 生成多语言文件: ${filePath}`);
|
|
70
70
|
});
|
|
71
71
|
}
|
|
@@ -73,53 +73,53 @@ class FileGenerator {
|
|
|
73
73
|
* 生成页面组件文件
|
|
74
74
|
*/
|
|
75
75
|
generatePageFile(controller, action, _fields, content) {
|
|
76
|
-
const pageDir = path.join(this.projectPath,
|
|
76
|
+
const pageDir = path.join(this.projectPath, "pages", controller);
|
|
77
77
|
const filePath = path.join(pageDir, `${action}.tsx`);
|
|
78
78
|
// 确保目录存在
|
|
79
79
|
this.ensureDirectoryExists(pageDir);
|
|
80
80
|
// 写入文件
|
|
81
|
-
fs.writeFileSync(filePath, content,
|
|
81
|
+
fs.writeFileSync(filePath, content, "utf8");
|
|
82
82
|
console.log(`✅ 生成页面文件: ${filePath}`);
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
85
85
|
* 生成样式文件
|
|
86
86
|
*/
|
|
87
87
|
generateStyleFile(controller, action) {
|
|
88
|
-
const styleDir = path.join(this.projectPath,
|
|
88
|
+
const styleDir = path.join(this.projectPath, "client", "styled", controller);
|
|
89
89
|
const filePath = path.join(styleDir, `${action}.ts`);
|
|
90
90
|
// 确保目录存在
|
|
91
91
|
this.ensureDirectoryExists(styleDir);
|
|
92
92
|
const content = this.generateStyledComponentsContent(controller, action);
|
|
93
93
|
// 写入文件
|
|
94
|
-
fs.writeFileSync(filePath, content,
|
|
94
|
+
fs.writeFileSync(filePath, content, "utf8");
|
|
95
95
|
console.log(`✅ 生成样式文件: ${filePath}`);
|
|
96
96
|
}
|
|
97
97
|
/**
|
|
98
98
|
* 生成Redux相关文件
|
|
99
99
|
*/
|
|
100
100
|
generateReduxFiles(controller, action, _fields) {
|
|
101
|
-
const reduxDir = path.join(this.projectPath,
|
|
101
|
+
const reduxDir = path.join(this.projectPath, "client", "redux", controller, action);
|
|
102
102
|
// 确保目录存在
|
|
103
103
|
this.ensureDirectoryExists(reduxDir);
|
|
104
104
|
// 生成actions文件
|
|
105
105
|
const actionsContent = this.generateActionsContent(controller, action);
|
|
106
|
-
fs.writeFileSync(path.join(reduxDir,
|
|
106
|
+
fs.writeFileSync(path.join(reduxDir, "actions.ts"), actionsContent, "utf8");
|
|
107
107
|
// 生成reducer文件
|
|
108
108
|
const reducerContent = this.generateReducerContent(controller, action);
|
|
109
|
-
fs.writeFileSync(path.join(reduxDir,
|
|
109
|
+
fs.writeFileSync(path.join(reduxDir, "reducer.ts"), reducerContent, "utf8");
|
|
110
110
|
console.log(`✅ 生成Redux文件: ${reduxDir}`);
|
|
111
111
|
}
|
|
112
112
|
/**
|
|
113
113
|
* 生成服务文件
|
|
114
114
|
*/
|
|
115
115
|
generateServiceFile(controller, action) {
|
|
116
|
-
const serviceDir = path.join(this.projectPath,
|
|
116
|
+
const serviceDir = path.join(this.projectPath, "client", "service", controller);
|
|
117
117
|
const filePath = path.join(serviceDir, `${action}.ts`);
|
|
118
118
|
// 确保目录存在
|
|
119
119
|
this.ensureDirectoryExists(serviceDir);
|
|
120
120
|
const content = this.generateServiceContent(controller, action);
|
|
121
121
|
// 写入文件
|
|
122
|
-
fs.writeFileSync(filePath, content,
|
|
122
|
+
fs.writeFileSync(filePath, content, "utf8");
|
|
123
123
|
console.log(`✅ 生成服务文件: ${filePath}`);
|
|
124
124
|
}
|
|
125
125
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { SQLGenerator } from
|
|
2
|
-
import { SchemaGenerator } from
|
|
3
|
-
import { ResolverGenerator } from
|
|
4
|
-
import { ServiceGenerator } from
|
|
5
|
-
import { FieldDefinition } from
|
|
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
6
|
/**
|
|
7
7
|
* 代码生成器工厂
|
|
8
8
|
* 统一管理所有代码生成器
|