nsgm-cli 2.1.31 → 2.1.32
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/layout/index.tsx
CHANGED
|
@@ -35,7 +35,7 @@ interface MenuItem {
|
|
|
35
35
|
// 安全获取 prefix 的辅助函数
|
|
36
36
|
const getPrefix = () => {
|
|
37
37
|
try {
|
|
38
|
-
if (typeof process !== "undefined" && process.env
|
|
38
|
+
if (typeof process !== "undefined" && process.env?.NEXT_PUBLIC_PREFIX) {
|
|
39
39
|
return process.env.NEXT_PUBLIC_PREFIX;
|
|
40
40
|
}
|
|
41
41
|
} catch {
|
package/client/utils/common.ts
CHANGED
|
@@ -4,7 +4,7 @@ export const getLocalEnv = () => {
|
|
|
4
4
|
// 安全地访问 process.env,避免在浏览器中直接访问 process 对象
|
|
5
5
|
let env = "uat";
|
|
6
6
|
try {
|
|
7
|
-
if (typeof process !== "undefined" && process.env
|
|
7
|
+
if (typeof process !== "undefined" && process.env?.NEXT_PUBLIC_ENV) {
|
|
8
8
|
env = process.env.NEXT_PUBLIC_ENV;
|
|
9
9
|
}
|
|
10
10
|
} catch {
|
|
@@ -5,8 +5,117 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.deleteConfigCommand = void 0;
|
|
7
7
|
const utils_1 = require("../utils");
|
|
8
|
-
const generate_1 = require("../../generate");
|
|
9
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const shelljs_1 = __importDefault(require("shelljs"));
|
|
11
|
+
const utils_2 = require("../../utils");
|
|
12
|
+
const constants_1 = require("../../constants");
|
|
13
|
+
/**
|
|
14
|
+
* 生成删除路径
|
|
15
|
+
*/
|
|
16
|
+
const generateDeletePaths = (controller, dictionary) => {
|
|
17
|
+
const basePath = dictionary || process.cwd();
|
|
18
|
+
return {
|
|
19
|
+
destPagesController: path_1.default.join(basePath, "pages", controller),
|
|
20
|
+
destClientReduxController: path_1.default.join(basePath, "client", "redux", controller),
|
|
21
|
+
destClientServiceController: path_1.default.join(basePath, "client", "service", controller),
|
|
22
|
+
destClientStyledController: path_1.default.join(basePath, "client", "styled", controller),
|
|
23
|
+
destServerModulesController: path_1.default.join(basePath, "server", "modules", controller),
|
|
24
|
+
destServerApisController: path_1.default.join(basePath, "server", "apis", `${controller}.js`),
|
|
25
|
+
destServerSqlController: path_1.default.join(basePath, "server", "sql", `${controller}.sql`),
|
|
26
|
+
destServerDataLoader: path_1.default.join(basePath, "server", "dataloaders", `${controller}-dataloader.ts`),
|
|
27
|
+
destClientReduxReducersAllPath: path_1.default.join(basePath, "client", "redux", "reducers.ts"),
|
|
28
|
+
destServerRestPath: path_1.default.join(basePath, "server", "rest.js"),
|
|
29
|
+
destClientUtilsMenuPath: path_1.default.join(basePath, "client", "utils", "menu.tsx"),
|
|
30
|
+
destI18nZhCN: path_1.default.join(basePath, "public", "locales", "zh-CN", `${controller}.json`),
|
|
31
|
+
destI18nEnUS: path_1.default.join(basePath, "public", "locales", "en-US", `${controller}.json`),
|
|
32
|
+
destI18nJaJP: path_1.default.join(basePath, "public", "locales", "ja-JP", `${controller}.json`),
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* 删除文件和目录
|
|
37
|
+
*/
|
|
38
|
+
const deleteModuleFiles = (paths) => {
|
|
39
|
+
const directoriesToDelete = [
|
|
40
|
+
paths.destPagesController,
|
|
41
|
+
paths.destClientReduxController,
|
|
42
|
+
paths.destClientServiceController,
|
|
43
|
+
paths.destClientStyledController,
|
|
44
|
+
paths.destServerModulesController,
|
|
45
|
+
];
|
|
46
|
+
const filesToDelete = [
|
|
47
|
+
paths.destServerApisController,
|
|
48
|
+
paths.destServerSqlController,
|
|
49
|
+
paths.destServerDataLoader,
|
|
50
|
+
paths.destI18nZhCN,
|
|
51
|
+
paths.destI18nEnUS,
|
|
52
|
+
paths.destI18nJaJP,
|
|
53
|
+
];
|
|
54
|
+
directoriesToDelete.forEach((dir) => (0, utils_2.rmdirSync)(dir));
|
|
55
|
+
filesToDelete.forEach((file) => (0, utils_2.rmFileSync)(file));
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* 清理 reducers 配置
|
|
59
|
+
*/
|
|
60
|
+
const cleanupReducers = (controller, reducersPath) => {
|
|
61
|
+
// 删除 import 语句
|
|
62
|
+
shelljs_1.default.sed("-i", new RegExp(`^.*import.*from.*['"].*\\/${controller}\\/.*['"].*$`, "gm"), "", reducersPath);
|
|
63
|
+
// 删除 export 对象中的属性行
|
|
64
|
+
shelljs_1.default.sed("-i", new RegExp(`^\\s*${controller}\\w*:\\s*${controller}\\w*Reducer,?\\s*$`, "gm"), "", reducersPath);
|
|
65
|
+
// 修复连续逗号
|
|
66
|
+
shelljs_1.default.sed("-i", /,,+/g, ",", reducersPath);
|
|
67
|
+
// 修复对象末尾的逗号
|
|
68
|
+
shelljs_1.default.sed("-i", /,(\s*\n\s*\})/, "$1", reducersPath);
|
|
69
|
+
// 移除空对象中的逗号
|
|
70
|
+
shelljs_1.default.sed("-i", /\{\s*,\s*\}/, "{}", reducersPath);
|
|
71
|
+
// 标准化空行
|
|
72
|
+
shelljs_1.default.sed("-i", /\n\s*\n\s*\n/g, "\n\n", reducersPath);
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* 清理菜单配置
|
|
76
|
+
*/
|
|
77
|
+
const cleanupMenu = (controller, menuPath) => {
|
|
78
|
+
// 删除所有匹配的菜单项
|
|
79
|
+
shelljs_1.default.sed("-i", new RegExp(`,?\\s*\\{\\s*//\\s*${controller}_\\w+_start[\\s\\S]*?//\\s*${controller}_\\w+_end\\s*\\n\\s*\\}\\s*,?`, "gm"), "", menuPath);
|
|
80
|
+
// 修复连续逗号
|
|
81
|
+
shelljs_1.default.sed("-i", /,,+/g, ",", menuPath);
|
|
82
|
+
// 修复对象前多余的逗号
|
|
83
|
+
shelljs_1.default.sed("-i", /\n\s*,\s*\{/gm, "\n {", menuPath);
|
|
84
|
+
// 修复数组中缺失的逗号
|
|
85
|
+
shelljs_1.default.sed("-i", /(\})\s*(\{)/gm, "$1,\n $2", menuPath);
|
|
86
|
+
// 清理缩进问题
|
|
87
|
+
shelljs_1.default.sed("-i", /^[ ]{0,2}\/\*\{/gm, " /*{", menuPath);
|
|
88
|
+
shelljs_1.default.sed("-i", /^[ ]{0,4}key:/gm, " key:", menuPath);
|
|
89
|
+
shelljs_1.default.sed("-i", /^[ ]{0,4}text:/gm, " text:", menuPath);
|
|
90
|
+
shelljs_1.default.sed("-i", /^[ ]{0,4}url:/gm, " url:", menuPath);
|
|
91
|
+
shelljs_1.default.sed("-i", /^[ ]{0,4}icon:/gm, " icon:", menuPath);
|
|
92
|
+
shelljs_1.default.sed("-i", /^[ ]{0,4}subMenus:/gm, " subMenus:", menuPath);
|
|
93
|
+
shelljs_1.default.sed("-i", /^[ ]{0,2}\}\*\//gm, " }*/", menuPath);
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* 清理 REST API 配置
|
|
97
|
+
*/
|
|
98
|
+
const cleanupRestApi = (controller, restPath) => {
|
|
99
|
+
// 删除 require 语句
|
|
100
|
+
shelljs_1.default.sed("-i", new RegExp(`^const\\s+${controller}\\s*=\\s*require.*${controller}['"].*$`, "gm"), "", restPath);
|
|
101
|
+
// 删除 router.use 语句
|
|
102
|
+
shelljs_1.default.sed("-i", new RegExp(`^router\\.use\\(['"]\\/${controller}['"]\\s*,\\s*${controller}\\)\\s*$`, "gm"), "", restPath);
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* 删除数据库表
|
|
106
|
+
*/
|
|
107
|
+
const dropDatabaseTable = (controller) => {
|
|
108
|
+
try {
|
|
109
|
+
// 创建临时的 DROP TABLE SQL
|
|
110
|
+
const dropSql = `DROP TABLE IF EXISTS \`${controller}\`;`;
|
|
111
|
+
const mysqlCommand = `mysql -u${constants_1.mysqlUser} -p${constants_1.mysqlPassword} -h${constants_1.mysqlHost} -P${constants_1.mysqlPort} -e "${dropSql}"`;
|
|
112
|
+
shelljs_1.default.exec(mysqlCommand);
|
|
113
|
+
utils_1.Console.info(`已删除数据库表: ${controller}`);
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
utils_1.Console.error(`删除数据库表失败: ${error}`);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
10
119
|
/**
|
|
11
120
|
* 从配置文件删除命令
|
|
12
121
|
*/
|
|
@@ -147,8 +256,18 @@ exports.deleteConfigCommand = {
|
|
|
147
256
|
try {
|
|
148
257
|
const spinner = utils_1.Console.spinner("正在删除文件...", "red");
|
|
149
258
|
spinner.start();
|
|
150
|
-
//
|
|
151
|
-
|
|
259
|
+
// 生成删除路径
|
|
260
|
+
const paths = generateDeletePaths(module.controller, module.dictionary);
|
|
261
|
+
// 1. 删除文件和目录
|
|
262
|
+
deleteModuleFiles(paths);
|
|
263
|
+
// 2. 清理配置文件
|
|
264
|
+
cleanupReducers(module.controller, paths.destClientReduxReducersAllPath);
|
|
265
|
+
cleanupRestApi(module.controller, paths.destServerRestPath);
|
|
266
|
+
cleanupMenu(module.controller, paths.destClientUtilsMenuPath);
|
|
267
|
+
// 3. 删除数据库表(如果指定)
|
|
268
|
+
if (options.db) {
|
|
269
|
+
dropDatabaseTable(module.controller);
|
|
270
|
+
}
|
|
152
271
|
spinner.succeed("删除完成!");
|
|
153
272
|
successCount++;
|
|
154
273
|
utils_1.Console.newLine();
|
|
@@ -96,9 +96,11 @@ class SQLGenerator extends base_generator_1.BaseGenerator {
|
|
|
96
96
|
const primaryKeyField = this.fields.find((f) => f.isPrimaryKey);
|
|
97
97
|
const primaryKey = primaryKeyField ? ` PRIMARY KEY (\`${primaryKeyField.name}\`)` : "";
|
|
98
98
|
const databaseName = this.getDatabaseName();
|
|
99
|
-
return `
|
|
99
|
+
return `CREATE DATABASE IF NOT EXISTS ${databaseName} CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
use ${databaseName};
|
|
102
|
+
|
|
103
|
+
CREATE TABLE IF NOT EXISTS \`${this.controller}\` (
|
|
102
104
|
${fieldDefinitions.join(",\n")},
|
|
103
105
|
${primaryKey}
|
|
104
106
|
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;`;
|