@kubb/cli 4.22.0 → 4.22.2

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.
Files changed (47) hide show
  1. package/dist/{generate-Bjj-OR20.js → generate-CBsaUUvV.js} +49 -674
  2. package/dist/generate-CBsaUUvV.js.map +1 -0
  3. package/dist/{generate-BJyvkuLI.cjs → generate-CLDVb4hB.cjs} +53 -678
  4. package/dist/generate-CLDVb4hB.cjs.map +1 -0
  5. package/dist/getCosmiConfig-Co29x0Wv.cjs +458 -0
  6. package/dist/getCosmiConfig-Co29x0Wv.cjs.map +1 -0
  7. package/dist/getCosmiConfig-y2n_oW_y.js +438 -0
  8. package/dist/getCosmiConfig-y2n_oW_y.js.map +1 -0
  9. package/dist/index.cjs +9 -7
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.js +9 -7
  12. package/dist/index.js.map +1 -1
  13. package/dist/{init-CxLDdq2k.cjs → init-Bs1GxKWV.cjs} +3 -3
  14. package/dist/{init-CxLDdq2k.cjs.map → init-Bs1GxKWV.cjs.map} +1 -1
  15. package/dist/{init-D37jPiGV.js → init-D3zCeqU-.js} +3 -3
  16. package/dist/{init-D37jPiGV.js.map → init-D3zCeqU-.js.map} +1 -1
  17. package/dist/{mcp-By2JUPa8.js → mcp-BdwwUv36.js} +1 -1
  18. package/dist/{mcp-By2JUPa8.js.map → mcp-BdwwUv36.js.map} +1 -1
  19. package/dist/{mcp-l-_Z-WU6.cjs → mcp-Hy_PYnFp.cjs} +1 -1
  20. package/dist/{mcp-l-_Z-WU6.cjs.map → mcp-Hy_PYnFp.cjs.map} +1 -1
  21. package/dist/package-BFidNEkS.js +6 -0
  22. package/dist/package-BFidNEkS.js.map +1 -0
  23. package/dist/{package-Cnl_fuIC.cjs → package-CiB5tqr0.cjs} +2 -2
  24. package/dist/package-CiB5tqr0.cjs.map +1 -0
  25. package/dist/start-BeoZd1fL.cjs +128 -0
  26. package/dist/start-BeoZd1fL.cjs.map +1 -0
  27. package/dist/start-Ohz4V8k2.js +125 -0
  28. package/dist/start-Ohz4V8k2.js.map +1 -0
  29. package/dist/{validate-DkHCd-Tl.cjs → validate-Cvb5aOEb.cjs} +1 -1
  30. package/dist/{validate-DkHCd-Tl.cjs.map → validate-Cvb5aOEb.cjs.map} +1 -1
  31. package/dist/{validate-0Qu8SxVA.js → validate-YI4YkVTl.js} +1 -1
  32. package/dist/{validate-0Qu8SxVA.js.map → validate-YI4YkVTl.js.map} +1 -1
  33. package/package.json +4 -4
  34. package/src/commands/generate.ts +0 -38
  35. package/src/commands/init.ts +3 -1
  36. package/src/commands/start.ts +149 -0
  37. package/src/index.ts +2 -1
  38. package/src/loggers/clackLogger.ts +32 -12
  39. package/src/loggers/githubActionsLogger.ts +21 -8
  40. package/src/loggers/plainLogger.ts +20 -8
  41. package/dist/generate-BJyvkuLI.cjs.map +0 -1
  42. package/dist/generate-Bjj-OR20.js.map +0 -1
  43. package/dist/package-Cnl_fuIC.cjs.map +0 -1
  44. package/dist/package-Qh9BQXK6.js +0 -6
  45. package/dist/package-Qh9BQXK6.js.map +0 -1
  46. package/src/loggers/streamLogger.ts +0 -93
  47. package/src/utils/streamServer.ts +0 -163
@@ -1,5 +1,6 @@
1
1
  const require_chunk = require('./chunk-C1_xRkKa.cjs');
