@fxri/swagger2api 1.0.2 → 1.0.4

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/.swaggerrc CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "url": "http://develop-daggoo-technology.daggoo-k8s.com/backend/pub/v3/api-docs",
3
- "output": "./src/api",
3
+ "output": "D:\\Work\\Dev-Space\\fxri\\0001.base\\fxri-swagger2api\\src\\api",
4
4
  "name": "index"
5
5
  }
package/dist/index.js CHANGED
@@ -1,11 +1,17 @@
1
1
  import axios from "axios";
2
2
  import { execSync } from "node:child_process";
3
+ import os from "node:os";
3
4
  import fs from "node:fs";
4
5
  import path from "node:path";
5
6
  import prompts from "prompts";
6
7
  import { getParam, isUrl, saveFile } from "./utils/index.js";
7
8
  /** 配置集合 */
8
- let confs = { file: path.resolve(getParam("--config") ?? ".swaggerrc"), param: {} };
9
+ let confs = {
10
+ /** 文件 */
11
+ file: path.resolve(getParam("--config") ?? ".swaggerrc"),
12
+ /** 参数 */
13
+ param: {}
14
+ };
9
15
  try {
10
16
  confs.param = JSON.parse(fs.readFileSync(confs.file, "utf-8"));
11
17
  }
@@ -21,10 +27,18 @@ if ([confs.param.url, confs.param.output, confs.param.name].includes(undefined))
21
27
  console.log("失败:手动退出");
22
28
  process.exit();
23
29
  }
30
+ // 补全路径
31
+ confs.param.output = path.resolve(confs.param.output);
24
32
  /** 数据集合 */
25
33
  let datas = {
34
+ /** 用户目录 */
35
+ home: os.homedir(),
36
+ /** 脚本 */
37
+ script: path.resolve(import.meta.dirname, "../node_modules/.bin/swagger-typescript-api"),
38
+ /** 参数 */
39
+ param: process.argv.filter((_item, index) => index > 1),
26
40
  /** 文件 */
27
- file: `${confs.param.output}/${confs.param.name}-${new Date().getTime()}.json`,
41
+ file: path.resolve(`${confs.param.output}/${confs.param.name}-${new Date().getTime()}.json`),
28
42
  /** 枚举 */
29
43
  enum: {}
30
44
  };
@@ -53,8 +67,8 @@ function onGenerate(data) {
53
67
  // 保存文档
54
68
  saveFile(datas.file, JSON.stringify(data));
55
69
  // 生成接口
56
- const param = ["--axios", `-n ${confs.param.name}.ts`, `-o ${confs.param.output}`, `-p ${datas.file}`, ...process.argv.filter((_item, index) => index > 1)];
57
- console.log("执行:", execSync(`${path.resolve(import.meta.dirname, "../node_modules/.bin/swagger-typescript-api")} generate ${param.join(" ")}`).toString());
70
+ const param = ["generate", "--axios", "-n", `${confs.param.name}.ts`, "-o", confs.param.output, "-p", datas.file, ...datas.param];
71
+ console.log("执行:", execSync(`${datas.script} ${param.join(" ")}`, { cwd: datas.home }).toString());
58
72
  // 删除文档
59
73
  fs.unlinkSync(datas.file);
60
74
  // 保存配置
@@ -68,7 +82,7 @@ function onRun(url = confs.param.url) {
68
82
  axios
69
83
  .get(url)
70
84
  .then((res) => onGenerate(res.data))
71
- .catch((err) => console.log("失败:", err.status ? `接口异常,状态码${err.status}` : err));
85
+ .catch((err) => console.log("失败:", err));
72
86
  }
73
87
  else {
74
88
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fxri/swagger2api",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "基于 swagger-typescript-api,将 Swagger 文档自动转为 TypeScript 格式的 API 文件",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -34,6 +34,14 @@
34
34
  "publishConfig": {
35
35
  "registry": "https://registry.npmjs.org/"
36
36
  },
37
+ "homepage": "https://github.com/fxri-net/fxri-swagger2api#readme",
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "https://github.com/fxri-net/fxri-swagger2api.git"
41
+ },
42
+ "bugs": {
43
+ "url": "https://github.com/fxri-net/fxri-swagger2api/issues"
44
+ },
37
45
  "scripts": {
38
46
  "dev": "pnpm build && node ./dist/index.js",
39
47
  "prebuild": "rimraf dist",