feima-shortcuts 1.0.1 → 1.0.2
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/package.json +1 -1
- package/src/generateApi/index.js +17 -1
package/package.json
CHANGED
package/src/generateApi/index.js
CHANGED
|
@@ -2,6 +2,8 @@ const { Command } = require("commander");
|
|
|
2
2
|
const { spawn } = require("child_process");
|
|
3
3
|
const fs = require("fs");
|
|
4
4
|
const path = require("path");
|
|
5
|
+
const { deleteFolder } = require("../utils/deleteFolder");
|
|
6
|
+
const { makeDir } = require("../utils/makeDir");
|
|
5
7
|
|
|
6
8
|
|
|
7
9
|
const requestStrFun = (baseUrl) => {
|
|
@@ -190,13 +192,27 @@ exports.run = () => {
|
|
|
190
192
|
""
|
|
191
193
|
)
|
|
192
194
|
.allowUnknownOption(true) // 保持向后兼容,忽略未知参数
|
|
193
|
-
.action((opts) => {
|
|
195
|
+
.action(async (opts) => {
|
|
194
196
|
const input = opts?.input || "http://192.168.0.74:9999/app/v3/api-docs";
|
|
195
197
|
const output = opts?.output || "src/api";
|
|
196
198
|
const baseUrl = opts?.baseUrl || "";
|
|
197
199
|
console.log(`📥 generate-api 输入地址: ${input}`);
|
|
198
200
|
console.log(`📦 输出目录: ${output}`);
|
|
199
201
|
|
|
202
|
+
|
|
203
|
+
// 生成前清空并重建输出目录,避免遗留文件
|
|
204
|
+
try {
|
|
205
|
+
const fullOutputDir = path.resolve(process.cwd(), output);
|
|
206
|
+
if (fs.existsSync(fullOutputDir)) {
|
|
207
|
+
deleteFolder(fullOutputDir);
|
|
208
|
+
}
|
|
209
|
+
makeDir(fullOutputDir);
|
|
210
|
+
console.log("🧹 已清空并初始化输出目录");
|
|
211
|
+
} catch (e) {
|
|
212
|
+
console.error("❌ 初始化输出目录失败:", e.message);
|
|
213
|
+
process.exit(1);
|
|
214
|
+
}
|
|
215
|
+
|
|
200
216
|
// 确保 ./tmpRequest.ts 使用内置的 requestStr(放在项目根目录)
|
|
201
217
|
const requestFile = path.resolve(process.cwd(), "tmpRequest.ts");
|
|
202
218
|
try {
|