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_create.js
CHANGED
|
@@ -50,24 +50,24 @@ const page_generator_1 = require("./generators/page-generator");
|
|
|
50
50
|
const file_generator_1 = require("./generators/file-generator");
|
|
51
51
|
// 常量定义
|
|
52
52
|
const TEMPLATE_FILES = {
|
|
53
|
-
reduxActions:
|
|
54
|
-
reduxReducers:
|
|
55
|
-
reduxTypes:
|
|
56
|
-
styled:
|
|
57
|
-
serverApi:
|
|
53
|
+
reduxActions: "redux/template/manage/actions.ts",
|
|
54
|
+
reduxReducers: "redux/template/manage/reducers.ts",
|
|
55
|
+
reduxTypes: "redux/template/manage/types.ts",
|
|
56
|
+
styled: "styled/template/manage.ts",
|
|
57
|
+
serverApi: "apis/template.js",
|
|
58
58
|
};
|
|
59
59
|
const MYSQL_TIMEOUT = 1000;
|
|
60
60
|
// 辅助函数
|
|
61
61
|
const createDirectoryStructure = (basePaths) => {
|
|
62
62
|
basePaths.forEach((path) => (0, utils_1.mkdirSync)(path));
|
|
63
63
|
};
|
|
64
|
-
const generateFilePaths = (controller, action, dictionary =
|
|
64
|
+
const generateFilePaths = (controller, action, dictionary = ".") => {
|
|
65
65
|
// 根据 dictionary 确定目标路径
|
|
66
66
|
const getDestPath = (basePath) => {
|
|
67
|
-
if (!dictionary || dictionary ===
|
|
67
|
+
if (!dictionary || dictionary === ".") {
|
|
68
68
|
return basePath;
|
|
69
69
|
}
|
|
70
|
-
return path_1.default.join(constants_1.destFolder, dictionary, basePath.replace(`${constants_1.destFolder}/`,
|
|
70
|
+
return path_1.default.join(constants_1.destFolder, dictionary, basePath.replace(`${constants_1.destFolder}/`, ""));
|
|
71
71
|
};
|
|
72
72
|
const paths = {
|
|
73
73
|
// Pages - 动态生成,不需要源文件
|
|
@@ -99,11 +99,11 @@ const generateFilePaths = (controller, action, dictionary = '.') => {
|
|
|
99
99
|
// Server SQL - 动态生成
|
|
100
100
|
destServerSqlController: (0, path_1.resolve)(`${getDestPath(constants_1.destServerSqlPath)}/${controller}.sql`),
|
|
101
101
|
// Configuration files
|
|
102
|
-
destClientReduxReducersAllPath: !dictionary || dictionary ===
|
|
102
|
+
destClientReduxReducersAllPath: !dictionary || dictionary === "."
|
|
103
103
|
? constants_1.destClientReduxReducersAllPath
|
|
104
104
|
: (0, path_1.resolve)(`${getDestPath(constants_1.destClientReduxPath)}/reducers.ts`),
|
|
105
|
-
destServerRestPath: !dictionary || dictionary ===
|
|
106
|
-
destClientUtilsMenuPath: !dictionary || dictionary ===
|
|
105
|
+
destServerRestPath: !dictionary || dictionary === "." ? constants_1.destServerRestPath : (0, path_1.resolve)(`${getDestPath(constants_1.destServerPath)}/rest.js`),
|
|
106
|
+
destClientUtilsMenuPath: !dictionary || dictionary === "."
|
|
107
107
|
? constants_1.destClientUtilsMenuPath
|
|
108
108
|
: (0, path_1.resolve)(`${getDestPath(constants_1.destClientPath)}/utils/menu.tsx`),
|
|
109
109
|
};
|
|
@@ -112,7 +112,7 @@ const generateFilePaths = (controller, action, dictionary = '.') => {
|
|
|
112
112
|
const performBasicReplacements = (controller, action, paths) => {
|
|
113
113
|
const replacements = [
|
|
114
114
|
{
|
|
115
|
-
regex:
|
|
115
|
+
regex: "template",
|
|
116
116
|
replacement: controller,
|
|
117
117
|
paths: [
|
|
118
118
|
paths.destPagesAction,
|
|
@@ -125,7 +125,7 @@ const performBasicReplacements = (controller, action, paths) => {
|
|
|
125
125
|
],
|
|
126
126
|
},
|
|
127
127
|
{
|
|
128
|
-
regex:
|
|
128
|
+
regex: "Template",
|
|
129
129
|
replacement: (0, utils_1.firstUpperCase)(controller),
|
|
130
130
|
paths: [
|
|
131
131
|
paths.destPagesAction,
|
|
@@ -136,17 +136,17 @@ const performBasicReplacements = (controller, action, paths) => {
|
|
|
136
136
|
],
|
|
137
137
|
},
|
|
138
138
|
{
|
|
139
|
-
regex:
|
|
139
|
+
regex: "TEMPLATE",
|
|
140
140
|
replacement: controller.toUpperCase(),
|
|
141
141
|
paths: [paths.destClientReduxActions, paths.destClientReduxReducers, paths.destClientReduxTypes],
|
|
142
142
|
},
|
|
143
143
|
{
|
|
144
|
-
regex:
|
|
144
|
+
regex: "manage",
|
|
145
145
|
replacement: action,
|
|
146
146
|
paths: [paths.destPagesAction, paths.destClientReduxActions],
|
|
147
147
|
},
|
|
148
148
|
{
|
|
149
|
-
regex:
|
|
149
|
+
regex: "Manage",
|
|
150
150
|
replacement: (0, utils_1.firstUpperCase)(action),
|
|
151
151
|
paths: [paths.destPagesAction, paths.destClientReduxReducers],
|
|
152
152
|
},
|
|
@@ -192,11 +192,11 @@ const performAdvancedReplacements = (controller, action, paths) => {
|
|
|
192
192
|
});
|
|
193
193
|
}
|
|
194
194
|
// 清理之前的配置
|
|
195
|
-
shelljs_1.default.sed(
|
|
196
|
-
shelljs_1.default.sed(
|
|
195
|
+
shelljs_1.default.sed("-i", /.*${controller}${firstUpperCase(action)}Reducer.*/, "", paths.destClientReduxReducersAllPath);
|
|
196
|
+
shelljs_1.default.sed("-i", /.*${controller}.*/, "", paths.destServerRestPath);
|
|
197
197
|
setTimeout(() => {
|
|
198
198
|
(0, utils_1.replaceInFileAll)(optionsArr, 0, () => {
|
|
199
|
-
console.log(
|
|
199
|
+
console.log("special replace dest files finished");
|
|
200
200
|
});
|
|
201
201
|
}, MYSQL_TIMEOUT);
|
|
202
202
|
};
|
|
@@ -208,7 +208,7 @@ const generateDynamicFiles = (controller, action, paths, fields, dictionary) =>
|
|
|
208
208
|
const serviceGenerator = new service_generator_1.ServiceGenerator(controller, action, fields);
|
|
209
209
|
const pageGenerator = new page_generator_1.PageGenerator(controller, action, fields);
|
|
210
210
|
// 根据 dictionary 确定文件生成器的项目路径
|
|
211
|
-
const projectPath = !dictionary || dictionary ===
|
|
211
|
+
const projectPath = !dictionary || dictionary === "." ? "." : path_1.default.join(constants_1.destFolder, dictionary);
|
|
212
212
|
const fileGenerator = new file_generator_1.FileGenerator(projectPath);
|
|
213
213
|
// 生成并写入文件
|
|
214
214
|
fs_1.default.writeFileSync(paths.destServerSqlController, sqlGenerator.generate());
|
|
@@ -243,10 +243,10 @@ const setupDynamicDatabase = (_controller, paths, _fields) => {
|
|
|
243
243
|
const mysqlCommand = `mysql -u${constants_1.mysqlUser} -p${constants_1.mysqlPassword} -h${constants_1.mysqlHost} -P${constants_1.mysqlPort} < ${paths.destServerSqlController}`;
|
|
244
244
|
try {
|
|
245
245
|
shelljs_1.default.exec(mysqlCommand);
|
|
246
|
-
console.log(
|
|
246
|
+
console.log("Dynamic database setup completed");
|
|
247
247
|
}
|
|
248
248
|
catch (error) {
|
|
249
|
-
console.error(
|
|
249
|
+
console.error("Failed to execute dynamic SQL script:", error);
|
|
250
250
|
}
|
|
251
251
|
};
|
|
252
252
|
/**
|
|
@@ -257,33 +257,33 @@ const setupDynamicDatabase = (_controller, paths, _fields) => {
|
|
|
257
257
|
* @param fields 字段定义数组(可选)
|
|
258
258
|
*/
|
|
259
259
|
const createFiles = (controller, action, dictionary, fields) => {
|
|
260
|
-
console.log(
|
|
260
|
+
console.log("createFiles", constants_1.sourceFolder, constants_1.destFolder, constants_1.isLocal, controller, action, dictionary);
|
|
261
261
|
try {
|
|
262
262
|
// 如果没有提供字段定义,使用默认字段
|
|
263
263
|
const defaultFields = [
|
|
264
|
-
{ name:
|
|
264
|
+
{ name: "id", type: "integer", required: true, comment: "主键", isPrimaryKey: true, isAutoIncrement: true },
|
|
265
265
|
{
|
|
266
|
-
name:
|
|
267
|
-
type:
|
|
266
|
+
name: "name",
|
|
267
|
+
type: "varchar",
|
|
268
268
|
length: 100,
|
|
269
269
|
required: true,
|
|
270
|
-
comment:
|
|
270
|
+
comment: "名称",
|
|
271
271
|
showInList: true,
|
|
272
272
|
showInForm: true,
|
|
273
273
|
searchable: true,
|
|
274
274
|
},
|
|
275
|
-
{ name:
|
|
276
|
-
{ name:
|
|
275
|
+
{ name: "create_date", type: "timestamp", required: true, comment: "创建时间", isSystemField: true },
|
|
276
|
+
{ name: "update_date", type: "timestamp", required: true, comment: "更新时间", isSystemField: true },
|
|
277
277
|
];
|
|
278
278
|
const finalFields = fields && fields.length > 0 ? fields : defaultFields;
|
|
279
279
|
// 1. 生成文件路径
|
|
280
280
|
const paths = generateFilePaths(controller, action, dictionary);
|
|
281
281
|
// 2. 根据 dictionary 确定基础路径
|
|
282
282
|
const getDestPath = (basePath) => {
|
|
283
|
-
if (!dictionary || dictionary ===
|
|
283
|
+
if (!dictionary || dictionary === ".") {
|
|
284
284
|
return basePath;
|
|
285
285
|
}
|
|
286
|
-
return path_1.default.join(constants_1.destFolder, dictionary, basePath.replace(`${constants_1.destFolder}/`,
|
|
286
|
+
return path_1.default.join(constants_1.destFolder, dictionary, basePath.replace(`${constants_1.destFolder}/`, ""));
|
|
287
287
|
};
|
|
288
288
|
// 3. 创建目录结构(包括基础目录和特定目录)
|
|
289
289
|
const basePaths = [
|
|
@@ -304,25 +304,25 @@ const createFiles = (controller, action, dictionary, fields) => {
|
|
|
304
304
|
paths.destServerModulesController,
|
|
305
305
|
];
|
|
306
306
|
createDirectoryStructure(basePaths);
|
|
307
|
-
console.log(
|
|
307
|
+
console.log("Directory structure created");
|
|
308
308
|
// 4. 生成动态文件内容
|
|
309
309
|
generateDynamicFiles(controller, action, paths, finalFields, dictionary);
|
|
310
|
-
console.log(
|
|
310
|
+
console.log("Dynamic files generated");
|
|
311
311
|
// 5. 复制并自定义模板文件
|
|
312
312
|
copyAndCustomizeTemplateFiles(paths, finalFields);
|
|
313
|
-
console.log(
|
|
313
|
+
console.log("Template files processed");
|
|
314
314
|
// 6. 执行基本替换
|
|
315
315
|
performBasicReplacements(controller, action, paths);
|
|
316
|
-
console.log(
|
|
316
|
+
console.log("Basic replacements completed");
|
|
317
317
|
// 7. 执行高级替换
|
|
318
318
|
performAdvancedReplacements(controller, action, paths);
|
|
319
|
-
console.log(
|
|
319
|
+
console.log("Advanced replacements initiated");
|
|
320
320
|
// 8. 设置数据库
|
|
321
321
|
setupDynamicDatabase(controller, paths, finalFields);
|
|
322
|
-
console.log(
|
|
322
|
+
console.log("createFiles completed successfully");
|
|
323
323
|
}
|
|
324
324
|
catch (error) {
|
|
325
|
-
console.error(
|
|
325
|
+
console.error("Failed to create files:", error);
|
|
326
326
|
throw error;
|
|
327
327
|
}
|
|
328
328
|
};
|
package/lib/generate_delete.js
CHANGED
|
@@ -14,26 +14,26 @@ const CLEANUP_TIMEOUT = 1000;
|
|
|
14
14
|
const generateDeletePaths = (controller, action, dictionary) => {
|
|
15
15
|
const basePath = dictionary || process.cwd();
|
|
16
16
|
return {
|
|
17
|
-
destPagesController: path_1.default.join(basePath,
|
|
18
|
-
destClientReduxController: path_1.default.join(basePath,
|
|
19
|
-
destClientServiceController: path_1.default.join(basePath,
|
|
20
|
-
destClientStyledController: path_1.default.join(basePath,
|
|
21
|
-
destServerModulesController: path_1.default.join(basePath,
|
|
22
|
-
destServerApisController: path_1.default.join(basePath,
|
|
23
|
-
destServerSqlController: path_1.default.join(basePath,
|
|
17
|
+
destPagesController: path_1.default.join(basePath, "pages", controller),
|
|
18
|
+
destClientReduxController: path_1.default.join(basePath, "client", "redux", controller),
|
|
19
|
+
destClientServiceController: path_1.default.join(basePath, "client", "service", controller),
|
|
20
|
+
destClientStyledController: path_1.default.join(basePath, "client", "styled", controller),
|
|
21
|
+
destServerModulesController: path_1.default.join(basePath, "server", "modules", controller),
|
|
22
|
+
destServerApisController: path_1.default.join(basePath, "server", "apis", `${controller}.js`),
|
|
23
|
+
destServerSqlController: path_1.default.join(basePath, "server", "sql", `${controller}.sql`),
|
|
24
24
|
// 配置文件路径
|
|
25
|
-
destClientReduxReducersAllPath: path_1.default.join(basePath,
|
|
26
|
-
destClientUtilsMenuPath: path_1.default.join(basePath,
|
|
27
|
-
destServerRestPath: path_1.default.join(basePath,
|
|
25
|
+
destClientReduxReducersAllPath: path_1.default.join(basePath, "client", "redux", "reducers.ts"),
|
|
26
|
+
destClientUtilsMenuPath: path_1.default.join(basePath, "client", "utils", "menu.tsx"),
|
|
27
|
+
destServerRestPath: path_1.default.join(basePath, "server", "rest.js"),
|
|
28
28
|
// 多语言文件路径
|
|
29
|
-
destI18nZhCN: path_1.default.join(basePath,
|
|
30
|
-
destI18nEnUS: path_1.default.join(basePath,
|
|
31
|
-
destI18nJaJP: path_1.default.join(basePath,
|
|
29
|
+
destI18nZhCN: path_1.default.join(basePath, "public", "locales", "zh-CN", `${controller}.json`),
|
|
30
|
+
destI18nEnUS: path_1.default.join(basePath, "public", "locales", "en-US", `${controller}.json`),
|
|
31
|
+
destI18nJaJP: path_1.default.join(basePath, "public", "locales", "ja-JP", `${controller}.json`),
|
|
32
32
|
...(action && {
|
|
33
|
-
destPagesAction: path_1.default.join(basePath,
|
|
34
|
-
destClientReduxControllerAction: path_1.default.join(basePath,
|
|
35
|
-
destClientAction: path_1.default.join(basePath,
|
|
36
|
-
destClientStyledAction: path_1.default.join(basePath,
|
|
33
|
+
destPagesAction: path_1.default.join(basePath, "pages", controller, `${action}.tsx`),
|
|
34
|
+
destClientReduxControllerAction: path_1.default.join(basePath, "client", "redux", controller, action),
|
|
35
|
+
destClientAction: path_1.default.join(basePath, "client", "components", controller, action),
|
|
36
|
+
destClientStyledAction: path_1.default.join(basePath, "client", "styled", controller, `${action}.js`),
|
|
37
37
|
}),
|
|
38
38
|
};
|
|
39
39
|
};
|
|
@@ -64,7 +64,7 @@ const deleteSpecificActionFiles = (paths) => {
|
|
|
64
64
|
}
|
|
65
65
|
};
|
|
66
66
|
const deleteI18nFiles = (paths) => {
|
|
67
|
-
console.log(
|
|
67
|
+
console.log("Deleting i18n files...");
|
|
68
68
|
const i18nFilesToDelete = [paths.destI18nZhCN, paths.destI18nEnUS, paths.destI18nJaJP];
|
|
69
69
|
i18nFilesToDelete.forEach((filePath) => {
|
|
70
70
|
(0, utils_1.rmFileSync)(filePath);
|
|
@@ -72,41 +72,41 @@ const deleteI18nFiles = (paths) => {
|
|
|
72
72
|
});
|
|
73
73
|
};
|
|
74
74
|
const cleanupConfigurationFiles = (controller, action, paths) => {
|
|
75
|
-
if (action ===
|
|
75
|
+
if (action === "all") {
|
|
76
76
|
// 清理所有控制器相关的配置
|
|
77
77
|
// 1. 删除 import 语句
|
|
78
|
-
shelljs_1.default.sed(
|
|
78
|
+
shelljs_1.default.sed("-i", new RegExp(`^.*import.*${controller}.*Reducer.*from.*$`, "gm"), "", paths.destClientReduxReducersAllPath);
|
|
79
79
|
// 2. 删除 export 对象中的属性行
|
|
80
|
-
shelljs_1.default.sed(
|
|
80
|
+
shelljs_1.default.sed("-i", new RegExp(`^\\s*${controller}[^:]*:\\s*${controller}.*Reducer,?\\s*$`, "gm"), "", paths.destClientReduxReducersAllPath);
|
|
81
81
|
// 3. 修复可能出现的语法问题
|
|
82
82
|
// 移除空行
|
|
83
|
-
shelljs_1.default.sed(
|
|
84
|
-
shelljs_1.default.sed(
|
|
83
|
+
shelljs_1.default.sed("-i", /^\s*$/g, "", paths.destClientReduxReducersAllPath);
|
|
84
|
+
shelljs_1.default.sed("-i", /\n\n\n/g, "\n\n", paths.destClientReduxReducersAllPath);
|
|
85
85
|
// 4. 修复对象末尾的逗号问题
|
|
86
86
|
// 如果对象只剩一个属性,移除末尾逗号
|
|
87
|
-
shelljs_1.default.sed(
|
|
87
|
+
shelljs_1.default.sed("-i", /,(\s*\n\s*\})/, "$1", paths.destClientReduxReducersAllPath);
|
|
88
88
|
// 5. 清理服务器端配置
|
|
89
|
-
shelljs_1.default.sed(
|
|
89
|
+
shelljs_1.default.sed("-i", new RegExp(`.*${controller}.*`, "g"), "", paths.destServerRestPath);
|
|
90
90
|
}
|
|
91
91
|
else {
|
|
92
92
|
// 清理特定动作的配置
|
|
93
|
-
shelljs_1.default.sed(
|
|
94
|
-
shelljs_1.default.sed(
|
|
93
|
+
shelljs_1.default.sed("-i", new RegExp(`^.*import.*${controller}${(0, utils_1.firstUpperCase)(action)}Reducer.*from.*$`, "gm"), "", paths.destClientReduxReducersAllPath);
|
|
94
|
+
shelljs_1.default.sed("-i", new RegExp(`^\\s*${controller}${(0, utils_1.firstUpperCase)(action)}[^:]*:\\s*${controller}${(0, utils_1.firstUpperCase)(action)}.*Reducer,?\\s*$`, "gm"), "", paths.destClientReduxReducersAllPath);
|
|
95
95
|
// 修复语法问题
|
|
96
|
-
shelljs_1.default.sed(
|
|
97
|
-
shelljs_1.default.sed(
|
|
96
|
+
shelljs_1.default.sed("-i", /^\s*$/g, "", paths.destClientReduxReducersAllPath);
|
|
97
|
+
shelljs_1.default.sed("-i", /,(\s*\n\s*\})/, "$1", paths.destClientReduxReducersAllPath);
|
|
98
98
|
}
|
|
99
99
|
};
|
|
100
100
|
const performDatabaseCleanup = (controller, paths) => {
|
|
101
101
|
try {
|
|
102
|
-
shelljs_1.default.sed(
|
|
103
|
-
shelljs_1.default.sed(
|
|
102
|
+
shelljs_1.default.sed("-i", new RegExp(`${constants_1.mysqlDatabase};`, "g"), `${constants_1.mysqlDatabase};\nDROP TABLE \`${controller}\`;\n/*`, paths.destServerSqlController);
|
|
103
|
+
shelljs_1.default.sed("-i", /utf8mb4;/g, "utf8mb4;\n*/", paths.destServerSqlController);
|
|
104
104
|
const mysqlCommand = `mysql -u${constants_1.mysqlUser} -p${constants_1.mysqlPassword} -h${constants_1.mysqlHost} -P${constants_1.mysqlPort} < ${paths.destServerSqlController}`;
|
|
105
105
|
shelljs_1.default.exec(mysqlCommand);
|
|
106
|
-
console.log(
|
|
106
|
+
console.log("Database cleanup completed");
|
|
107
107
|
}
|
|
108
108
|
catch (error) {
|
|
109
|
-
console.error(
|
|
109
|
+
console.error("Failed to execute database cleanup:", error);
|
|
110
110
|
}
|
|
111
111
|
};
|
|
112
112
|
const performAdvancedCleanup = (controller, action, paths) => {
|
|
@@ -114,17 +114,17 @@ const performAdvancedCleanup = (controller, action, paths) => {
|
|
|
114
114
|
// 标准化空行
|
|
115
115
|
{
|
|
116
116
|
from: /\n\s*\n\s*\n/g,
|
|
117
|
-
to:
|
|
117
|
+
to: "\n\n",
|
|
118
118
|
files: [paths.destClientReduxReducersAllPath],
|
|
119
119
|
},
|
|
120
120
|
// 修复 reducers.ts 中可能的语法问题
|
|
121
121
|
{
|
|
122
122
|
from: /(\w+Reducer),?\s*\n\s*\}/g,
|
|
123
|
-
to:
|
|
123
|
+
to: "$1,\n}",
|
|
124
124
|
files: [paths.destClientReduxReducersAllPath],
|
|
125
125
|
},
|
|
126
126
|
];
|
|
127
|
-
if (action ===
|
|
127
|
+
if (action === "all") {
|
|
128
128
|
cleanupRules.push(
|
|
129
129
|
// 服务器端 REST 文件清理
|
|
130
130
|
{
|
|
@@ -133,23 +133,23 @@ const performAdvancedCleanup = (controller, action, paths) => {
|
|
|
133
133
|
files: [paths.destServerRestPath],
|
|
134
134
|
}, {
|
|
135
135
|
from: /template\)\s*\n/,
|
|
136
|
-
to:
|
|
136
|
+
to: "template)\n\n",
|
|
137
137
|
files: [paths.destServerRestPath],
|
|
138
138
|
},
|
|
139
139
|
// 菜单清理 - 改进版本,保持正确的缩进和逗号
|
|
140
140
|
{
|
|
141
|
-
from: new RegExp(`,?\\s*\\{\\s*//\\s*${controller}_.*_start[\\s\\S]*?//\\s*${controller}_.*_end\\s*\\}\\s*,?`,
|
|
142
|
-
to:
|
|
141
|
+
from: new RegExp(`,?\\s*\\{\\s*//\\s*${controller}_.*_start[\\s\\S]*?//\\s*${controller}_.*_end\\s*\\}\\s*,?`, "gm"),
|
|
142
|
+
to: ",", // 保留逗号,确保数组语法正确
|
|
143
143
|
files: [paths.destClientUtilsMenuPath],
|
|
144
144
|
});
|
|
145
145
|
}
|
|
146
146
|
setTimeout(() => {
|
|
147
147
|
(0, utils_1.replaceInFileAll)(cleanupRules, 0, () => {
|
|
148
|
-
console.log(
|
|
148
|
+
console.log("Advanced cleanup completed");
|
|
149
149
|
// 执行额外的清理步骤
|
|
150
150
|
performFinalCleanup(paths);
|
|
151
151
|
// 如果是删除整个控制器,还需要清理菜单缩进
|
|
152
|
-
if (action ===
|
|
152
|
+
if (action === "all") {
|
|
153
153
|
cleanupMenuIndentation(paths);
|
|
154
154
|
}
|
|
155
155
|
});
|
|
@@ -162,20 +162,20 @@ const cleanupMenuIndentation = (paths) => {
|
|
|
162
162
|
// 使用更智能的方式处理菜单清理,保持正确的缩进
|
|
163
163
|
setTimeout(() => {
|
|
164
164
|
// 清理可能出现的缩进问题,确保注释代码块有正确的缩进
|
|
165
|
-
shelljs_1.default.sed(
|
|
166
|
-
shelljs_1.default.sed(
|
|
167
|
-
shelljs_1.default.sed(
|
|
168
|
-
shelljs_1.default.sed(
|
|
169
|
-
shelljs_1.default.sed(
|
|
170
|
-
shelljs_1.default.sed(
|
|
171
|
-
shelljs_1.default.sed(
|
|
165
|
+
shelljs_1.default.sed("-i", /^[ ]{0,2}\/\*\{/gm, " /*{", menuFile);
|
|
166
|
+
shelljs_1.default.sed("-i", /^[ ]{0,4}key:/gm, " key:", menuFile);
|
|
167
|
+
shelljs_1.default.sed("-i", /^[ ]{0,4}text:/gm, " text:", menuFile);
|
|
168
|
+
shelljs_1.default.sed("-i", /^[ ]{0,4}url:/gm, " url:", menuFile);
|
|
169
|
+
shelljs_1.default.sed("-i", /^[ ]{0,4}icon:/gm, " icon:", menuFile);
|
|
170
|
+
shelljs_1.default.sed("-i", /^[ ]{0,4}subMenus:/gm, " subMenus:", menuFile);
|
|
171
|
+
shelljs_1.default.sed("-i", /^[ ]{0,2}\}\*\//gm, " }*/", menuFile);
|
|
172
172
|
// 修复可能出现的连续逗号问题
|
|
173
|
-
shelljs_1.default.sed(
|
|
173
|
+
shelljs_1.default.sed("-i", /,,+/g, ",", menuFile);
|
|
174
174
|
// 修复数组末尾多余的逗号(在注释前)
|
|
175
|
-
shelljs_1.default.sed(
|
|
175
|
+
shelljs_1.default.sed("-i", /,(\s*\/\*)/g, "$1", menuFile);
|
|
176
176
|
// 确保数组项之间有正确的逗号
|
|
177
|
-
shelljs_1.default.sed(
|
|
178
|
-
console.log(
|
|
177
|
+
shelljs_1.default.sed("-i", /(\})(\s*\/\*)/g, "$1,$2", menuFile);
|
|
178
|
+
console.log("Menu indentation cleanup completed");
|
|
179
179
|
}, 1500);
|
|
180
180
|
};
|
|
181
181
|
// 新增:最终清理函数
|
|
@@ -183,12 +183,12 @@ const performFinalCleanup = (paths) => {
|
|
|
183
183
|
// 修复 reducers.ts 的最终格式
|
|
184
184
|
setTimeout(() => {
|
|
185
185
|
// 确保最后一个属性有逗号(如果不是空对象)
|
|
186
|
-
shelljs_1.default.sed(
|
|
186
|
+
shelljs_1.default.sed("-i", /(\w+Reducer)(\s*\n\s*\})/, "$1,$2", paths.destClientReduxReducersAllPath);
|
|
187
187
|
// 移除空对象中的逗号
|
|
188
|
-
shelljs_1.default.sed(
|
|
188
|
+
shelljs_1.default.sed("-i", /\{\s*,\s*\}/, "{}", paths.destClientReduxReducersAllPath);
|
|
189
189
|
// 标准化缩进
|
|
190
|
-
shelljs_1.default.sed(
|
|
191
|
-
console.log(
|
|
190
|
+
shelljs_1.default.sed("-i", /^[ ]{2}/gm, " ", paths.destClientReduxReducersAllPath);
|
|
191
|
+
console.log("Final cleanup completed");
|
|
192
192
|
}, 500);
|
|
193
193
|
};
|
|
194
194
|
/**
|
|
@@ -199,13 +199,13 @@ const performFinalCleanup = (paths) => {
|
|
|
199
199
|
* @param dictionary 目标目录路径(可选,默认为当前目录)
|
|
200
200
|
*/
|
|
201
201
|
const deleteFiles = (controller, action, deleteDBFlag = false, dictionary) => {
|
|
202
|
-
console.log(
|
|
202
|
+
console.log("deleteFiles", constants_1.sourceFolder, constants_1.destFolder, constants_1.isLocal, controller, action, deleteDBFlag, dictionary);
|
|
203
203
|
try {
|
|
204
204
|
// 1. 生成删除路径
|
|
205
205
|
const paths = generateDeletePaths(controller, action, dictionary);
|
|
206
206
|
// 2. 删除文件和目录
|
|
207
|
-
if (action ===
|
|
208
|
-
console.log(
|
|
207
|
+
if (action === "all") {
|
|
208
|
+
console.log("Deleting all controller files...");
|
|
209
209
|
deleteAllControllerFiles(paths);
|
|
210
210
|
// 删除多语言文件
|
|
211
211
|
deleteI18nFiles(paths);
|
|
@@ -216,17 +216,17 @@ const deleteFiles = (controller, action, deleteDBFlag = false, dictionary) => {
|
|
|
216
216
|
}
|
|
217
217
|
// 3. 清理配置文件
|
|
218
218
|
cleanupConfigurationFiles(controller, action, paths);
|
|
219
|
-
console.log(
|
|
219
|
+
console.log("Configuration files cleaned up");
|
|
220
220
|
// 4. 处理数据库清理(仅在删除整个控制器且设置了标志时)
|
|
221
|
-
if (action ===
|
|
221
|
+
if (action === "all" && deleteDBFlag) {
|
|
222
222
|
performDatabaseCleanup(controller, paths);
|
|
223
223
|
}
|
|
224
224
|
// 5. 执行高级清理
|
|
225
225
|
performAdvancedCleanup(controller, action, paths);
|
|
226
|
-
console.log(
|
|
226
|
+
console.log("deleteFiles completed successfully");
|
|
227
227
|
}
|
|
228
228
|
catch (error) {
|
|
229
|
-
console.error(
|
|
229
|
+
console.error("Failed to delete files:", error);
|
|
230
230
|
throw error;
|
|
231
231
|
}
|
|
232
232
|
};
|