feima-shortcuts 0.0.5 → 0.0.6

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/scripts/old.js +20 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "feima-shortcuts",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "快捷指令",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -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