@karry.sun/yapi-gen 0.2.4 → 0.2.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.
- package/README.md +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +19 -0
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +9 -24
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -110,7 +110,7 @@ pnpm yapi-gen --output-dir src/yapi --mapping-file src/yapi/gen-api-mapping.json
|
|
|
110
110
|
| `outputDir` | 生成根目录,默认 `src/yapi` | 否 |
|
|
111
111
|
| `projects` | 项目列表(token、categories) | 是 |
|
|
112
112
|
| `dataKey` | 业务数据字段(如 `'result'` / `'data'`),axios/nuxt-bbm 适配器会据此从响应中解包业务数据 | 否 |
|
|
113
|
-
| `preproccessInterface` |
|
|
113
|
+
| `preproccessInterface` | 预处理接口:可过滤或改写。不填时已内置按 YTT_INTERFACE_IDS / YTT_CATEGORY_IDS 过滤(支持按接口/分类生成) | 否 |
|
|
114
114
|
|
|
115
115
|
---
|
|
116
116
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAkClD;;GAEG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,iBAAiB,GAAG,iBAAiB,CAetE;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,iBAAiB,GAAG,iBAAiB,CAEhF;AAED,YAAY,EACV,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,UAAU,CAAC"}
|
package/dist/config/index.js
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
import { getDefaultConfig } from './schema';
|
|
2
|
+
/** 默认 preproccessInterface:按 YTT_INTERFACE_IDS / YTT_CATEGORY_IDS 过滤,支持按接口/分类生成 */
|
|
3
|
+
function getDefaultPreproccessInterface(interfaceInfo) {
|
|
4
|
+
const ids = process.env.YTT_INTERFACE_IDS;
|
|
5
|
+
const catIds = process.env.YTT_CATEGORY_IDS;
|
|
6
|
+
if (ids) {
|
|
7
|
+
const allowList = ids.split(',').map((s) => parseInt(s.trim(), 10));
|
|
8
|
+
if (!allowList.includes(interfaceInfo._id))
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
else if (catIds) {
|
|
12
|
+
const allowList = catIds.split(',').map((s) => s.trim());
|
|
13
|
+
if (!allowList.includes(String(interfaceInfo.catid)))
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
return interfaceInfo;
|
|
17
|
+
}
|
|
2
18
|
/** 默认 outputFilePath:按 outputDir + 分类映射生成,支持 YTT_INTERFACE_IDS / YTT_CAT_MAPPING */
|
|
3
19
|
function getDefaultOutputFilePath(outputDir) {
|
|
4
20
|
return (interfaceInfo) => {
|
|
@@ -32,6 +48,9 @@ export function mergeConfig(user) {
|
|
|
32
48
|
const outputDir = merged.outputDir ?? 'src/yapi';
|
|
33
49
|
merged.outputFilePath = getDefaultOutputFilePath(outputDir);
|
|
34
50
|
}
|
|
51
|
+
if (merged.preproccessInterface == null) {
|
|
52
|
+
merged.preproccessInterface = getDefaultPreproccessInterface;
|
|
53
|
+
}
|
|
35
54
|
return merged;
|
|
36
55
|
}
|
|
37
56
|
/**
|
package/dist/run.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AA0IA,wBAAgB,GAAG,CAAC,OAAO,GAAE;IAC3B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACZ,GAAG,MAAM,CAqFd"}
|
package/dist/run.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { spawnSync } from 'child_process';
|
|
7
7
|
import { existsSync, mkdirSync, writeFileSync } from 'fs';
|
|
8
|
-
import { resolve, dirname,
|
|
8
|
+
import { resolve, dirname, join } from 'path';
|
|
9
9
|
import { fileURLToPath } from 'url';
|
|
10
10
|
import { createRequire } from 'module';
|
|
11
11
|
import { readFileSync } from 'fs';
|
|
@@ -51,21 +51,19 @@ function findConfig(cwd) {
|
|
|
51
51
|
function getWrapperContent(cwd, configPath) {
|
|
52
52
|
const packageName = getPackageName();
|
|
53
53
|
const absoluteConfig = resolve(cwd, configPath);
|
|
54
|
-
const
|
|
55
|
-
const configBase = basename(absoluteConfig).replace(/\.[^.]+$/, '') || 'yapi-gen.config';
|
|
56
|
-
const wrapperDir = resolve(cwd, WRAPPER_DIR);
|
|
57
|
-
const rel = relative(wrapperDir, configDir).replace(/\\/g, '/');
|
|
58
|
-
const relativeImport = (rel ? rel + '/' : '') + configBase;
|
|
54
|
+
const configPathEscaped = JSON.stringify(absoluteConfig);
|
|
59
55
|
return `/* 由 yapi-gen 自动生成,请勿修改 */
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
const { defineConfig } = require('yapi-to-typescript');
|
|
57
|
+
const { resolveConfig } = require('${packageName}');
|
|
58
|
+
const { createRequire } = require('module');
|
|
62
59
|
|
|
63
|
-
const
|
|
60
|
+
const require = createRequire(__filename);
|
|
61
|
+
const userConfig = require(${configPathEscaped});
|
|
64
62
|
const raw = userConfig.default ?? userConfig;
|
|
65
63
|
const configList = Array.isArray(raw) ? raw : [raw];
|
|
66
64
|
const resolvedList = configList.map((c) => resolveConfig(c, process.cwd()));
|
|
67
65
|
|
|
68
|
-
|
|
66
|
+
module.exports = { default: defineConfig(resolvedList) };
|
|
69
67
|
`;
|
|
70
68
|
}
|
|
71
69
|
function runInit(cwd) {
|
|
@@ -92,21 +90,8 @@ export default defineYapiGenConfig({
|
|
|
92
90
|
// axios 时可选指定实例路径,默认 '/@/utils/http/axios'
|
|
93
91
|
// requestAdapter: { type: 'axios', axiosInstancePath: '/@/utils/http/axios' },
|
|
94
92
|
requestAdapter: 'axios',
|
|
95
|
-
// outputFilePath
|
|
93
|
+
// outputFilePath、preproccessInterface 可不填,已内置按 outputDir + 分类映射及按接口/分类过滤
|
|
96
94
|
dataKey: 'result',
|
|
97
|
-
preproccessInterface(interfaceInfo) {
|
|
98
|
-
// 可选:按环境变量过滤接口。YTT_INTERFACE_IDS=1,2,3 或 YTT_CATEGORY_IDS=401,413
|
|
99
|
-
const ids = process.env.YTT_INTERFACE_IDS;
|
|
100
|
-
const catIds = process.env.YTT_CATEGORY_IDS;
|
|
101
|
-
if (ids) {
|
|
102
|
-
const allowList = ids.split(',').map((s) => parseInt(s.trim(), 10));
|
|
103
|
-
if (!allowList.includes(interfaceInfo._id)) return false;
|
|
104
|
-
} else if (catIds) {
|
|
105
|
-
const allowList = catIds.split(',').map((s) => s.trim());
|
|
106
|
-
if (!allowList.includes(String(interfaceInfo.catid))) return false;
|
|
107
|
-
}
|
|
108
|
-
return interfaceInfo;
|
|
109
|
-
},
|
|
110
95
|
projects: [
|
|
111
96
|
{
|
|
112
97
|
token: process.env.YAPI_TOKEN || 'your-project-token',
|