@kubb/cli 5.0.0-beta.5 → 5.0.0-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +177 -26
- package/dist/agent-DN7o8nlE.js +68 -0
- package/dist/agent-DN7o8nlE.js.map +1 -0
- package/dist/agent-Fm9_8BBH.cjs +70 -0
- package/dist/agent-Fm9_8BBH.cjs.map +1 -0
- package/dist/{chunk--u3MIqq1.js → chunk-BvFE5Tac.js} +1 -0
- package/dist/constants-B2JTeRBb.js +42 -0
- package/dist/constants-B2JTeRBb.js.map +1 -0
- package/dist/constants-BINTA5VZ.cjs +77 -0
- package/dist/constants-BINTA5VZ.cjs.map +1 -0
- package/dist/constants-BYGmiFs0.cjs +139 -0
- package/dist/constants-BYGmiFs0.cjs.map +1 -0
- package/dist/constants-DSJ-Xrbv.js +116 -0
- package/dist/constants-DSJ-Xrbv.js.map +1 -0
- package/dist/define-Bdn8j5VM.cjs.map +1 -1
- package/dist/{define-Ctii4bel.js → define-m_fp-Aqm.js} +2 -2
- package/dist/{define-Ctii4bel.js.map → define-m_fp-Aqm.js.map} +1 -1
- package/dist/{errors-CjPmyZHy.js → errors-CINO1EIv.js} +2 -2
- package/dist/{errors-CjPmyZHy.js.map → errors-CINO1EIv.js.map} +1 -1
- package/dist/errors-CLCjoSg0.cjs.map +1 -1
- package/dist/{generate-BqeFFQGD.js → generate-BY-juRdH.js} +12 -6
- package/dist/generate-BY-juRdH.js.map +1 -0
- package/dist/{generate-7td_hs73.cjs → generate-Bod9YCbF.cjs} +10 -4
- package/dist/generate-Bod9YCbF.cjs.map +1 -0
- package/dist/index.cjs +20 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +22 -13
- package/dist/index.js.map +1 -1
- package/dist/init-BIkZU6mB.cjs +53 -0
- package/dist/init-BIkZU6mB.cjs.map +1 -0
- package/dist/init-Cs3Fp6nN.js +53 -0
- package/dist/init-Cs3Fp6nN.js.map +1 -0
- package/dist/mcp-BSNulBcC.js +39 -0
- package/dist/mcp-BSNulBcC.js.map +1 -0
- package/dist/mcp-DcSrFhhP.cjs +39 -0
- package/dist/mcp-DcSrFhhP.cjs.map +1 -0
- package/dist/package-D5wmvFl4.js +6 -0
- package/dist/package-D5wmvFl4.js.map +1 -0
- package/dist/{package-BmYRU2hz.cjs → package-DrUndPET.cjs} +2 -2
- package/dist/package-DrUndPET.cjs.map +1 -0
- package/dist/{generate-DVmGtwWe.js → run-BAJubgdA.js} +298 -315
- package/dist/run-BAJubgdA.js.map +1 -0
- package/dist/{agent-IP0eLV3C.js → run-BzpYYOQs.js} +46 -43
- package/dist/run-BzpYYOQs.js.map +1 -0
- package/dist/run-CCZ24VKk.js +51 -0
- package/dist/run-CCZ24VKk.js.map +1 -0
- package/dist/{init-Cag3082g.js → run-CF97BWVa.js} +102 -147
- package/dist/run-CF97BWVa.js.map +1 -0
- package/dist/run-CQbj3ley.cjs +52 -0
- package/dist/run-CQbj3ley.cjs.map +1 -0
- package/dist/{generate-CUd1dUY5.cjs → run-CqKd6JNc.cjs} +295 -312
- package/dist/run-CqKd6JNc.cjs.map +1 -0
- package/dist/run-D0hmRpHy.js +49 -0
- package/dist/run-D0hmRpHy.js.map +1 -0
- package/dist/{agent-CS45W0kL.cjs → run-DwdAwnLG.cjs} +44 -41
- package/dist/run-DwdAwnLG.cjs.map +1 -0
- package/dist/{mcp-BfORW-mY.cjs → run-Lr0Ctnu0.cjs} +24 -21
- package/dist/run-Lr0Ctnu0.cjs.map +1 -0
- package/dist/{init-C5sZulT6.cjs → run-YsoCk5we.cjs} +100 -145
- package/dist/run-YsoCk5we.cjs.map +1 -0
- package/dist/shell-475fQKaX.cjs.map +1 -1
- package/dist/{shell-DLzN4fRo.js → shell-CN6DNqeC.js} +2 -2
- package/dist/{shell-DLzN4fRo.js.map → shell-CN6DNqeC.js.map} +1 -1
- package/dist/{telemetry-BU25EoI-.cjs → telemetry-B2iWkY5e.cjs} +5 -7
- package/dist/telemetry-B2iWkY5e.cjs.map +1 -0
- package/dist/{telemetry-CaNU4-Bf.js → telemetry-BkektVz6.js} +6 -8
- package/dist/telemetry-BkektVz6.js.map +1 -0
- package/dist/validate-Bfpf_UIh.cjs +26 -0
- package/dist/validate-Bfpf_UIh.cjs.map +1 -0
- package/dist/validate-lbUkWQ5o.js +26 -0
- package/dist/validate-lbUkWQ5o.js.map +1 -0
- package/package.json +12 -12
- package/src/commands/agent/start.ts +10 -7
- package/src/commands/agent.ts +3 -1
- package/src/commands/generate.ts +5 -3
- package/src/commands/init.ts +34 -3
- package/src/commands/mcp.ts +28 -4
- package/src/commands/validate.ts +6 -4
- package/src/constants.ts +1 -57
- package/src/index.ts +5 -3
- package/src/loggers/clackLogger.ts +45 -43
- package/src/loggers/fileSystemLogger.ts +11 -1
- package/src/loggers/githubActionsLogger.ts +13 -25
- package/src/loggers/plainLogger.ts +12 -23
- package/src/loggers/types.ts +6 -0
- package/src/loggers/utils.ts +155 -9
- package/src/runners/agent/run.ts +113 -0
- package/src/runners/agent/utils.ts +98 -0
- package/src/runners/generate/run.ts +276 -0
- package/src/runners/generate/utils.ts +209 -0
- package/src/runners/init/run.ts +211 -0
- package/src/{utils/packageManager.ts → runners/init/utils.ts} +10 -0
- package/src/runners/mcp/run.ts +55 -0
- package/src/runners/validate/run.ts +63 -0
- package/src/{utils/telemetry.ts → telemetry.ts} +12 -5
- package/dist/agent-BcUEl9yB.js +0 -56
- package/dist/agent-BcUEl9yB.js.map +0 -1
- package/dist/agent-CS45W0kL.cjs.map +0 -1
- package/dist/agent-CsMvXeqI.cjs +0 -58
- package/dist/agent-CsMvXeqI.cjs.map +0 -1
- package/dist/agent-IP0eLV3C.js.map +0 -1
- package/dist/constants-B4iBDvCe.cjs +0 -148
- package/dist/constants-B4iBDvCe.cjs.map +0 -1
- package/dist/constants-DmPrkaz8.js +0 -95
- package/dist/constants-DmPrkaz8.js.map +0 -1
- package/dist/generate-7td_hs73.cjs.map +0 -1
- package/dist/generate-BqeFFQGD.js.map +0 -1
- package/dist/generate-CUd1dUY5.cjs.map +0 -1
- package/dist/generate-DVmGtwWe.js.map +0 -1
- package/dist/init-C5sZulT6.cjs.map +0 -1
- package/dist/init-Cag3082g.js.map +0 -1
- package/dist/init-CfAn19gC.js +0 -25
- package/dist/init-CfAn19gC.js.map +0 -1
- package/dist/init-CfsYoyGe.cjs +0 -25
- package/dist/init-CfsYoyGe.cjs.map +0 -1
- package/dist/mcp-BfORW-mY.cjs.map +0 -1
- package/dist/mcp-BtOV6acy.js +0 -16
- package/dist/mcp-BtOV6acy.js.map +0 -1
- package/dist/mcp-CIbuLGMx.cjs +0 -16
- package/dist/mcp-CIbuLGMx.cjs.map +0 -1
- package/dist/mcp-DtQ5o0On.js +0 -46
- package/dist/mcp-DtQ5o0On.js.map +0 -1
- package/dist/package-BmYRU2hz.cjs.map +0 -1
- package/dist/package-DBU5ii-k.js +0 -6
- package/dist/package-DBU5ii-k.js.map +0 -1
- package/dist/telemetry-BU25EoI-.cjs.map +0 -1
- package/dist/telemetry-CaNU4-Bf.js.map +0 -1
- package/dist/validate-CQqM9siF.js +0 -25
- package/dist/validate-CQqM9siF.js.map +0 -1
- package/dist/validate-DBXLaLIn.cjs +0 -34
- package/dist/validate-DBXLaLIn.cjs.map +0 -1
- package/dist/validate-DI23zgmL.js +0 -33
- package/dist/validate-DI23zgmL.js.map +0 -1
- package/dist/validate-DwX4LzYq.cjs +0 -25
- package/dist/validate-DwX4LzYq.cjs.map +0 -1
- package/src/runners/agent.ts +0 -155
- package/src/runners/generate.ts +0 -333
- package/src/runners/init.ts +0 -296
- package/src/runners/mcp.ts +0 -51
- package/src/runners/validate.ts +0 -39
- package/src/types.ts +0 -11
- package/src/utils/Writables.ts +0 -17
- package/src/utils/executeHooks.ts +0 -45
- package/src/utils/flags.ts +0 -9
- package/src/utils/getConfig.ts +0 -10
- package/src/utils/getCosmiConfig.ts +0 -75
- package/src/utils/getSummary.ts +0 -68
- package/src/utils/runHook.ts +0 -91
- package/src/utils/watcher.ts +0 -19
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import "./chunk
|
|
2
|
-
import { n as toCause, r as toError } from "./errors-
|
|
3
|
-
import { a as canUseTTY, i as executeIfOnline, o as isGitHubActions, r as sendTelemetry, t as buildTelemetryEvent } from "./telemetry-
|
|
4
|
-
import { n as tokenize } from "./shell-
|
|
5
|
-
import { t as version } from "./package-
|
|
6
|
-
import { a as
|
|
1
|
+
import "./chunk-BvFE5Tac.js";
|
|
2
|
+
import { n as toCause, r as toError } from "./errors-CINO1EIv.js";
|
|
3
|
+
import { a as canUseTTY, i as executeIfOnline, o as isGitHubActions, r as sendTelemetry, t as buildTelemetryEvent } from "./telemetry-BkektVz6.js";
|
|
4
|
+
import { n as tokenize } from "./shell-CN6DNqeC.js";
|
|
5
|
+
import { t as version } from "./package-D5wmvFl4.js";
|
|
6
|
+
import { a as WATCHER_IGNORED_PATHS, i as SUMMARY_SEPARATOR, t as KUBB_NPM_PACKAGE_URL } from "./constants-B2JTeRBb.js";
|
|
7
7
|
import { styleText } from "node:util";
|
|
8
8
|
import { EventEmitter } from "node:events";
|
|
9
9
|
import { createHash } from "node:crypto";
|
|
@@ -14,10 +14,10 @@ import path, { dirname, relative, resolve } from "node:path";
|
|
|
14
14
|
import process$1 from "node:process";
|
|
15
15
|
import * as clack from "@clack/prompts";
|
|
16
16
|
import { createKubb, defineLogger, isInputPath, logLevel } from "@kubb/core";
|
|
17
|
-
import { NonZeroExitError, x } from "tinyexec";
|
|
18
17
|
import { Writable } from "node:stream";
|
|
19
18
|
import { cosmiconfig } from "cosmiconfig";
|
|
20
19
|
import { createJiti } from "jiti";
|
|
20
|
+
import { NonZeroExitError, x } from "tinyexec";
|
|
21
21
|
//#region ../../internals/utils/src/asyncEventEmitter.ts
|
|
22
22
|
/**
|
|
23
23
|
* Typed `EventEmitter` that awaits all async listeners before resolving.
|
|
@@ -486,100 +486,11 @@ async function detectLinter() {
|
|
|
486
486
|
return null;
|
|
487
487
|
}
|
|
488
488
|
//#endregion
|
|
489
|
-
//#region src/
|
|
490
|
-
function getSummary({ failedPlugins, filesCreated, status, hrStart, config, pluginTimings }) {
|
|
491
|
-
const duration = formatHrtime(hrStart);
|
|
492
|
-
const pluginsCount = config.plugins?.length ?? 0;
|
|
493
|
-
const successCount = pluginsCount - failedPlugins.size;
|
|
494
|
-
const meta = {
|
|
495
|
-
plugins: status === "success" ? `${styleText("green", `${successCount} successful`)}, ${pluginsCount} total` : `${styleText("green", `${successCount} successful`)}, ${styleText("red", `${failedPlugins.size} failed`)}, ${pluginsCount} total`,
|
|
496
|
-
pluginsFailed: status === "failed" ? [...failedPlugins].map(({ plugin }) => randomCliColor(plugin.name)).join(", ") : void 0,
|
|
497
|
-
filesCreated,
|
|
498
|
-
time: styleText("green", duration),
|
|
499
|
-
output: path.resolve(config.root, config.output.path)
|
|
500
|
-
};
|
|
501
|
-
const labels = {
|
|
502
|
-
plugins: "Plugins:",
|
|
503
|
-
failed: "Failed:",
|
|
504
|
-
generated: "Generated:",
|
|
505
|
-
pluginTimings: "Plugin Timings:",
|
|
506
|
-
output: "Output:"
|
|
507
|
-
};
|
|
508
|
-
const maxLength = Math.max(0, ...[...Object.values(labels), ...pluginTimings ? Array.from(pluginTimings.keys()) : []].map((s) => s.length));
|
|
509
|
-
const summaryLines = [];
|
|
510
|
-
summaryLines.push(`${labels.plugins.padEnd(maxLength + 2)} ${meta.plugins}`);
|
|
511
|
-
if (meta.pluginsFailed) summaryLines.push(`${labels.failed.padEnd(maxLength + 2)} ${meta.pluginsFailed}`);
|
|
512
|
-
summaryLines.push(`${labels.generated.padEnd(maxLength + 2)} ${meta.filesCreated} files in ${meta.time}`);
|
|
513
|
-
if (pluginTimings && pluginTimings.size > 0) {
|
|
514
|
-
const sortedTimings = Array.from(pluginTimings.entries()).sort((a, b) => b[1] - a[1]);
|
|
515
|
-
summaryLines.push(`${labels.pluginTimings}`);
|
|
516
|
-
sortedTimings.forEach(([name, time]) => {
|
|
517
|
-
const timeStr = time >= 1e3 ? `${(time / 1e3).toFixed(2)}s` : `${Math.round(time)}ms`;
|
|
518
|
-
const barLength = Math.min(Math.ceil(time / 100), 10);
|
|
519
|
-
const bar = styleText("dim", "█".repeat(barLength));
|
|
520
|
-
summaryLines.push(`${styleText("dim", "•")} ${name.padEnd(maxLength + 1)}${bar} ${timeStr}`);
|
|
521
|
-
});
|
|
522
|
-
}
|
|
523
|
-
summaryLines.push(`${labels.output.padEnd(maxLength + 2)} ${meta.output}`);
|
|
524
|
-
return summaryLines;
|
|
525
|
-
}
|
|
526
|
-
//#endregion
|
|
527
|
-
//#region src/utils/runHook.ts
|
|
489
|
+
//#region src/loggers/clackLogger.ts
|
|
528
490
|
/**
|
|
529
|
-
*
|
|
491
|
+
* Node.js `Writable` stream that forwards each chunk to a clack `taskLog` message.
|
|
492
|
+
* Used to pipe hook subprocess output into the clack task log UI.
|
|
530
493
|
*/
|
|
531
|
-
async function runHook({ id, command, args, commandWithArgs, context, stream = false, sink }) {
|
|
532
|
-
try {
|
|
533
|
-
const proc = x(command, [...args ?? []], {
|
|
534
|
-
nodeOptions: { detached: process.platform !== "win32" },
|
|
535
|
-
throwOnError: true
|
|
536
|
-
});
|
|
537
|
-
if (stream && sink?.onLine) for await (const line of proc) sink.onLine(line);
|
|
538
|
-
const result = await proc;
|
|
539
|
-
await context.emit("kubb:debug", {
|
|
540
|
-
date: /* @__PURE__ */ new Date(),
|
|
541
|
-
logs: [result.stdout.trimEnd()]
|
|
542
|
-
});
|
|
543
|
-
await context.emit("kubb:hook:end", {
|
|
544
|
-
command,
|
|
545
|
-
args,
|
|
546
|
-
id,
|
|
547
|
-
success: true,
|
|
548
|
-
error: null
|
|
549
|
-
});
|
|
550
|
-
} catch (err) {
|
|
551
|
-
if (!(err instanceof NonZeroExitError)) {
|
|
552
|
-
await context.emit("kubb:hook:end", {
|
|
553
|
-
command,
|
|
554
|
-
args,
|
|
555
|
-
id,
|
|
556
|
-
success: false,
|
|
557
|
-
error: toError(err)
|
|
558
|
-
});
|
|
559
|
-
await context.emit("kubb:error", { error: toError(err) });
|
|
560
|
-
return;
|
|
561
|
-
}
|
|
562
|
-
const stderr = err.output?.stderr ?? "";
|
|
563
|
-
const stdout = err.output?.stdout ?? "";
|
|
564
|
-
await context.emit("kubb:debug", {
|
|
565
|
-
date: /* @__PURE__ */ new Date(),
|
|
566
|
-
logs: [stdout, stderr].filter(Boolean)
|
|
567
|
-
});
|
|
568
|
-
if (stderr) sink?.onStderr?.(stderr);
|
|
569
|
-
if (stdout) sink?.onStdout?.(stdout);
|
|
570
|
-
const errorMessage = /* @__PURE__ */ new Error(`Hook execute failed: ${commandWithArgs}`);
|
|
571
|
-
await context.emit("kubb:hook:end", {
|
|
572
|
-
command,
|
|
573
|
-
args,
|
|
574
|
-
id,
|
|
575
|
-
success: false,
|
|
576
|
-
error: errorMessage
|
|
577
|
-
});
|
|
578
|
-
await context.emit("kubb:error", { error: errorMessage });
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
//#endregion
|
|
582
|
-
//#region src/utils/Writables.ts
|
|
583
494
|
var ClackWritable = class extends Writable {
|
|
584
495
|
taskLog;
|
|
585
496
|
constructor(taskLog, opts) {
|
|
@@ -591,8 +502,6 @@ var ClackWritable = class extends Writable {
|
|
|
591
502
|
callback();
|
|
592
503
|
}
|
|
593
504
|
};
|
|
594
|
-
//#endregion
|
|
595
|
-
//#region src/loggers/clackLogger.ts
|
|
596
505
|
/**
|
|
597
506
|
* TTY logger with beautiful UI and progress indicators for local development.
|
|
598
507
|
*/
|
|
@@ -818,40 +727,10 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
|
|
|
818
727
|
const text = getMessage("Lint completed");
|
|
819
728
|
clack.outro(text);
|
|
820
729
|
});
|
|
821
|
-
context.on("kubb:hook:start",
|
|
822
|
-
|
|
823
|
-
const text = getMessage(`Hook ${styleText("dim",
|
|
824
|
-
if (!id) return;
|
|
825
|
-
if (logLevel$8 <= logLevel.silent) {
|
|
826
|
-
await runHook({
|
|
827
|
-
id,
|
|
828
|
-
command,
|
|
829
|
-
args,
|
|
830
|
-
commandWithArgs,
|
|
831
|
-
context,
|
|
832
|
-
sink: {
|
|
833
|
-
onStderr: (s) => console.error(s),
|
|
834
|
-
onStdout: (s) => console.log(s)
|
|
835
|
-
}
|
|
836
|
-
});
|
|
837
|
-
return;
|
|
838
|
-
}
|
|
730
|
+
context.on("kubb:hook:start", ({ command, args }) => {
|
|
731
|
+
if (logLevel$8 <= logLevel.silent) return;
|
|
732
|
+
const text = getMessage(`Hook ${styleText("dim", formatCommandWithArgs(command, args))} started`);
|
|
839
733
|
clack.intro(text);
|
|
840
|
-
const logger = clack.taskLog({ title: getMessage(["Executing hook", logLevel$8 >= logLevel.info ? styleText("dim", commandWithArgs) : void 0].filter(Boolean).join(" ")) });
|
|
841
|
-
const writable = new ClackWritable(logger);
|
|
842
|
-
await runHook({
|
|
843
|
-
id,
|
|
844
|
-
command,
|
|
845
|
-
args,
|
|
846
|
-
commandWithArgs,
|
|
847
|
-
context,
|
|
848
|
-
stream: true,
|
|
849
|
-
sink: {
|
|
850
|
-
onLine: (line) => writable.write(line),
|
|
851
|
-
onStderr: (s) => logger.error(s),
|
|
852
|
-
onStdout: (s) => logger.message(s)
|
|
853
|
-
}
|
|
854
|
-
});
|
|
855
734
|
});
|
|
856
735
|
context.on("kubb:hook:end", ({ command, args }) => {
|
|
857
736
|
if (logLevel$8 <= logLevel.silent) return;
|
|
@@ -887,13 +766,28 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
|
|
|
887
766
|
context.on("kubb:lifecycle:end", () => {
|
|
888
767
|
reset();
|
|
889
768
|
});
|
|
769
|
+
return (commandWithArgs) => {
|
|
770
|
+
if (logLevel$8 <= logLevel.silent) return {
|
|
771
|
+
onStdout: (s) => console.log(s),
|
|
772
|
+
onStderr: (s) => console.error(s)
|
|
773
|
+
};
|
|
774
|
+
const logger = clack.taskLog({ title: getMessage(["Executing hook", logLevel$8 >= logLevel.info ? styleText("dim", commandWithArgs) : void 0].filter(Boolean).join(" ")) });
|
|
775
|
+
const writable = new ClackWritable(logger);
|
|
776
|
+
return {
|
|
777
|
+
stream: true,
|
|
778
|
+
onLine: (line) => writable.write(line),
|
|
779
|
+
onStdout: (s) => logger.message(s),
|
|
780
|
+
onStderr: (s) => logger.error(s)
|
|
781
|
+
};
|
|
782
|
+
};
|
|
890
783
|
}
|
|
891
784
|
});
|
|
892
785
|
//#endregion
|
|
893
786
|
//#region src/loggers/fileSystemLogger.ts
|
|
894
787
|
/**
|
|
895
788
|
* FileSystem logger that captures debug events and writes them to `.kubb` directory files.
|
|
896
|
-
*
|
|
789
|
+
*
|
|
790
|
+
* @note Logs are written on `kubb:lifecycle:end` or process exit. Cached logs may be lost if the process crashes before either event.
|
|
897
791
|
*/
|
|
898
792
|
const fileSystemLogger = defineLogger({
|
|
899
793
|
name: "filesystem",
|
|
@@ -1164,25 +1058,12 @@ const githubActionsLogger = defineLogger({
|
|
|
1164
1058
|
console.log(text);
|
|
1165
1059
|
if (state.currentConfigs.length === 1) closeGroup("Linting");
|
|
1166
1060
|
});
|
|
1167
|
-
context.on("kubb:hook:start",
|
|
1061
|
+
context.on("kubb:hook:start", ({ command, args }) => {
|
|
1062
|
+
if (logLevel$7 <= logLevel.silent) return;
|
|
1168
1063
|
const commandWithArgs = formatCommandWithArgs(command, args);
|
|
1169
1064
|
const text = getMessage(`Hook ${styleText("dim", commandWithArgs)} started`);
|
|
1170
|
-
if (
|
|
1171
|
-
|
|
1172
|
-
console.log(text);
|
|
1173
|
-
}
|
|
1174
|
-
if (!id) return;
|
|
1175
|
-
await runHook({
|
|
1176
|
-
id,
|
|
1177
|
-
command,
|
|
1178
|
-
args,
|
|
1179
|
-
commandWithArgs,
|
|
1180
|
-
context,
|
|
1181
|
-
sink: {
|
|
1182
|
-
onStdout: logLevel$7 > logLevel.silent ? (s) => console.log(s) : void 0,
|
|
1183
|
-
onStderr: logLevel$7 > logLevel.silent ? (s) => console.error(`::error::${s}`) : void 0
|
|
1184
|
-
}
|
|
1185
|
-
});
|
|
1065
|
+
if (state.currentConfigs.length === 1) openGroup(`Hook ${commandWithArgs}`);
|
|
1066
|
+
console.log(text);
|
|
1186
1067
|
});
|
|
1187
1068
|
context.on("kubb:hook:end", ({ command, args }) => {
|
|
1188
1069
|
if (logLevel$7 <= logLevel.silent) return;
|
|
@@ -1202,6 +1083,10 @@ const githubActionsLogger = defineLogger({
|
|
|
1202
1083
|
context.on("kubb:lifecycle:end", () => {
|
|
1203
1084
|
reset();
|
|
1204
1085
|
});
|
|
1086
|
+
return (_commandWithArgs) => ({
|
|
1087
|
+
onStdout: logLevel$7 > logLevel.silent ? (s) => console.log(s) : void 0,
|
|
1088
|
+
onStderr: logLevel$7 > logLevel.silent ? (s) => console.error(`::error::${s}`) : void 0
|
|
1089
|
+
});
|
|
1205
1090
|
}
|
|
1206
1091
|
});
|
|
1207
1092
|
//#endregion
|
|
@@ -1324,22 +1209,10 @@ const plainLogger = defineLogger({
|
|
|
1324
1209
|
const text = getMessage("Lint completed");
|
|
1325
1210
|
console.log(text);
|
|
1326
1211
|
});
|
|
1327
|
-
context.on("kubb:hook:start",
|
|
1328
|
-
|
|
1329
|
-
const text = getMessage(`Hook ${
|
|
1330
|
-
|
|
1331
|
-
if (!id) return;
|
|
1332
|
-
await runHook({
|
|
1333
|
-
id,
|
|
1334
|
-
command,
|
|
1335
|
-
args,
|
|
1336
|
-
commandWithArgs,
|
|
1337
|
-
context,
|
|
1338
|
-
sink: {
|
|
1339
|
-
onStdout: logLevel$6 > logLevel.silent ? (s) => console.log(s) : void 0,
|
|
1340
|
-
onStderr: logLevel$6 > logLevel.silent ? (s) => console.error(s) : void 0
|
|
1341
|
-
}
|
|
1342
|
-
});
|
|
1212
|
+
context.on("kubb:hook:start", ({ command, args }) => {
|
|
1213
|
+
if (logLevel$6 <= logLevel.silent) return;
|
|
1214
|
+
const text = getMessage(`Hook ${formatCommandWithArgs(command, args)} started`);
|
|
1215
|
+
console.log(text);
|
|
1343
1216
|
});
|
|
1344
1217
|
context.on("kubb:hook:end", ({ command, args }) => {
|
|
1345
1218
|
if (logLevel$6 <= logLevel.silent) return;
|
|
@@ -1359,6 +1232,10 @@ const plainLogger = defineLogger({
|
|
|
1359
1232
|
console.log(summary.join("\n"));
|
|
1360
1233
|
console.log(SUMMARY_SEPARATOR);
|
|
1361
1234
|
});
|
|
1235
|
+
return (_commandWithArgs) => ({
|
|
1236
|
+
onStdout: logLevel$6 > logLevel.silent ? (s) => console.log(s) : void 0,
|
|
1237
|
+
onStderr: logLevel$6 > logLevel.silent ? (s) => console.error(s) : void 0
|
|
1238
|
+
});
|
|
1362
1239
|
}
|
|
1363
1240
|
});
|
|
1364
1241
|
//#endregion
|
|
@@ -1413,49 +1290,52 @@ async function setupLogger(context, { logLevel: logLevel$5 }) {
|
|
|
1413
1290
|
const type = detectLogger();
|
|
1414
1291
|
const logger = logMapper[type];
|
|
1415
1292
|
if (!logger) throw new Error(`Unknown adapter type: ${type}`);
|
|
1416
|
-
const
|
|
1293
|
+
const makeSink = await logger.install(context, { logLevel: logLevel$5 });
|
|
1417
1294
|
if (logLevel$5 >= logLevel.debug) await fileSystemLogger.install(context, { logLevel: logLevel$5 });
|
|
1418
|
-
return
|
|
1295
|
+
return typeof makeSink === "function" ? makeSink : void 0;
|
|
1419
1296
|
}
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1297
|
+
/**
|
|
1298
|
+
* Builds the generation summary lines rendered in the end-of-run box.
|
|
1299
|
+
* Returns an array of styled strings, one per summary row.
|
|
1300
|
+
*/
|
|
1301
|
+
function getSummary({ failedPlugins, filesCreated, status, hrStart, config, pluginTimings }) {
|
|
1302
|
+
const duration = formatHrtime(hrStart);
|
|
1303
|
+
const pluginsCount = config.plugins?.length ?? 0;
|
|
1304
|
+
const successCount = pluginsCount - failedPlugins.size;
|
|
1305
|
+
const meta = {
|
|
1306
|
+
plugins: status === "success" ? `${styleText("green", `${successCount} successful`)}, ${pluginsCount} total` : `${styleText("green", `${successCount} successful`)}, ${styleText("red", `${failedPlugins.size} failed`)}, ${pluginsCount} total`,
|
|
1307
|
+
pluginsFailed: status === "failed" ? [...failedPlugins].map(({ plugin }) => randomCliColor(plugin.name)).join(", ") : void 0,
|
|
1308
|
+
filesCreated,
|
|
1309
|
+
time: styleText("green", duration),
|
|
1310
|
+
output: path.resolve(config.root, config.output.path)
|
|
1311
|
+
};
|
|
1312
|
+
const labels = {
|
|
1313
|
+
plugins: "Plugins:",
|
|
1314
|
+
failed: "Failed:",
|
|
1315
|
+
generated: "Generated:",
|
|
1316
|
+
pluginTimings: "Plugin Timings:",
|
|
1317
|
+
output: "Output:"
|
|
1318
|
+
};
|
|
1319
|
+
const maxLength = Math.max(0, ...[...Object.values(labels), ...pluginTimings ? Array.from(pluginTimings.keys()) : []].map((s) => s.length));
|
|
1320
|
+
const summaryLines = [];
|
|
1321
|
+
summaryLines.push(`${labels.plugins.padEnd(maxLength + 2)} ${meta.plugins}`);
|
|
1322
|
+
if (meta.pluginsFailed) summaryLines.push(`${labels.failed.padEnd(maxLength + 2)} ${meta.pluginsFailed}`);
|
|
1323
|
+
summaryLines.push(`${labels.generated.padEnd(maxLength + 2)} ${meta.filesCreated} files in ${meta.time}`);
|
|
1324
|
+
if (pluginTimings && pluginTimings.size > 0) {
|
|
1325
|
+
const sortedTimings = Array.from(pluginTimings.entries()).sort((a, b) => b[1] - a[1]);
|
|
1326
|
+
summaryLines.push(`${labels.pluginTimings}`);
|
|
1327
|
+
sortedTimings.forEach(([name, time]) => {
|
|
1328
|
+
const timeStr = time >= 1e3 ? `${(time / 1e3).toFixed(2)}s` : `${Math.round(time)}ms`;
|
|
1329
|
+
const barLength = Math.min(Math.ceil(time / 100), 10);
|
|
1330
|
+
const bar = styleText("dim", "█".repeat(barLength));
|
|
1331
|
+
summaryLines.push(`${styleText("dim", "•")} ${name.padEnd(maxLength + 1)}${bar} ${timeStr}`);
|
|
1444
1332
|
});
|
|
1445
|
-
await hookEndPromise;
|
|
1446
1333
|
}
|
|
1334
|
+
summaryLines.push(`${labels.output.padEnd(maxLength + 2)} ${meta.output}`);
|
|
1335
|
+
return summaryLines;
|
|
1447
1336
|
}
|
|
1448
1337
|
//#endregion
|
|
1449
|
-
//#region src/utils
|
|
1450
|
-
async function getConfigs(config, args) {
|
|
1451
|
-
const resolved = await (typeof config === "function" ? config(args) : config);
|
|
1452
|
-
return (Array.isArray(resolved) ? resolved : [resolved]).map((item) => ({
|
|
1453
|
-
...item,
|
|
1454
|
-
plugins: item.plugins ?? []
|
|
1455
|
-
}));
|
|
1456
|
-
}
|
|
1457
|
-
//#endregion
|
|
1458
|
-
//#region src/utils/getCosmiConfig.ts
|
|
1338
|
+
//#region src/runners/generate/utils.ts
|
|
1459
1339
|
const jiti = createJiti(import.meta.url, {
|
|
1460
1340
|
jsx: {
|
|
1461
1341
|
runtime: "automatic",
|
|
@@ -1463,73 +1343,180 @@ const jiti = createJiti(import.meta.url, {
|
|
|
1463
1343
|
},
|
|
1464
1344
|
moduleCache: false
|
|
1465
1345
|
});
|
|
1466
|
-
const tsLoader =
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1346
|
+
const tsLoader = (configFile) => jiti.import(configFile, { default: true });
|
|
1347
|
+
const MODULE_NAME = "kubb";
|
|
1348
|
+
const BASE_SEARCH_PLACES = [
|
|
1349
|
+
"package.json",
|
|
1350
|
+
`.${MODULE_NAME}rc`,
|
|
1351
|
+
`.${MODULE_NAME}rc.json`,
|
|
1352
|
+
`.${MODULE_NAME}rc.yaml`,
|
|
1353
|
+
`.${MODULE_NAME}rc.yml`,
|
|
1354
|
+
`.${MODULE_NAME}rc.ts`,
|
|
1355
|
+
`.${MODULE_NAME}rc.mts`,
|
|
1356
|
+
`.${MODULE_NAME}rc.cts`,
|
|
1357
|
+
`.${MODULE_NAME}rc.js`,
|
|
1358
|
+
`.${MODULE_NAME}rc.mjs`,
|
|
1359
|
+
`.${MODULE_NAME}rc.cjs`,
|
|
1360
|
+
`${MODULE_NAME}.config.ts`,
|
|
1361
|
+
`${MODULE_NAME}.config.mts`,
|
|
1362
|
+
`${MODULE_NAME}.config.cts`,
|
|
1363
|
+
`${MODULE_NAME}.config.js`,
|
|
1364
|
+
`${MODULE_NAME}.config.mjs`,
|
|
1365
|
+
`${MODULE_NAME}.config.cjs`
|
|
1366
|
+
];
|
|
1367
|
+
const SEARCH_PLACES = [
|
|
1368
|
+
"",
|
|
1369
|
+
".config/",
|
|
1370
|
+
"configs/"
|
|
1371
|
+
].flatMap((prefix) => BASE_SEARCH_PLACES.map((p) => `${prefix}${p}`));
|
|
1372
|
+
async function getCosmiConfig(configFile) {
|
|
1373
|
+
const explorer = cosmiconfig(MODULE_NAME, {
|
|
1491
1374
|
cache: false,
|
|
1492
|
-
searchPlaces:
|
|
1493
|
-
...searchPlaces.map((searchPlace) => {
|
|
1494
|
-
return `.config/${searchPlace}`;
|
|
1495
|
-
}),
|
|
1496
|
-
...searchPlaces.map((searchPlace) => {
|
|
1497
|
-
return `configs/${searchPlace}`;
|
|
1498
|
-
}),
|
|
1499
|
-
...searchPlaces
|
|
1500
|
-
],
|
|
1375
|
+
searchPlaces: SEARCH_PLACES,
|
|
1501
1376
|
loaders: {
|
|
1502
1377
|
".ts": tsLoader,
|
|
1503
1378
|
".mts": tsLoader,
|
|
1504
1379
|
".cts": tsLoader
|
|
1505
1380
|
}
|
|
1506
1381
|
});
|
|
1382
|
+
let result;
|
|
1507
1383
|
try {
|
|
1508
|
-
result =
|
|
1384
|
+
result = configFile ? await explorer.load(configFile) : await explorer.search();
|
|
1509
1385
|
} catch (error) {
|
|
1510
1386
|
throw new Error("Config failed loading", { cause: error });
|
|
1511
1387
|
}
|
|
1512
|
-
if (result?.
|
|
1388
|
+
if (!result?.config || result.isEmpty) throw new Error("Config not defined, create a kubb.config.js or pass through your config with the option --config");
|
|
1513
1389
|
return result;
|
|
1514
1390
|
}
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1391
|
+
/**
|
|
1392
|
+
* Discovers the Kubb config via cosmiconfig and resolves it into a normalized array of configs.
|
|
1393
|
+
* Every config in the result is guaranteed to have a `plugins` array.
|
|
1394
|
+
*/
|
|
1395
|
+
async function getConfigs({ configPath, input }) {
|
|
1396
|
+
const result = await getCosmiConfig(configPath);
|
|
1397
|
+
const resolved = await (typeof result.config === "function" ? result.config({ input }) : result.config);
|
|
1398
|
+
const userConfigs = Array.isArray(resolved) ? resolved : [resolved];
|
|
1399
|
+
return {
|
|
1400
|
+
configPath: result.filepath,
|
|
1401
|
+
configs: userConfigs.map((item) => ({
|
|
1402
|
+
...item,
|
|
1403
|
+
plugins: item.plugins ?? []
|
|
1404
|
+
}))
|
|
1405
|
+
};
|
|
1406
|
+
}
|
|
1407
|
+
/**
|
|
1408
|
+
* Runs the `done` hooks defined in a Kubb config in sequence.
|
|
1409
|
+
*/
|
|
1410
|
+
async function executeHooks({ configHooks, hooks, makeSink }) {
|
|
1411
|
+
const commands = Array.isArray(configHooks.done) ? configHooks.done : [configHooks.done].filter(Boolean);
|
|
1412
|
+
for (const command of commands) {
|
|
1413
|
+
const [cmd, ...args] = tokenize(command);
|
|
1414
|
+
if (!cmd) continue;
|
|
1415
|
+
const hookId = createHash("sha256").update(command).digest("hex");
|
|
1416
|
+
const commandWithArgs = [cmd, ...args].join(" ");
|
|
1417
|
+
await hooks.emit("kubb:hook:start", {
|
|
1418
|
+
id: hookId,
|
|
1419
|
+
command: cmd,
|
|
1420
|
+
args
|
|
1421
|
+
});
|
|
1422
|
+
const { stream = false, onLine, onStdout, onStderr } = makeSink?.(commandWithArgs) ?? {};
|
|
1423
|
+
await runHook({
|
|
1424
|
+
id: hookId,
|
|
1425
|
+
command: cmd,
|
|
1426
|
+
args,
|
|
1427
|
+
commandWithArgs,
|
|
1428
|
+
context: hooks,
|
|
1429
|
+
stream,
|
|
1430
|
+
sink: {
|
|
1431
|
+
onLine,
|
|
1432
|
+
onStdout,
|
|
1433
|
+
onStderr
|
|
1434
|
+
}
|
|
1435
|
+
});
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
async function runHook({ id, command, args, commandWithArgs, context, stream = false, sink }) {
|
|
1439
|
+
const emitEnd = (success, error) => context.emit("kubb:hook:end", {
|
|
1440
|
+
command,
|
|
1441
|
+
args,
|
|
1442
|
+
id,
|
|
1443
|
+
success,
|
|
1444
|
+
error
|
|
1445
|
+
});
|
|
1446
|
+
try {
|
|
1447
|
+
const proc = x(command, [...args ?? []], {
|
|
1448
|
+
nodeOptions: { detached: process.platform !== "win32" },
|
|
1449
|
+
throwOnError: true
|
|
1450
|
+
});
|
|
1451
|
+
if (stream && sink?.onLine) for await (const line of proc) sink.onLine(line);
|
|
1452
|
+
const result = await proc;
|
|
1453
|
+
await context.emit("kubb:debug", {
|
|
1454
|
+
date: /* @__PURE__ */ new Date(),
|
|
1455
|
+
logs: [result.stdout.trimEnd()]
|
|
1456
|
+
});
|
|
1457
|
+
await context.emit("kubb:success", { message: `${styleText("dim", commandWithArgs)} successfully executed` });
|
|
1458
|
+
await emitEnd(true, null);
|
|
1459
|
+
} catch (err) {
|
|
1460
|
+
if (!(err instanceof NonZeroExitError)) {
|
|
1461
|
+
const error = toError(err);
|
|
1462
|
+
await emitEnd(false, error);
|
|
1463
|
+
await context.emit("kubb:error", { error });
|
|
1464
|
+
return;
|
|
1465
|
+
}
|
|
1466
|
+
const stderr = err.output?.stderr ?? "";
|
|
1467
|
+
const stdout = err.output?.stdout ?? "";
|
|
1468
|
+
await context.emit("kubb:debug", {
|
|
1469
|
+
date: /* @__PURE__ */ new Date(),
|
|
1470
|
+
logs: [stdout, stderr].filter(Boolean)
|
|
1471
|
+
});
|
|
1472
|
+
if (stderr) sink?.onStderr?.(stderr);
|
|
1473
|
+
if (stdout) sink?.onStdout?.(stdout);
|
|
1474
|
+
const error = /* @__PURE__ */ new Error(`Hook execute failed: ${commandWithArgs}`);
|
|
1475
|
+
await emitEnd(false, error);
|
|
1476
|
+
await context.emit("kubb:error", { error });
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
/**
|
|
1480
|
+
* Starts a file watcher on the given paths and calls `cb` on any change.
|
|
1481
|
+
* Ignores `.git` and `node_modules` directories.
|
|
1482
|
+
*/
|
|
1483
|
+
async function startWatcher(path, cb, log = {
|
|
1484
|
+
info: console.log,
|
|
1485
|
+
error: console.log
|
|
1486
|
+
}) {
|
|
1518
1487
|
const { watch } = await import("chokidar");
|
|
1519
1488
|
watch(path, {
|
|
1520
1489
|
ignorePermissionErrors: true,
|
|
1521
1490
|
ignored: WATCHER_IGNORED_PATHS
|
|
1522
1491
|
}).on("all", async (type, file) => {
|
|
1523
|
-
|
|
1492
|
+
log.info(styleText("yellow", styleText("bold", `Change detected: ${type} ${file}`)));
|
|
1524
1493
|
try {
|
|
1525
1494
|
await cb(path);
|
|
1526
1495
|
} catch (_e) {
|
|
1527
|
-
|
|
1496
|
+
log.error(styleText("red", "Watcher failed"));
|
|
1528
1497
|
}
|
|
1529
1498
|
});
|
|
1530
1499
|
}
|
|
1531
1500
|
//#endregion
|
|
1532
|
-
//#region src/runners/generate.ts
|
|
1501
|
+
//#region src/runners/generate/run.ts
|
|
1502
|
+
/**
|
|
1503
|
+
* Registers a one-shot `kubb:hook:end` listener for `hookId` BEFORE the caller emits `kubb:hook:start`,
|
|
1504
|
+
* avoiding the race where a synchronous emitter fires end before the listener is attached.
|
|
1505
|
+
*/
|
|
1506
|
+
function waitForHookEnd(hooks, hookId, onSuccess, fallbackErrorMessage) {
|
|
1507
|
+
return new Promise((resolve, reject) => {
|
|
1508
|
+
const handler = (ctx) => {
|
|
1509
|
+
if (ctx.id !== hookId) return;
|
|
1510
|
+
hooks.off("kubb:hook:end", handler);
|
|
1511
|
+
if (!ctx.success) {
|
|
1512
|
+
reject(ctx.error ?? new Error(fallbackErrorMessage));
|
|
1513
|
+
return;
|
|
1514
|
+
}
|
|
1515
|
+
onSuccess().then(resolve).catch(reject);
|
|
1516
|
+
};
|
|
1517
|
+
hooks.on("kubb:hook:end", handler);
|
|
1518
|
+
});
|
|
1519
|
+
}
|
|
1533
1520
|
async function runToolPass({ toolValue, detect, toolMap, toolLabel, successPrefix, noToolMessage, configName, outputPath, logLevel: logLevel$1, hooks, onStart, onEnd }) {
|
|
1534
1521
|
await onStart();
|
|
1535
1522
|
let resolvedTool = toolValue;
|
|
@@ -1544,24 +1531,14 @@ async function runToolPass({ toolValue, detect, toolMap, toolLabel, successPrefi
|
|
|
1544
1531
|
let toolError;
|
|
1545
1532
|
if (resolvedTool && resolvedTool !== "auto" && resolvedTool in toolMap) {
|
|
1546
1533
|
const toolConfig = toolMap[resolvedTool];
|
|
1534
|
+
const hookId = createHash("sha256").update([configName, resolvedTool].filter(Boolean).join("-")).digest("hex");
|
|
1535
|
+
const successMessage = [
|
|
1536
|
+
`${successPrefix} with ${styleText("dim", resolvedTool)}`,
|
|
1537
|
+
logLevel$1 >= logLevel.info ? `on ${styleText("dim", outputPath)}` : void 0,
|
|
1538
|
+
"successfully"
|
|
1539
|
+
].filter(Boolean).join(" ");
|
|
1547
1540
|
try {
|
|
1548
|
-
const
|
|
1549
|
-
const hookEndPromise = new Promise((resolve, reject) => {
|
|
1550
|
-
const handler = (ctx) => {
|
|
1551
|
-
if (ctx.id !== hookId) return;
|
|
1552
|
-
hooks.off("kubb:hook:end", handler);
|
|
1553
|
-
if (!ctx.success) {
|
|
1554
|
-
reject(ctx.error ?? /* @__PURE__ */ new Error(`${toolConfig.errorMessage}`));
|
|
1555
|
-
return;
|
|
1556
|
-
}
|
|
1557
|
-
hooks.emit("kubb:success", { message: [
|
|
1558
|
-
`${successPrefix} with ${styleText("dim", resolvedTool)}`,
|
|
1559
|
-
logLevel$1 >= logLevel.info ? `on ${styleText("dim", outputPath)}` : void 0,
|
|
1560
|
-
"successfully"
|
|
1561
|
-
].filter(Boolean).join(" ") }).then(resolve).catch(reject);
|
|
1562
|
-
};
|
|
1563
|
-
hooks.on("kubb:hook:end", handler);
|
|
1564
|
-
});
|
|
1541
|
+
const hookEndPromise = waitForHookEnd(hooks, hookId, () => hooks.emit("kubb:success", { message: successMessage }), toolConfig.errorMessage);
|
|
1565
1542
|
await hooks.emit("kubb:hook:start", {
|
|
1566
1543
|
id: hookId,
|
|
1567
1544
|
command: toolConfig.command,
|
|
@@ -1578,7 +1555,7 @@ async function runToolPass({ toolValue, detect, toolMap, toolLabel, successPrefi
|
|
|
1578
1555
|
if (toolError) throw toolError;
|
|
1579
1556
|
}
|
|
1580
1557
|
async function generate(options) {
|
|
1581
|
-
const { input, hooks, logLevel: logLevel$2 } = options;
|
|
1558
|
+
const { input, hooks, logLevel: logLevel$2, makeSink } = options;
|
|
1582
1559
|
const hrStart = process$1.hrtime();
|
|
1583
1560
|
const inputPath = input ?? (options.config.input && "path" in options.config.input ? options.config.input.path : void 0);
|
|
1584
1561
|
const config = {
|
|
@@ -1602,8 +1579,20 @@ async function generate(options) {
|
|
|
1602
1579
|
});
|
|
1603
1580
|
const { files, failedPlugins, pluginTimings, error, driver } = await kubb.safeBuild();
|
|
1604
1581
|
await hooks.emit("kubb:info", { message: "Load summary" });
|
|
1582
|
+
const telemetryPlugins = Array.from(driver.plugins.values(), (p) => ({
|
|
1583
|
+
name: p.name,
|
|
1584
|
+
options: p.options
|
|
1585
|
+
}));
|
|
1586
|
+
const reportTelemetry = (status) => sendTelemetry(buildTelemetryEvent({
|
|
1587
|
+
command: "generate",
|
|
1588
|
+
kubbVersion: version,
|
|
1589
|
+
plugins: telemetryPlugins,
|
|
1590
|
+
hrStart,
|
|
1591
|
+
filesCreated: files.length,
|
|
1592
|
+
status
|
|
1593
|
+
}));
|
|
1605
1594
|
if (failedPlugins.size > 0 || error) {
|
|
1606
|
-
const allErrors = [error, ...Array.from(failedPlugins
|
|
1595
|
+
const allErrors = [error, ...Array.from(failedPlugins, (it) => it.error)].filter(Boolean);
|
|
1607
1596
|
for (const err of allErrors) await hooks.emit("kubb:error", { error: err });
|
|
1608
1597
|
await hooks.emit("kubb:generation:end", {
|
|
1609
1598
|
config,
|
|
@@ -1618,21 +1607,11 @@ async function generate(options) {
|
|
|
1618
1607
|
hrStart,
|
|
1619
1608
|
pluginTimings: logLevel$2 >= logLevel.verbose ? pluginTimings : void 0
|
|
1620
1609
|
});
|
|
1621
|
-
await
|
|
1622
|
-
command: "generate",
|
|
1623
|
-
kubbVersion: version,
|
|
1624
|
-
plugins: Array.from(driver.plugins.values(), (p) => ({
|
|
1625
|
-
name: p.name,
|
|
1626
|
-
options: p.options
|
|
1627
|
-
})),
|
|
1628
|
-
hrStart,
|
|
1629
|
-
filesCreated: files.length,
|
|
1630
|
-
status: "failed"
|
|
1631
|
-
}));
|
|
1610
|
+
await reportTelemetry("failed");
|
|
1632
1611
|
process$1.exit(1);
|
|
1633
1612
|
}
|
|
1634
1613
|
await hooks.emit("kubb:success", {
|
|
1635
|
-
message: "Generation
|
|
1614
|
+
message: "Generation succeeded",
|
|
1636
1615
|
info: inputPath
|
|
1637
1616
|
});
|
|
1638
1617
|
await hooks.emit("kubb:generation:end", {
|
|
@@ -1641,39 +1620,38 @@ async function generate(options) {
|
|
|
1641
1620
|
sources: kubb.sources
|
|
1642
1621
|
});
|
|
1643
1622
|
const outputPath = path.resolve(config.root, config.output.path);
|
|
1644
|
-
|
|
1623
|
+
const toolPasses = [config.output.format && {
|
|
1645
1624
|
toolValue: config.output.format,
|
|
1646
1625
|
detect: detectFormatter,
|
|
1647
1626
|
toolMap: formatters,
|
|
1648
1627
|
toolLabel: "formatter",
|
|
1649
1628
|
successPrefix: "Formatting",
|
|
1650
1629
|
noToolMessage: "No formatter found (oxfmt, biome, or prettier). Skipping formatting.",
|
|
1651
|
-
configName: config.name,
|
|
1652
|
-
outputPath,
|
|
1653
|
-
logLevel: logLevel$2,
|
|
1654
|
-
hooks,
|
|
1655
1630
|
onStart: () => hooks.emit("kubb:format:start"),
|
|
1656
1631
|
onEnd: () => hooks.emit("kubb:format:end")
|
|
1657
|
-
}
|
|
1658
|
-
if (config.output.lint) await runToolPass({
|
|
1632
|
+
}, config.output.lint && {
|
|
1659
1633
|
toolValue: config.output.lint,
|
|
1660
1634
|
detect: detectLinter,
|
|
1661
1635
|
toolMap: linters,
|
|
1662
1636
|
toolLabel: "linter",
|
|
1663
1637
|
successPrefix: "Linting",
|
|
1664
1638
|
noToolMessage: "No linter found (oxlint, biome, or eslint). Skipping linting.",
|
|
1639
|
+
onStart: () => hooks.emit("kubb:lint:start"),
|
|
1640
|
+
onEnd: () => hooks.emit("kubb:lint:end")
|
|
1641
|
+
}].filter(Boolean);
|
|
1642
|
+
for (const pass of toolPasses) await runToolPass({
|
|
1643
|
+
...pass,
|
|
1665
1644
|
configName: config.name,
|
|
1666
1645
|
outputPath,
|
|
1667
1646
|
logLevel: logLevel$2,
|
|
1668
|
-
hooks
|
|
1669
|
-
onStart: () => hooks.emit("kubb:lint:start"),
|
|
1670
|
-
onEnd: () => hooks.emit("kubb:lint:end")
|
|
1647
|
+
hooks
|
|
1671
1648
|
});
|
|
1672
1649
|
if (config.hooks) {
|
|
1673
1650
|
await hooks.emit("kubb:hooks:start");
|
|
1674
1651
|
await executeHooks({
|
|
1675
1652
|
configHooks: config.hooks,
|
|
1676
|
-
hooks
|
|
1653
|
+
hooks,
|
|
1654
|
+
makeSink
|
|
1677
1655
|
});
|
|
1678
1656
|
await hooks.emit("kubb:hooks:end");
|
|
1679
1657
|
}
|
|
@@ -1685,42 +1663,42 @@ async function generate(options) {
|
|
|
1685
1663
|
hrStart,
|
|
1686
1664
|
pluginTimings
|
|
1687
1665
|
});
|
|
1688
|
-
await
|
|
1689
|
-
command: "generate",
|
|
1690
|
-
kubbVersion: version,
|
|
1691
|
-
plugins: Array.from(driver.plugins.values(), (p) => ({
|
|
1692
|
-
name: p.name,
|
|
1693
|
-
options: p.options
|
|
1694
|
-
})),
|
|
1695
|
-
hrStart,
|
|
1696
|
-
filesCreated: files.length,
|
|
1697
|
-
status: "success"
|
|
1698
|
-
}));
|
|
1666
|
+
await reportTelemetry("success");
|
|
1699
1667
|
}
|
|
1700
|
-
async function
|
|
1701
|
-
const logLevel$3 = logLevel[logLevelKey] ?? logLevel.info;
|
|
1702
|
-
const hooks = new AsyncEventEmitter();
|
|
1703
|
-
await setupLogger(hooks, { logLevel: logLevel$3 });
|
|
1668
|
+
async function checkForUpdate(hooks) {
|
|
1704
1669
|
await executeIfOnline(async () => {
|
|
1705
1670
|
try {
|
|
1706
|
-
const
|
|
1707
|
-
if (
|
|
1671
|
+
const data = await (await fetch(KUBB_NPM_PACKAGE_URL)).json();
|
|
1672
|
+
if (data.version && version < data.version) await hooks.emit("kubb:version:new", {
|
|
1708
1673
|
currentVersion: version,
|
|
1709
|
-
latestVersion
|
|
1674
|
+
latestVersion: data.version
|
|
1710
1675
|
});
|
|
1711
1676
|
} catch {}
|
|
1712
1677
|
});
|
|
1678
|
+
}
|
|
1679
|
+
/**
|
|
1680
|
+
* Runs the full Kubb generation lifecycle for the given CLI options.
|
|
1681
|
+
* Sets up the logger, checks for a newer version, loads configs, and calls `generate` for each config entry.
|
|
1682
|
+
*/
|
|
1683
|
+
async function run({ input, configPath, logLevel: logLevelKey, watch }) {
|
|
1684
|
+
const logLevel$3 = logLevel[logLevelKey] ?? logLevel.info;
|
|
1685
|
+
const hooks = new AsyncEventEmitter();
|
|
1686
|
+
const makeSink = await setupLogger(hooks, { logLevel: logLevel$3 });
|
|
1687
|
+
await checkForUpdate(hooks);
|
|
1713
1688
|
try {
|
|
1714
|
-
const
|
|
1715
|
-
|
|
1689
|
+
const { configs, configPath: resolvedConfigPath } = await getConfigs({
|
|
1690
|
+
configPath,
|
|
1691
|
+
input
|
|
1692
|
+
});
|
|
1693
|
+
const relativeConfigPath = path.relative(process$1.cwd(), resolvedConfigPath);
|
|
1716
1694
|
await hooks.emit("kubb:config:start");
|
|
1717
1695
|
await hooks.emit("kubb:info", {
|
|
1718
1696
|
message: "Config loaded",
|
|
1719
|
-
info:
|
|
1697
|
+
info: relativeConfigPath
|
|
1720
1698
|
});
|
|
1721
1699
|
await hooks.emit("kubb:success", {
|
|
1722
1700
|
message: "Config loaded successfully",
|
|
1723
|
-
info:
|
|
1701
|
+
info: relativeConfigPath
|
|
1724
1702
|
});
|
|
1725
1703
|
await hooks.emit("kubb:config:end", { configs });
|
|
1726
1704
|
await hooks.emit("kubb:lifecycle:start", { version });
|
|
@@ -1730,15 +1708,20 @@ async function runGenerateCommand({ input, configPath, logLevel: logLevelKey, wa
|
|
|
1730
1708
|
input,
|
|
1731
1709
|
config,
|
|
1732
1710
|
logLevel: logLevel$3,
|
|
1733
|
-
hooks
|
|
1711
|
+
hooks,
|
|
1712
|
+
makeSink
|
|
1734
1713
|
});
|
|
1735
1714
|
clack.log.step(styleText("yellow", `Watching for changes in ${paths.join(" and ")}`));
|
|
1715
|
+
}, {
|
|
1716
|
+
info: (msg) => clack.log.info(msg),
|
|
1717
|
+
error: (msg) => clack.log.error(msg)
|
|
1736
1718
|
});
|
|
1737
1719
|
else await generate({
|
|
1738
1720
|
input,
|
|
1739
1721
|
config,
|
|
1740
1722
|
logLevel: logLevel$3,
|
|
1741
|
-
hooks
|
|
1723
|
+
hooks,
|
|
1724
|
+
makeSink
|
|
1742
1725
|
});
|
|
1743
1726
|
await hooks.emit("kubb:lifecycle:end");
|
|
1744
1727
|
} catch (error) {
|
|
@@ -1747,6 +1730,6 @@ async function runGenerateCommand({ input, configPath, logLevel: logLevelKey, wa
|
|
|
1747
1730
|
}
|
|
1748
1731
|
}
|
|
1749
1732
|
//#endregion
|
|
1750
|
-
export {
|
|
1733
|
+
export { run };
|
|
1751
1734
|
|
|
1752
|
-
//# sourceMappingURL=
|
|
1735
|
+
//# sourceMappingURL=run-BAJubgdA.js.map
|