feima-shortcuts 1.0.1 → 1.0.3
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 +20 -9
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) => {
|
|
@@ -140,22 +142,17 @@ export const request = <T>(
|
|
|
140
142
|
options: ApiRequestOptions
|
|
141
143
|
): CancelablePromise<T> => {
|
|
142
144
|
return new CancelablePromise((resolve, reject, onCancel) => {
|
|
143
|
-
// Get the request URL. Depending on your needs, this might need additional processing,
|
|
144
|
-
// @see ./src/templates/core/functions/getUrl.hbs
|
|
145
145
|
const url = \`\${config.BASE}\${options.path}\`;
|
|
146
|
-
|
|
147
|
-
// Optional: Get and link the cancelation token, so the request can be aborted.
|
|
146
|
+
|
|
148
147
|
const source = service.CancelToken.source();
|
|
148
|
+
|
|
149
149
|
onCancel(() => source.cancel("The user aborted a request."));
|
|
150
150
|
|
|
151
|
-
// Execute the request. This is a minimal example, in real world scenarios
|
|
152
|
-
// you will need to add headers, process form data, etc.
|
|
153
|
-
// @see ./src/templates/core/axios/request.hbs
|
|
154
151
|
service
|
|
155
152
|
.request({
|
|
156
153
|
url,
|
|
157
154
|
data: options.body,
|
|
158
|
-
|
|
155
|
+
...options,
|
|
159
156
|
cancelToken: source.token,
|
|
160
157
|
})
|
|
161
158
|
.then((data: any) => {
|
|
@@ -190,13 +187,27 @@ exports.run = () => {
|
|
|
190
187
|
""
|
|
191
188
|
)
|
|
192
189
|
.allowUnknownOption(true) // 保持向后兼容,忽略未知参数
|
|
193
|
-
.action((opts) => {
|
|
190
|
+
.action(async (opts) => {
|
|
194
191
|
const input = opts?.input || "http://192.168.0.74:9999/app/v3/api-docs";
|
|
195
192
|
const output = opts?.output || "src/api";
|
|
196
193
|
const baseUrl = opts?.baseUrl || "";
|
|
197
194
|
console.log(`📥 generate-api 输入地址: ${input}`);
|
|
198
195
|
console.log(`📦 输出目录: ${output}`);
|
|
199
196
|
|
|
197
|
+
|
|
198
|
+
// 生成前清空并重建输出目录,避免遗留文件
|
|
199
|
+
try {
|
|
200
|
+
const fullOutputDir = path.resolve(process.cwd(), output);
|
|
201
|
+
if (fs.existsSync(fullOutputDir)) {
|
|
202
|
+
deleteFolder(fullOutputDir);
|
|
203
|
+
}
|
|
204
|
+
makeDir(fullOutputDir);
|
|
205
|
+
console.log("🧹 已清空并初始化输出目录");
|
|
206
|
+
} catch (e) {
|
|
207
|
+
console.error("❌ 初始化输出目录失败:", e.message);
|
|
208
|
+
process.exit(1);
|
|
209
|
+
}
|
|
210
|
+
|
|
200
211
|
// 确保 ./tmpRequest.ts 使用内置的 requestStr(放在项目根目录)
|
|
201
212
|
const requestFile = path.resolve(process.cwd(), "tmpRequest.ts");
|
|
202
213
|
try {
|