feima-shortcuts 1.0.0 → 1.0.1
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 +12 -5
package/package.json
CHANGED
package/src/generateApi/index.js
CHANGED
|
@@ -4,7 +4,8 @@ const fs = require("fs");
|
|
|
4
4
|
const path = require("path");
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
const
|
|
7
|
+
const requestStrFun = (baseUrl) => {
|
|
8
|
+
return `/**
|
|
8
9
|
* 通过 feima generate-api 命令生成
|
|
9
10
|
* 请勿手动修改此文件
|
|
10
11
|
*/
|
|
@@ -29,7 +30,7 @@ export enum CommonHeaderEnum {
|
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
const service: any = axios.create({
|
|
32
|
-
baseURL: import.meta.env.VITE_API_URL
|
|
33
|
+
baseURL: \`\${import.meta.env.VITE_API_URL}${baseUrl}\`,
|
|
33
34
|
timeout: 50000, // 全局超时时间
|
|
34
35
|
paramsSerializer: {
|
|
35
36
|
serialize: (params: any) => {
|
|
@@ -164,7 +165,8 @@ export const request = <T>(
|
|
|
164
165
|
reject(error);
|
|
165
166
|
});
|
|
166
167
|
});
|
|
167
|
-
}
|
|
168
|
+
};`;
|
|
169
|
+
};
|
|
168
170
|
|
|
169
171
|
|
|
170
172
|
exports.run = () => {
|
|
@@ -181,19 +183,24 @@ exports.run = () => {
|
|
|
181
183
|
"-o, --output <dir>",
|
|
182
184
|
"输出目录,默认 src/api",
|
|
183
185
|
"src/api"
|
|
186
|
+
)
|
|
187
|
+
.option(
|
|
188
|
+
"-bu, --base-url <dir>",
|
|
189
|
+
"基础URL,默认 空",
|
|
190
|
+
""
|
|
184
191
|
)
|
|
185
192
|
.allowUnknownOption(true) // 保持向后兼容,忽略未知参数
|
|
186
193
|
.action((opts) => {
|
|
187
194
|
const input = opts?.input || "http://192.168.0.74:9999/app/v3/api-docs";
|
|
188
195
|
const output = opts?.output || "src/api";
|
|
189
|
-
|
|
196
|
+
const baseUrl = opts?.baseUrl || "";
|
|
190
197
|
console.log(`📥 generate-api 输入地址: ${input}`);
|
|
191
198
|
console.log(`📦 输出目录: ${output}`);
|
|
192
199
|
|
|
193
200
|
// 确保 ./tmpRequest.ts 使用内置的 requestStr(放在项目根目录)
|
|
194
201
|
const requestFile = path.resolve(process.cwd(), "tmpRequest.ts");
|
|
195
202
|
try {
|
|
196
|
-
fs.writeFileSync(requestFile,
|
|
203
|
+
fs.writeFileSync(requestFile, requestStrFun(baseUrl), "utf8");
|
|
197
204
|
console.log("📝 已写入 ./tmpRequest.ts");
|
|
198
205
|
} catch (e) {
|
|
199
206
|
console.error("❌ 写入 ./tmpRequest.ts 失败:", e.message);
|