2
- const require_package = require('./package-Cnl_fuIC.cjs');
2
+ const require_package = require('./package-CiB5tqr0.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
  /**
@@ -442,25 +437,30 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
442
437
  error: null
443
438
  });
444
439
  } catch (err) {
445
- const error = /* @__PURE__ */ new Error("Hook execute failed");
446
- error.cause = err;
440
+ const error = err;
441
+ const stderr = typeof error.stderr === "string" ? error.stderr : String(error.stderr);
442
+ const stdout = typeof error.stdout === "string" ? error.stdout : String(error.stdout);
447
443
  await context.emit("debug", {
448
444
  date: /* @__PURE__ */ new Date(),
449
- logs: [err.stdout]
445
+ logs: [stdout, stderr].filter(Boolean)
450
446
  });
447
+ if (stderr) console.error(stderr);
448
+ if (stdout) console.log(stdout);
449
+ const errorMessage = /* @__PURE__ */ new Error(`Hook execute failed: ${commandWithArgs}`);
451
450
  await context.emit("hook:end", {
452
451
  command: command$1,
453
452
  args,
454
453
  id,
455
454
  success: false,
456
- error
455
+ error: errorMessage
457
456
  });
458
- await context.emit("error", error);
457
+ await context.emit("error", errorMessage);
459
458
  }
460
459
  return;
461
460
  }
462
461
  _clack_prompts.intro(text);
463
- const writable = new ClackWritable(_clack_prompts.taskLog({ title: getMessage(["Executing hook", logLevel >= _kubb_core.LogLevel.info ? picocolors.default.dim(commandWithArgs) : void 0].filter(Boolean).join(" ")) }));
462
+ const logger = _clack_prompts.taskLog({ title: getMessage(["Executing hook", logLevel >= _kubb_core.LogLevel.info ? picocolors.default.dim(commandWithArgs) : void 0].filter(Boolean).join(" ")) });
463
+ const writable = new ClackWritable(logger);
464
464
  try {
465
465
  const result = await (0, execa.execa)(command$1, args, {
466
466
  detached: true,
@@ -479,20 +479,24 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
479
479
  error: null
480
480
  });
481
481
  } catch (err) {
482
- const error = /* @__PURE__ */ new Error("Hook execute failed");
483
- error.cause = err;
482
+ const error = err;
483
+ const stderr = typeof error.stderr === "string" ? error.stderr : String(error.stderr);
484
+ const stdout = typeof error.stdout === "string" ? error.stdout : String(error.stdout);
484
485
  await context.emit("debug", {
485
486
  date: /* @__PURE__ */ new Date(),
486
- logs: [err.stdout]
487
+ logs: [stdout, stderr].filter(Boolean)
487
488
  });
489
+ if (stderr) logger.error(stderr);
490
+ if (stdout) logger.message(stdout);
491
+ const errorMessage = /* @__PURE__ */ new Error(`Hook execute failed: ${commandWithArgs}`);
488
492
  await context.emit("hook:end", {
489
493
  command: command$1,
490
494
  args,
491
495
  id,
492
- success: true,
493
- error
496
+ success: false,
497
+ error: errorMessage
494
498
  });
495
- await context.emit("error", error);
499
+ await context.emit("error", errorMessage);
496
500
  }
497
501
  });
