wormajs 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 +49 -0
- package/dist/bin/actions.js +245 -0
- package/dist/bin/cli.js +27 -0
- package/dist/bin/progressRenderer.js +47 -0
- package/dist/bin/renderer.js +551 -0
- package/dist/bin/theme.js +26 -0
- package/dist/config.js +19 -0
- package/dist/constant.js +162 -0
- package/dist/core/WorkerPool.js +102 -0
- package/dist/core/loader/astLoader/generates/array.js +34 -0
- package/dist/core/loader/astLoader/generates/enum.js +61 -0
- package/dist/core/loader/astLoader/generates/group.js +41 -0
- package/dist/core/loader/astLoader/generates/index.js +71 -0
- package/dist/core/loader/astLoader/generates/interface.js +59 -0
- package/dist/core/loader/astLoader/generates/simple.js +67 -0
- package/dist/core/loader/astLoader/generates/tuple.js +54 -0
- package/dist/core/loader/astLoader/generates/type.js +2 -0
- package/dist/core/loader/astLoader/generates/utils.js +86 -0
- package/dist/core/loader/astLoader/helper.js +21 -0
- package/dist/core/loader/astLoader/index.js +24 -0
- package/dist/core/loader/astLoader/normalize/index.js +70 -0
- package/dist/core/loader/astLoader/normalize/normalizer.js +69 -0
- package/dist/core/loader/astLoader/normalize/rules/convertTypeArray.js +68 -0
- package/dist/core/loader/astLoader/normalize/rules/handleEmptyType.js +8 -0
- package/dist/core/loader/astLoader/normalize/rules/inferType.js +43 -0
- package/dist/core/loader/astLoader/normalize/rules/mergeAnyOf.js +45 -0
- package/dist/core/loader/astLoader/normalize/rules/normalizeCombiningKeywords.js +26 -0
- package/dist/core/loader/astLoader/normalize/rules/normalizeEnum.js +38 -0
- package/dist/core/loader/astLoader/normalize/rules/normalizeNullType.js +24 -0
- package/dist/core/loader/astLoader/normalize/rules/removeRedundantKeywords.js +27 -0
- package/dist/core/loader/astLoader/normalize/rules/simplifySingleType.js +8 -0
- package/dist/core/loader/astLoader/normalize/rules/validateSchema.js +14 -0
- package/dist/core/loader/astLoader/parsers/array.js +28 -0
- package/dist/core/loader/astLoader/parsers/enum.js +49 -0
- package/dist/core/loader/astLoader/parsers/forward/array.js +12 -0
- package/dist/core/loader/astLoader/parsers/forward/enum.js +10 -0
- package/dist/core/loader/astLoader/parsers/forward/group.js +12 -0
- package/dist/core/loader/astLoader/parsers/forward/index.js +20 -0
- package/dist/core/loader/astLoader/parsers/forward/object.js +12 -0
- package/dist/core/loader/astLoader/parsers/forward/tuple.js +11 -0
- package/dist/core/loader/astLoader/parsers/forward/type.js +2 -0
- package/dist/core/loader/astLoader/parsers/group.js +50 -0
- package/dist/core/loader/astLoader/parsers/index.js +66 -0
- package/dist/core/loader/astLoader/parsers/object.js +44 -0
- package/dist/core/loader/astLoader/parsers/reference.js +41 -0
- package/dist/core/loader/astLoader/parsers/simple.js +48 -0
- package/dist/core/loader/astLoader/parsers/tuple.js +36 -0
- package/dist/core/loader/astLoader/parsers/type.js +2 -0
- package/dist/core/loader/astLoader/parsers/utils.js +58 -0
- package/dist/core/loader/callingCodeLoader/helper.js +183 -0
- package/dist/core/loader/callingCodeLoader/index.js +40 -0
- package/dist/core/loader/index.js +20 -0
- package/dist/core/loader/schemaLoader/index.js +101 -0
- package/dist/core/loader/standardLoader/helper.js +142 -0
- package/dist/core/loader/standardLoader/index.js +38 -0
- package/dist/core/loader/standardLoader/standards.js +105 -0
- package/dist/core/parser/index.js +18 -0
- package/dist/core/parser/openApiParser/helper.js +165 -0
- package/dist/core/parser/openApiParser/index.js +14 -0
- package/dist/core/parser/templateParser/helper.js +333 -0
- package/dist/core/parser/templateParser/index.js +314 -0
- package/dist/core/workerPool/index.js +6 -0
- package/dist/core/workerPool/poolManager.js +45 -0
- package/dist/core/workerPool/swagger2Worker.js +24 -0
- package/dist/core/workerPool/worker.js +61 -0
- package/dist/createConfig.js +37 -0
- package/dist/defineConfig.js +6 -0
- package/dist/functions/getAutoTemplateType.js +37 -0
- package/dist/functions/getFrameworkTag.js +18 -0
- package/dist/functions/prepareConfig.js +41 -0
- package/dist/functions/readWormaRc.js +155 -0
- package/dist/functions/wormaJson.js +232 -0
- package/dist/generate.js +84 -0
- package/dist/helper/PluginDriver.js +98 -0
- package/dist/helper/comment.js +88 -0
- package/dist/helper/config/ConfigHelper.js +79 -0
- package/dist/helper/config/ConfigManager.js +88 -0
- package/dist/helper/config/GeneratorHelper.js +343 -0
- package/dist/helper/config/index.js +19 -0
- package/dist/helper/config/type.js +2 -0
- package/dist/helper/config/zType.js +170 -0
- package/dist/helper/document/index.js +160 -0
- package/dist/helper/index.js +23 -0
- package/dist/helper/logger/index.js +76 -0
- package/dist/helper/progress.js +66 -0
- package/dist/helper/template/index.js +475 -0
- package/dist/index.js +33 -0
- package/dist/plugins/createPlugin.js +30 -0
- package/dist/plugins/index.js +34 -0
- package/dist/plugins/presets/aiDoc.js +173 -0
- package/dist/plugins/presets/apifox.js +56 -0
- package/dist/plugins/presets/filterApi.js +129 -0
- package/dist/plugins/presets/importType.js +49 -0
- package/dist/plugins/presets/payloadModifier/hepler.js +195 -0
- package/dist/plugins/presets/payloadModifier/index.js +122 -0
- package/dist/plugins/presets/payloadModifier/type.js +2 -0
- package/dist/plugins/presets/platform.js +73 -0
- package/dist/plugins/presets/rename.js +209 -0
- package/dist/plugins/presets/tagModifier.js +104 -0
- package/dist/plugins/presets/utils.js +36 -0
- package/dist/readConfig.js +92 -0
- package/dist/resolveWorkspaces.js +83 -0
- package/dist/template/index.js +180 -0
- package/dist/template/presets/ai-doc/SKILL.md.handlebars +29 -0
- package/dist/template/presets/ai-doc/references/{tag}/{api}.md.handlebars +54 -0
- package/dist/template/presets/alova/common/#index.cjs.handlebars +12 -0
- package/dist/template/presets/alova/common/components.d.cts.handlebars +1 -0
- package/dist/template/presets/alova/common/helper.cjs.handlebars +13 -0
- package/dist/template/presets/alova/common/services/#index.cjs.handlebars +13 -0
- package/dist/template/presets/alova/common/services/{tag}.cjs.handlebars +28 -0
- package/dist/template/presets/alova/common/services/{tag}.d.cts.handlebars +15 -0
- package/dist/template/presets/alova/common/typed.d.cts.handlebars +1 -0
- package/dist/template/presets/alova/module/#index.js.handlebars +12 -0
- package/dist/template/presets/alova/module/components.d.ts.handlebars +1 -0
- package/dist/template/presets/alova/module/helper.js.handlebars +11 -0
- package/dist/template/presets/alova/module/services/#index.js.handlebars +9 -0
- package/dist/template/presets/alova/module/services/{tag}.d.ts.handlebars +15 -0
- package/dist/template/presets/alova/module/services/{tag}.js.handlebars +21 -0
- package/dist/template/presets/alova/module/typed.d.ts.handlebars +1 -0
- package/dist/template/presets/alova/partials/api-jsdoc.handlebars +44 -0
- package/dist/template/presets/alova/partials/build-payload-body.handlebars +22 -0
- package/dist/template/presets/alova/partials/comment.handlebars +19 -0
- package/dist/template/presets/alova/partials/components-body.handlebars +4 -0
- package/dist/template/presets/alova/partials/dts-extra-config.handlebars +8 -0
- package/dist/template/presets/alova/partials/dts-fn-declare.handlebars +1 -0
- package/dist/template/presets/alova/partials/extract-responded.handlebars +11 -0
- package/dist/template/presets/alova/partials/stateshook-import.handlebars +9 -0
- package/dist/template/presets/alova/partials/stateshook-option.handlebars +9 -0
- package/dist/template/presets/alova/partials/typed-body.handlebars +43 -0
- package/dist/template/presets/alova/typescript/#index.ts.handlebars +14 -0
- package/dist/template/presets/alova/typescript/components.d.ts.handlebars +1 -0
- package/dist/template/presets/alova/typescript/helper.ts.handlebars +9 -0
- package/dist/template/presets/alova/typescript/services/#index.ts.handlebars +9 -0
- package/dist/template/presets/alova/typescript/services/{tag}.ts.handlebars +35 -0
- package/dist/template/presets/alova/typescript/typed.ts.handlebars +1 -0
- package/dist/template/presets/alova-globals/common/#index.cjs.handlebars +41 -0
- package/dist/template/presets/alova-globals/common/apiDefinitions.cjs.handlebars +12 -0
- package/dist/template/presets/alova-globals/common/createApis.cjs.handlebars +48 -0
- package/dist/template/presets/alova-globals/common/globals.d.cts.handlebars +2 -0
- package/dist/template/presets/alova-globals/module/#index.js.handlebars +2 -0
- package/dist/template/presets/alova-globals/module/apiDefinitions.js.handlebars +12 -0
- package/dist/template/presets/alova-globals/module/createApis.js.handlebars +44 -0
- package/dist/template/presets/alova-globals/module/globals.d.ts.handlebars +2 -0
- package/dist/template/presets/alova-globals/partials/comment.handlebars +19 -0
- package/dist/template/presets/alova-globals/partials/createApis-proxy-js.handlebars +55 -0
- package/dist/template/presets/alova-globals/partials/globals-d-ts.handlebars +148 -0
- package/dist/template/presets/alova-globals/partials/index-esm.handlebars +38 -0
- package/dist/template/presets/alova-globals/partials/withConfigType-jsdoc.handlebars +22 -0
- package/dist/template/presets/alova-globals/typescript/#index.ts.handlebars +2 -0
- package/dist/template/presets/alova-globals/typescript/apiDefinitions.ts.handlebars +12 -0
- package/dist/template/presets/alova-globals/typescript/createApis.ts.handlebars +99 -0
- package/dist/template/presets/alova-globals/typescript/globals.d.ts.handlebars +2 -0
- package/dist/template/presets/axios/common/#index.cjs.handlebars +22 -0
- package/dist/template/presets/axios/common/components.d.cts.handlebars +1 -0
- package/dist/template/presets/axios/common/helper.cjs.handlebars +27 -0
- package/dist/template/presets/axios/common/services/#index.cjs.handlebars +13 -0
- package/dist/template/presets/axios/common/services/{tag}.cjs.handlebars +28 -0
- package/dist/template/presets/axios/common/services/{tag}.d.cts.handlebars +11 -0
- package/dist/template/presets/axios/module/#index.js.handlebars +20 -0
- package/dist/template/presets/axios/module/components.d.ts.handlebars +1 -0
- package/dist/template/presets/axios/module/helper.js.handlebars +25 -0
- package/dist/template/presets/axios/module/services/#index.js.handlebars +9 -0
- package/dist/template/presets/axios/module/services/{tag}.d.ts.handlebars +11 -0
- package/dist/template/presets/axios/module/services/{tag}.js.handlebars +20 -0
- package/dist/template/presets/axios/partials/api-jsdoc.handlebars +44 -0
- package/dist/template/presets/axios/partials/comment.handlebars +19 -0
- package/dist/template/presets/axios/partials/components-body.handlebars +4 -0
- package/dist/template/presets/axios/partials/dts-fn-declare.handlebars +1 -0
- package/dist/template/presets/axios/partials/dts-types.handlebars +7 -0
- package/dist/template/presets/axios/typescript/#index.ts.handlebars +20 -0
- package/dist/template/presets/axios/typescript/components.d.ts.handlebars +1 -0
- package/dist/template/presets/axios/typescript/helper.ts.handlebars +28 -0
- package/dist/template/presets/axios/typescript/services/#index.ts.handlebars +9 -0
- package/dist/template/presets/axios/typescript/services/{tag}.ts.handlebars +31 -0
- package/dist/template/presets/config/common/worma.config.js.handlebars +9 -0
- package/dist/template/presets/config/module/worma.config.js.handlebars +9 -0
- package/dist/template/presets/config/partials/generator-content.handlebars +45 -0
- package/dist/template/presets/config/typescript/worma.config.ts.handlebars +9 -0
- package/dist/template/presets/fetch/common/#index.cjs.handlebars +17 -0
- package/dist/template/presets/fetch/common/FetchClient.cjs.handlebars +48 -0
- package/dist/template/presets/fetch/common/components.d.cts.handlebars +1 -0
- package/dist/template/presets/fetch/common/helper.cjs.handlebars +27 -0
- package/dist/template/presets/fetch/common/services/#index.cjs.handlebars +13 -0
- package/dist/template/presets/fetch/common/services/{tag}.cjs.handlebars +23 -0
- package/dist/template/presets/fetch/common/services/{tag}.d.cts.handlebars +10 -0
- package/dist/template/presets/fetch/module/#index.js.handlebars +15 -0
- package/dist/template/presets/fetch/module/FetchClient.js.handlebars +46 -0
- package/dist/template/presets/fetch/module/components.d.ts.handlebars +1 -0
- package/dist/template/presets/fetch/module/helper.js.handlebars +25 -0
- package/dist/template/presets/fetch/module/services/#index.js.handlebars +9 -0
- package/dist/template/presets/fetch/module/services/{tag}.d.ts.handlebars +10 -0
- package/dist/template/presets/fetch/module/services/{tag}.js.handlebars +15 -0
- package/dist/template/presets/fetch/partials/api-jsdoc.handlebars +44 -0
- package/dist/template/presets/fetch/partials/comment.handlebars +19 -0
- package/dist/template/presets/fetch/partials/components-body.handlebars +4 -0
- package/dist/template/presets/fetch/partials/dts-fn-declare.handlebars +1 -0
- package/dist/template/presets/fetch/partials/dts-types.handlebars +7 -0
- package/dist/template/presets/fetch/typescript/#index.ts.handlebars +15 -0
- package/dist/template/presets/fetch/typescript/FetchClient.ts.handlebars +59 -0
- package/dist/template/presets/fetch/typescript/components.d.ts.handlebars +1 -0
- package/dist/template/presets/fetch/typescript/helper.ts.handlebars +28 -0
- package/dist/template/presets/fetch/typescript/services/#index.ts.handlebars +9 -0
- package/dist/template/presets/fetch/typescript/services/{tag}.ts.handlebars +25 -0
- package/dist/template/presets/ky/module/#index.js.handlebars +14 -0
- package/dist/template/presets/ky/module/components.d.ts.handlebars +1 -0
- package/dist/template/presets/ky/module/helper.js.handlebars +27 -0
- package/dist/template/presets/ky/module/services/#index.js.handlebars +9 -0
- package/dist/template/presets/ky/module/services/{tag}.d.ts.handlebars +11 -0
- package/dist/template/presets/ky/module/services/{tag}.js.handlebars +19 -0
- package/dist/template/presets/ky/partials/api-jsdoc.handlebars +44 -0
- package/dist/template/presets/ky/partials/comment.handlebars +19 -0
- package/dist/template/presets/ky/partials/components-body.handlebars +4 -0
- package/dist/template/presets/ky/partials/dts-fn-declare.handlebars +1 -0
- package/dist/template/presets/ky/partials/dts-types.handlebars +9 -0
- package/dist/template/presets/ky/typescript/#index.ts.handlebars +14 -0
- package/dist/template/presets/ky/typescript/components.d.ts.handlebars +1 -0
- package/dist/template/presets/ky/typescript/helper.ts.handlebars +30 -0
- package/dist/template/presets/ky/typescript/services/#index.ts.handlebars +9 -0
- package/dist/template/presets/ky/typescript/services/{tag}.ts.handlebars +30 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/type/api.js +14 -0
- package/dist/type/ast.js +24 -0
- package/dist/type/base.js +17 -0
- package/dist/type/index.js +20 -0
- package/dist/type/lib.js +17 -0
- package/dist/type/openapi.js +2 -0
- package/dist/utils/base.js +212 -0
- package/dist/utils/format.js +64 -0
- package/dist/utils/index.js +21 -0
- package/dist/utils/openapi.js +417 -0
- package/dist/utils/readPackageJson.js +35 -0
- package/dist/utils/template.js +93 -0
- package/package.json +88 -0
- package/typings/index.d.ts +512 -0
- package/typings/plugins.d.ts +727 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.openApiHelper = exports.OpenApiHelper = exports.supportedApiMethods = void 0;
|
|
4
|
+
const type_1 = require("../../type");
|
|
5
|
+
const utils_1 = require("../../utils");
|
|
6
|
+
/**
|
|
7
|
+
* 支持的API方法列表
|
|
8
|
+
* @see https://github.com/alovajs/alova/blob/main/packages/alova/typings/index.d.ts#L640
|
|
9
|
+
*/
|
|
10
|
+
exports.supportedApiMethods = [
|
|
11
|
+
type_1.HttpMethod.GET,
|
|
12
|
+
type_1.HttpMethod.PUT,
|
|
13
|
+
type_1.HttpMethod.POST,
|
|
14
|
+
type_1.HttpMethod.DELETE,
|
|
15
|
+
type_1.HttpMethod.PATCH,
|
|
16
|
+
type_1.HttpMethod.HEAD,
|
|
17
|
+
type_1.HttpMethod.OPTIONS,
|
|
18
|
+
];
|
|
19
|
+
class OpenApiHelper {
|
|
20
|
+
constructor() {
|
|
21
|
+
this.usedRefsCache = new Set();
|
|
22
|
+
}
|
|
23
|
+
load(document) {
|
|
24
|
+
this.document = document;
|
|
25
|
+
// reset cache when document changes
|
|
26
|
+
this.usedRefsCache.clear();
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
static load(document) {
|
|
30
|
+
const ins = new OpenApiHelper();
|
|
31
|
+
return ins.load(document);
|
|
32
|
+
}
|
|
33
|
+
getApiMethods() {
|
|
34
|
+
const paths = this.document.paths || [];
|
|
35
|
+
const apiMethods = [];
|
|
36
|
+
for (const [url, pathInfo] of Object.entries(paths)) {
|
|
37
|
+
if (!pathInfo) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
for (const [method, operationObject] of Object.entries(pathInfo)) {
|
|
41
|
+
if (!exports.supportedApiMethods.includes(method)) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (typeof operationObject === 'string' || Array.isArray(operationObject)) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
apiMethods.push({
|
|
48
|
+
url,
|
|
49
|
+
method,
|
|
50
|
+
operationObject,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return apiMethods;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* 将 ApiMethods 数组写回到 openapi document 的 paths 中。
|
|
58
|
+
* 仅更新传入的 url+method 对应的 operationObject,保留其它未涉及的内容。
|
|
59
|
+
*/
|
|
60
|
+
saveApiMethods(apiMethods) {
|
|
61
|
+
this.document.paths = {};
|
|
62
|
+
// 构建 url -> { method -> operationObject } 映射,后写入覆盖前者
|
|
63
|
+
const grouped = {};
|
|
64
|
+
for (const item of apiMethods || []) {
|
|
65
|
+
if (!item || !item.url || !item.method || !item.operationObject) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const method = String(item.method).toLowerCase();
|
|
69
|
+
if (!exports.supportedApiMethods.includes(method)) {
|
|
70
|
+
// 跳过不支持的 http 方法
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (!grouped[item.url]) {
|
|
74
|
+
grouped[item.url] = {};
|
|
75
|
+
}
|
|
76
|
+
grouped[item.url][method] = item.operationObject;
|
|
77
|
+
}
|
|
78
|
+
// 将分组后的方法写回到 document.paths
|
|
79
|
+
for (const [url, methodsMap] of Object.entries(grouped)) {
|
|
80
|
+
const pathInfo = (this.document.paths?.[url] || {});
|
|
81
|
+
for (const [method, operationObject] of Object.entries(methodsMap)) {
|
|
82
|
+
pathInfo[method] = operationObject;
|
|
83
|
+
}
|
|
84
|
+
if (this.document.paths) {
|
|
85
|
+
this.document.paths[url] = pathInfo;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// 更新后清除引用缓存,确保后续计算的使用引用为最新
|
|
89
|
+
this.usedRefsCache.clear();
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* 判断某个引用是否在文档中被使用
|
|
94
|
+
* @param ref ReferenceObject 或其 `$ref` 路径字符串
|
|
95
|
+
*/
|
|
96
|
+
isReferenceUsed(ref) {
|
|
97
|
+
const refPath = typeof ref === 'string' ? ref : ref.$ref;
|
|
98
|
+
const usedSet = this.getUsedReferenceSet();
|
|
99
|
+
return usedSet.has(refPath);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* 预计算并返回已使用的 `$ref` 集合,仅从 paths 可达
|
|
103
|
+
*/
|
|
104
|
+
getUsedReferenceSet() {
|
|
105
|
+
if (this.usedRefsCache.size > 0) {
|
|
106
|
+
return this.usedRefsCache;
|
|
107
|
+
}
|
|
108
|
+
const used = this.usedRefsCache;
|
|
109
|
+
const visitedRefs = new Set();
|
|
110
|
+
const stack = [];
|
|
111
|
+
const roots = [];
|
|
112
|
+
if (this.document.paths) {
|
|
113
|
+
roots.push(this.document.paths);
|
|
114
|
+
}
|
|
115
|
+
stack.push(...roots);
|
|
116
|
+
while (stack.length) {
|
|
117
|
+
const node = stack.pop();
|
|
118
|
+
if (!node || typeof node !== 'object') {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if ((0, utils_1.isReferenceObject)(node)) {
|
|
122
|
+
const currentRef = node.$ref;
|
|
123
|
+
used.add(currentRef);
|
|
124
|
+
if (!visitedRefs.has(currentRef)) {
|
|
125
|
+
visitedRefs.add(currentRef);
|
|
126
|
+
try {
|
|
127
|
+
const target = (0, utils_1.findBy$ref)(currentRef, this.document);
|
|
128
|
+
stack.push(target);
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
// ignore invalid refs
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (Array.isArray(node)) {
|
|
137
|
+
for (const item of node) {
|
|
138
|
+
stack.push(item);
|
|
139
|
+
}
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
for (const key of Object.keys(node)) {
|
|
143
|
+
stack.push(node[key]);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return used;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* 过滤掉未使用的引用,返回仍被使用的引用列表
|
|
150
|
+
*/
|
|
151
|
+
filterUsedReferences(refs) {
|
|
152
|
+
const usedSet = this.getUsedReferenceSet();
|
|
153
|
+
return (refs || []).filter((ref) => {
|
|
154
|
+
const refPath = typeof ref === 'string' ? ref : ref.$ref;
|
|
155
|
+
return usedSet.has(refPath);
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
exports.OpenApiHelper = OpenApiHelper;
|
|
160
|
+
exports.openApiHelper = new OpenApiHelper();
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./comment"), exports);
|
|
18
|
+
__exportStar(require("./config"), exports);
|
|
19
|
+
__exportStar(require("./document"), exports);
|
|
20
|
+
__exportStar(require("./logger"), exports);
|
|
21
|
+
__exportStar(require("./PluginDriver"), exports);
|
|
22
|
+
__exportStar(require("./progress"), exports);
|
|
23
|
+
__exportStar(require("./template"), exports);
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logger = void 0;
|
|
4
|
+
const config_1 = require("../../config");
|
|
5
|
+
const DEFAULT_CONFIG = (0, config_1.getGlobalConfig)();
|
|
6
|
+
class Logger {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.options = {
|
|
9
|
+
level: 'info',
|
|
10
|
+
timestamp: true,
|
|
11
|
+
colors: true,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
configure(options) {
|
|
15
|
+
this.options = { ...this.options, ...options };
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
getTimestamp() {
|
|
19
|
+
return this.options.timestamp ? `[${new Date().toISOString()}] ` : '';
|
|
20
|
+
}
|
|
21
|
+
formatMessage(level, message, details) {
|
|
22
|
+
const timestamp = this.getTimestamp();
|
|
23
|
+
const prefix = this.options.prefix ? `[${this.options.prefix}] ` : '';
|
|
24
|
+
const detailsStr = details ? `\n${JSON.stringify(details, null, 2)}` : '';
|
|
25
|
+
if (this.options.colors) {
|
|
26
|
+
const colors = {
|
|
27
|
+
debug: '\x1B[34m', // blue
|
|
28
|
+
info: '\x1B[32m', // green
|
|
29
|
+
warn: '\x1B[33m', // yellow
|
|
30
|
+
error: '\x1B[31m', // red
|
|
31
|
+
reset: '\x1B[0m',
|
|
32
|
+
};
|
|
33
|
+
return `${timestamp}${prefix}${colors[level]}[${level.toUpperCase()}]${colors.reset} ${message}${detailsStr}`;
|
|
34
|
+
}
|
|
35
|
+
return `${timestamp}${prefix}[${level.toUpperCase()}] ${message}${detailsStr}`;
|
|
36
|
+
}
|
|
37
|
+
shouldLog(level) {
|
|
38
|
+
const levels = ['debug', 'info', 'warn', 'error'];
|
|
39
|
+
return levels.indexOf(level) >= levels.indexOf(this.options.level);
|
|
40
|
+
}
|
|
41
|
+
debug(message, details) {
|
|
42
|
+
if (this.shouldLog('debug')) {
|
|
43
|
+
// eslint-disable-next-line no-console
|
|
44
|
+
console.debug(this.formatMessage('debug', message, details));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
info(message, details) {
|
|
48
|
+
if (this.shouldLog('info')) {
|
|
49
|
+
// eslint-disable-next-line no-console
|
|
50
|
+
console.info(this.formatMessage('info', message, details));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
warn(message, details) {
|
|
54
|
+
if (this.shouldLog('warn')) {
|
|
55
|
+
console.warn(this.formatMessage('warn', message, details));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
errorMsg(msg) {
|
|
59
|
+
return msg instanceof Error ? msg.message : msg;
|
|
60
|
+
}
|
|
61
|
+
error(message, details) {
|
|
62
|
+
if (this.shouldLog('error')) {
|
|
63
|
+
console.error(this.formatMessage('error', message, details));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
throwError(error, details) {
|
|
67
|
+
this.debug(this.errorMsg(error), details);
|
|
68
|
+
return new DEFAULT_CONFIG.Error(this.errorMsg(error));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// 导出单例实例
|
|
72
|
+
exports.logger = new Logger().configure({
|
|
73
|
+
level: 'info',
|
|
74
|
+
timestamp: true,
|
|
75
|
+
colors: true,
|
|
76
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.noopReportProgress = exports.ProgressTracker = exports.GeneratorStage = exports.CORE_PROGRESS_SOURCE = void 0;
|
|
4
|
+
exports.CORE_PROGRESS_SOURCE = 'core';
|
|
5
|
+
/**
|
|
6
|
+
* Named stages for the generator lifecycle.
|
|
7
|
+
* These are used by the CLI renderer to display human-readable progress stages.
|
|
8
|
+
*/
|
|
9
|
+
exports.GeneratorStage = {
|
|
10
|
+
INIT: 'init',
|
|
11
|
+
BEFORE_OPENAPI_PARSE: 'beforeOpenapiParse',
|
|
12
|
+
PARSE_OPENAPI: 'parseOpenapi',
|
|
13
|
+
OPENAPI_PARSED: 'openapiParsed',
|
|
14
|
+
TEMPLATE_LOADED: 'templateLoaded',
|
|
15
|
+
TEMPLATE_DATA_PARSED: 'templateDataParsed',
|
|
16
|
+
BEFORE_CODE_GENERATE: 'beforeCodeGenerate',
|
|
17
|
+
PROCESS_TEMPLATES: 'processTemplates',
|
|
18
|
+
WRITE_FILES: 'writeFiles',
|
|
19
|
+
CODE_GENERATED: 'codeGenerated',
|
|
20
|
+
COMPLETED: 'completed',
|
|
21
|
+
FAILED: 'failed',
|
|
22
|
+
SKIPPED: 'skipped',
|
|
23
|
+
};
|
|
24
|
+
class ProgressTracker {
|
|
25
|
+
constructor(listener, interval = 500) {
|
|
26
|
+
this.snapshot = {};
|
|
27
|
+
this.dirty = false;
|
|
28
|
+
this.timer = null;
|
|
29
|
+
this.listener = listener;
|
|
30
|
+
this.interval = interval;
|
|
31
|
+
}
|
|
32
|
+
start() {
|
|
33
|
+
if (!this.listener || this.timer || this.interval <= 0) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
this.timer = setInterval(() => this.flush(), this.interval);
|
|
37
|
+
}
|
|
38
|
+
stop() {
|
|
39
|
+
if (this.timer) {
|
|
40
|
+
clearInterval(this.timer);
|
|
41
|
+
this.timer = null;
|
|
42
|
+
}
|
|
43
|
+
this.flush();
|
|
44
|
+
}
|
|
45
|
+
update(source, progress, message) {
|
|
46
|
+
const clamped = Math.max(0, Math.min(100, progress));
|
|
47
|
+
this.snapshot[source] = { source, progress: clamped, message };
|
|
48
|
+
this.dirty = true;
|
|
49
|
+
if (this.listener && this.interval <= 0) {
|
|
50
|
+
this.flush();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
flush() {
|
|
54
|
+
if (!this.dirty || !this.listener) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
this.dirty = false;
|
|
58
|
+
this.listener({ ...this.snapshot });
|
|
59
|
+
}
|
|
60
|
+
reporterFor(source) {
|
|
61
|
+
return (progress, message) => this.update(source, progress, message);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.ProgressTracker = ProgressTracker;
|
|
65
|
+
const noopReportProgress = () => { };
|
|
66
|
+
exports.noopReportProgress = noopReportProgress;
|