ol-base-components 2.2.5 → 2.2.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/api/api.js +15 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ol-base-components",
3
- "version": "2.2.5",
3
+ "version": "2.2.7",
4
4
  "private": false,
5
5
  "main": "src/package/index.js",
6
6
  "bin": {
package/src/api/api.js CHANGED
@@ -29,11 +29,23 @@ SwaggerClient(swaggerUrl)
29
29
  fs.writeFileSync(outputPath, apiModules[fileName], "utf-8");
30
30
  console.log(`API接口已生成并保存到 ${outputPath}`);
31
31
  });
32
+
33
+ // 生成index.js入口文件
34
+ createIndexFile(apiModules);
32
35
  })
33
36
  .catch((err) => {
34
37
  console.error("获取 Swagger 数据时出错:", err);
35
38
  });
36
39
 
40
+ function createIndexFile(apiModules) {
41
+ let str = "";
42
+ Object.keys(apiModules).forEach((fileName) => {
43
+ str += `import * from "./${fileName}.js"\n`;
44
+ });
45
+ const outputPath = path.join(modulesDir, `index.js`);
46
+ fs.writeFileSync(outputPath, str, "utf-8");
47
+ }
48
+
37
49
  // url转成键名规则
38
50
  function generateKeyName(url, method) {
39
51
  // 移除前缀 "/api/app"
@@ -179,13 +191,13 @@ const generateApiModules = (swagger) => {
179
191
  let functionParams = [];
180
192
  if (hasQuery) functionParams.push("params");
181
193
  if (hasBody) functionParams.push("body");
182
- functionParams = functionParams.concat(pathParameters);
183
- functionParams = functionParams.push("options = {}").join(", ");
194
+ Object.assign(functionParams, pathParameters);
195
+ functionParams.push("options = {}");
184
196
  // 函数
185
197
  functionDoc += `export const ${generateKeyName(
186
198
  url,
187
199
  method
188
- )} = (${functionParams}, options = {}) => {\n`;
200
+ )} = (${functionParams.join(", ")}) => {\n`;
189
201
 
190
202
  functionDoc += ` return api({\n`;
191
203
  functionDoc += ` url: \`${url.replace(/{/g, "${")}\`,\n`;