@keq-request/cli 5.0.0-alpha.29 → 5.0.0-alpha.31
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/CHANGELOG.md +21 -0
- package/dist/chunk-7HHTHYRA.cjs +2895 -0
- package/dist/chunk-7HHTHYRA.cjs.map +1 -0
- package/dist/chunk-DZ2SC5HL.js +2895 -0
- package/dist/chunk-DZ2SC5HL.js.map +1 -0
- package/dist/chunk-HN7ZZFKC.js +19 -0
- package/dist/chunk-HN7ZZFKC.js.map +1 -0
- package/dist/chunk-JX74ZR2O.cjs +670 -0
- package/dist/chunk-JX74ZR2O.cjs.map +1 -0
- package/dist/chunk-OC36G3PF.cjs +19 -0
- package/dist/chunk-OC36G3PF.cjs.map +1 -0
- package/dist/chunk-XRZLO2PB.js +670 -0
- package/dist/chunk-XRZLO2PB.js.map +1 -0
- package/dist/cli.cjs +171 -2757
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +161 -2724
- package/dist/cli.js.map +1 -1
- package/dist/compiler/compiler.d.ts +2 -0
- package/dist/compiler/compiler.d.ts.map +1 -1
- package/dist/index.cjs +8 -2777
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +15 -2738
- package/dist/index.js.map +1 -1
- package/dist/plugins/body-fallback/constants/metadata-storage.d.ts +1 -0
- package/dist/plugins/body-fallback/constants/metadata-storage.d.ts.map +1 -1
- package/dist/plugins/body-fallback/index.d.ts.map +1 -1
- package/dist/plugins/chinese-to-pinyin/chinese-to-pinyin.plugin.d.ts.map +1 -1
- package/dist/plugins/chinese-to-pinyin/constants/metadata-storage.d.ts +1 -0
- package/dist/plugins/chinese-to-pinyin/constants/metadata-storage.d.ts.map +1 -1
- package/dist/plugins/download-http-file/constants/metadata-storage.d.ts +1 -0
- package/dist/plugins/download-http-file/constants/metadata-storage.d.ts.map +1 -1
- package/dist/plugins/download-http-file/download-http-file.plugin.d.ts.map +1 -1
- package/dist/plugins/download-local-file/constants/metadata-storage.d.ts +1 -0
- package/dist/plugins/download-local-file/constants/metadata-storage.d.ts.map +1 -1
- package/dist/plugins/download-local-file/download-local-file.plugin.d.ts.map +1 -1
- package/dist/plugins/eslint/constants/metadata-storage.d.ts +1 -0
- package/dist/plugins/eslint/constants/metadata-storage.d.ts.map +1 -1
- package/dist/plugins/eslint/eslint.plugin.d.ts.map +1 -1
- package/dist/plugins/generate-declaration/constants/metadata-storage.d.ts +2 -1
- package/dist/plugins/generate-declaration/constants/metadata-storage.d.ts.map +1 -1
- package/dist/plugins/generate-declaration/generate-declaration.plugin.d.ts.map +1 -1
- package/dist/plugins/generate-micro-function/constants/metadata-storage.d.ts +1 -0
- package/dist/plugins/generate-micro-function/constants/metadata-storage.d.ts.map +1 -1
- package/dist/plugins/generate-micro-function/generate-micro-function.plugin.d.ts.map +1 -1
- package/dist/plugins/generate-nestjs-module/constants/metadata-storage.d.ts +1 -0
- package/dist/plugins/generate-nestjs-module/constants/metadata-storage.d.ts.map +1 -1
- package/dist/plugins/generate-nestjs-module/generate-nestjs-module.d.ts.map +1 -1
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/prettier/constants/metadata-storage.d.ts +1 -0
- package/dist/plugins/prettier/constants/metadata-storage.d.ts.map +1 -1
- package/dist/plugins/prettier/prettier.plugin.d.ts.map +1 -1
- package/dist/plugins/shaking/constants/metadata-storage.d.ts +1 -0
- package/dist/plugins/shaking/constants/metadata-storage.d.ts.map +1 -1
- package/dist/plugins/shaking/shaking.plugin.d.ts.map +1 -1
- package/dist/plugins/terminal-select/constants/metadata-storage.d.ts +1 -0
- package/dist/plugins/terminal-select/constants/metadata-storage.d.ts.map +1 -1
- package/dist/plugins/terminal-select/terminal-select.plugin.d.ts.map +1 -1
- package/dist/plugins/use-valibot/constants/index.d.ts +2 -0
- package/dist/plugins/use-valibot/constants/index.d.ts.map +1 -0
- package/dist/plugins/use-valibot/constants/metadata-storage.d.ts +6 -0
- package/dist/plugins/use-valibot/constants/metadata-storage.d.ts.map +1 -0
- package/dist/plugins/use-valibot/index.d.ts +3 -0
- package/dist/plugins/use-valibot/index.d.ts.map +1 -0
- package/dist/plugins/use-valibot/use-valibot.plugin.d.ts +12 -0
- package/dist/plugins/use-valibot/use-valibot.plugin.d.ts.map +1 -0
- package/dist/plugins.cjs +3 -2532
- package/dist/plugins.cjs.map +1 -1
- package/dist/plugins.js +31 -2500
- package/dist/plugins.js.map +1 -1
- package/dist/transformers/json-schema/json-schema.transformer.d.ts +2 -0
- package/dist/transformers/json-schema/json-schema.transformer.d.ts.map +1 -1
- package/dist/transformers/json-schema/valibot.renderer.d.ts +26 -0
- package/dist/transformers/json-schema/valibot.renderer.d.ts.map +1 -0
- package/dist/transformers/schema-definition/schema-definition.transformer.d.ts +5 -0
- package/dist/transformers/schema-definition/schema-definition.transformer.d.ts.map +1 -1
- package/dist/translators.cjs +8 -2047
- package/dist/translators.cjs.map +1 -1
- package/dist/translators.js +7 -2008
- package/dist/translators.js.map +1 -1
- package/dist/utils/scan-generated-files.d.ts +15 -0
- package/dist/utils/scan-generated-files.d.ts.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,670 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
|
|
2
|
+
|
|
3
|
+
var _chunkOC36G3PFcjs = require('./chunk-OC36G3PF.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var _chunk7HHTHYRAcjs = require('./chunk-7HHTHYRA.cjs');
|
|
13
|
+
|
|
14
|
+
// src/compiler/compiler.ts
|
|
15
|
+
var _listr2 = require('listr2');
|
|
16
|
+
var _tapable = require('tapable');
|
|
17
|
+
|
|
18
|
+
// src/compiler/tasks/setup/index.ts
|
|
19
|
+
var _fsextra = require('fs-extra'); var _fsextra2 = _interopRequireDefault(_fsextra);
|
|
20
|
+
var _path = require('path'); var path3 = _interopRequireWildcard(_path);
|
|
21
|
+
var _cosmiconfig = require('cosmiconfig');
|
|
22
|
+
|
|
23
|
+
// src/utils/ignore-matcher.ts
|
|
24
|
+
var _ramda = require('ramda'); var R = _interopRequireWildcard(_ramda); var R2 = _interopRequireWildcard(_ramda); var R3 = _interopRequireWildcard(_ramda);
|
|
25
|
+
|
|
26
|
+
var IgnoreMatcher = class _IgnoreMatcher {
|
|
27
|
+
|
|
28
|
+
constructor(rules) {
|
|
29
|
+
this.rules = rules;
|
|
30
|
+
}
|
|
31
|
+
static async read(filepath) {
|
|
32
|
+
let content = await _fsextra2.default.readFile(filepath, "utf-8");
|
|
33
|
+
content = content.replace(/\r\n/g, "\n").replace(/\r/g, "\n").replace(/#.*$/gm, "").replace(/\n+/g, "\n").trim();
|
|
34
|
+
let rules = content.split("\n").map((line) => line.trim()).filter((line) => line.length > 0).map((line) => {
|
|
35
|
+
const matched = line.match(/^(!)?\s*([^\s/]+)\s+([^\s/]+)\s+([^\s]+)$/);
|
|
36
|
+
if (!matched) throw new Error(`Invalid ignore rule: "${line}"`);
|
|
37
|
+
const [, flag, moduleName, operationMethod, operationPathname] = matched;
|
|
38
|
+
return {
|
|
39
|
+
persist: true,
|
|
40
|
+
ignore: !flag,
|
|
41
|
+
moduleName,
|
|
42
|
+
operationMethod: operationMethod.toLowerCase(),
|
|
43
|
+
operationPathname
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
rules = R.sortBy(
|
|
47
|
+
R.prop("ignore"),
|
|
48
|
+
rules
|
|
49
|
+
);
|
|
50
|
+
rules = R.uniqWith(
|
|
51
|
+
(a, b) => a.moduleName === b.moduleName && a.operationMethod === b.operationMethod && a.operationPathname === b.operationPathname,
|
|
52
|
+
rules
|
|
53
|
+
);
|
|
54
|
+
return new _IgnoreMatcher(rules);
|
|
55
|
+
}
|
|
56
|
+
async write(filepath) {
|
|
57
|
+
const ruleGroups = R.compose(
|
|
58
|
+
R.groupBy((rule) => rule.moduleName),
|
|
59
|
+
R.reverse,
|
|
60
|
+
R.uniqWith(
|
|
61
|
+
(a, b) => a.moduleName === b.moduleName && a.operationMethod === b.operationMethod && a.operationPathname === b.operationPathname
|
|
62
|
+
),
|
|
63
|
+
R.filter((rule) => rule.persist)
|
|
64
|
+
)(this.rules);
|
|
65
|
+
const content = Object.entries(ruleGroups).sort((a, b) => {
|
|
66
|
+
const aModuleName = a[0];
|
|
67
|
+
const bModuleName = b[0];
|
|
68
|
+
if (aModuleName === "*") return -1;
|
|
69
|
+
if (bModuleName === "*") return 1;
|
|
70
|
+
return aModuleName.localeCompare(bModuleName);
|
|
71
|
+
}).map(([, rules]) => (rules || []).sort((a, b) => {
|
|
72
|
+
if (a.ignore !== b.ignore) return a.ignore ? -1 : 1;
|
|
73
|
+
if (a.operationMethod === "*") return -1;
|
|
74
|
+
if (b.operationMethod === "*") return 1;
|
|
75
|
+
if (a.operationPathname === "*") return -1;
|
|
76
|
+
if (b.operationPathname === "*") return 1;
|
|
77
|
+
if (a.operationMethod !== b.operationMethod) return a.operationMethod.localeCompare(b.operationMethod);
|
|
78
|
+
if (a.operationPathname !== b.operationPathname) return a.operationPathname.localeCompare(b.operationPathname);
|
|
79
|
+
return 0;
|
|
80
|
+
}).map((rule) => `${rule.ignore ? "" : "! "}${rule.moduleName} ${rule.operationMethod.toUpperCase()} ${rule.operationPathname}`).join("\n")).join("\n\n");
|
|
81
|
+
await _fsextra2.default.writeFile(filepath, content, "utf-8");
|
|
82
|
+
}
|
|
83
|
+
append(rule) {
|
|
84
|
+
this.rules.unshift(rule);
|
|
85
|
+
}
|
|
86
|
+
// if operation is ignored, return true
|
|
87
|
+
isOperationIgnored(operationDefinition) {
|
|
88
|
+
const moduleName = operationDefinition.module.name;
|
|
89
|
+
const operationMethod = operationDefinition.method.toLowerCase();
|
|
90
|
+
const operationPathname = operationDefinition.pathname;
|
|
91
|
+
for (const rule of this.rules) {
|
|
92
|
+
if (rule.moduleName !== "*" && rule.moduleName !== moduleName) continue;
|
|
93
|
+
if (rule.operationMethod !== "*" && rule.operationMethod !== operationMethod) continue;
|
|
94
|
+
if (rule.operationPathname !== "*" && rule.operationPathname !== operationPathname) continue;
|
|
95
|
+
return rule.ignore;
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
isModuleIgnored(moduleDefinition) {
|
|
100
|
+
const moduleName = moduleDefinition.name;
|
|
101
|
+
for (const rule of this.rules) {
|
|
102
|
+
if (!rule.ignore) {
|
|
103
|
+
if (rule.moduleName === "*" || rule.moduleName === moduleName) return false;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (rule.operationMethod !== "*") continue;
|
|
107
|
+
if (rule.operationPathname !== "*") continue;
|
|
108
|
+
if (rule.moduleName === "*" || rule.moduleName === moduleName) return true;
|
|
109
|
+
}
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// src/compiler/tasks/setup/utils/find-nearest-package-json.ts
|
|
115
|
+
var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
|
|
116
|
+
|
|
117
|
+
function findNearestPackageJson(startDir = process.cwd()) {
|
|
118
|
+
let dir = startDir;
|
|
119
|
+
while (true) {
|
|
120
|
+
const pkgPath = path3.default.join(dir, "package.json");
|
|
121
|
+
if (_fs2.default.existsSync(pkgPath)) {
|
|
122
|
+
const json = JSON.parse(_fs2.default.readFileSync(pkgPath, "utf8"));
|
|
123
|
+
return { json, path: pkgPath };
|
|
124
|
+
}
|
|
125
|
+
const parent = path3.default.dirname(dir);
|
|
126
|
+
if (parent === dir) break;
|
|
127
|
+
dir = parent;
|
|
128
|
+
}
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// src/compiler/tasks/setup/utils/get-project-module-system.ts
|
|
133
|
+
function getProjectModuleSystem(pkgInfo) {
|
|
134
|
+
if (!_optionalChain([pkgInfo, 'optionalAccess', _2 => _2.json])) return "cjs";
|
|
135
|
+
const { json } = pkgInfo;
|
|
136
|
+
if (json.type === "module") return "esm";
|
|
137
|
+
return "cjs";
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// src/compiler/tasks/setup/utils/parse-runtime-config.ts
|
|
141
|
+
var _value = require('@sinclair/typebox/value');
|
|
142
|
+
|
|
143
|
+
// src/types/address.ts
|
|
144
|
+
var _typebox = require('@sinclair/typebox');
|
|
145
|
+
var Address = _typebox.Type.Object({
|
|
146
|
+
url: _typebox.Type.String(),
|
|
147
|
+
headers: _typebox.Type.Optional(_typebox.Type.Record(_typebox.Type.String(), _typebox.Type.String(), { default: {} })),
|
|
148
|
+
encoding: _typebox.Type.Optional(
|
|
149
|
+
_typebox.Type.Union([
|
|
150
|
+
_typebox.Type.Literal("utf8"),
|
|
151
|
+
_typebox.Type.Literal("ascii")
|
|
152
|
+
], { default: "utf8" })
|
|
153
|
+
)
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// src/types/runtime-config.ts
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
// src/utils/is-valid-url.ts
|
|
161
|
+
var URL_REGEX = /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\/(?:[^\s@]+@)?[^\s/:?#]*(?::\d+)?(?:\/[^\s?#]*)?(?:\?[^\s#]*)?(?:#[^\s]*)?$/;
|
|
162
|
+
function isValidURL(url) {
|
|
163
|
+
return URL_REGEX.test(url);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// src/types/runtime-config.ts
|
|
167
|
+
var Modules = _typebox.Type.Transform(
|
|
168
|
+
_typebox.Type.Record(
|
|
169
|
+
_typebox.Type.String(),
|
|
170
|
+
_typebox.Type.Union([_typebox.Type.String(), Address])
|
|
171
|
+
)
|
|
172
|
+
).Decode((value) => {
|
|
173
|
+
const keys = Object.keys(value);
|
|
174
|
+
for (const key of keys) {
|
|
175
|
+
if (!/^[A-Za-z_][A-Za-z0-9_$]*$/.test(key)) {
|
|
176
|
+
throw new Error(`Module name "${key}" is not valid. It must start with a letter or underscore, and can only contain letters, numbers, and underscores.`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
const keysGroupByLowerCase = R2.groupBy(R2.toLower, keys);
|
|
180
|
+
for (const groupKey in keysGroupByLowerCase) {
|
|
181
|
+
const keys2 = keysGroupByLowerCase[groupKey] || [];
|
|
182
|
+
if (keys2.length > 1) {
|
|
183
|
+
throw new Error(`Module names ${keys2.map((name) => `"${name}"`).join(", ")} are case-insensitively duplicated.`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
for (const key in value) {
|
|
187
|
+
const url = typeof value[key] === "string" ? value[key] : value[key].url;
|
|
188
|
+
if (isValidURL(url)) continue;
|
|
189
|
+
throw new Error(`The ${JSON.stringify(url)} of module "${key}" is not a valid URL.`);
|
|
190
|
+
}
|
|
191
|
+
return R2.map(
|
|
192
|
+
(item) => typeof item !== "string" ? item : { url: item, headers: {}, encoding: "utf8" },
|
|
193
|
+
value
|
|
194
|
+
);
|
|
195
|
+
}).Encode((value) => value);
|
|
196
|
+
var RawConfig = _typebox.Type.Object({
|
|
197
|
+
/**
|
|
198
|
+
* Whether to generate ES Module code
|
|
199
|
+
*
|
|
200
|
+
* If not specified, the module system will be inferred from the nearest package.json "type" field
|
|
201
|
+
* or defaults to "cjs" if no package.json is found.
|
|
202
|
+
*/
|
|
203
|
+
esm: _typebox.Type.Optional(_typebox.Type.Boolean({ default: false })),
|
|
204
|
+
/**
|
|
205
|
+
* Output directory for generated files
|
|
206
|
+
*/
|
|
207
|
+
outdir: _typebox.Type.String({ default: `${process.cwd()}/api` }),
|
|
208
|
+
/**
|
|
209
|
+
* File naming style for generated files
|
|
210
|
+
*/
|
|
211
|
+
fileNamingStyle: _typebox.Type.Enum(_chunk7HHTHYRAcjs.FileNamingStyle, { default: "snakeCase" /* snakeCase */ }),
|
|
212
|
+
/**
|
|
213
|
+
* OpenAPI/Swagger document sources
|
|
214
|
+
*
|
|
215
|
+
* A map of module names to their document URLs or Address objects.
|
|
216
|
+
* The module name must be a valid JavaScript identifier.
|
|
217
|
+
*/
|
|
218
|
+
modules: Modules,
|
|
219
|
+
/**
|
|
220
|
+
* Enable debug mode to output detailed logs during compilation
|
|
221
|
+
*/
|
|
222
|
+
debug: _typebox.Type.Optional(_typebox.Type.Boolean({ default: false })),
|
|
223
|
+
/**
|
|
224
|
+
* Whether to tolerate wrong openapi/swagger structure
|
|
225
|
+
*/
|
|
226
|
+
tolerant: _typebox.Type.Optional(_typebox.Type.Boolean({ default: false })),
|
|
227
|
+
/**
|
|
228
|
+
* Translators to transform generated code
|
|
229
|
+
*
|
|
230
|
+
* Used to customize the code generation process for different frameworks or patterns.
|
|
231
|
+
* Can be a single translator or an array of translators.
|
|
232
|
+
*/
|
|
233
|
+
translators: _typebox.Type.Optional(
|
|
234
|
+
_typebox.Type.Transform(
|
|
235
|
+
_typebox.Type.Union([
|
|
236
|
+
_typebox.Type.Unsafe(_typebox.Type.Any()),
|
|
237
|
+
_typebox.Type.Array(_typebox.Type.Unsafe(_typebox.Type.Any()))
|
|
238
|
+
], { default: [] })
|
|
239
|
+
).Decode((value) => {
|
|
240
|
+
if (value === void 0) return [];
|
|
241
|
+
if (Array.isArray(value)) return value;
|
|
242
|
+
return [value];
|
|
243
|
+
}).Encode((value) => value)
|
|
244
|
+
),
|
|
245
|
+
/**
|
|
246
|
+
* Plugins to extend code generation functionality
|
|
247
|
+
*
|
|
248
|
+
* An array of plugin instances that can hook into various stages of the compilation process,
|
|
249
|
+
* such as code transformation, formatting, linting, or custom file generation.
|
|
250
|
+
*/
|
|
251
|
+
plugins: _typebox.Type.Optional(_typebox.Type.Array(_typebox.Type.Unsafe(_typebox.Type.Any()), { default: [] }))
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
// src/compiler/tasks/setup/utils/parse-runtime-config.ts
|
|
255
|
+
function parseRuntimeConfig(data) {
|
|
256
|
+
try {
|
|
257
|
+
const originalPlugins = typeof data === "object" && data !== null && "plugins" in data ? data.plugins : void 0;
|
|
258
|
+
const originTranslators = typeof data === "object" && data !== null && "translators" in data ? data.translators : void 0;
|
|
259
|
+
const parsed = _value.Value.Parse(RawConfig, data);
|
|
260
|
+
if (originalPlugins !== void 0) {
|
|
261
|
+
parsed.plugins = originalPlugins;
|
|
262
|
+
}
|
|
263
|
+
if (originTranslators !== void 0) {
|
|
264
|
+
parsed.translators = originTranslators;
|
|
265
|
+
}
|
|
266
|
+
return parsed;
|
|
267
|
+
} catch (error) {
|
|
268
|
+
if (error instanceof Error) {
|
|
269
|
+
error.message = `Invalid Config: ${error.message}`;
|
|
270
|
+
}
|
|
271
|
+
throw error;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// src/compiler/tasks/setup/index.ts
|
|
276
|
+
var explore = _cosmiconfig.cosmiconfig.call(void 0, "keq");
|
|
277
|
+
function main(compiler, options) {
|
|
278
|
+
return {
|
|
279
|
+
task: async (context, task) => {
|
|
280
|
+
const result = _optionalChain([options, 'optionalAccess', _3 => _3.config]) ? await explore.load(options.config) : await explore.search();
|
|
281
|
+
if (!result || "isEmpty" in result && result.isEmpty) {
|
|
282
|
+
throw new Error("Cannot find config file.");
|
|
283
|
+
}
|
|
284
|
+
const rc = parseRuntimeConfig(result.config);
|
|
285
|
+
if (_optionalChain([options, 'optionalAccess', _4 => _4.debug])) {
|
|
286
|
+
await _fsextra2.default.ensureDir(".keq");
|
|
287
|
+
rc.debug = true;
|
|
288
|
+
}
|
|
289
|
+
rc.tolerant = Boolean(rc.tolerant);
|
|
290
|
+
if (!rc.translators || !rc.translators.length) {
|
|
291
|
+
rc.translators = [new (0, _chunkOC36G3PFcjs.MicroFunctionTranslator)()];
|
|
292
|
+
}
|
|
293
|
+
const packageJsonInfo = findNearestPackageJson();
|
|
294
|
+
if (packageJsonInfo) {
|
|
295
|
+
const moduleSystem = getProjectModuleSystem(packageJsonInfo);
|
|
296
|
+
rc.esm = moduleSystem === "esm";
|
|
297
|
+
}
|
|
298
|
+
context.rc = rc;
|
|
299
|
+
let matcher = new IgnoreMatcher([]);
|
|
300
|
+
if (result.filepath) {
|
|
301
|
+
const ignoreFilepath = path3.default.resolve(path3.default.dirname(result.filepath), ".keqignore");
|
|
302
|
+
if (await _fsextra2.default.exists(ignoreFilepath)) {
|
|
303
|
+
matcher = await IgnoreMatcher.read(ignoreFilepath);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
const ignoreRules = options.ignore === false ? [] : _optionalChain([options, 'access', _5 => _5.ignore, 'optionalAccess', _6 => _6.rules]) || [];
|
|
307
|
+
for (const rule of ignoreRules) {
|
|
308
|
+
matcher.append({
|
|
309
|
+
persist: !!rule.persist,
|
|
310
|
+
ignore: rule.ignore,
|
|
311
|
+
moduleName: rule.moduleName,
|
|
312
|
+
operationMethod: rule.operationMethod,
|
|
313
|
+
operationPathname: rule.operationPathname
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
context.matcher = matcher;
|
|
317
|
+
await compiler.hooks.setup.promise(task);
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
function createSetupTask(compiler, options) {
|
|
322
|
+
return {
|
|
323
|
+
title: "Setup",
|
|
324
|
+
enabled: _optionalChain([options, 'optionalAccess', _7 => _7.enabled]),
|
|
325
|
+
skip: _optionalChain([options, 'optionalAccess', _8 => _8.skip]),
|
|
326
|
+
task: (context, task) => task.newListr(
|
|
327
|
+
[
|
|
328
|
+
main(compiler, options),
|
|
329
|
+
{
|
|
330
|
+
task: (context2, task2) => compiler.hooks.afterSetup.promise(task2)
|
|
331
|
+
}
|
|
332
|
+
],
|
|
333
|
+
{
|
|
334
|
+
concurrent: false
|
|
335
|
+
}
|
|
336
|
+
)
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// src/compiler/tasks/download/index.ts
|
|
341
|
+
|
|
342
|
+
var _openapiparser = require('@scalar/openapi-parser');
|
|
343
|
+
function main2(compiler, options) {
|
|
344
|
+
return {
|
|
345
|
+
task: (context, task) => {
|
|
346
|
+
if (!context.rc || !context.matcher) {
|
|
347
|
+
throw new Error("Please run setup task first.");
|
|
348
|
+
}
|
|
349
|
+
const rc = context.rc;
|
|
350
|
+
const matcher = context.matcher;
|
|
351
|
+
context.documents = [];
|
|
352
|
+
return task.newListr(
|
|
353
|
+
Object.entries(rc.modules).map(([moduleName, address]) => new (0, _chunk7HHTHYRAcjs.ModuleDefinition)(moduleName, address)).map((moduleDefinition) => ({
|
|
354
|
+
title: moduleDefinition.name,
|
|
355
|
+
task: async (ctx, task2) => {
|
|
356
|
+
if (_optionalChain([options, 'optionalAccess', _9 => _9.skipIgnoredModules]) && matcher.isModuleIgnored(moduleDefinition)) {
|
|
357
|
+
task2.skip(`(${moduleDefinition.name}) is ignored`);
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
task2.output = `Downloaded from ${moduleDefinition.address.url}`;
|
|
361
|
+
const content = await compiler.hooks.download.promise(moduleDefinition.address, moduleDefinition, task2);
|
|
362
|
+
if (!content) {
|
|
363
|
+
throw new (0, _chunk7HHTHYRAcjs.Exception)(moduleDefinition, `Cannot download document from ${moduleDefinition.address.url}`);
|
|
364
|
+
}
|
|
365
|
+
const spec = JSON.parse(content);
|
|
366
|
+
const { valid, errors } = await _openapiparser.validate.call(void 0, spec);
|
|
367
|
+
if (!valid) {
|
|
368
|
+
const message = `${moduleDefinition.name} module openapi/swagger file does not conform to the openapi specifications or have grammatical errors, which may cause unexpected errors:
|
|
369
|
+
${_optionalChain([errors, 'optionalAccess', _10 => _10.map, 'call', _11 => _11((e) => ` - ${e.message}`), 'access', _12 => _12.join, 'call', _13 => _13("\n")])}`;
|
|
370
|
+
task2.output = message;
|
|
371
|
+
}
|
|
372
|
+
_chunk7HHTHYRAcjs.OpenapiUtils.dereferenceOperation(spec);
|
|
373
|
+
const document = new (0, _chunk7HHTHYRAcjs.ApiDocumentV3_1)(
|
|
374
|
+
spec,
|
|
375
|
+
moduleDefinition
|
|
376
|
+
);
|
|
377
|
+
_optionalChain([ctx, 'access', _14 => _14.documents, 'optionalAccess', _15 => _15.push, 'call', _16 => _16(document)]);
|
|
378
|
+
}
|
|
379
|
+
})),
|
|
380
|
+
{
|
|
381
|
+
concurrent: true,
|
|
382
|
+
exitOnError: false,
|
|
383
|
+
collectErrors: "minimal",
|
|
384
|
+
rendererOptions: {
|
|
385
|
+
collapseSubtasks: false,
|
|
386
|
+
// collapseSkips: false,
|
|
387
|
+
suffixSkips: true,
|
|
388
|
+
timer: _listr2.PRESET_TIMER
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
function createDownloadTask(compiler, options) {
|
|
396
|
+
return {
|
|
397
|
+
title: "Download",
|
|
398
|
+
enabled: _optionalChain([options, 'optionalAccess', _17 => _17.enabled]),
|
|
399
|
+
skip: _optionalChain([options, 'optionalAccess', _18 => _18.skip]),
|
|
400
|
+
task: (_, task) => task.newListr(
|
|
401
|
+
[
|
|
402
|
+
main2(compiler, options),
|
|
403
|
+
{
|
|
404
|
+
task: (context, task2) => compiler.hooks.afterDownload.promise(task2)
|
|
405
|
+
}
|
|
406
|
+
],
|
|
407
|
+
{
|
|
408
|
+
concurrent: false
|
|
409
|
+
}
|
|
410
|
+
)
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// src/compiler/tasks/persist/index.ts
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
function createPersistArtifactTask() {
|
|
418
|
+
return {
|
|
419
|
+
title: "Write files",
|
|
420
|
+
task: async (context, task) => {
|
|
421
|
+
if (!context.rc) throw new Error("Please run setup task first.");
|
|
422
|
+
if (!context.artifacts || context.artifacts.length === 0) {
|
|
423
|
+
task.skip("No compiled artifacts to persist.");
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
const rc = context.rc;
|
|
427
|
+
const artifacts = context.artifacts;
|
|
428
|
+
const total = artifacts.length;
|
|
429
|
+
let completed = 0;
|
|
430
|
+
const files = await Promise.all(artifacts.map(async (artifact) => {
|
|
431
|
+
const realpath = `./${path3.join(rc.outdir, artifact.filepath)}`;
|
|
432
|
+
await _fsextra2.default.ensureFile(realpath);
|
|
433
|
+
await _fsextra2.default.writeFile(realpath, artifact.renderer());
|
|
434
|
+
completed += 1;
|
|
435
|
+
task.output = `Persisted ${completed}/${total} files`;
|
|
436
|
+
return new (0, _chunk7HHTHYRAcjs.Asset)(path3.resolve(realpath));
|
|
437
|
+
}));
|
|
438
|
+
context.assets = files;
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
function createPersistIgnoreTask() {
|
|
443
|
+
return {
|
|
444
|
+
title: "Update .keqignore",
|
|
445
|
+
task: async (context, task) => {
|
|
446
|
+
if (!context.matcher) throw new Error("Please run setup task first.");
|
|
447
|
+
const matcher = context.matcher;
|
|
448
|
+
await matcher.write(".keqignore");
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
function main3() {
|
|
453
|
+
return {
|
|
454
|
+
task: (context, task) => task.newListr(
|
|
455
|
+
[
|
|
456
|
+
createPersistArtifactTask(),
|
|
457
|
+
createPersistIgnoreTask()
|
|
458
|
+
],
|
|
459
|
+
{
|
|
460
|
+
concurrent: true,
|
|
461
|
+
rendererOptions: {
|
|
462
|
+
collapseSubtasks: true
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
)
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
function createPersistTask(compiler, options) {
|
|
469
|
+
return {
|
|
470
|
+
title: "Persist",
|
|
471
|
+
enabled: _optionalChain([options, 'optionalAccess', _19 => _19.enabled]),
|
|
472
|
+
skip: _optionalChain([options, 'optionalAccess', _20 => _20.skip]),
|
|
473
|
+
task: (context, task) => task.newListr(
|
|
474
|
+
[
|
|
475
|
+
main3(),
|
|
476
|
+
{
|
|
477
|
+
task: (context2, task2) => compiler.hooks.afterPersist.promise(task2)
|
|
478
|
+
}
|
|
479
|
+
],
|
|
480
|
+
{
|
|
481
|
+
concurrent: false
|
|
482
|
+
}
|
|
483
|
+
)
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
// src/compiler/tasks/compile/index.ts
|
|
488
|
+
function main4(compiler) {
|
|
489
|
+
return {
|
|
490
|
+
task: async (context, task) => {
|
|
491
|
+
if (!context.rc) throw new Error("Please run setup task first.");
|
|
492
|
+
if (!context.documents) throw new Error("Please run shaking task first.");
|
|
493
|
+
context.artifacts = [];
|
|
494
|
+
await compiler.hooks.compile.promise(task);
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
function createCompileTask(compiler, options) {
|
|
499
|
+
return {
|
|
500
|
+
title: "Compile",
|
|
501
|
+
enabled: _optionalChain([options, 'optionalAccess', _21 => _21.enabled]),
|
|
502
|
+
skip: _optionalChain([options, 'optionalAccess', _22 => _22.skip]),
|
|
503
|
+
task: (context, task) => task.newListr(
|
|
504
|
+
[
|
|
505
|
+
{
|
|
506
|
+
task: (context2, task2) => compiler.hooks.beforeCompile.promise(task2)
|
|
507
|
+
},
|
|
508
|
+
main4(compiler),
|
|
509
|
+
{
|
|
510
|
+
task: (context2, task2) => compiler.hooks.afterCompile.promise(task2)
|
|
511
|
+
}
|
|
512
|
+
],
|
|
513
|
+
{
|
|
514
|
+
concurrent: false
|
|
515
|
+
}
|
|
516
|
+
)
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
// src/compiler/intercepter/print-information.ts
|
|
521
|
+
function proxyTaskWrapper(pluginName, task) {
|
|
522
|
+
return new Proxy(task, {
|
|
523
|
+
set(target, prop2, value) {
|
|
524
|
+
if (prop2 !== "output") {
|
|
525
|
+
return Reflect.set(target, prop2, value);
|
|
526
|
+
}
|
|
527
|
+
target.output = `[Plugin: ${pluginName}] ${value}`;
|
|
528
|
+
return true;
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
function printInformation(taskIndex) {
|
|
533
|
+
return {
|
|
534
|
+
register: (tap) => {
|
|
535
|
+
const fn = tap.fn;
|
|
536
|
+
if (tap.type === "promise") {
|
|
537
|
+
tap.fn = (...args) => {
|
|
538
|
+
const task = args[taskIndex];
|
|
539
|
+
const proxyTask = proxyTaskWrapper(tap.name, task);
|
|
540
|
+
args[taskIndex] = proxyTask;
|
|
541
|
+
proxyTask.output = "Processing...";
|
|
542
|
+
return fn(...args);
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
if (tap.type === "sync") {
|
|
546
|
+
tap.fn = (...args) => {
|
|
547
|
+
const task = args[taskIndex];
|
|
548
|
+
const proxyTask = proxyTaskWrapper(tap.name, task);
|
|
549
|
+
args[taskIndex] = proxyTask;
|
|
550
|
+
proxyTask.output = "Processing...";
|
|
551
|
+
return fn(...args);
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
if (tap.type === "async") {
|
|
555
|
+
tap.fn = (...args) => {
|
|
556
|
+
const task = args[taskIndex];
|
|
557
|
+
const proxyTask = proxyTaskWrapper(tap.name, task);
|
|
558
|
+
args[taskIndex] = proxyTask;
|
|
559
|
+
proxyTask.output = "Processing...";
|
|
560
|
+
return fn(...args);
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
return tap;
|
|
564
|
+
}
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
// src/compiler/intercepter/perfect-error-message.ts
|
|
569
|
+
|
|
570
|
+
function perfectErrorMessage() {
|
|
571
|
+
return {
|
|
572
|
+
register: (tap) => {
|
|
573
|
+
const fn = tap.fn;
|
|
574
|
+
function prefix(err) {
|
|
575
|
+
if (err instanceof Error) {
|
|
576
|
+
err.message = `[Plugin: ${tap.name}] ${err.message}`;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
if (tap.type === "promise") {
|
|
580
|
+
tap.fn = async (...args) => {
|
|
581
|
+
try {
|
|
582
|
+
return await fn(...args);
|
|
583
|
+
} catch (err) {
|
|
584
|
+
prefix(err);
|
|
585
|
+
throw err;
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
if (tap.type === "sync") {
|
|
590
|
+
tap.fn = (...args) => {
|
|
591
|
+
try {
|
|
592
|
+
return fn(...args);
|
|
593
|
+
} catch (err) {
|
|
594
|
+
prefix(err);
|
|
595
|
+
throw err;
|
|
596
|
+
}
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
if (tap.type === "async") {
|
|
600
|
+
tap.fn = (...args) => {
|
|
601
|
+
const callback = R3.last(args);
|
|
602
|
+
return fn(...R3.init(args), (err, result) => {
|
|
603
|
+
prefix(err);
|
|
604
|
+
return callback(err, result);
|
|
605
|
+
});
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
return tap;
|
|
609
|
+
}
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
// src/compiler/compiler.ts
|
|
614
|
+
var Compiler = (_class = class {
|
|
615
|
+
constructor(options) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);
|
|
616
|
+
this.options = options;
|
|
617
|
+
for (const hook of Object.values(this.hooks)) {
|
|
618
|
+
hook.intercept(perfectErrorMessage());
|
|
619
|
+
}
|
|
620
|
+
this.hooks.afterSetup.intercept(printInformation(0));
|
|
621
|
+
this.hooks.afterPersist.intercept(printInformation(0));
|
|
622
|
+
new (0, _chunk7HHTHYRAcjs.InitializePlugin)({
|
|
623
|
+
build: options.build,
|
|
624
|
+
interactive: options.interactive,
|
|
625
|
+
includes: options.includes
|
|
626
|
+
}).apply(this);
|
|
627
|
+
}
|
|
628
|
+
__init() {this.context = {}}
|
|
629
|
+
__init2() {this.hooks = {
|
|
630
|
+
setup: new (0, _tapable.AsyncParallelHook)(["task"]),
|
|
631
|
+
afterSetup: new (0, _tapable.AsyncSeriesHook)(["task"]),
|
|
632
|
+
beforeDownload: new (0, _tapable.AsyncSeriesHook)(["task"]),
|
|
633
|
+
download: new (0, _tapable.AsyncSeriesBailHook)(["address", "moduleDefinition", "task"]),
|
|
634
|
+
afterDownload: new (0, _tapable.AsyncSeriesHook)(["task"]),
|
|
635
|
+
beforeCompile: new (0, _tapable.AsyncSeriesHook)(["task"]),
|
|
636
|
+
compile: new (0, _tapable.AsyncParallelHook)(["task"]),
|
|
637
|
+
afterCompile: new (0, _tapable.AsyncSeriesHook)(["task"]),
|
|
638
|
+
beforePersist: new (0, _tapable.AsyncSeriesHook)(["task"]),
|
|
639
|
+
persist: new (0, _tapable.AsyncParallelHook)(["task"]),
|
|
640
|
+
afterPersist: new (0, _tapable.AsyncSeriesHook)(["task"]),
|
|
641
|
+
done: new (0, _tapable.SyncHook)()
|
|
642
|
+
}}
|
|
643
|
+
async run() {
|
|
644
|
+
const options = this.options;
|
|
645
|
+
const tasks = new (0, _listr2.Listr)(
|
|
646
|
+
[
|
|
647
|
+
createSetupTask(this, options),
|
|
648
|
+
createDownloadTask(this, { skipIgnoredModules: !options.interactive }),
|
|
649
|
+
createCompileTask(this, { enabled: !!options.build }),
|
|
650
|
+
createPersistTask(this, { enabled: !!options.persist })
|
|
651
|
+
],
|
|
652
|
+
{
|
|
653
|
+
concurrent: false,
|
|
654
|
+
renderer: options.silent ? "silent" : "default",
|
|
655
|
+
rendererOptions: {
|
|
656
|
+
suffixSkips: true,
|
|
657
|
+
collapseSubtasks: false,
|
|
658
|
+
collapseErrors: false
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
);
|
|
662
|
+
await tasks.run(this.context);
|
|
663
|
+
await this.hooks.done.promise();
|
|
664
|
+
}
|
|
665
|
+
}, _class);
|
|
666
|
+
|
|
667
|
+
|
|
668
|
+
|
|
669
|
+
exports.Compiler = Compiler;
|
|
670
|
+
//# sourceMappingURL=chunk-JX74ZR2O.cjs.map
|