498
502
  context.on("hook:end", ({ command: command$1, args }) => {
@@ -885,7 +889,7 @@ const githubActionsLogger = (0, _kubb_core.defineLogger)({
885
889
  date: /* @__PURE__ */ new Date(),
886
890
  logs: [result.stdout]
887
891
  });
888
- console.log(result.stdout);
892
+ if (logLevel > _kubb_core.LogLevel.silent) console.log(result.stdout);
889
893
  await context.emit("hook:end", {
890
894
  command: command$1,
891
895
  args,
@@ -894,20 +898,24 @@ const githubActionsLogger = (0, _kubb_core.defineLogger)({
894
898
  error: null
895
899
  });
896
900
  } catch (err) {
897
- const error = /* @__PURE__ */ new Error("Hook execute failed");
898
- error.cause = err;
901
+ const error = err;
902
+ const stderr = typeof error.stderr === "string" ? error.stderr : String(error.stderr);
903
+ const stdout = typeof error.stdout === "string" ? error.stdout : String(error.stdout);
899
904
  await context.emit("debug", {
900
905
  date: /* @__PURE__ */ new Date(),
901
- logs: [err.stdout]
906
+ logs: [stdout, stderr].filter(Boolean)
902
907
  });
908
+ if (stderr) console.error(`::error::${stderr}`);
909
+ if (stdout) console.log(stdout);
910
+ const errorMessage = /* @__PURE__ */ new Error(`Hook execute failed: ${commandWithArgs}`);
903
911
  await context.emit("hook:end", {
904
912
  command: command$1,
905
913
  args,
906
914
  id,
907
915
  success: false,
908
- error
916
+ error: errorMessage
909
917
  });
910
- await context.emit("error", error);
918
+ await context.emit("error", errorMessage);
911
919
  }
912
920
  });
913
921
  context.on("hook:end", ({ command: command$1, args }) => {
@@ -1056,7 +1064,8 @@ const plainLogger = (0, _kubb_core.defineLogger)({
1056
1064
  console.log(text);
1057
1065
  });
1058
1066
  context.on("hook:start", async ({ id, command: command$1, args }) => {
1059
- const text = getMessage(`Hook ${args?.length ? `${command$1} ${args.join(" ")}` : command$1} started`);
1067
+ const commandWithArgs = args?.length ? `${command$1} ${args.join(" ")}` : command$1;
1068
+ const text = getMessage(`Hook ${commandWithArgs} started`);
1060
1069
  if (logLevel > _kubb_core.LogLevel.silent) console.log(text);
1061
1070
  if (!id) return;
1062
1071
  try {
@@ -1068,7 +1077,7 @@ const plainLogger = (0, _kubb_core.defineLogger)({
1068
1077
  date: /* @__PURE__ */ new Date(),
1069
1078
  logs: [result.stdout]
1070
1079
  });
1071
- console.log(result.stdout);
1080
+ if (logLevel > _kubb_core.LogLevel.silent) console.log(result.stdout);
1072
1081
  await context.emit("hook:end", {
1073
1082
  command: command$1,
1074
1083
  args,
@@ -1077,20 +1086,24 @@ const plainLogger = (0, _kubb_core.defineLogger)({
1077
1086
  error: null
1078
1087
  });
1079
1088
  } catch (err) {
1080
- const error = /* @__PURE__ */ new Error("Hook execute failed");
1081
- error.cause = err;
1089
+ const error = err;
1090
+ const stderr = typeof error.stderr === "string" ? error.stderr : String(error.stderr);
1091
+ const stdout = typeof error.stdout === "string" ? error.stdout : String(error.stdout);
1082
1092
  await context.emit("debug", {
1083
1093
  date: /* @__PURE__ */ new Date(),
1084
- logs: [err.stdout]
1094
+ logs: [stdout, stderr].filter(Boolean)
1085
1095
  });
1096
+ if (stderr) console.error(stderr);
1097
+ if (stdout) console.log(stdout);
1098
+ const errorMessage = /* @__PURE__ */ new Error(`Hook execute failed: ${commandWithArgs}`);
1086
1099
  await context.emit("hook:end", {
1087
1100
  command: command$1,
1088
1101
  args,
1089
1102
  id,
1090
1103
  success: false,
1091
- error
1104
+ error: errorMessage
1092
1105
  });
1093
- await context.emit("error", error);
1106
+ await context.emit("error", errorMessage);
1094
1107
  }
1095
1108
  });
1096
1109
  context.on("hook:end", ({ command: command$1, args }) => {
@@ -1135,626 +1148,17 @@ async function setupLogger(context, { logLevel }) {
1135
1148
  return cleanup;
1136
1149
  }
1137
1150
 
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
- const streamEvent = {
1723
- type,
1724
- data
1725
- };
1726
- res.write(`data: ${JSON.stringify(streamEvent)}\n\n`);
1727
- }
1728
- await createStreamLogger(res).install(events, { logLevel });
1729
- try {
1730
- await generate({
1731
- input,
1732
- config,
1733
- logLevel,
1734
- events
1735
- });
1736
- send("lifecycle:end");
1737
- } catch (error) {
1738
- send("error", {
1739
- message: error instanceof Error ? error.message : "Unknown error",
1740
- stack: error instanceof Error ? error.stack : void 0
1741
- });
1742
- } finally {
1743
- res.end();
1744
- }
1745
- }
1746
-
1747
1151
  //#endregion
1748
1152
  //#region src/utils/watcher.ts
1749
- async function startWatcher(path$4, cb) {
1153
+ async function startWatcher(path$2, cb) {
1750
1154
  const { watch } = await import("chokidar");
1751
- watch(path$4, {
1155
+ watch(path$2, {
1752
1156
  ignorePermissionErrors: true,
1753
1157
  ignored: "**/{.git,node_modules}/**"
1754
1158
  }).on("all", async (type, file) => {
1755
1159
  console.log(picocolors.default.yellow(picocolors.default.bold(`Change detected: ${type} ${file}`)));
1756
1160
  try {
1757
- await cb(path$4);
1161
+ await cb(path$2);
1758
1162
  } catch (_e) {
1759
1163
  console.log(picocolors.default.red("Watcher failed"));
1760
1164
  }
@@ -1805,21 +1209,6 @@ const command = (0, citty.defineCommand)({
1805
1209
  alias: "s",
1806
1210
  default: false
1807
1211
  },
1808
- stream: {
1809
- type: "boolean",
1810
- description: "Start HTTP server with SSE streaming",
1811
- default: false
1812
- },
1813
- port: {
1814
- type: "string",
1815
- description: "Port for stream server (requires --stream). If not specified, an available port is automatically selected.",
1816
- alias: "p"
1817
- },
1818
- host: {
1819
- type: "string",
1820
- description: "Host for stream server (requires --stream)",
1821
- default: "localhost"
1822
- },
1823
1212
  help: {
1824
1213
  type: "boolean",
1825
1214
  description: "Show help",
@@ -1843,22 +1232,8 @@ const command = (0, citty.defineCommand)({
1843
1232
  if ((0, semver.lt)(require_package.version, latestVersion)) await events.emit("version:new", require_package.version, latestVersion);
1844
1233
  });
1845
1234
  try {
1846
- const result = await getCosmiConfig("kubb", args.config);
1847
- const configs = await getConfigs(result, args);
1848
- if (args.stream) {
1849
- 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."));
1850
- const port = args.port ? Number.parseInt(args.port, 10) : 0;
1851
- const host = args.host;
1852
- await startStreamServer({
1853
- port,
1854
- host,
1855
- configPath: result.filepath,
1856
- config: configs[0],
1857
- input,
1858
- args
1859
- });
1860
- return;
1861
- }
1235
+ const result = await require_getCosmiConfig.getCosmiConfig("kubb", args.config);
1236
+ const configs = await require_getCosmiConfig.getConfigs(result, args);
1862
1237
  await events.emit("config:start");
1863
1238
  await events.emit("info", "Config loaded", node_path.default.relative(node_process.cwd(), result.filepath));
1864
1239
  await events.emit("success", "Config loaded successfully", node_path.default.relative(node_process.cwd(), result.filepath));
@@ -1868,7 +1243,7 @@ const command = (0, citty.defineCommand)({
1868
1243
  return async () => {
1869
1244
  if ((0, _kubb_core.isInputPath)(config) && args.watch) {
1870
1245
  await startWatcher([input || config.input.path], async (paths) => {
1871
- await generate({
1246
+ await require_getCosmiConfig.generate({
1872
1247
  input,
1873
1248
  config,
1874
1249
  logLevel,
@@ -1878,7 +1253,7 @@ const command = (0, citty.defineCommand)({
1878
1253
  });
1879
1254
  return;
1880
1255
  }
1881
- await generate({
1256
+ await require_getCosmiConfig.generate({
1882
1257
  input,
1883
1258
  config,
1884
1259
  logLevel,
@@ -1898,4 +1273,4 @@ var generate_default = command;
1898
1273
 
1899
1274
  //#endregion
1900
1275
  exports.default = generate_default;
1901
- //# sourceMappingURL=generate-BJyvkuLI.cjs.map
1276
+ //# sourceMappingURL=generate-CLDVb4hB.cjs.map