@kubb/cli 4.21.2 → 4.22.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/dist/{generate-DgWO-YRb.js → generate-Bgpw_dcv.js} +6 -648
- package/dist/generate-Bgpw_dcv.js.map +1 -0
- package/dist/{generate-R5HtGqSp.cjs → generate-BxSL_NKj.cjs} +10 -652
- package/dist/generate-BxSL_NKj.cjs.map +1 -0
- package/dist/getCosmiConfig-Co29x0Wv.cjs +458 -0
- package/dist/getCosmiConfig-Co29x0Wv.cjs.map +1 -0
- package/dist/getCosmiConfig-y2n_oW_y.js +438 -0
- package/dist/getCosmiConfig-y2n_oW_y.js.map +1 -0
- package/dist/index.cjs +9 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +9 -7
- package/dist/index.js.map +1 -1
- package/dist/{init-C9XEA7L6.js → init-CfRtJpHs.js} +3 -3
- package/dist/{init-C9XEA7L6.js.map → init-CfRtJpHs.js.map} +1 -1
- package/dist/{init-B7j_UJk9.cjs → init-DZzYaf0D.cjs} +3 -3
- package/dist/{init-B7j_UJk9.cjs.map → init-DZzYaf0D.cjs.map} +1 -1
- package/dist/{mcp-By2JUPa8.js → mcp-BdwwUv36.js} +1 -1
- package/dist/{mcp-By2JUPa8.js.map → mcp-BdwwUv36.js.map} +1 -1
- package/dist/{mcp-l-_Z-WU6.cjs → mcp-Hy_PYnFp.cjs} +1 -1
- package/dist/{mcp-l-_Z-WU6.cjs.map → mcp-Hy_PYnFp.cjs.map} +1 -1
- package/dist/package-BQu01PU2.js +6 -0
- package/dist/package-BQu01PU2.js.map +1 -0
- package/dist/{package-C1biCSPI.cjs → package-Cmbk_MZB.cjs} +2 -2
- package/dist/package-Cmbk_MZB.cjs.map +1 -0
- package/dist/start-Dtqs_9NV.js +125 -0
- package/dist/start-Dtqs_9NV.js.map +1 -0
- package/dist/start-iXbqdw8g.cjs +128 -0
- package/dist/start-iXbqdw8g.cjs.map +1 -0
- package/dist/{validate-DkHCd-Tl.cjs → validate-Cvb5aOEb.cjs} +1 -1
- package/dist/{validate-DkHCd-Tl.cjs.map → validate-Cvb5aOEb.cjs.map} +1 -1
- package/dist/{validate-0Qu8SxVA.js → validate-YI4YkVTl.js} +1 -1
- package/dist/{validate-0Qu8SxVA.js.map → validate-YI4YkVTl.js.map} +1 -1
- package/package.json +4 -4
- package/src/commands/generate.ts +0 -38
- package/src/commands/init.ts +3 -1
- package/src/commands/start.ts +149 -0
- package/src/index.ts +2 -1
- package/dist/generate-DgWO-YRb.js.map +0 -1
- package/dist/generate-R5HtGqSp.cjs.map +0 -1
- package/dist/package-C1biCSPI.cjs.map +0 -1
- package/dist/package-DRskcFXO.js +0 -6
- package/dist/package-DRskcFXO.js.map +0 -1
- package/src/loggers/streamLogger.ts +0 -93
- package/src/utils/streamServer.ts +0 -160
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-C1_xRkKa.cjs');
|
|
2
|
-
const require_package = require('./package-
|
|
2
|
+
const require_package = require('./package-Cmbk_MZB.cjs');
|
|
3
|
+
const require_getCosmiConfig = require('./getCosmiConfig-Co29x0Wv.cjs');
|
|
3
4
|
let citty = require("citty");
|
|
4
5
|
let node_path = require("node:path");
|
|
5
6
|
node_path = require_chunk.__toESM(node_path);
|
|
@@ -21,12 +22,6 @@ let seedrandom = require("seedrandom");
|
|
|
21
22
|
seedrandom = require_chunk.__toESM(seedrandom);
|
|
22
23
|
let node_stream = require("node:stream");
|
|
23
24
|
let _kubb_core_fs = require("@kubb/core/fs");
|
|
24
|
-
let node_crypto = require("node:crypto");
|
|
25
|
-
let string_argv = require("string-argv");
|
|
26
|
-
let cosmiconfig = require("cosmiconfig");
|
|
27
|
-
let jiti = require("jiti");
|
|
28
|
-
let node_fs = require("node:fs");
|
|
29
|
-
let node_http = require("node:http");
|
|
30
25
|
|
|
31
26
|
//#region src/utils/formatMsWithColor.ts
|
|
32
27
|
/**
|
|
@@ -1135,625 +1130,17 @@ async function setupLogger(context, { logLevel }) {
|
|
|
1135
1130
|
return cleanup;
|
|
1136
1131
|
}
|
|
1137
1132
|
|
|
1138
|
-
//#endregion
|
|
1139
|
-
//#region src/utils/detectFormatter.ts
|
|
1140
|
-
/**
|
|
1141
|
-
* Check if a formatter command is available in the system.
|
|
1142
|
-
*
|
|
1143
|
-
* @param formatter - The formatter to check ('biome', 'prettier', or 'oxfmt')
|
|
1144
|
-
* @returns Promise that resolves to true if the formatter is available, false otherwise
|
|
1145
|
-
*
|
|
1146
|
-
* @remarks
|
|
1147
|
-
* This function checks availability by running `<formatter> --version` command.
|
|
1148
|
-
* All supported formatters (biome, prettier, oxfmt) implement the --version flag.
|
|
1149
|
-
*/
|
|
1150
|
-
async function isFormatterAvailable(formatter) {
|
|
1151
|
-
try {
|
|
1152
|
-
await (0, execa.execaCommand)(`${formatter} --version`, { stdio: "ignore" });
|
|
1153
|
-
return true;
|
|
1154
|
-
} catch {
|
|
1155
|
-
return false;
|
|
1156
|
-
}
|
|
1157
|
-
}
|
|
1158
|
-
/**
|
|
1159
|
-
* Detect which formatter is available in the system.
|
|
1160
|
-
*
|
|
1161
|
-
* @returns Promise that resolves to the first available formatter or undefined if none are found
|
|
1162
|
-
*
|
|
1163
|
-
* @remarks
|
|
1164
|
-
* Checks in order of preference: biome, oxfmt, prettier.
|
|
1165
|
-
* Uses the `--version` flag to detect if each formatter command is available.
|
|
1166
|
-
* This is a reliable method as all supported formatters implement this flag.
|
|
1167
|
-
*
|
|
1168
|
-
* @example
|
|
1169
|
-
* ```typescript
|
|
1170
|
-
* const formatter = await detectFormatter()
|
|
1171
|
-
* if (formatter) {
|
|
1172
|
-
* console.log(`Using ${formatter} for formatting`)
|
|
1173
|
-
* } else {
|
|
1174
|
-
* console.log('No formatter found')
|
|
1175
|
-
* }
|
|
1176
|
-
* ```
|
|
1177
|
-
*/
|
|
1178
|
-
async function detectFormatter() {
|
|
1179
|
-
for (const formatter of [
|
|
1180
|
-
"biome",
|
|
1181
|
-
"oxfmt",
|
|
1182
|
-
"prettier"
|
|
1183
|
-
]) if (await isFormatterAvailable(formatter)) return formatter;
|
|
1184
|
-
}
|
|
1185
|
-
|
|
1186
|
-
//#endregion
|
|
1187
|
-
//#region src/utils/detectLinter.ts
|
|
1188
|
-
/**
|
|
1189
|
-
* Check if a linter command is available in the system.
|
|
1190
|
-
*
|
|
1191
|
-
* @param linter - The linter to check ('biome', 'oxlint', or 'eslint')
|
|
1192
|
-
* @returns Promise that resolves to true if the linter is available, false otherwise
|
|
1193
|
-
*
|
|
1194
|
-
* @remarks
|
|
1195
|
-
* This function checks availability by running `<linter> --version` command.
|
|
1196
|
-
* All supported linters (biome, oxlint, eslint) implement the --version flag.
|
|
1197
|
-
*/
|
|
1198
|
-
async function isLinterAvailable(linter) {
|
|
1199
|
-
try {
|
|
1200
|
-
await (0, execa.execaCommand)(`${linter} --version`, { stdio: "ignore" });
|
|
1201
|
-
return true;
|
|
1202
|
-
} catch {
|
|
1203
|
-
return false;
|
|
1204
|
-
}
|
|
1205
|
-
}
|
|
1206
|
-
/**
|
|
1207
|
-
* Detect which linter is available in the system.
|
|
1208
|
-
*
|
|
1209
|
-
* @returns Promise that resolves to the first available linter or undefined if none are found
|
|
1210
|
-
*
|
|
1211
|
-
* @remarks
|
|
1212
|
-
* Checks in order of preference: biome, oxlint, eslint.
|
|
1213
|
-
* Uses the `--version` flag to detect if each linter command is available.
|
|
1214
|
-
* This is a reliable method as all supported linters implement this flag.
|
|
1215
|
-
*
|
|
1216
|
-
* @example
|
|
1217
|
-
* ```typescript
|
|
1218
|
-
* const linter = await detectLinter()
|
|
1219
|
-
* if (linter) {
|
|
1220
|
-
* console.log(`Using ${linter} for linting`)
|
|
1221
|
-
* } else {
|
|
1222
|
-
* console.log('No linter found')
|
|
1223
|
-
* }
|
|
1224
|
-
* ```
|
|
1225
|
-
*/
|
|
1226
|
-
async function detectLinter() {
|
|
1227
|
-
for (const linter of [
|
|
1228
|
-
"biome",
|
|
1229
|
-
"oxlint",
|
|
1230
|
-
"eslint"
|
|
1231
|
-
]) if (await isLinterAvailable(linter)) return linter;
|
|
1232
|
-
}
|
|
1233
|
-
|
|
1234
|
-
//#endregion
|
|
1235
|
-
//#region src/utils/executeHooks.ts
|
|
1236
|
-
async function executeHooks({ hooks, events }) {
|
|
1237
|
-
const commands = Array.isArray(hooks.done) ? hooks.done : [hooks.done].filter(Boolean);
|
|
1238
|
-
for (const command$1 of commands) {
|
|
1239
|
-
const [cmd, ...args] = [...(0, string_argv.parseArgsStringToArgv)(command$1)];
|
|
1240
|
-
if (!cmd) continue;
|
|
1241
|
-
const hookId = (0, node_crypto.createHash)("sha256").update(command$1).digest("hex");
|
|
1242
|
-
await events.emit("hook:start", {
|
|
1243
|
-
id: hookId,
|
|
1244
|
-
command: cmd,
|
|
1245
|
-
args
|
|
1246
|
-
});
|
|
1247
|
-
await events.onOnce("hook:end", async ({ success, error }) => {
|
|
1248
|
-
if (!success) throw error;
|
|
1249
|
-
await events.emit("success", `${picocolors.default.dim(command$1)} successfully executed`);
|
|
1250
|
-
});
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1253
|
-
|
|
1254
|
-
//#endregion
|
|
1255
|
-
//#region src/utils/formatters.ts
|
|
1256
|
-
const formatters = {
|
|
1257
|
-
prettier: {
|
|
1258
|
-
command: "prettier",
|
|
1259
|
-
args: (outputPath) => [
|
|
1260
|
-
"--ignore-unknown",
|
|
1261
|
-
"--write",
|
|
1262
|
-
outputPath
|
|
1263
|
-
],
|
|
1264
|
-
errorMessage: "Prettier not found"
|
|
1265
|
-
},
|
|
1266
|
-
biome: {
|
|
1267
|
-
command: "biome",
|
|
1268
|
-
args: (outputPath) => [
|
|
1269
|
-
"format",
|
|
1270
|
-
"--write",
|
|
1271
|
-
outputPath
|
|
1272
|
-
],
|
|
1273
|
-
errorMessage: "Biome not found"
|
|
1274
|
-
},
|
|
1275
|
-
oxfmt: {
|
|
1276
|
-
command: "oxfmt",
|
|
1277
|
-
args: (outputPath) => [outputPath],
|
|
1278
|
-
errorMessage: "Oxfmt not found"
|
|
1279
|
-
}
|
|
1280
|
-
};
|
|
1281
|
-
|
|
1282
|
-
//#endregion
|
|
1283
|
-
//#region src/runners/generate.ts
|
|
1284
|
-
async function generate({ input, config: userConfig, events, logLevel }) {
|
|
1285
|
-
const inputPath = input ?? ("path" in userConfig.input ? userConfig.input.path : void 0);
|
|
1286
|
-
const hrStart = node_process.default.hrtime();
|
|
1287
|
-
const config = {
|
|
1288
|
-
...userConfig,
|
|
1289
|
-
root: userConfig.root || node_process.default.cwd(),
|
|
1290
|
-
input: inputPath ? {
|
|
1291
|
-
...userConfig.input,
|
|
1292
|
-
path: inputPath
|
|
1293
|
-
} : userConfig.input,
|
|
1294
|
-
output: {
|
|
1295
|
-
write: true,
|
|
1296
|
-
barrelType: "named",
|
|
1297
|
-
extension: { ".ts": ".ts" },
|
|
1298
|
-
format: "prettier",
|
|
1299
|
-
...userConfig.output
|
|
1300
|
-
}
|
|
1301
|
-
};
|
|
1302
|
-
await events.emit("generation:start", config);
|
|
1303
|
-
await events.emit("info", config.name ? `Setup generation ${picocolors.default.bold(config.name)}` : "Setup generation", inputPath);
|
|
1304
|
-
const { sources, fabric, pluginManager } = await (0, _kubb_core.setup)({
|
|
1305
|
-
config,
|
|
1306
|
-
events
|
|
1307
|
-
});
|
|
1308
|
-
await events.emit("info", config.name ? `Build generation ${picocolors.default.bold(config.name)}` : "Build generation", inputPath);
|
|
1309
|
-
const { files, failedPlugins, pluginTimings, error } = await (0, _kubb_core.safeBuild)({
|
|
1310
|
-
config,
|
|
1311
|
-
events
|
|
1312
|
-
}, {
|
|
1313
|
-
pluginManager,
|
|
1314
|
-
fabric,
|
|
1315
|
-
events,
|
|
1316
|
-
sources
|
|
1317
|
-
});
|
|
1318
|
-
await events.emit("info", "Load summary");
|
|
1319
|
-
if (failedPlugins.size > 0 || error) {
|
|
1320
|
-
[error, ...Array.from(failedPlugins).filter((it) => it.error).map((it) => it.error)].filter(Boolean).forEach((err) => {
|
|
1321
|
-
events.emit("error", err);
|
|
1322
|
-
});
|
|
1323
|
-
await events.emit("generation:end", config, files, sources);
|
|
1324
|
-
await events.emit("generation:summary", config, {
|
|
1325
|
-
failedPlugins,
|
|
1326
|
-
filesCreated: files.length,
|
|
1327
|
-
status: failedPlugins.size > 0 || error ? "failed" : "success",
|
|
1328
|
-
hrStart,
|
|
1329
|
-
pluginTimings: logLevel >= _kubb_core.LogLevel.verbose ? pluginTimings : void 0
|
|
1330
|
-
});
|
|
1331
|
-
node_process.default.exit(1);
|
|
1332
|
-
}
|
|
1333
|
-
await events.emit("success", "Generation successfully", inputPath);
|
|
1334
|
-
await events.emit("generation:end", config, files, sources);
|
|
1335
|
-
if (config.output.format) {
|
|
1336
|
-
await events.emit("format:start");
|
|
1337
|
-
let formatter = config.output.format;
|
|
1338
|
-
if (formatter === "auto") {
|
|
1339
|
-
const detectedFormatter = await detectFormatter();
|
|
1340
|
-
if (!detectedFormatter) await events.emit("warn", "No formatter found (biome, prettier, or oxfmt). Skipping formatting.");
|
|
1341
|
-
else {
|
|
1342
|
-
formatter = detectedFormatter;
|
|
1343
|
-
await events.emit("info", `Auto-detected formatter: ${picocolors.default.dim(formatter)}`);
|
|
1344
|
-
}
|
|
1345
|
-
}
|
|
1346
|
-
if (formatter && formatter !== "auto" && formatter in formatters) {
|
|
1347
|
-
const formatterConfig = formatters[formatter];
|
|
1348
|
-
const outputPath = node_path.default.resolve(config.root, config.output.path);
|
|
1349
|
-
try {
|
|
1350
|
-
const hookId = (0, node_crypto.createHash)("sha256").update([config.name, formatter].filter(Boolean).join("-")).digest("hex");
|
|
1351
|
-
await events.emit("hook:start", {
|
|
1352
|
-
id: hookId,
|
|
1353
|
-
command: formatterConfig.command,
|
|
1354
|
-
args: formatterConfig.args(outputPath)
|
|
1355
|
-
});
|
|
1356
|
-
await events.onOnce("hook:end", async ({ success, error: error$1 }) => {
|
|
1357
|
-
if (!success) throw error$1;
|
|
1358
|
-
await events.emit("success", [
|
|
1359
|
-
`Formatting with ${picocolors.default.dim(formatter)}`,
|
|
1360
|
-
logLevel >= _kubb_core.LogLevel.info ? `on ${picocolors.default.dim(outputPath)}` : void 0,
|
|
1361
|
-
"successfully"
|
|
1362
|
-
].filter(Boolean).join(" "));
|
|
1363
|
-
});
|
|
1364
|
-
} catch (caughtError) {
|
|
1365
|
-
const error$1 = new Error(formatterConfig.errorMessage);
|
|
1366
|
-
error$1.cause = caughtError;
|
|
1367
|
-
await events.emit("error", error$1);
|
|
1368
|
-
}
|
|
1369
|
-
}
|
|
1370
|
-
await events.emit("format:end");
|
|
1371
|
-
}
|
|
1372
|
-
if (config.output.lint) {
|
|
1373
|
-
await events.emit("lint:start");
|
|
1374
|
-
let linter = config.output.lint;
|
|
1375
|
-
if (linter === "auto") {
|
|
1376
|
-
const detectedLinter = await detectLinter();
|
|
1377
|
-
if (!detectedLinter) await events.emit("warn", "No linter found (biome, oxlint, or eslint). Skipping linting.");
|
|
1378
|
-
else {
|
|
1379
|
-
linter = detectedLinter;
|
|
1380
|
-
await events.emit("info", `Auto-detected linter: ${picocolors.default.dim(linter)}`);
|
|
1381
|
-
}
|
|
1382
|
-
}
|
|
1383
|
-
if (linter && linter !== "auto") {
|
|
1384
|
-
await events.emit("info", [`Linting with ${picocolors.default.dim(linter)}`, logLevel >= _kubb_core.LogLevel.info ? `on ${picocolors.default.dim(node_path.default.resolve(config.root, config.output.path))}` : void 0].filter(Boolean).join(" "));
|
|
1385
|
-
if (linter === "eslint") try {
|
|
1386
|
-
const hookId = (0, node_crypto.createHash)("sha256").update([config.name, linter].filter(Boolean).join("-")).digest("hex");
|
|
1387
|
-
await events.emit("hook:start", {
|
|
1388
|
-
id: hookId,
|
|
1389
|
-
command: "eslint",
|
|
1390
|
-
args: [node_path.default.resolve(config.root, config.output.path), "--fix"]
|
|
1391
|
-
});
|
|
1392
|
-
await events.onOnce("hook:end", async ({ success, error: error$1 }) => {
|
|
1393
|
-
if (!success) throw error$1;
|
|
1394
|
-
await events.emit("success", [
|
|
1395
|
-
`Linted with ${picocolors.default.dim(linter)}`,
|
|
1396
|
-
logLevel >= _kubb_core.LogLevel.info ? `on ${picocolors.default.dim(node_path.default.resolve(config.root, config.output.path))}` : void 0,
|
|
1397
|
-
"successfully"
|
|
1398
|
-
].filter(Boolean).join(" "));
|
|
1399
|
-
});
|
|
1400
|
-
} catch (caughtError) {
|
|
1401
|
-
const error$1 = /* @__PURE__ */ new Error("Eslint not found");
|
|
1402
|
-
error$1.cause = caughtError;
|
|
1403
|
-
await events.emit("error", error$1);
|
|
1404
|
-
}
|
|
1405
|
-
if (linter === "biome") try {
|
|
1406
|
-
const hookId = (0, node_crypto.createHash)("sha256").update([config.name, linter].filter(Boolean).join("-")).digest("hex");
|
|
1407
|
-
await events.emit("hook:start", {
|
|
1408
|
-
id: hookId,
|
|
1409
|
-
command: "biome",
|
|
1410
|
-
args: [
|
|
1411
|
-
"lint",
|
|
1412
|
-
"--fix",
|
|
1413
|
-
node_path.default.resolve(config.root, config.output.path)
|
|
1414
|
-
]
|
|
1415
|
-
});
|
|
1416
|
-
await events.onOnce("hook:end", async ({ success, error: error$1 }) => {
|
|
1417
|
-
if (!success) throw error$1;
|
|
1418
|
-
await events.emit("success", [
|
|
1419
|
-
`Linted with ${picocolors.default.dim(linter)}`,
|
|
1420
|
-
logLevel >= _kubb_core.LogLevel.info ? `on ${picocolors.default.dim(node_path.default.resolve(config.root, config.output.path))}` : void 0,
|
|
1421
|
-
"successfully"
|
|
1422
|
-
].filter(Boolean).join(" "));
|
|
1423
|
-
});
|
|
1424
|
-
} catch (caughtError) {
|
|
1425
|
-
const error$1 = /* @__PURE__ */ new Error("Biome not found");
|
|
1426
|
-
error$1.cause = caughtError;
|
|
1427
|
-
await events.emit("error", error$1);
|
|
1428
|
-
}
|
|
1429
|
-
if (linter === "oxlint") try {
|
|
1430
|
-
const hookId = (0, node_crypto.createHash)("sha256").update([config.name, linter].filter(Boolean).join("-")).digest("hex");
|
|
1431
|
-
await events.emit("hook:start", {
|
|
1432
|
-
id: hookId,
|
|
1433
|
-
command: "oxlint",
|
|
1434
|
-
args: ["--fix", node_path.default.resolve(config.root, config.output.path)]
|
|
1435
|
-
});
|
|
1436
|
-
await events.onOnce("hook:end", async ({ success, error: error$1 }) => {
|
|
1437
|
-
if (!success) throw error$1;
|
|
1438
|
-
await events.emit("success", [
|
|
1439
|
-
`Linted with ${picocolors.default.dim(linter)}`,
|
|
1440
|
-
logLevel >= _kubb_core.LogLevel.info ? `on ${picocolors.default.dim(node_path.default.resolve(config.root, config.output.path))}` : void 0,
|
|
1441
|
-
"successfully"
|
|
1442
|
-
].filter(Boolean).join(" "));
|
|
1443
|
-
});
|
|
1444
|
-
} catch (caughtError) {
|
|
1445
|
-
const error$1 = /* @__PURE__ */ new Error("Oxlint not found");
|
|
1446
|
-
error$1.cause = caughtError;
|
|
1447
|
-
await events.emit("error", error$1);
|
|
1448
|
-
}
|
|
1449
|
-
}
|
|
1450
|
-
await events.emit("lint:end");
|
|
1451
|
-
}
|
|
1452
|
-
if (config.hooks) {
|
|
1453
|
-
await events.emit("hooks:start");
|
|
1454
|
-
await executeHooks({
|
|
1455
|
-
hooks: config.hooks,
|
|
1456
|
-
events
|
|
1457
|
-
});
|
|
1458
|
-
await events.emit("hooks:end");
|
|
1459
|
-
}
|
|
1460
|
-
await events.emit("generation:summary", config, {
|
|
1461
|
-
failedPlugins,
|
|
1462
|
-
filesCreated: files.length,
|
|
1463
|
-
status: failedPlugins.size > 0 || error ? "failed" : "success",
|
|
1464
|
-
hrStart,
|
|
1465
|
-
pluginTimings
|
|
1466
|
-
});
|
|
1467
|
-
}
|
|
1468
|
-
|
|
1469
|
-
//#endregion
|
|
1470
|
-
//#region src/utils/getPlugins.ts
|
|
1471
|
-
function isJSONPlugins(plugins) {
|
|
1472
|
-
return !!plugins?.some((plugin) => {
|
|
1473
|
-
return Array.isArray(plugin) && typeof plugin?.at(0) === "string";
|
|
1474
|
-
});
|
|
1475
|
-
}
|
|
1476
|
-
function isObjectPlugins(plugins) {
|
|
1477
|
-
return plugins instanceof Object && !Array.isArray(plugins);
|
|
1478
|
-
}
|
|
1479
|
-
function getPlugins(plugins) {
|
|
1480
|
-
if (isObjectPlugins(plugins)) throw new Error("Object plugins are not supported anymore, best to use http://kubb.dev/getting-started/configure#json");
|
|
1481
|
-
if (isJSONPlugins(plugins)) throw new Error("JSON plugins are not supported anymore, best to use http://kubb.dev/getting-started/configure#json");
|
|
1482
|
-
return Promise.resolve(plugins);
|
|
1483
|
-
}
|
|
1484
|
-
|
|
1485
|
-
//#endregion
|
|
1486
|
-
//#region src/utils/getConfigs.ts
|
|
1487
|
-
/**
|
|
1488
|
-
* Converting UserConfig to Config Array without a change in the object beside the JSON convert.
|
|
1489
|
-
*/
|
|
1490
|
-
async function getConfigs(result, args) {
|
|
1491
|
-
const config = result?.config;
|
|
1492
|
-
let kubbUserConfig = Promise.resolve(config);
|
|
1493
|
-
if (typeof config === "function") {
|
|
1494
|
-
const possiblePromise = config(args);
|
|
1495
|
-
if ((0, _kubb_core_utils.isPromise)(possiblePromise)) kubbUserConfig = possiblePromise;
|
|
1496
|
-
kubbUserConfig = Promise.resolve(possiblePromise);
|
|
1497
|
-
}
|
|
1498
|
-
let JSONConfig = await kubbUserConfig;
|
|
1499
|
-
if (!Array.isArray(JSONConfig)) JSONConfig = [JSONConfig];
|
|
1500
|
-
const results = [];
|
|
1501
|
-
for (const item of JSONConfig) {
|
|
1502
|
-
const plugins = item.plugins ? await getPlugins(item.plugins) : void 0;
|
|
1503
|
-
results.push({
|
|
1504
|
-
...item,
|
|
1505
|
-
plugins
|
|
1506
|
-
});
|
|
1507
|
-
}
|
|
1508
|
-
return results;
|
|
1509
|
-
}
|
|
1510
|
-
|
|
1511
|
-
//#endregion
|
|
1512
|
-
//#region src/utils/getCosmiConfig.ts
|
|
1513
|
-
const tsLoader = async (configFile) => {
|
|
1514
|
-
return await (0, jiti.createJiti)(configFile, {
|
|
1515
|
-
jsx: {
|
|
1516
|
-
runtime: "automatic",
|
|
1517
|
-
importSource: "@kubb/react-fabric"
|
|
1518
|
-
},
|
|
1519
|
-
sourceMaps: true,
|
|
1520
|
-
interopDefault: true
|
|
1521
|
-
}).import(configFile, { default: true });
|
|
1522
|
-
};
|
|
1523
|
-
async function getCosmiConfig(moduleName, config) {
|
|
1524
|
-
let result;
|
|
1525
|
-
const searchPlaces = [
|
|
1526
|
-
"package.json",
|
|
1527
|
-
`.${moduleName}rc`,
|
|
1528
|
-
`.${moduleName}rc.json`,
|
|
1529
|
-
`.${moduleName}rc.yaml`,
|
|
1530
|
-
`.${moduleName}rc.yml`,
|
|
1531
|
-
`.${moduleName}rc.ts`,
|
|
1532
|
-
`.${moduleName}rc.js`,
|
|
1533
|
-
`.${moduleName}rc.mjs`,
|
|
1534
|
-
`.${moduleName}rc.cjs`,
|
|
1535
|
-
`${moduleName}.config.ts`,
|
|
1536
|
-
`${moduleName}.config.js`,
|
|
1537
|
-
`${moduleName}.config.mjs`,
|
|
1538
|
-
`${moduleName}.config.cjs`
|
|
1539
|
-
];
|
|
1540
|
-
const explorer = (0, cosmiconfig.cosmiconfig)(moduleName, {
|
|
1541
|
-
cache: false,
|
|
1542
|
-
searchPlaces: [
|
|
1543
|
-
...searchPlaces.map((searchPlace) => {
|
|
1544
|
-
return `.config/${searchPlace}`;
|
|
1545
|
-
}),
|
|
1546
|
-
...searchPlaces.map((searchPlace) => {
|
|
1547
|
-
return `configs/${searchPlace}`;
|
|
1548
|
-
}),
|
|
1549
|
-
...searchPlaces
|
|
1550
|
-
],
|
|
1551
|
-
loaders: { ".ts": tsLoader }
|
|
1552
|
-
});
|
|
1553
|
-
try {
|
|
1554
|
-
result = config ? await explorer.load(config) : await explorer.search();
|
|
1555
|
-
} catch (error) {
|
|
1556
|
-
throw new Error("Config failed loading", { cause: error });
|
|
1557
|
-
}
|
|
1558
|
-
if (result?.isEmpty || !result || !result.config) throw new Error("Config not defined, create a kubb.config.js or pass through your config with the option --config");
|
|
1559
|
-
return result;
|
|
1560
|
-
}
|
|
1561
|
-
|
|
1562
|
-
//#endregion
|
|
1563
|
-
//#region src/loggers/streamLogger.ts
|
|
1564
|
-
/**
|
|
1565
|
-
* Stream logger for SSE (Server-Sent Events) streaming
|
|
1566
|
-
* Sends Kubb events to HTTP client via SSE protocol
|
|
1567
|
-
*/
|
|
1568
|
-
function createStreamLogger(res) {
|
|
1569
|
-
return (0, _kubb_core.defineLogger)({
|
|
1570
|
-
name: "stream",
|
|
1571
|
-
install(context, options) {
|
|
1572
|
-
const logLevel = options?.logLevel || _kubb_core.LogLevel.info;
|
|
1573
|
-
const state = { res };
|
|
1574
|
-
function send(type, ...data) {
|
|
1575
|
-
if (!state.res.destroyed) state.res.write(`data: ${JSON.stringify({
|
|
1576
|
-
type,
|
|
1577
|
-
data
|
|
1578
|
-
})}\n\n`);
|
|
1579
|
-
}
|
|
1580
|
-
context.on("plugin:start", (plugin) => {
|
|
1581
|
-
send("plugin:start", { name: plugin.name });
|
|
1582
|
-
});
|
|
1583
|
-
context.on("plugin:end", (plugin, { duration, success }) => {
|
|
1584
|
-
send("plugin:end", { name: plugin.name }, {
|
|
1585
|
-
duration,
|
|
1586
|
-
success
|
|
1587
|
-
});
|
|
1588
|
-
});
|
|
1589
|
-
context.on("files:processing:start", (files) => {
|
|
1590
|
-
send("files:processing:start", { total: files.length });
|
|
1591
|
-
});
|
|
1592
|
-
context.on("file:processing:update", ({ file, processed, total, percentage, config }) => {
|
|
1593
|
-
send("file:processing:update", {
|
|
1594
|
-
file: file.path ? (0, node_path.relative)(config.root, file.path) : file.baseName || "unknown",
|
|
1595
|
-
processed,
|
|
1596
|
-
total,
|
|
1597
|
-
percentage
|
|
1598
|
-
});
|
|
1599
|
-
});
|
|
1600
|
-
context.on("files:processing:end", (files) => {
|
|
1601
|
-
send("files:processing:end", { total: files.length });
|
|
1602
|
-
});
|
|
1603
|
-
context.on("info", (message, info) => {
|
|
1604
|
-
if (logLevel <= _kubb_core.LogLevel.silent) return;
|
|
1605
|
-
send("info", message, info);
|
|
1606
|
-
});
|
|
1607
|
-
context.on("success", (message, info) => {
|
|
1608
|
-
if (logLevel <= _kubb_core.LogLevel.silent) return;
|
|
1609
|
-
send("success", message, info);
|
|
1610
|
-
});
|
|
1611
|
-
context.on("warn", (message, info) => {
|
|
1612
|
-
if (logLevel < _kubb_core.LogLevel.warn) return;
|
|
1613
|
-
send("warn", message, info);
|
|
1614
|
-
});
|
|
1615
|
-
context.on("error", (error) => {
|
|
1616
|
-
send("error", {
|
|
1617
|
-
message: error.message,
|
|
1618
|
-
stack: logLevel >= _kubb_core.LogLevel.debug ? error.stack : void 0
|
|
1619
|
-
});
|
|
1620
|
-
});
|
|
1621
|
-
context.on("generation:start", (config) => {
|
|
1622
|
-
send("generation:start", {
|
|
1623
|
-
name: config.name,
|
|
1624
|
-
plugins: config.plugins?.length || 0
|
|
1625
|
-
});
|
|
1626
|
-
});
|
|
1627
|
-
context.on("generation:end", (config, files, sources) => {
|
|
1628
|
-
send("generation:end", config, files, Object.fromEntries(sources));
|
|
1629
|
-
});
|
|
1630
|
-
}
|
|
1631
|
-
});
|
|
1632
|
-
}
|
|
1633
|
-
|
|
1634
|
-
//#endregion
|
|
1635
|
-
//#region src/utils/streamServer.ts
|
|
1636
|
-
async function startStreamServer({ port, host, configPath, config, input, args }) {
|
|
1637
|
-
const server = (0, node_http.createServer)(async (req, res) => {
|
|
1638
|
-
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
1639
|
-
res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
|
|
1640
|
-
res.setHeader("Access-Control-Allow-Headers", "Content-Type");
|
|
1641
|
-
if (req.method === "OPTIONS") {
|
|
1642
|
-
res.writeHead(204);
|
|
1643
|
-
res.end();
|
|
1644
|
-
return;
|
|
1645
|
-
}
|
|
1646
|
-
if (req.url === "/api/health" && req.method === "GET") {
|
|
1647
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
1648
|
-
const body = {
|
|
1649
|
-
status: "ok",
|
|
1650
|
-
version: require_package.version,
|
|
1651
|
-
configPath: node_path.default.relative(node_process.default.cwd(), configPath)
|
|
1652
|
-
};
|
|
1653
|
-
res.end(JSON.stringify(body));
|
|
1654
|
-
return;
|
|
1655
|
-
}
|
|
1656
|
-
if (req.url === "/api/info" && req.method === "GET") {
|
|
1657
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
1658
|
-
let specContent;
|
|
1659
|
-
if (config && "path" in config.input) {
|
|
1660
|
-
const specPath = node_path.default.resolve(node_process.default.cwd(), config.root, config.input.path);
|
|
1661
|
-
try {
|
|
1662
|
-
specContent = (0, node_fs.readFileSync)(specPath, "utf-8");
|
|
1663
|
-
} catch {}
|
|
1664
|
-
}
|
|
1665
|
-
const body = {
|
|
1666
|
-
version: require_package.version,
|
|
1667
|
-
configPath: node_path.default.relative(node_process.default.cwd(), configPath),
|
|
1668
|
-
spec: specContent,
|
|
1669
|
-
config: {
|
|
1670
|
-
name: config.name,
|
|
1671
|
-
root: config.root,
|
|
1672
|
-
input: { path: "path" in config.input ? config.input.path : void 0 },
|
|
1673
|
-
output: {
|
|
1674
|
-
path: config.output.path,
|
|
1675
|
-
write: config.output.write,
|
|
1676
|
-
extension: config.output.extension,
|
|
1677
|
-
barrelType: config.output.barrelType
|
|
1678
|
-
},
|
|
1679
|
-
plugins: config.plugins?.map((plugin) => ({
|
|
1680
|
-
name: `@kubb/${plugin.name}`,
|
|
1681
|
-
options: (0, _kubb_core_utils.serializePluginOptions)(plugin.options)
|
|
1682
|
-
}))
|
|
1683
|
-
}
|
|
1684
|
-
};
|
|
1685
|
-
res.end(JSON.stringify(body));
|
|
1686
|
-
return;
|
|
1687
|
-
}
|
|
1688
|
-
if (req.url === "/api/stream" && req.method === "POST") {
|
|
1689
|
-
await handleGenerate(res, config, input, args);
|
|
1690
|
-
return;
|
|
1691
|
-
}
|
|
1692
|
-
res.writeHead(404, { "Content-Type": "application/json" });
|
|
1693
|
-
res.end(JSON.stringify({ error: "Not found" }));
|
|
1694
|
-
});
|
|
1695
|
-
server.listen(port, host, () => {
|
|
1696
|
-
const address = server.address();
|
|
1697
|
-
const serverUrl = `http://${host}:${typeof address === "object" && address ? address.port : port}`;
|
|
1698
|
-
_clack_prompts.log.success(picocolors.default.green(`Stream server started on ${picocolors.default.bold(serverUrl)}`));
|
|
1699
|
-
_clack_prompts.log.info(picocolors.default.dim(`Config: ${node_path.default.relative(node_process.default.cwd(), configPath)}`));
|
|
1700
|
-
_clack_prompts.log.info(picocolors.default.dim(`Connect: ${serverUrl}/api/info`));
|
|
1701
|
-
_clack_prompts.log.info(picocolors.default.dim(`Stream: ${serverUrl}/api/stream`));
|
|
1702
|
-
_clack_prompts.log.info(picocolors.default.dim(`Health: ${serverUrl}/api/health`));
|
|
1703
|
-
_clack_prompts.log.step(picocolors.default.yellow("Waiting for requests... (Press Ctrl+C to stop)"));
|
|
1704
|
-
});
|
|
1705
|
-
node_process.default.on("SIGINT", () => {
|
|
1706
|
-
_clack_prompts.log.info("Shutting down stream server...");
|
|
1707
|
-
server.close(() => {
|
|
1708
|
-
_clack_prompts.log.success("Server stopped");
|
|
1709
|
-
node_process.default.exit(0);
|
|
1710
|
-
});
|
|
1711
|
-
});
|
|
1712
|
-
}
|
|
1713
|
-
async function handleGenerate(res, config, input, args) {
|
|
1714
|
-
const events = new _kubb_core_utils.AsyncEventEmitter();
|
|
1715
|
-
const logLevel = _kubb_core.LogLevel[args.logLevel] || 3;
|
|
1716
|
-
res.writeHead(200, {
|
|
1717
|
-
"Content-Type": "text/event-stream",
|
|
1718
|
-
"Cache-Control": "no-cache",
|
|
1719
|
-
Connection: "keep-alive"
|
|
1720
|
-
});
|
|
1721
|
-
function send(type, ...data) {
|
|
1722
|
-
res.write(`data: ${JSON.stringify({
|
|
1723
|
-
type,
|
|
1724
|
-
data
|
|
1725
|
-
})}\n\n`);
|
|
1726
|
-
}
|
|
1727
|
-
await createStreamLogger(res).install(events, { logLevel });
|
|
1728
|
-
try {
|
|
1729
|
-
await generate({
|
|
1730
|
-
input,
|
|
1731
|
-
config,
|
|
1732
|
-
logLevel,
|
|
1733
|
-
events
|
|
1734
|
-
});
|
|
1735
|
-
send("lifecycle:end");
|
|
1736
|
-
} catch (error) {
|
|
1737
|
-
send("error", {
|
|
1738
|
-
message: error instanceof Error ? error.message : "Unknown error",
|
|
1739
|
-
stack: error instanceof Error ? error.stack : void 0
|
|
1740
|
-
});
|
|
1741
|
-
} finally {
|
|
1742
|
-
res.end();
|
|
1743
|
-
}
|
|
1744
|
-
}
|
|
1745
|
-
|
|
1746
1133
|
//#endregion
|
|
1747
1134
|
//#region src/utils/watcher.ts
|
|
1748
|
-
async function startWatcher(path$
|
|
1135
|
+
async function startWatcher(path$2, cb) {
|
|
1749
1136
|
const { watch } = await import("chokidar");
|
|
1750
|
-
watch(path$
|
|
1137
|
+
watch(path$2, {
|
|
1751
1138
|
ignorePermissionErrors: true,
|
|
1752
1139
|
ignored: "**/{.git,node_modules}/**"
|
|
1753
1140
|
}).on("all", async (type, file) => {
|
|
1754
1141
|
console.log(picocolors.default.yellow(picocolors.default.bold(`Change detected: ${type} ${file}`)));
|
|
1755
1142
|
try {
|
|
1756
|
-
await cb(path$
|
|
1143
|
+
await cb(path$2);
|
|
1757
1144
|
} catch (_e) {
|
|
1758
1145
|
console.log(picocolors.default.red("Watcher failed"));
|
|
1759
1146
|
}
|
|
@@ -1804,21 +1191,6 @@ const command = (0, citty.defineCommand)({
|
|
|
1804
1191
|
alias: "s",
|
|
1805
1192
|
default: false
|
|
1806
1193
|
},
|
|
1807
|
-
stream: {
|
|
1808
|
-
type: "boolean",
|
|
1809
|
-
description: "Start HTTP server with SSE streaming",
|
|
1810
|
-
default: false
|
|
1811
|
-
},
|
|
1812
|
-
port: {
|
|
1813
|
-
type: "string",
|
|
1814
|
-
description: "Port for stream server (requires --stream). If not specified, an available port is automatically selected.",
|
|
1815
|
-
alias: "p"
|
|
1816
|
-
},
|
|
1817
|
-
host: {
|
|
1818
|
-
type: "string",
|
|
1819
|
-
description: "Host for stream server (requires --stream)",
|
|
1820
|
-
default: "localhost"
|
|
1821
|
-
},
|
|
1822
1194
|
help: {
|
|
1823
1195
|
type: "boolean",
|
|
1824
1196
|
description: "Show help",
|
|
@@ -1842,22 +1214,8 @@ const command = (0, citty.defineCommand)({
|
|
|
1842
1214
|
if ((0, semver.lt)(require_package.version, latestVersion)) await events.emit("version:new", require_package.version, latestVersion);
|
|
1843
1215
|
});
|
|
1844
1216
|
try {
|
|
1845
|
-
const result = await getCosmiConfig("kubb", args.config);
|
|
1846
|
-
const configs = await getConfigs(result, args);
|
|
1847
|
-
if (args.stream) {
|
|
1848
|
-
if (configs.length > 1) _clack_prompts.log.warn(picocolors.default.yellow("Stream mode only supports a single configuration. Only the first config will be used."));
|
|
1849
|
-
const port = args.port ? Number.parseInt(args.port, 10) : 0;
|
|
1850
|
-
const host = args.host;
|
|
1851
|
-
await startStreamServer({
|
|
1852
|
-
port,
|
|
1853
|
-
host,
|
|
1854
|
-
configPath: result.filepath,
|
|
1855
|
-
config: configs[0],
|
|
1856
|
-
input,
|
|
1857
|
-
args
|
|
1858
|
-
});
|
|
1859
|
-
return;
|
|
1860
|
-
}
|
|
1217
|
+
const result = await require_getCosmiConfig.getCosmiConfig("kubb", args.config);
|
|
1218
|
+
const configs = await require_getCosmiConfig.getConfigs(result, args);
|
|
1861
1219
|
await events.emit("config:start");
|
|
1862
1220
|
await events.emit("info", "Config loaded", node_path.default.relative(node_process.cwd(), result.filepath));
|
|
1863
1221
|
await events.emit("success", "Config loaded successfully", node_path.default.relative(node_process.cwd(), result.filepath));
|
|
@@ -1867,7 +1225,7 @@ const command = (0, citty.defineCommand)({
|
|
|
1867
1225
|
return async () => {
|
|
1868
1226
|
if ((0, _kubb_core.isInputPath)(config) && args.watch) {
|
|
1869
1227
|
await startWatcher([input || config.input.path], async (paths) => {
|
|
1870
|
-
await generate({
|
|
1228
|
+
await require_getCosmiConfig.generate({
|
|
1871
1229
|
input,
|
|
1872
1230
|
config,
|
|
1873
1231
|
logLevel,
|
|
@@ -1877,7 +1235,7 @@ const command = (0, citty.defineCommand)({
|
|
|
1877
1235
|
});
|
|
1878
1236
|
return;
|
|
1879
1237
|
}
|
|
1880
|
-
await generate({
|
|
1238
|
+
await require_getCosmiConfig.generate({
|
|
1881
1239
|
input,
|
|
1882
1240
|
config,
|
|
1883
1241
|
logLevel,
|
|
@@ -1897,4 +1255,4 @@ var generate_default = command;
|
|
|
1897
1255
|
|
|
1898
1256
|
//#endregion
|
|
1899
1257
|
exports.default = generate_default;
|
|
1900
|
-
//# sourceMappingURL=generate-
|
|
1258
|
+
//# sourceMappingURL=generate-BxSL_NKj.cjs.map
|