@1szx1/vite-plugin-swagger2ts 1.3.0 → 1.3.2

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/dist/bin.cjs CHANGED
@@ -6,5 +6,6 @@ require('path');
6
6
  require('swagger2openapi');
7
7
  require('cross-fetch');
8
8
  require('unconfig');
9
+ require('chalk');
9
10
 
10
11
  index.default();
package/dist/bin.mjs CHANGED
@@ -4,5 +4,6 @@ import 'path';
4
4
  import 'swagger2openapi';
5
5
  import 'cross-fetch';
6
6
  import 'unconfig';
7
+ import 'chalk';
7
8
 
8
9
  swagger2TsPlugin();
package/dist/index.cjs CHANGED
@@ -7,10 +7,12 @@ const path = require('path');
7
7
  const swagger2openapi = require('swagger2openapi');
8
8
  const fetch = require('cross-fetch');
9
9
  const unconfig = require('unconfig');
10
+ const chalk = require('chalk');
10
11
 
11
12
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
12
13
 
13
14
  const fetch__default = /*#__PURE__*/_interopDefaultCompat(fetch);
15
+ const chalk__default = /*#__PURE__*/_interopDefaultCompat(chalk);
14
16
 
15
17
  function loadConfig() {
16
18
  return unconfig.loadConfig({
@@ -231,14 +233,14 @@ function convertObjPromise(docs) {
231
233
  async function loadSwaggerSource(options) {
232
234
  const { swaggerUrl, jsonUrl, jsonPath, output, formatDocs, formatSchema } = options;
233
235
  async function genInterface(docs, docsName) {
234
- let openapiDocs = formatDocs ? formatDocs(docs) : docs;
235
- if (!("openapi" in openapiDocs)) {
236
+ docs = formatDocs ? formatDocs(docs) : docs;
237
+ if (!("openapi" in docs)) {
236
238
  if (docs.swagger)
237
- openapiDocs = await convertObjPromise(openapiDocs);
239
+ docs = await convertObjPromise(docs);
238
240
  else
239
241
  throw new Error(JSON.stringify(docs));
240
242
  }
241
- return generateDocs(openapiDocs, { docsName, baseUrl: docs.basePath ?? "", formatSchema });
243
+ return generateDocs(docs, { docsName, baseUrl: docs.basePath ?? "", formatSchema });
242
244
  }
243
245
  async function genResourcesCode(source) {
244
246
  const { url, name } = source;
@@ -247,7 +249,7 @@ async function loadSwaggerSource(options) {
247
249
  const code2 = await genInterface(docs, name);
248
250
  return code2;
249
251
  } catch (error) {
250
- console.log(`%c[vite-plugin-swagger2ts]: ${name} error`, "color: #ff0000;", error.message);
252
+ console.log(chalk__default.yellow(`[vite-plugin-swagger2ts]: ${name} error;`) + error.message);
251
253
  return "";
252
254
  }
253
255
  }
@@ -255,18 +257,18 @@ async function loadSwaggerSource(options) {
255
257
  let sources2 = void 0;
256
258
  let interfaces2 = [];
257
259
  if (typeof swaggerUrl === "string") {
258
- const resources = await fetchUrl(`${swaggerUrl}/swagger-resources`).catch((error) => error);
260
+ const resources = await fetchUrl(`${swaggerUrl}/swagger-resources;`).catch((error) => error);
259
261
  if (Array.isArray(resources)) {
260
262
  sources2 = resources;
261
263
  interfaces2.push(...await Promise.all(sources2.map(genResourcesCode)));
262
264
  } else {
263
- console.log(`%c[vite-plugin-swagger2ts]: resources error`, "color: #ff0000;", JSON.stringify(resources));
265
+ console.log(chalk__default.yellow(`[vite-plugin-swagger2ts]: resources error`) + JSON.stringify(resources));
264
266
  }
265
267
  }
266
268
  if (typeof jsonUrl === "string") {
267
269
  const swaggerJson = await fetchUrl(jsonUrl);
268
270
  if (!swaggerJson.info)
269
- return console.log(`%c[vite-plugin-swagger2ts]: jsonUrl error`, "color: #ff0000;", JSON.stringify(swaggerJson));
271
+ return console.log(chalk__default.yellow(`[vite-plugin-swagger2ts]: jsonUrl error;`) + JSON.stringify(swaggerJson));
270
272
  interfaces2.push(await genInterface(swaggerJson, getApiName(swaggerJson)));
271
273
  }
272
274
  if (typeof jsonPath === "string") {
package/dist/index.mjs CHANGED
@@ -3,6 +3,7 @@ import { resolve } from 'path';
3
3
  import { convertObj } from 'swagger2openapi';
4
4
  import fetch from 'cross-fetch';
5
5
  import { loadConfig as loadConfig$1 } from 'unconfig';
6
+ import chalk from 'chalk';
6
7
 
7
8
  function loadConfig() {
8
9
  return loadConfig$1({
@@ -223,14 +224,14 @@ function convertObjPromise(docs) {
223
224
  async function loadSwaggerSource(options) {
224
225
  const { swaggerUrl, jsonUrl, jsonPath, output, formatDocs, formatSchema } = options;
225
226
  async function genInterface(docs, docsName) {
226
- let openapiDocs = formatDocs ? formatDocs(docs) : docs;
227
- if (!("openapi" in openapiDocs)) {
227
+ docs = formatDocs ? formatDocs(docs) : docs;
228
+ if (!("openapi" in docs)) {
228
229
  if (docs.swagger)
229
- openapiDocs = await convertObjPromise(openapiDocs);
230
+ docs = await convertObjPromise(docs);
230
231
  else
231
232
  throw new Error(JSON.stringify(docs));
232
233
  }
233
- return generateDocs(openapiDocs, { docsName, baseUrl: docs.basePath ?? "", formatSchema });
234
+ return generateDocs(docs, { docsName, baseUrl: docs.basePath ?? "", formatSchema });
234
235
  }
235
236
  async function genResourcesCode(source) {
236
237
  const { url, name } = source;
@@ -239,7 +240,7 @@ async function loadSwaggerSource(options) {
239
240
  const code2 = await genInterface(docs, name);
240
241
  return code2;
241
242
  } catch (error) {
242
- console.log(`%c[vite-plugin-swagger2ts]: ${name} error`, "color: #ff0000;", error.message);
243
+ console.log(chalk.yellow(`[vite-plugin-swagger2ts]: ${name} error;`) + error.message);
243
244
  return "";
244
245
  }
245
246
  }
@@ -247,18 +248,18 @@ async function loadSwaggerSource(options) {
247
248
  let sources2 = void 0;
248
249
  let interfaces2 = [];
249
250
  if (typeof swaggerUrl === "string") {
250
- const resources = await fetchUrl(`${swaggerUrl}/swagger-resources`).catch((error) => error);
251
+ const resources = await fetchUrl(`${swaggerUrl}/swagger-resources;`).catch((error) => error);
251
252
  if (Array.isArray(resources)) {
252
253
  sources2 = resources;
253
254
  interfaces2.push(...await Promise.all(sources2.map(genResourcesCode)));
254
255
  } else {
255
- console.log(`%c[vite-plugin-swagger2ts]: resources error`, "color: #ff0000;", JSON.stringify(resources));
256
+ console.log(chalk.yellow(`[vite-plugin-swagger2ts]: resources error`) + JSON.stringify(resources));
256
257
  }
257
258
  }
258
259
  if (typeof jsonUrl === "string") {
259
260
  const swaggerJson = await fetchUrl(jsonUrl);
260
261
  if (!swaggerJson.info)
261
- return console.log(`%c[vite-plugin-swagger2ts]: jsonUrl error`, "color: #ff0000;", JSON.stringify(swaggerJson));
262
+ return console.log(chalk.yellow(`[vite-plugin-swagger2ts]: jsonUrl error;`) + JSON.stringify(swaggerJson));
262
263
  interfaces2.push(await genInterface(swaggerJson, getApiName(swaggerJson)));
263
264
  }
264
265
  if (typeof jsonPath === "string") {
package/package.json CHANGED
@@ -1,108 +1,112 @@
1
- {
2
- "name": "@1szx1/vite-plugin-swagger2ts",
3
- "description": "forked from https://github.com/morelearn1990/vite-plugin-swagger2ts",
4
- "version": "1.3.0",
5
- "license": "MIT",
6
- "author": "1SZX1 <2414126198@qq.com>",
7
- "repository": {
8
- "type": "git",
9
- "url": "https://github.com/1SZX1/vite-plugin-swagger2ts"
10
- },
11
- "homepage": "https://github.com/1SZX1/vite-plugin-swagger2ts",
12
- "bugs": "https://github.com/1SZX1/vite-plugin-swagger2ts/issues",
13
- "files": [
14
- "dist"
15
- ],
16
- "exports": {
17
- ".": {
18
- "require": "./dist/index.cjs",
19
- "import": "./dist/index.mjs",
20
- "types": "./dist/index.d.ts"
21
- },
22
- "./adapters": {
23
- "require": "./dist/adapters.cjs",
24
- "import": "./dist/adapters.mjs",
25
- "types": "./dist/adapters.d.ts"
26
- }
27
- },
28
- "main": "dist/index.cjs",
29
- "module": "dist/index.mjs",
30
- "types": "dist/index.d.ts",
31
- "typesVersions": {
32
- "*": {
33
- "adapters": [
34
- "./dist/adapters"
35
- ]
36
- }
37
- },
38
- "bin": {
39
- "swagger2ts": "./dist/bin.mjs"
40
- },
41
- "scripts": {
42
- "build": "unbuild",
43
- "stub": "unbuild --stub",
44
- "prepublishOnly": "pnpm run build",
45
- "release": "pnpx git-ensure -a && pnpx bumpp --commit --tag --push",
46
- "demo:dev": "pnpm -C examples/demo run dev",
47
- "demo:build": "pnpm -C examples/demo run build",
48
- "demo:preview": "pnpm -C examples/demo run preview",
49
- "test": "jest",
50
- "lint": "eslint --fix --ext .ts ./",
51
- "version": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md",
52
- "preinstall": "npx only-allow pnpm"
53
- },
54
- "dependencies": {
55
- "axios": "^1.4.0",
56
- "cross-fetch": "^3.1.5",
57
- "luch-request": "^3.1.0",
58
- "openapi3-ts": "^2.0.2",
59
- "swagger2openapi": "^7.0.8",
60
- "unconfig": "^0.3.9"
61
- },
62
- "peerDependencies": {
63
- "axios": "^1.4.0",
64
- "luch-request": "^3.1.0",
65
- "vite": "^2.0.0"
66
- },
67
- "devDependencies": {
68
- "@antfu/eslint-config": "^0.6.6",
69
- "@commitlint/cli": "^12.1.4",
70
- "@commitlint/config-conventional": "^12.1.4",
71
- "@dcloudio/types": "^3.3.3",
72
- "@types/eslint": "^8.44.0",
73
- "@types/jest": "^26.0.24",
74
- "@types/node": "^14.18.12",
75
- "@typescript-eslint/eslint-plugin": "^4.33.0",
76
- "@typescript-eslint/parser": "^5.14.0",
77
- "conventional-changelog": "^3.1.25",
78
- "cz-conventional-changelog": "^3.3.0",
79
- "eslint": "^8.44.0",
80
- "husky": "^8.0.3",
81
- "jest": "^26.6.3",
82
- "jest-esbuild": "^0.1.6",
83
- "lint-staged": "^10.5.4",
84
- "typescript": "^4.7.0",
85
- "unbuild": "^2.0.0",
86
- "vite": "^2.8.6"
87
- },
88
- "lint-staged": {
89
- "*.{ts}": "eslint --fix --ext",
90
- "*.{ts,md}": "prettier --write"
91
- },
92
- "husky": {
93
- "hooks": {
94
- "commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
95
- "pre-commit": "lint-staged"
96
- }
97
- },
98
- "commitlint": {
99
- "extends": [
100
- "@commitlint/config-conventional"
101
- ]
102
- },
103
- "config": {
104
- "commitizen": {
105
- "path": "./node_modules/cz-conventional-changelog"
106
- }
107
- }
1
+ {
2
+ "name": "@1szx1/vite-plugin-swagger2ts",
3
+ "description": "forked from https://github.com/morelearn1990/vite-plugin-swagger2ts",
4
+ "version": "1.3.2",
5
+ "license": "MIT",
6
+ "author": "1SZX1 <2414126198@qq.com>",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/1SZX1/vite-plugin-swagger2ts"
10
+ },
11
+ "homepage": "https://github.com/1SZX1/vite-plugin-swagger2ts",
12
+ "bugs": "https://github.com/1SZX1/vite-plugin-swagger2ts/issues",
13
+ "publishConfig": {
14
+ "registry": "https://registry.npmjs.org"
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "exports": {
20
+ ".": {
21
+ "require": "./dist/index.cjs",
22
+ "import": "./dist/index.mjs",
23
+ "types": "./dist/index.d.ts"
24
+ },
25
+ "./adapters": {
26
+ "require": "./dist/adapters.cjs",
27
+ "import": "./dist/adapters.mjs",
28
+ "types": "./dist/adapters.d.ts"
29
+ }
30
+ },
31
+ "main": "dist/index.cjs",
32
+ "module": "dist/index.mjs",
33
+ "types": "dist/index.d.ts",
34
+ "typesVersions": {
35
+ "*": {
36
+ "adapters": [
37
+ "./dist/adapters"
38
+ ]
39
+ }
40
+ },
41
+ "bin": {
42
+ "swagger2ts": "./dist/bin.mjs"
43
+ },
44
+ "scripts": {
45
+ "build": "unbuild",
46
+ "stub": "unbuild --stub",
47
+ "prepublishOnly": "pnpm run build",
48
+ "release": "pnpx git-ensure -a && pnpx bumpp --commit --tag --push",
49
+ "demo:dev": "pnpm -C examples/demo run dev",
50
+ "demo:build": "pnpm -C examples/demo run build",
51
+ "demo:preview": "pnpm -C examples/demo run preview",
52
+ "test": "jest",
53
+ "lint": "eslint --fix --ext .ts ./",
54
+ "version": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md",
55
+ "preinstall": "npx only-allow pnpm"
56
+ },
57
+ "dependencies": {
58
+ "axios": "^1.4.0",
59
+ "cross-fetch": "^3.1.5",
60
+ "luch-request": "^3.1.0",
61
+ "openapi3-ts": "^2.0.2",
62
+ "swagger2openapi": "^7.0.8",
63
+ "unconfig": "^0.3.9"
64
+ },
65
+ "peerDependencies": {
66
+ "axios": "^1.4.0",
67
+ "luch-request": "^3.1.0",
68
+ "chalk": "^5.3.0",
69
+ "vite": "^2.0.0"
70
+ },
71
+ "devDependencies": {
72
+ "@antfu/eslint-config": "^0.6.6",
73
+ "@commitlint/cli": "^12.1.4",
74
+ "@commitlint/config-conventional": "^12.1.4",
75
+ "@dcloudio/types": "^3.3.3",
76
+ "@types/eslint": "^8.44.0",
77
+ "@types/jest": "^26.0.24",
78
+ "@types/node": "^14.18.12",
79
+ "@typescript-eslint/eslint-plugin": "^4.33.0",
80
+ "@typescript-eslint/parser": "^5.14.0",
81
+ "conventional-changelog": "^3.1.25",
82
+ "cz-conventional-changelog": "^3.3.0",
83
+ "eslint": "^8.44.0",
84
+ "husky": "^8.0.3",
85
+ "jest": "^26.6.3",
86
+ "jest-esbuild": "^0.1.6",
87
+ "lint-staged": "^10.5.4",
88
+ "typescript": "^4.7.0",
89
+ "unbuild": "^2.0.0",
90
+ "vite": "^2.8.6"
91
+ },
92
+ "lint-staged": {
93
+ "*.{ts}": "eslint --fix --ext",
94
+ "*.{ts,md}": "prettier --write"
95
+ },
96
+ "husky": {
97
+ "hooks": {
98
+ "commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
99
+ "pre-commit": "lint-staged"
100
+ }
101
+ },
102
+ "commitlint": {
103
+ "extends": [
104
+ "@commitlint/config-conventional"
105
+ ]
106
+ },
107
+ "config": {
108
+ "commitizen": {
109
+ "path": "./node_modules/cz-conventional-changelog"
110
+ }
111
+ }
108
112
  }