vite-plugin-swagger-typescript-api-transform 0.0.1
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/LICENSE +21 -0
- package/README.md +195 -0
- package/dist/astro.d.ts +7 -0
- package/dist/astro.js +14 -0
- package/dist/esbuild.d.ts +8 -0
- package/dist/esbuild.js +9 -0
- package/dist/farm.d.ts +8 -0
- package/dist/farm.js +9 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +4 -0
- package/dist/nuxt.d.ts +9 -0
- package/dist/nuxt.js +21 -0
- package/dist/prompt-CQ_38Ofh.js +852 -0
- package/dist/rollup.d.ts +8 -0
- package/dist/rollup.js +9 -0
- package/dist/rspack.d.ts +7 -0
- package/dist/rspack.js +9 -0
- package/dist/src-DPpaOQvV.js +197001 -0
- package/dist/types-CpgPraRT.d.ts +69 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.js +0 -0
- package/dist/utils-BypLbD1p.js +112 -0
- package/dist/utils.d.ts +80 -0
- package/dist/utils.js +3 -0
- package/dist/vite-BKknryyS.js +8 -0
- package/dist/vite.d.ts +8 -0
- package/dist/vite.js +5 -0
- package/dist/webpack-9obP3bLC.js +8 -0
- package/dist/webpack.d.ts +8 -0
- package/dist/webpack.js +5 -0
- package/package.json +114 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* HTTP 客户端类型
|
|
4
|
+
*/
|
|
5
|
+
type HttpClientType = 'fetch' | 'axios';
|
|
6
|
+
/**
|
|
7
|
+
* 合并后的配置选项类型
|
|
8
|
+
*/
|
|
9
|
+
interface MergedOptions {
|
|
10
|
+
rootDir?: string;
|
|
11
|
+
outputDir: string;
|
|
12
|
+
generateClient: boolean;
|
|
13
|
+
httpClient: HttpClientType;
|
|
14
|
+
baseURL?: string;
|
|
15
|
+
watch: boolean;
|
|
16
|
+
moduleNameFormat: 'kebab' | 'camel' | 'pascal';
|
|
17
|
+
apiClassName?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 插件配置选项
|
|
21
|
+
*/
|
|
22
|
+
interface Options {
|
|
23
|
+
/**
|
|
24
|
+
* 扫描的根目录
|
|
25
|
+
* 默认值:process.cwd()(当前工作目录)
|
|
26
|
+
*/
|
|
27
|
+
rootDir?: string;
|
|
28
|
+
/**
|
|
29
|
+
* 生成的 API 代码输出目录(相对于项目根目录)
|
|
30
|
+
* 默认值:'src/api'
|
|
31
|
+
*/
|
|
32
|
+
outputDir?: string;
|
|
33
|
+
/**
|
|
34
|
+
* 是否生成请求函数
|
|
35
|
+
* 默认值:true
|
|
36
|
+
*/
|
|
37
|
+
generateClient?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* HTTP 客户端类型
|
|
40
|
+
* 默认值:'axios'
|
|
41
|
+
*/
|
|
42
|
+
httpClient?: 'axios' | 'fetch';
|
|
43
|
+
/**
|
|
44
|
+
* API 基础 URL
|
|
45
|
+
* 默认值:''
|
|
46
|
+
*/
|
|
47
|
+
baseURL?: string;
|
|
48
|
+
/**
|
|
49
|
+
* 是否在开发模式下监听文件变化并重新生成
|
|
50
|
+
* 默认值:true
|
|
51
|
+
*/
|
|
52
|
+
watch?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* 包含的 yaml 文件匹配模式
|
|
55
|
+
* 默认值:匹配所有 yaml 文件夹下的 .yaml 和 .yml 文件
|
|
56
|
+
*/
|
|
57
|
+
include?: string[];
|
|
58
|
+
/**
|
|
59
|
+
* 排除的文件匹配模式
|
|
60
|
+
* 默认值:[]
|
|
61
|
+
*/
|
|
62
|
+
exclude?: string[];
|
|
63
|
+
/**
|
|
64
|
+
* 生成的模块名称格式
|
|
65
|
+
* 默认值:'kebab'(短横线命名)
|
|
66
|
+
*/
|
|
67
|
+
moduleNameFormat?: 'kebab' | 'camel' | 'pascal';
|
|
68
|
+
} //#endregion
|
|
69
|
+
export { HttpClientType, MergedOptions, Options };
|
package/dist/types.d.ts
ADDED
package/dist/types.js
ADDED
|
File without changes
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import _ from "lodash-es";
|
|
4
|
+
|
|
5
|
+
//#region src/utils.ts
|
|
6
|
+
/**
|
|
7
|
+
* 安全读取目录内容
|
|
8
|
+
* 如果目录不存在或读取失败,返回空数组
|
|
9
|
+
*
|
|
10
|
+
* @param dir - 要读取的目录路径
|
|
11
|
+
* @returns 目录中的文件和子目录列表
|
|
12
|
+
*/
|
|
13
|
+
function safeReaddir(dir) {
|
|
14
|
+
try {
|
|
15
|
+
return fs.readdirSync(dir, { withFileTypes: true });
|
|
16
|
+
} catch {
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 递归查找项目中所有名为 "yaml" 的目录
|
|
22
|
+
*
|
|
23
|
+
* @param rootDir - 搜索的根目录
|
|
24
|
+
* @returns 所有名为 "yaml" 的目录路径数组
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* // 假设项目结构如下:
|
|
28
|
+
* // project/
|
|
29
|
+
* // yaml/
|
|
30
|
+
* // src/
|
|
31
|
+
* // yaml/
|
|
32
|
+
* // findYamlDirectories('/project') => ['/project/yaml', '/project/src/yaml']
|
|
33
|
+
*/
|
|
34
|
+
function findYamlDirectories(rootDir) {
|
|
35
|
+
const walk = (dir) => {
|
|
36
|
+
const entries = safeReaddir(dir);
|
|
37
|
+
const yamlDirs = _(entries).filter("isDirectory").filter({ name: "yaml" }).map((entry) => path.join(dir, entry.name)).value();
|
|
38
|
+
const subDirs = _(entries).filter("isDirectory").reject({ name: "yaml" }).map((entry) => walk(path.join(dir, entry.name))).flatten().value();
|
|
39
|
+
return [...yamlDirs, ...subDirs];
|
|
40
|
+
};
|
|
41
|
+
return walk(rootDir);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* 递归查找目录中的所有 YAML 文件(.yaml 和 .yml)
|
|
45
|
+
*
|
|
46
|
+
* @param dir - 要搜索的目录
|
|
47
|
+
* @returns 所有 YAML 文件的完整路径数组
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* // 查找 yaml 目录下的所有 yaml 文件
|
|
51
|
+
* findYamlFiles('/project/yaml') => ['/project/yaml/user.yaml', '/project/yaml/order.yml']
|
|
52
|
+
*/
|
|
53
|
+
function findYamlFiles(dir) {
|
|
54
|
+
const walk = (currentDir) => {
|
|
55
|
+
const entries = safeReaddir(currentDir);
|
|
56
|
+
const files = _(entries).filter("isFile").filter((entry) => /\.ya?ml$/i.test(entry.name)).map((entry) => path.join(currentDir, entry.name)).value();
|
|
57
|
+
const subDirFiles = _(entries).filter("isDirectory").map((entry) => walk(path.join(currentDir, entry.name))).flatten().value();
|
|
58
|
+
return [...files, ...subDirFiles];
|
|
59
|
+
};
|
|
60
|
+
return walk(dir);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 将文件名转换为指定的命名格式
|
|
64
|
+
*
|
|
65
|
+
* @param name - 原始文件名(不含扩展名)
|
|
66
|
+
* @param format - 目标命名格式
|
|
67
|
+
* @returns 转换后的模块名称
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* formatModuleName('user-profile', 'kebab') => 'user-profile'
|
|
71
|
+
* formatModuleName('user-profile', 'camel') => 'userProfile'
|
|
72
|
+
* formatModuleName('user-profile', 'pascal') => 'UserProfile'
|
|
73
|
+
*/
|
|
74
|
+
function formatModuleName(name, format) {
|
|
75
|
+
const kebabName = name.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[_\s]+/g, "-").toLowerCase();
|
|
76
|
+
if (format === "kebab") return kebabName;
|
|
77
|
+
const camelName = kebabName.split("-").map((word, index) => {
|
|
78
|
+
if (index === 0 && format === "camel") return word;
|
|
79
|
+
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
80
|
+
}).join("");
|
|
81
|
+
return camelName;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* 确保目录存在,如果不存在则创建
|
|
85
|
+
*
|
|
86
|
+
* @param dir - 目录路径
|
|
87
|
+
*/
|
|
88
|
+
function ensureDir(dir) {
|
|
89
|
+
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* 判断文件是否存在
|
|
93
|
+
*
|
|
94
|
+
* @param filePath - 文件路径
|
|
95
|
+
* @returns 文件是否存在
|
|
96
|
+
*/
|
|
97
|
+
function fileExists(filePath) {
|
|
98
|
+
return fs.existsSync(filePath);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* 获取相对于项目根目录的相对路径
|
|
102
|
+
*
|
|
103
|
+
* @param filePath - 文件绝对路径
|
|
104
|
+
* @param rootDir - 项目根目录
|
|
105
|
+
* @returns 相对路径
|
|
106
|
+
*/
|
|
107
|
+
function getRelativePath(filePath, rootDir) {
|
|
108
|
+
return path.relative(rootDir, filePath);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
//#endregion
|
|
112
|
+
export { ensureDir, fileExists, findYamlDirectories, findYamlFiles, formatModuleName, getRelativePath, safeReaddir };
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
|
|
3
|
+
//#region src/utils.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* 安全读取目录内容
|
|
6
|
+
* 如果目录不存在或读取失败,返回空数组
|
|
7
|
+
*
|
|
8
|
+
* @param dir - 要读取的目录路径
|
|
9
|
+
* @returns 目录中的文件和子目录列表
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 安全读取目录内容
|
|
14
|
+
* 如果目录不存在或读取失败,返回空数组
|
|
15
|
+
*
|
|
16
|
+
* @param dir - 要读取的目录路径
|
|
17
|
+
* @returns 目录中的文件和子目录列表
|
|
18
|
+
*/
|
|
19
|
+
declare function safeReaddir(dir: string): fs.Dirent[];
|
|
20
|
+
/**
|
|
21
|
+
* 递归查找项目中所有名为 "yaml" 的目录
|
|
22
|
+
*
|
|
23
|
+
* @param rootDir - 搜索的根目录
|
|
24
|
+
* @returns 所有名为 "yaml" 的目录路径数组
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* // 假设项目结构如下:
|
|
28
|
+
* // project/
|
|
29
|
+
* // yaml/
|
|
30
|
+
* // src/
|
|
31
|
+
* // yaml/
|
|
32
|
+
* // findYamlDirectories('/project') => ['/project/yaml', '/project/src/yaml']
|
|
33
|
+
*/
|
|
34
|
+
declare function findYamlDirectories(rootDir: string): string[];
|
|
35
|
+
/**
|
|
36
|
+
* 递归查找目录中的所有 YAML 文件(.yaml 和 .yml)
|
|
37
|
+
*
|
|
38
|
+
* @param dir - 要搜索的目录
|
|
39
|
+
* @returns 所有 YAML 文件的完整路径数组
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* // 查找 yaml 目录下的所有 yaml 文件
|
|
43
|
+
* findYamlFiles('/project/yaml') => ['/project/yaml/user.yaml', '/project/yaml/order.yml']
|
|
44
|
+
*/
|
|
45
|
+
declare function findYamlFiles(dir: string): string[];
|
|
46
|
+
/**
|
|
47
|
+
* 将文件名转换为指定的命名格式
|
|
48
|
+
*
|
|
49
|
+
* @param name - 原始文件名(不含扩展名)
|
|
50
|
+
* @param format - 目标命名格式
|
|
51
|
+
* @returns 转换后的模块名称
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* formatModuleName('user-profile', 'kebab') => 'user-profile'
|
|
55
|
+
* formatModuleName('user-profile', 'camel') => 'userProfile'
|
|
56
|
+
* formatModuleName('user-profile', 'pascal') => 'UserProfile'
|
|
57
|
+
*/
|
|
58
|
+
declare function formatModuleName(name: string, format: 'kebab' | 'camel' | 'pascal'): string;
|
|
59
|
+
/**
|
|
60
|
+
* 确保目录存在,如果不存在则创建
|
|
61
|
+
*
|
|
62
|
+
* @param dir - 目录路径
|
|
63
|
+
*/
|
|
64
|
+
declare function ensureDir(dir: string): void;
|
|
65
|
+
/**
|
|
66
|
+
* 判断文件是否存在
|
|
67
|
+
*
|
|
68
|
+
* @param filePath - 文件路径
|
|
69
|
+
* @returns 文件是否存在
|
|
70
|
+
*/
|
|
71
|
+
declare function fileExists(filePath: string): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* 获取相对于项目根目录的相对路径
|
|
74
|
+
*
|
|
75
|
+
* @param filePath - 文件绝对路径
|
|
76
|
+
* @param rootDir - 项目根目录
|
|
77
|
+
* @returns 相对路径
|
|
78
|
+
*/
|
|
79
|
+
declare function getRelativePath(filePath: string, rootDir: string): string; //#endregion
|
|
80
|
+
export { ensureDir, fileExists, findYamlDirectories, findYamlFiles, formatModuleName, getRelativePath, safeReaddir };
|
package/dist/utils.js
ADDED
package/dist/vite.d.ts
ADDED
package/dist/vite.js
ADDED
package/dist/webpack.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vite-plugin-swagger-typescript-api-transform",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"packageManager": "pnpm@10.11.0",
|
|
6
|
+
"description": "",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"homepage": "https://github.com/antfu/unplugin-starter#readme",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/antfu/unplugin-starter.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/antfu/unplugin-starter/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"unplugin",
|
|
18
|
+
"vite",
|
|
19
|
+
"webpack",
|
|
20
|
+
"rollup",
|
|
21
|
+
"transform"
|
|
22
|
+
],
|
|
23
|
+
"exports": {
|
|
24
|
+
".": "./dist/index.js",
|
|
25
|
+
"./astro": "./dist/astro.js",
|
|
26
|
+
"./esbuild": "./dist/esbuild.js",
|
|
27
|
+
"./farm": "./dist/farm.js",
|
|
28
|
+
"./nuxt": "./dist/nuxt.js",
|
|
29
|
+
"./rollup": "./dist/rollup.js",
|
|
30
|
+
"./rspack": "./dist/rspack.js",
|
|
31
|
+
"./types": "./dist/types.js",
|
|
32
|
+
"./vite": "./dist/vite.js",
|
|
33
|
+
"./webpack": "./dist/webpack.js",
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
36
|
+
"main": "./dist/index.js",
|
|
37
|
+
"module": "./dist/index.js",
|
|
38
|
+
"types": "./dist/index.d.ts",
|
|
39
|
+
"typesVersions": {
|
|
40
|
+
"*": {
|
|
41
|
+
"*": [
|
|
42
|
+
"./dist/*",
|
|
43
|
+
"./*"
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"files": [
|
|
48
|
+
"dist"
|
|
49
|
+
],
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "tsdown",
|
|
52
|
+
"dev": "tsdown -w",
|
|
53
|
+
"lint": "eslint .",
|
|
54
|
+
"play": "npm -C playground run dev",
|
|
55
|
+
"prepublishOnly": "npm run build",
|
|
56
|
+
"release": "bumpp && pnpm publish",
|
|
57
|
+
"start": "tsx src/index.ts",
|
|
58
|
+
"test": "vitest"
|
|
59
|
+
},
|
|
60
|
+
"peerDependencies": {
|
|
61
|
+
"@farmfe/core": ">=1",
|
|
62
|
+
"@nuxt/kit": "^3",
|
|
63
|
+
"@nuxt/schema": "^3",
|
|
64
|
+
"esbuild": "*",
|
|
65
|
+
"rollup": "^3",
|
|
66
|
+
"vite": ">=3",
|
|
67
|
+
"webpack": "^4 || ^5"
|
|
68
|
+
},
|
|
69
|
+
"peerDependenciesMeta": {
|
|
70
|
+
"@farmfe/core": {
|
|
71
|
+
"optional": true
|
|
72
|
+
},
|
|
73
|
+
"@nuxt/kit": {
|
|
74
|
+
"optional": true
|
|
75
|
+
},
|
|
76
|
+
"@nuxt/schema": {
|
|
77
|
+
"optional": true
|
|
78
|
+
},
|
|
79
|
+
"esbuild": {
|
|
80
|
+
"optional": true
|
|
81
|
+
},
|
|
82
|
+
"rollup": {
|
|
83
|
+
"optional": true
|
|
84
|
+
},
|
|
85
|
+
"vite": {
|
|
86
|
+
"optional": true
|
|
87
|
+
},
|
|
88
|
+
"webpack": {
|
|
89
|
+
"optional": true
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
"dependencies": {
|
|
93
|
+
"lodash-es": "^4.18.1",
|
|
94
|
+
"unplugin": "^2.3.4"
|
|
95
|
+
},
|
|
96
|
+
"devDependencies": {
|
|
97
|
+
"@antfu/eslint-config": "^4.13.2",
|
|
98
|
+
"@nuxt/kit": "^3.17.4",
|
|
99
|
+
"@nuxt/schema": "^3.17.4",
|
|
100
|
+
"@types/lodash-es": "^4.17.12",
|
|
101
|
+
"@types/node": "^22.15.21",
|
|
102
|
+
"bumpp": "^10.1.1",
|
|
103
|
+
"eslint": "^9.27.0",
|
|
104
|
+
"nodemon": "^3.1.10",
|
|
105
|
+
"rollup": "^4.41.0",
|
|
106
|
+
"swagger-typescript-api": "^13.6.7",
|
|
107
|
+
"tsdown": "^0.12.0",
|
|
108
|
+
"tsx": "^4.19.4",
|
|
109
|
+
"typescript": "^5.8.3",
|
|
110
|
+
"vite": "^6.3.5",
|
|
111
|
+
"vitest": "^3.1.4",
|
|
112
|
+
"webpack": "^5.99.9"
|
|
113
|
+
}
|
|
114
|
+
}
|