feima-shortcuts 0.0.5 → 0.0.7

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "feima-shortcuts",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "快捷指令",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -21,5 +21,6 @@
21
21
  "fs-extra": "^9.0.1",
22
22
  "inquirer": "^7.3.0",
23
23
  "uuid": "^9.0.0"
24
- }
24
+ },
25
+ "packageManager": "pnpm@10.6.3+sha512.bb45e34d50a9a76e858a95837301bfb6bd6d35aea2c5d52094fa497a467c43f5c440103ce2511e9e0a2f89c3d6071baac3358fc68ac6fb75e2ceb3d2736065e6"
25
26
  }
@@ -24,7 +24,7 @@ const fileData = (functionName, filePath) => {
24
24
  }
25
25
  return data;
26
26
  }
27
- return `import request from '@/utils/request'`;
27
+ return `import request from '@/utils/service'`;
28
28
  };
29
29
 
30
30
  // 根据 URL 获取函数名(取最后一段)
@@ -64,7 +64,7 @@ exports.run = function ({ api }) {
64
64
  const dir = getDirFromApi(api);
65
65
 
66
66
  // 基于当前工作目录计算 API 路径
67
- const pagePath = path.resolve(process.cwd(), `src/api/${dir}`);
67
+ const pagePath = path.resolve(process.cwd(), `src/service/${dir}`);
68
68
 
69
69
  // 创建目录并生成 API 方法
70
70
  makeDir(pagePath);
@@ -5,13 +5,23 @@ const fileName = "index.js";
5
5
 
6
6
  const postTemplat = (apiPath, functionName) => {
7
7
  return `export const ${functionName} = (options) => {
8
+ const isFormData = options?.data instanceof FormData;
9
+
10
+ const data = isFormData
11
+ ? (() => {
12
+ const formData = options.data;
13
+ formData.append("api", "${apiPath}");
14
+ return formData;
15
+ })()
16
+ : {
17
+ ...(options?.data || {}),
18
+ api: "${apiPath}",
19
+ };
20
+
8
21
  return request({
9
22
  method: "post",
10
23
  ...(options || {}),
11
- data: {
12
- ...(options?.data || {}),
13
- api: "${apiPath}",
14
- },
24
+ data,
15
25
  });
16
26
  };
17
27
  `
@@ -24,11 +34,15 @@ function splitString(input) {
24
34
  return { path, functionName };
25
35
  }
26
36
 
37
+ const isFunctionExists = (data, functionName) => {
38
+ const regex = new RegExp(`export\\s+const\\s+${functionName}\\s*=`, 'g');
39
+ return regex.test(data);
40
+ };
27
41
 
28
42
  const fileData = (answers, functionName) => {
29
43
  if (fs.existsSync(`./${fileName}`)) {
30
44
  const data = fs.readFileSync(`./${fileName}`, "utf8");
31
- if (data.includes(functionName)) {
45
+ if (isFunctionExists(data, functionName)) {
32
46
  return "";
33
47
  }
34
48
  return data;
@@ -39,7 +53,7 @@ const fileData = (answers, functionName) => {
39
53
  const apiAllTemplate = (answers,functionName) => {
40
54
  const fileTemplate = fileData(answers, functionName);
41
55
 
42
- if (!fileTemplate) return console.log(`无需重复添加 ${type}`);
56
+ if (!fileTemplate) return console.error(`无需重复添加 ${answers.path}`);
43
57
 
44
58
  const template = `${fileTemplate}
45
59