nsgm-cli 2.1.32 → 2.1.34

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.
@@ -53,6 +53,7 @@ const deleteModuleFiles = (paths) => {
53
53
  ];
54
54
  directoriesToDelete.forEach((dir) => (0, utils_2.rmdirSync)(dir));
55
55
  filesToDelete.forEach((file) => (0, utils_2.rmFileSync)(file));
56
+ console.log(`✅ 已删除 ${directoriesToDelete.length} 个目录和 ${filesToDelete.length} 个文件`);
56
57
  };
57
58
  /**
58
59
  * 清理 reducers 配置
@@ -70,27 +71,33 @@ const cleanupReducers = (controller, reducersPath) => {
70
71
  shelljs_1.default.sed("-i", /\{\s*,\s*\}/, "{}", reducersPath);
71
72
  // 标准化空行
72
73
  shelljs_1.default.sed("-i", /\n\s*\n\s*\n/g, "\n\n", reducersPath);
74
+ console.log(`✅ 已清理 reducers 配置: ${controller}`);
73
75
  };
74
76
  /**
75
77
  * 清理菜单配置
76
78
  */
77
79
  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
+ let content = fs_1.default.readFileSync(menuPath, "utf8");
82
+ // 删除所有匹配的菜单项(使用与 generate_delete.ts 相同的正则)
83
+ content = content.replace(new RegExp(`,?\\s*\\{\\s*//\\s*${controller}_.*_start[\\s\\S]*?//\\s*${controller}_.*_end\\s*\\}\\s*,?`, "gm"), "");
80
84
  // 修复连续逗号
81
- shelljs_1.default.sed("-i", /,,+/g, ",", menuPath);
85
+ content = content.replace(/,,+/g, ",");
82
86
  // 修复对象前多余的逗号
83
- shelljs_1.default.sed("-i", /\n\s*,\s*\{/gm, "\n {", menuPath);
87
+ content = content.replace(/\n\s*,\s*\{/gm, "\n {");
84
88
  // 修复数组中缺失的逗号
85
- shelljs_1.default.sed("-i", /(\})\s*(\{)/gm, "$1,\n $2", menuPath);
89
+ content = content.replace(/(\})\s*(\{)/gm, "$1,\n $2");
86
90
  // 清理缩进问题
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);
91
+ content = content.replace(/^[ ]{0,2}\/\*\{/gm, " /*{");
92
+ content = content.replace(/^[ ]{0,4}key:/gm, " key:");
93
+ content = content.replace(/^[ ]{0,4}text:/gm, " text:");
94
+ content = content.replace(/^[ ]{0,4}url:/gm, " url:");
95
+ content = content.replace(/^[ ]{0,4}icon:/gm, " icon:");
96
+ content = content.replace(/^[ ]{0,4}subMenus:/gm, " subMenus:");
97
+ content = content.replace(/^[ ]{0,2}\}\*\//gm, " }*/");
98
+ // 写回文件
99
+ fs_1.default.writeFileSync(menuPath, content, "utf8");
100
+ console.log(`✅ 已清理菜单配置: ${controller}`);
94
101
  };
95
102
  /**
96
103
  * 清理 REST API 配置
@@ -100,6 +107,7 @@ const cleanupRestApi = (controller, restPath) => {
100
107
  shelljs_1.default.sed("-i", new RegExp(`^const\\s+${controller}\\s*=\\s*require.*${controller}['"].*$`, "gm"), "", restPath);
101
108
  // 删除 router.use 语句
102
109
  shelljs_1.default.sed("-i", new RegExp(`^router\\.use\\(['"]\\/${controller}['"]\\s*,\\s*${controller}\\)\\s*$`, "gm"), "", restPath);
110
+ console.log(`✅ 已清理 REST API 配置: ${controller}`);
103
111
  };
104
112
  /**
105
113
  * 删除数据库表
@@ -253,28 +261,30 @@ exports.deleteConfigCommand = {
253
261
  for (const module of targetModules) {
254
262
  utils_1.Console.separator();
255
263
  utils_1.Console.highlight(`🗑️ 删除模块 ${successCount + failureCount + 1}/${targetModules.length}: ${module.controller}`);
264
+ utils_1.Console.newLine();
256
265
  try {
257
- const spinner = utils_1.Console.spinner("正在删除文件...", "red");
258
- spinner.start();
259
266
  // 生成删除路径
260
267
  const paths = generateDeletePaths(module.controller, module.dictionary);
261
268
  // 1. 删除文件和目录
269
+ utils_1.Console.info("📁 正在删除文件和目录...");
262
270
  deleteModuleFiles(paths);
263
271
  // 2. 清理配置文件
272
+ utils_1.Console.info("🔧 正在清理配置文件...");
264
273
  cleanupReducers(module.controller, paths.destClientReduxReducersAllPath);
265
274
  cleanupRestApi(module.controller, paths.destServerRestPath);
266
275
  cleanupMenu(module.controller, paths.destClientUtilsMenuPath);
267
276
  // 3. 删除数据库表(如果指定)
268
277
  if (options.db) {
278
+ utils_1.Console.info("💾 正在删除数据库表...");
269
279
  dropDatabaseTable(module.controller);
270
280
  }
271
- spinner.succeed("删除完成!");
272
- successCount++;
281
+ utils_1.Console.success(`✅ ${module.controller} 删除完成!`);
273
282
  utils_1.Console.newLine();
283
+ successCount++;
274
284
  }
275
285
  catch (error) {
276
286
  const errorMessage = error instanceof Error ? error.message : String(error);
277
- utils_1.Console.error(`错误: ${errorMessage}`);
287
+ utils_1.Console.error(`❌ 错误: ${errorMessage}`);
278
288
  failures.push({ module: module.controller, error: errorMessage });
279
289
  failureCount++;
280
290
  utils_1.Console.newLine();