@kubb/cli 5.0.0-alpha.34 → 5.0.0-alpha.36
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/{agent-C5na5bbz.cjs → agent-CRQdwSar.cjs} +6 -6
- package/dist/{agent-C5na5bbz.cjs.map → agent-CRQdwSar.cjs.map} +1 -1
- package/dist/{agent-DmErNHkG.js → agent-D1I8zBrQ.js} +2 -2
- package/dist/{agent-DmErNHkG.js.map → agent-D1I8zBrQ.js.map} +1 -1
- package/dist/{agent-DG5HV-tW.cjs → agent-yOLMZKYB.cjs} +3 -3
- package/dist/{agent-DG5HV-tW.cjs.map → agent-yOLMZKYB.cjs.map} +1 -1
- package/dist/{generate-CUJnCnIQ.js → generate-BqY9Y4hu.js} +2 -2
- package/dist/{generate-CUJnCnIQ.js.map → generate-BqY9Y4hu.js.map} +1 -1
- package/dist/{generate-B4tku_7i.cjs → generate-Cf1qSeSJ.cjs} +173 -154
- package/dist/generate-Cf1qSeSJ.cjs.map +1 -0
- package/dist/{generate-DUL1xmJg.cjs → generate-DLF8yBO-.cjs} +2 -2
- package/dist/{generate-DUL1xmJg.cjs.map → generate-DLF8yBO-.cjs.map} +1 -1
- package/dist/{generate-XrHYSmsI.js → generate-tDgmJWNE.js} +169 -150
- package/dist/generate-tDgmJWNE.js.map +1 -0
- package/dist/index.cjs +7 -7
- package/dist/index.js +6 -6
- package/dist/{init-V5FRBsV7.cjs → init-COClpOHO.cjs} +3 -3
- package/dist/{init-V5FRBsV7.cjs.map → init-COClpOHO.cjs.map} +1 -1
- package/dist/{init-CrlY2xYZ.js → init-DsJPxNVQ.js} +3 -3
- package/dist/{init-CrlY2xYZ.js.map → init-DsJPxNVQ.js.map} +1 -1
- package/dist/{init-BlriFVH6.cjs → init-cAbMOLut.cjs} +6 -6
- package/dist/init-cAbMOLut.cjs.map +1 -0
- package/dist/{init-Y1TNCdzh.js → init-hcm7zvPn.js} +2 -2
- package/dist/init-hcm7zvPn.js.map +1 -0
- package/dist/{mcp-jMZ56bqT.cjs → mcp-9yURBP26.cjs} +3 -3
- package/dist/{mcp-jMZ56bqT.cjs.map → mcp-9yURBP26.cjs.map} +1 -1
- package/dist/{mcp-CAeC6a-k.js → mcp-BCpQsb0N.js} +2 -2
- package/dist/{mcp-CAeC6a-k.js.map → mcp-BCpQsb0N.js.map} +1 -1
- package/dist/{mcp-J47QdVFi.cjs → mcp-SALpMGkp.cjs} +3 -3
- package/dist/{mcp-J47QdVFi.cjs.map → mcp-SALpMGkp.cjs.map} +1 -1
- package/dist/package-Cx_eJU6W.js +6 -0
- package/dist/package-Cx_eJU6W.js.map +1 -0
- package/dist/{package-Dh1zBdCJ.cjs → package-_aRwmOp5.cjs} +2 -2
- package/dist/package-_aRwmOp5.cjs.map +1 -0
- package/dist/{telemetry-YO-uwAbf.cjs → telemetry-D_Bi2E3I.cjs} +3 -3
- package/dist/{telemetry-YO-uwAbf.cjs.map → telemetry-D_Bi2E3I.cjs.map} +1 -1
- package/dist/{validate-gCh1hrgS.js → validate-BLlD33VV.js} +2 -2
- package/dist/{validate-gCh1hrgS.js.map → validate-BLlD33VV.js.map} +1 -1
- package/dist/{validate-B-LfVNlS.cjs → validate-DIKeUU8K.cjs} +3 -3
- package/dist/{validate-B-LfVNlS.cjs.map → validate-DIKeUU8K.cjs.map} +1 -1
- package/dist/{validate-CbcHhnj0.cjs → validate-DPTV1XRk.cjs} +3 -3
- package/dist/{validate-CbcHhnj0.cjs.map → validate-DPTV1XRk.cjs.map} +1 -1
- package/package.json +5 -5
- package/src/loggers/clackLogger.ts +24 -24
- package/src/loggers/fileSystemLogger.ts +10 -10
- package/src/loggers/githubActionsLogger.ts +22 -22
- package/src/loggers/plainLogger.ts +21 -21
- package/src/runners/generate.ts +53 -65
- package/src/runners/init.ts +1 -1
- package/src/utils/executeHooks.ts +11 -11
- package/src/utils/getConfig.ts +10 -0
- package/src/utils/getCosmiConfig.ts +2 -2
- package/src/utils/runHook.ts +9 -9
- package/dist/generate-B4tku_7i.cjs.map +0 -1
- package/dist/generate-XrHYSmsI.js.map +0 -1
- package/dist/init-BlriFVH6.cjs.map +0 -1
- package/dist/init-Y1TNCdzh.js.map +0 -1
- package/dist/package-CTCPKXJv.js +0 -6
- package/dist/package-CTCPKXJv.js.map +0 -1
- package/dist/package-Dh1zBdCJ.cjs.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const require_chunk = require("./chunk-ByKO4r7w.cjs");
|
|
2
2
|
const require_errors = require("./errors-CLCjoSg0.cjs");
|
|
3
|
-
const require_telemetry = require("./telemetry-
|
|
3
|
+
const require_telemetry = require("./telemetry-D_Bi2E3I.cjs");
|
|
4
4
|
const require_shell = require("./shell-475fQKaX.cjs");
|
|
5
|
-
const require_package = require("./package-
|
|
5
|
+
const require_package = require("./package-_aRwmOp5.cjs");
|
|
6
6
|
const require_constants = require("./constants-D0XHAHeZ.cjs");
|
|
7
7
|
let node_util = require("node:util");
|
|
8
8
|
let node_events = require("node:events");
|
|
@@ -10,11 +10,11 @@ let node_crypto = require("node:crypto");
|
|
|
10
10
|
require("node:fs");
|
|
11
11
|
let node_fs_promises = require("node:fs/promises");
|
|
12
12
|
let node_path = require("node:path");
|
|
13
|
-
node_path = require_chunk.__toESM(node_path);
|
|
13
|
+
node_path = require_chunk.__toESM(node_path, 1);
|
|
14
14
|
let node_process = require("node:process");
|
|
15
|
-
node_process = require_chunk.__toESM(node_process);
|
|
15
|
+
node_process = require_chunk.__toESM(node_process, 1);
|
|
16
16
|
let _clack_prompts = require("@clack/prompts");
|
|
17
|
-
_clack_prompts = require_chunk.__toESM(_clack_prompts);
|
|
17
|
+
_clack_prompts = require_chunk.__toESM(_clack_prompts, 1);
|
|
18
18
|
let _kubb_core = require("@kubb/core");
|
|
19
19
|
let tinyexec = require("tinyexec");
|
|
20
20
|
let node_stream = require("node:stream");
|
|
@@ -103,6 +103,18 @@ var AsyncEventEmitter = class {
|
|
|
103
103
|
this.#emitter.off(eventName, handler);
|
|
104
104
|
}
|
|
105
105
|
/**
|
|
106
|
+
* Returns the number of listeners registered for `eventName`.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```ts
|
|
110
|
+
* emitter.on('build', handler)
|
|
111
|
+
* emitter.listenerCount('build') // 1
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
listenerCount(eventName) {
|
|
115
|
+
return this.#emitter.listenerCount(eventName);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
106
118
|
* Removes all listeners from every event channel.
|
|
107
119
|
*
|
|
108
120
|
* @example
|
|
@@ -370,11 +382,11 @@ async function runHook({ id, command, args, commandWithArgs, context, stream = f
|
|
|
370
382
|
});
|
|
371
383
|
if (stream && sink?.onLine) for await (const line of proc) sink.onLine(line);
|
|
372
384
|
const result = await proc;
|
|
373
|
-
await context.emit("debug", {
|
|
385
|
+
await context.emit("kubb:debug", {
|
|
374
386
|
date: /* @__PURE__ */ new Date(),
|
|
375
387
|
logs: [result.stdout.trimEnd()]
|
|
376
388
|
});
|
|
377
|
-
await context.emit("hook:end", {
|
|
389
|
+
await context.emit("kubb:hook:end", {
|
|
378
390
|
command,
|
|
379
391
|
args,
|
|
380
392
|
id,
|
|
@@ -383,33 +395,33 @@ async function runHook({ id, command, args, commandWithArgs, context, stream = f
|
|
|
383
395
|
});
|
|
384
396
|
} catch (err) {
|
|
385
397
|
if (!(err instanceof tinyexec.NonZeroExitError)) {
|
|
386
|
-
await context.emit("hook:end", {
|
|
398
|
+
await context.emit("kubb:hook:end", {
|
|
387
399
|
command,
|
|
388
400
|
args,
|
|
389
401
|
id,
|
|
390
402
|
success: false,
|
|
391
403
|
error: require_errors.toError(err)
|
|
392
404
|
});
|
|
393
|
-
await context.emit("error", require_errors.toError(err));
|
|
405
|
+
await context.emit("kubb:error", require_errors.toError(err));
|
|
394
406
|
return;
|
|
395
407
|
}
|
|
396
408
|
const stderr = err.output?.stderr ?? "";
|
|
397
409
|
const stdout = err.output?.stdout ?? "";
|
|
398
|
-
await context.emit("debug", {
|
|
410
|
+
await context.emit("kubb:debug", {
|
|
399
411
|
date: /* @__PURE__ */ new Date(),
|
|
400
412
|
logs: [stdout, stderr].filter(Boolean)
|
|
401
413
|
});
|
|
402
414
|
if (stderr) sink?.onStderr?.(stderr);
|
|
403
415
|
if (stdout) sink?.onStdout?.(stdout);
|
|
404
416
|
const errorMessage = /* @__PURE__ */ new Error(`Hook execute failed: ${commandWithArgs}`);
|
|
405
|
-
await context.emit("hook:end", {
|
|
417
|
+
await context.emit("kubb:hook:end", {
|
|
406
418
|
command,
|
|
407
419
|
args,
|
|
408
420
|
id,
|
|
409
421
|
success: false,
|
|
410
422
|
error: errorMessage
|
|
411
423
|
});
|
|
412
|
-
await context.emit("error", errorMessage);
|
|
424
|
+
await context.emit("kubb:error", errorMessage);
|
|
413
425
|
}
|
|
414
426
|
}
|
|
415
427
|
//#endregion
|
|
@@ -477,7 +489,7 @@ const clackLogger = (0, _kubb_core.defineLogger)({
|
|
|
477
489
|
state.spinner.stop(text);
|
|
478
490
|
state.isSpinning = false;
|
|
479
491
|
}
|
|
480
|
-
context.on("info", (message, info = "") => {
|
|
492
|
+
context.on("kubb:info", (message, info = "") => {
|
|
481
493
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
482
494
|
const text = getMessage([
|
|
483
495
|
(0, node_util.styleText)("blue", "ℹ"),
|
|
@@ -487,7 +499,7 @@ const clackLogger = (0, _kubb_core.defineLogger)({
|
|
|
487
499
|
if (state.isSpinning) state.spinner.message(text);
|
|
488
500
|
else _clack_prompts.log.info(text);
|
|
489
501
|
});
|
|
490
|
-
context.on("success", (message, info = "") => {
|
|
502
|
+
context.on("kubb:success", (message, info = "") => {
|
|
491
503
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
492
504
|
const text = getMessage([
|
|
493
505
|
(0, node_util.styleText)("blue", "✓"),
|
|
@@ -497,7 +509,7 @@ const clackLogger = (0, _kubb_core.defineLogger)({
|
|
|
497
509
|
if (state.isSpinning) stopSpinner(text);
|
|
498
510
|
else _clack_prompts.log.success(text);
|
|
499
511
|
});
|
|
500
|
-
context.on("warn", (message, info) => {
|
|
512
|
+
context.on("kubb:warn", (message, info) => {
|
|
501
513
|
if (logLevel < _kubb_core.logLevel.warn) return;
|
|
502
514
|
const text = getMessage([
|
|
503
515
|
(0, node_util.styleText)("yellow", "⚠"),
|
|
@@ -506,7 +518,7 @@ const clackLogger = (0, _kubb_core.defineLogger)({
|
|
|
506
518
|
].filter(Boolean).join(" "));
|
|
507
519
|
_clack_prompts.log.warn(text);
|
|
508
520
|
});
|
|
509
|
-
context.on("error", (error) => {
|
|
521
|
+
context.on("kubb:error", (error) => {
|
|
510
522
|
const caused = require_errors.toCause(error);
|
|
511
523
|
const text = [(0, node_util.styleText)("red", "✗"), error.message].join(" ");
|
|
512
524
|
if (state.isSpinning) stopSpinner(getMessage(text));
|
|
@@ -521,7 +533,7 @@ const clackLogger = (0, _kubb_core.defineLogger)({
|
|
|
521
533
|
}
|
|
522
534
|
}
|
|
523
535
|
});
|
|
524
|
-
context.on("version:new", (version, latestVersion) => {
|
|
536
|
+
context.on("kubb:version:new", (version, latestVersion) => {
|
|
525
537
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
526
538
|
try {
|
|
527
539
|
_clack_prompts.box(`\`v${version}\` → \`v${latestVersion}\`
|
|
@@ -538,7 +550,7 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
|
|
|
538
550
|
console.log("Run `npm install -g @kubb/cli` to update");
|
|
539
551
|
}
|
|
540
552
|
});
|
|
541
|
-
context.on("lifecycle:start", async (version) => {
|
|
553
|
+
context.on("kubb:lifecycle:start", async (version) => {
|
|
542
554
|
console.log(`\n${getIntro({
|
|
543
555
|
title: "The ultimate toolkit for working with APIs",
|
|
544
556
|
description: "Ready to start",
|
|
@@ -547,24 +559,24 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
|
|
|
547
559
|
})}\n`);
|
|
548
560
|
reset();
|
|
549
561
|
});
|
|
550
|
-
context.on("config:start", () => {
|
|
562
|
+
context.on("kubb:config:start", () => {
|
|
551
563
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
552
564
|
const text = getMessage("Configuration started");
|
|
553
565
|
_clack_prompts.intro(text);
|
|
554
566
|
startSpinner(getMessage("Configuration loading"));
|
|
555
567
|
});
|
|
556
|
-
context.on("config:end", (_configs) => {
|
|
568
|
+
context.on("kubb:config:end", (_configs) => {
|
|
557
569
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
558
570
|
const text = getMessage("Configuration completed");
|
|
559
571
|
_clack_prompts.outro(text);
|
|
560
572
|
});
|
|
561
|
-
context.on("generation:start", (config) => {
|
|
573
|
+
context.on("kubb:generation:start", (config) => {
|
|
562
574
|
reset();
|
|
563
575
|
state.totalPlugins = config.plugins?.length ?? 0;
|
|
564
576
|
const text = getMessage(["Generation started", config.name ? `for ${(0, node_util.styleText)("dim", config.name)}` : void 0].filter(Boolean).join(" "));
|
|
565
577
|
_clack_prompts.intro(text);
|
|
566
578
|
});
|
|
567
|
-
context.on("plugin:start", (plugin) => {
|
|
579
|
+
context.on("kubb:plugin:start", (plugin) => {
|
|
568
580
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
569
581
|
stopSpinner();
|
|
570
582
|
const progressBar = _clack_prompts.progress({
|
|
@@ -582,7 +594,7 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
|
|
|
582
594
|
interval
|
|
583
595
|
});
|
|
584
596
|
});
|
|
585
|
-
context.on("plugin:end", (plugin, { duration, success }) => {
|
|
597
|
+
context.on("kubb:plugin:end", (plugin, { duration, success }) => {
|
|
586
598
|
stopSpinner();
|
|
587
599
|
const active = state.activeProgress.get(plugin.name);
|
|
588
600
|
if (!active || logLevel === _kubb_core.logLevel.silent) return;
|
|
@@ -595,7 +607,7 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
|
|
|
595
607
|
state.activeProgress.delete(plugin.name);
|
|
596
608
|
showProgressStep();
|
|
597
609
|
});
|
|
598
|
-
context.on("files:processing:start", (files) => {
|
|
610
|
+
context.on("kubb:files:processing:start", (files) => {
|
|
599
611
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
600
612
|
stopSpinner();
|
|
601
613
|
state.totalFiles = files.length;
|
|
@@ -606,11 +618,11 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
|
|
|
606
618
|
max: files.length,
|
|
607
619
|
size: 30
|
|
608
620
|
});
|
|
609
|
-
context.emit("info", text);
|
|
621
|
+
context.emit("kubb:info", text);
|
|
610
622
|
progressBar.start(getMessage(text));
|
|
611
623
|
state.activeProgress.set("files", { progressBar });
|
|
612
624
|
});
|
|
613
|
-
context.on("file:processing:update", ({ file, config }) => {
|
|
625
|
+
context.on("kubb:file:processing:update", ({ file, config }) => {
|
|
614
626
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
615
627
|
stopSpinner();
|
|
616
628
|
state.processedFiles++;
|
|
@@ -619,7 +631,7 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
|
|
|
619
631
|
if (!active) return;
|
|
620
632
|
active.progressBar.advance(void 0, text);
|
|
621
633
|
});
|
|
622
|
-
context.on("files:processing:end", () => {
|
|
634
|
+
context.on("kubb:files:processing:end", () => {
|
|
623
635
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
624
636
|
stopSpinner();
|
|
625
637
|
const text = getMessage("Files written successfully");
|
|
@@ -629,31 +641,31 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
|
|
|
629
641
|
state.activeProgress.delete("files");
|
|
630
642
|
showProgressStep();
|
|
631
643
|
});
|
|
632
|
-
context.on("generation:end", (config) => {
|
|
644
|
+
context.on("kubb:generation:end", (config) => {
|
|
633
645
|
const text = getMessage(config.name ? `Generation completed for ${(0, node_util.styleText)("dim", config.name)}` : "Generation completed");
|
|
634
646
|
_clack_prompts.outro(text);
|
|
635
647
|
});
|
|
636
|
-
context.on("format:start", () => {
|
|
648
|
+
context.on("kubb:format:start", () => {
|
|
637
649
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
638
650
|
const text = getMessage("Format started");
|
|
639
651
|
_clack_prompts.intro(text);
|
|
640
652
|
});
|
|
641
|
-
context.on("format:end", () => {
|
|
653
|
+
context.on("kubb:format:end", () => {
|
|
642
654
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
643
655
|
const text = getMessage("Format completed");
|
|
644
656
|
_clack_prompts.outro(text);
|
|
645
657
|
});
|
|
646
|
-
context.on("lint:start", () => {
|
|
658
|
+
context.on("kubb:lint:start", () => {
|
|
647
659
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
648
660
|
const text = getMessage("Lint started");
|
|
649
661
|
_clack_prompts.intro(text);
|
|
650
662
|
});
|
|
651
|
-
context.on("lint:end", () => {
|
|
663
|
+
context.on("kubb:lint:end", () => {
|
|
652
664
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
653
665
|
const text = getMessage("Lint completed");
|
|
654
666
|
_clack_prompts.outro(text);
|
|
655
667
|
});
|
|
656
|
-
context.on("hook:start", async ({ id, command, args }) => {
|
|
668
|
+
context.on("kubb:hook:start", async ({ id, command, args }) => {
|
|
657
669
|
const commandWithArgs = formatCommandWithArgs(command, args);
|
|
658
670
|
const text = getMessage(`Hook ${(0, node_util.styleText)("dim", commandWithArgs)} started`);
|
|
659
671
|
if (!id) return;
|
|
@@ -688,12 +700,12 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
|
|
|
688
700
|
}
|
|
689
701
|
});
|
|
690
702
|
});
|
|
691
|
-
context.on("hook:end", ({ command, args }) => {
|
|
703
|
+
context.on("kubb:hook:end", ({ command, args }) => {
|
|
692
704
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
693
705
|
const text = getMessage(`Hook ${(0, node_util.styleText)("dim", formatCommandWithArgs(command, args))} successfully executed`);
|
|
694
706
|
_clack_prompts.outro(text);
|
|
695
707
|
});
|
|
696
|
-
context.on("generation:summary", (config, { pluginTimings, failedPlugins, filesCreated, status, hrStart }) => {
|
|
708
|
+
context.on("kubb:generation:summary", (config, { pluginTimings, failedPlugins, filesCreated, status, hrStart }) => {
|
|
697
709
|
const summary = getSummary({
|
|
698
710
|
failedPlugins,
|
|
699
711
|
filesCreated,
|
|
@@ -719,7 +731,7 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
|
|
|
719
731
|
console.log(summary.join("\n"));
|
|
720
732
|
}
|
|
721
733
|
});
|
|
722
|
-
context.on("lifecycle:end", () => {
|
|
734
|
+
context.on("kubb:lifecycle:end", () => {
|
|
723
735
|
reset();
|
|
724
736
|
});
|
|
725
737
|
}
|
|
@@ -763,60 +775,60 @@ const fileSystemLogger = (0, _kubb_core.defineLogger)({
|
|
|
763
775
|
for (const [fileName, logs] of Object.entries(files)) await write(fileName, logs.join("\n\n"));
|
|
764
776
|
return Object.keys(files);
|
|
765
777
|
}
|
|
766
|
-
context.on("info", (message, info) => {
|
|
778
|
+
context.on("kubb:info", (message, info) => {
|
|
767
779
|
state.cachedLogs.add({
|
|
768
780
|
date: /* @__PURE__ */ new Date(),
|
|
769
781
|
logs: [`ℹ ${message} ${info}`]
|
|
770
782
|
});
|
|
771
783
|
});
|
|
772
|
-
context.on("success", (message, info) => {
|
|
784
|
+
context.on("kubb:success", (message, info) => {
|
|
773
785
|
state.cachedLogs.add({
|
|
774
786
|
date: /* @__PURE__ */ new Date(),
|
|
775
787
|
logs: [`✓ ${message} ${info}`]
|
|
776
788
|
});
|
|
777
789
|
});
|
|
778
|
-
context.on("warn", (message, info) => {
|
|
790
|
+
context.on("kubb:warn", (message, info) => {
|
|
779
791
|
state.cachedLogs.add({
|
|
780
792
|
date: /* @__PURE__ */ new Date(),
|
|
781
793
|
logs: [`⚠ ${message} ${info}`]
|
|
782
794
|
});
|
|
783
795
|
});
|
|
784
|
-
context.on("error", (error) => {
|
|
796
|
+
context.on("kubb:error", (error) => {
|
|
785
797
|
state.cachedLogs.add({
|
|
786
798
|
date: /* @__PURE__ */ new Date(),
|
|
787
799
|
logs: [`✗ ${error.message}`, error.stack || "unknown stack"]
|
|
788
800
|
});
|
|
789
801
|
});
|
|
790
|
-
context.on("debug", (message) => {
|
|
802
|
+
context.on("kubb:debug", (message) => {
|
|
791
803
|
state.cachedLogs.add({
|
|
792
804
|
date: /* @__PURE__ */ new Date(),
|
|
793
805
|
logs: message.logs
|
|
794
806
|
});
|
|
795
807
|
});
|
|
796
|
-
context.on("plugin:start", (plugin) => {
|
|
808
|
+
context.on("kubb:plugin:start", (plugin) => {
|
|
797
809
|
state.cachedLogs.add({
|
|
798
810
|
date: /* @__PURE__ */ new Date(),
|
|
799
811
|
logs: [`Generating ${plugin.name}`]
|
|
800
812
|
});
|
|
801
813
|
});
|
|
802
|
-
context.on("plugin:end", (plugin, { duration, success }) => {
|
|
814
|
+
context.on("kubb:plugin:end", (plugin, { duration, success }) => {
|
|
803
815
|
const durationStr = formatMs(duration);
|
|
804
816
|
state.cachedLogs.add({
|
|
805
817
|
date: /* @__PURE__ */ new Date(),
|
|
806
818
|
logs: [success ? `${plugin.name} completed in ${durationStr}` : `${plugin.name} failed in ${durationStr}`]
|
|
807
819
|
});
|
|
808
820
|
});
|
|
809
|
-
context.on("files:processing:start", (files) => {
|
|
821
|
+
context.on("kubb:files:processing:start", (files) => {
|
|
810
822
|
state.cachedLogs.add({
|
|
811
823
|
date: /* @__PURE__ */ new Date(),
|
|
812
824
|
logs: [`Start ${files.length} writing:`, ...files.map((file) => file.path)]
|
|
813
825
|
});
|
|
814
826
|
});
|
|
815
|
-
context.on("generation:end", async (config) => {
|
|
827
|
+
context.on("kubb:generation:end", async (config) => {
|
|
816
828
|
const writtenFilePaths = await writeLogs(config.name);
|
|
817
829
|
if (writtenFilePaths.length > 0) {
|
|
818
830
|
const files = writtenFilePaths.map((f) => (0, node_path.relative)(node_process.default.cwd(), f));
|
|
819
|
-
await context.emit("info", "Debug files written to:", files.join(", "));
|
|
831
|
+
await context.emit("kubb:info", "Debug files written to:", files.join(", "));
|
|
820
832
|
}
|
|
821
833
|
reset();
|
|
822
834
|
});
|
|
@@ -870,7 +882,7 @@ const githubActionsLogger = (0, _kubb_core.defineLogger)({
|
|
|
870
882
|
function closeGroup(_name) {
|
|
871
883
|
console.log("::endgroup::");
|
|
872
884
|
}
|
|
873
|
-
context.on("info", (message, info = "") => {
|
|
885
|
+
context.on("kubb:info", (message, info = "") => {
|
|
874
886
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
875
887
|
const text = getMessage([
|
|
876
888
|
(0, node_util.styleText)("blue", "ℹ"),
|
|
@@ -879,7 +891,7 @@ const githubActionsLogger = (0, _kubb_core.defineLogger)({
|
|
|
879
891
|
].join(" "));
|
|
880
892
|
console.log(text);
|
|
881
893
|
});
|
|
882
|
-
context.on("success", (message, info = "") => {
|
|
894
|
+
context.on("kubb:success", (message, info = "") => {
|
|
883
895
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
884
896
|
const text = getMessage([
|
|
885
897
|
(0, node_util.styleText)("blue", "✓"),
|
|
@@ -888,7 +900,7 @@ const githubActionsLogger = (0, _kubb_core.defineLogger)({
|
|
|
888
900
|
].filter(Boolean).join(" "));
|
|
889
901
|
console.log(text);
|
|
890
902
|
});
|
|
891
|
-
context.on("warn", (message, info = "") => {
|
|
903
|
+
context.on("kubb:warn", (message, info = "") => {
|
|
892
904
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
893
905
|
const text = getMessage([
|
|
894
906
|
(0, node_util.styleText)("yellow", "⚠"),
|
|
@@ -897,7 +909,7 @@ const githubActionsLogger = (0, _kubb_core.defineLogger)({
|
|
|
897
909
|
].filter(Boolean).join(" "));
|
|
898
910
|
console.warn(`::warning::${text}`);
|
|
899
911
|
});
|
|
900
|
-
context.on("error", (error) => {
|
|
912
|
+
context.on("kubb:error", (error) => {
|
|
901
913
|
const caused = require_errors.toCause(error);
|
|
902
914
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
903
915
|
const message = error.message || String(error);
|
|
@@ -912,37 +924,37 @@ const githubActionsLogger = (0, _kubb_core.defineLogger)({
|
|
|
912
924
|
}
|
|
913
925
|
}
|
|
914
926
|
});
|
|
915
|
-
context.on("lifecycle:start", (version) => {
|
|
927
|
+
context.on("kubb:lifecycle:start", (version) => {
|
|
916
928
|
console.log((0, node_util.styleText)("yellow", `Kubb ${version} 🧩`));
|
|
917
929
|
reset();
|
|
918
930
|
});
|
|
919
|
-
context.on("config:start", () => {
|
|
931
|
+
context.on("kubb:config:start", () => {
|
|
920
932
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
921
933
|
const text = getMessage("Configuration started");
|
|
922
934
|
openGroup("Configuration");
|
|
923
935
|
console.log(text);
|
|
924
936
|
});
|
|
925
|
-
context.on("config:end", (configs) => {
|
|
937
|
+
context.on("kubb:config:end", (configs) => {
|
|
926
938
|
state.currentConfigs = configs;
|
|
927
939
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
928
940
|
const text = getMessage("Configuration completed");
|
|
929
941
|
console.log(text);
|
|
930
942
|
closeGroup("Configuration");
|
|
931
943
|
});
|
|
932
|
-
context.on("generation:start", (config) => {
|
|
944
|
+
context.on("kubb:generation:start", (config) => {
|
|
933
945
|
reset();
|
|
934
946
|
state.totalPlugins = config.plugins?.length ?? 0;
|
|
935
947
|
const text = config.name ? `Generation for ${(0, node_util.styleText)("bold", config.name)}` : "Generation";
|
|
936
948
|
if (state.currentConfigs.length > 1) openGroup(text);
|
|
937
949
|
if (state.currentConfigs.length === 1) console.log(getMessage(text));
|
|
938
950
|
});
|
|
939
|
-
context.on("plugin:start", (plugin) => {
|
|
951
|
+
context.on("kubb:plugin:start", (plugin) => {
|
|
940
952
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
941
953
|
const text = getMessage(`Generating ${(0, node_util.styleText)("bold", plugin.name)}`);
|
|
942
954
|
if (state.currentConfigs.length === 1) openGroup(`Plugin: ${plugin.name}`);
|
|
943
955
|
console.log(text);
|
|
944
956
|
});
|
|
945
|
-
context.on("plugin:end", (plugin, { duration, success }) => {
|
|
957
|
+
context.on("kubb:plugin:end", (plugin, { duration, success }) => {
|
|
946
958
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
947
959
|
if (success) state.completedPlugins++;
|
|
948
960
|
else state.failedPlugins++;
|
|
@@ -953,7 +965,7 @@ const githubActionsLogger = (0, _kubb_core.defineLogger)({
|
|
|
953
965
|
if (state.currentConfigs.length === 1) closeGroup(`Plugin: ${plugin.name}`);
|
|
954
966
|
showProgressStep();
|
|
955
967
|
});
|
|
956
|
-
context.on("files:processing:start", (files) => {
|
|
968
|
+
context.on("kubb:files:processing:start", (files) => {
|
|
957
969
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
958
970
|
state.totalFiles = files.length;
|
|
959
971
|
state.processedFiles = 0;
|
|
@@ -961,46 +973,46 @@ const githubActionsLogger = (0, _kubb_core.defineLogger)({
|
|
|
961
973
|
const text = getMessage(`Writing ${files.length} files`);
|
|
962
974
|
console.log(text);
|
|
963
975
|
});
|
|
964
|
-
context.on("files:processing:end", () => {
|
|
976
|
+
context.on("kubb:files:processing:end", () => {
|
|
965
977
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
966
978
|
const text = getMessage("Files written successfully");
|
|
967
979
|
console.log(text);
|
|
968
980
|
if (state.currentConfigs.length === 1) closeGroup("File Generation");
|
|
969
981
|
showProgressStep();
|
|
970
982
|
});
|
|
971
|
-
context.on("file:processing:update", () => {
|
|
983
|
+
context.on("kubb:file:processing:update", () => {
|
|
972
984
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
973
985
|
state.processedFiles++;
|
|
974
986
|
});
|
|
975
|
-
context.on("generation:end", (config) => {
|
|
987
|
+
context.on("kubb:generation:end", (config) => {
|
|
976
988
|
const text = getMessage(config.name ? `${(0, node_util.styleText)("blue", "✓")} Generation completed for ${(0, node_util.styleText)("dim", config.name)}` : `${(0, node_util.styleText)("blue", "✓")} Generation completed`);
|
|
977
989
|
console.log(text);
|
|
978
990
|
});
|
|
979
|
-
context.on("format:start", () => {
|
|
991
|
+
context.on("kubb:format:start", () => {
|
|
980
992
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
981
993
|
const text = getMessage("Format started");
|
|
982
994
|
if (state.currentConfigs.length === 1) openGroup("Formatting");
|
|
983
995
|
console.log(text);
|
|
984
996
|
});
|
|
985
|
-
context.on("format:end", () => {
|
|
997
|
+
context.on("kubb:format:end", () => {
|
|
986
998
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
987
999
|
const text = getMessage("Format completed");
|
|
988
1000
|
console.log(text);
|
|
989
1001
|
if (state.currentConfigs.length === 1) closeGroup("Formatting");
|
|
990
1002
|
});
|
|
991
|
-
context.on("lint:start", () => {
|
|
1003
|
+
context.on("kubb:lint:start", () => {
|
|
992
1004
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
993
1005
|
const text = getMessage("Lint started");
|
|
994
1006
|
if (state.currentConfigs.length === 1) openGroup("Linting");
|
|
995
1007
|
console.log(text);
|
|
996
1008
|
});
|
|
997
|
-
context.on("lint:end", () => {
|
|
1009
|
+
context.on("kubb:lint:end", () => {
|
|
998
1010
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
999
1011
|
const text = getMessage("Lint completed");
|
|
1000
1012
|
console.log(text);
|
|
1001
1013
|
if (state.currentConfigs.length === 1) closeGroup("Linting");
|
|
1002
1014
|
});
|
|
1003
|
-
context.on("hook:start", async ({ id, command, args }) => {
|
|
1015
|
+
context.on("kubb:hook:start", async ({ id, command, args }) => {
|
|
1004
1016
|
const commandWithArgs = formatCommandWithArgs(command, args);
|
|
1005
1017
|
const text = getMessage(`Hook ${(0, node_util.styleText)("dim", commandWithArgs)} started`);
|
|
1006
1018
|
if (logLevel > _kubb_core.logLevel.silent) {
|
|
@@ -1020,14 +1032,14 @@ const githubActionsLogger = (0, _kubb_core.defineLogger)({
|
|
|
1020
1032
|
}
|
|
1021
1033
|
});
|
|
1022
1034
|
});
|
|
1023
|
-
context.on("hook:end", ({ command, args }) => {
|
|
1035
|
+
context.on("kubb:hook:end", ({ command, args }) => {
|
|
1024
1036
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
1025
1037
|
const commandWithArgs = formatCommandWithArgs(command, args);
|
|
1026
1038
|
const text = getMessage(`Hook ${(0, node_util.styleText)("dim", commandWithArgs)} completed`);
|
|
1027
1039
|
console.log(text);
|
|
1028
1040
|
if (state.currentConfigs.length === 1) closeGroup(`Hook ${commandWithArgs}`);
|
|
1029
1041
|
});
|
|
1030
|
-
context.on("generation:summary", (config, { status, hrStart, failedPlugins }) => {
|
|
1042
|
+
context.on("kubb:generation:summary", (config, { status, hrStart, failedPlugins }) => {
|
|
1031
1043
|
const pluginsCount = config.plugins?.length ?? 0;
|
|
1032
1044
|
const successCount = pluginsCount - failedPlugins.size;
|
|
1033
1045
|
const duration = formatHrtime(hrStart);
|
|
@@ -1035,7 +1047,7 @@ const githubActionsLogger = (0, _kubb_core.defineLogger)({
|
|
|
1035
1047
|
console.log(status === "success" ? `Kubb Summary: ${(0, node_util.styleText)("blue", "✓")} ${`${successCount} successful`}, ${pluginsCount} total, ${(0, node_util.styleText)("green", duration)}` : `Kubb Summary: ${(0, node_util.styleText)("blue", "✓")} ${`${successCount} successful`}, ✗ ${`${failedPlugins.size} failed`}, ${pluginsCount} total, ${(0, node_util.styleText)("green", duration)}`);
|
|
1036
1048
|
if (state.currentConfigs.length > 1) closeGroup(config.name ? `Generation for ${(0, node_util.styleText)("bold", config.name)}` : "Generation");
|
|
1037
1049
|
});
|
|
1038
|
-
context.on("lifecycle:end", () => {
|
|
1050
|
+
context.on("kubb:lifecycle:end", () => {
|
|
1039
1051
|
reset();
|
|
1040
1052
|
});
|
|
1041
1053
|
}
|
|
@@ -1053,7 +1065,7 @@ const plainLogger = (0, _kubb_core.defineLogger)({
|
|
|
1053
1065
|
function getMessage(message) {
|
|
1054
1066
|
return formatMessage(message, logLevel);
|
|
1055
1067
|
}
|
|
1056
|
-
context.on("info", (message, info) => {
|
|
1068
|
+
context.on("kubb:info", (message, info) => {
|
|
1057
1069
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
1058
1070
|
const text = getMessage([
|
|
1059
1071
|
"ℹ",
|
|
@@ -1062,7 +1074,7 @@ const plainLogger = (0, _kubb_core.defineLogger)({
|
|
|
1062
1074
|
].join(" "));
|
|
1063
1075
|
console.log(text);
|
|
1064
1076
|
});
|
|
1065
|
-
context.on("success", (message, info = "") => {
|
|
1077
|
+
context.on("kubb:success", (message, info = "") => {
|
|
1066
1078
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
1067
1079
|
const text = getMessage([
|
|
1068
1080
|
"✓",
|
|
@@ -1071,7 +1083,7 @@ const plainLogger = (0, _kubb_core.defineLogger)({
|
|
|
1071
1083
|
].filter(Boolean).join(" "));
|
|
1072
1084
|
console.log(text);
|
|
1073
1085
|
});
|
|
1074
|
-
context.on("warn", (message, info) => {
|
|
1086
|
+
context.on("kubb:warn", (message, info) => {
|
|
1075
1087
|
if (logLevel < _kubb_core.logLevel.warn) return;
|
|
1076
1088
|
const text = getMessage([
|
|
1077
1089
|
"⚠",
|
|
@@ -1080,7 +1092,7 @@ const plainLogger = (0, _kubb_core.defineLogger)({
|
|
|
1080
1092
|
].filter(Boolean).join(" "));
|
|
1081
1093
|
console.log(text);
|
|
1082
1094
|
});
|
|
1083
|
-
context.on("error", (error) => {
|
|
1095
|
+
context.on("kubb:error", (error) => {
|
|
1084
1096
|
const caused = require_errors.toCause(error);
|
|
1085
1097
|
const text = getMessage(["✗", error.message].join(" "));
|
|
1086
1098
|
console.log(text);
|
|
@@ -1094,74 +1106,74 @@ const plainLogger = (0, _kubb_core.defineLogger)({
|
|
|
1094
1106
|
}
|
|
1095
1107
|
}
|
|
1096
1108
|
});
|
|
1097
|
-
context.on("lifecycle:start", () => {
|
|
1109
|
+
context.on("kubb:lifecycle:start", () => {
|
|
1098
1110
|
console.log("Kubb CLI 🧩");
|
|
1099
1111
|
});
|
|
1100
|
-
context.on("config:start", () => {
|
|
1112
|
+
context.on("kubb:config:start", () => {
|
|
1101
1113
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
1102
1114
|
const text = getMessage("Configuration started");
|
|
1103
1115
|
console.log(text);
|
|
1104
1116
|
});
|
|
1105
|
-
context.on("config:end", () => {
|
|
1117
|
+
context.on("kubb:config:end", () => {
|
|
1106
1118
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
1107
1119
|
const text = getMessage("Configuration completed");
|
|
1108
1120
|
console.log(text);
|
|
1109
1121
|
});
|
|
1110
|
-
context.on("generation:start", () => {
|
|
1122
|
+
context.on("kubb:generation:start", () => {
|
|
1111
1123
|
const text = getMessage("Generation started");
|
|
1112
1124
|
console.log(text);
|
|
1113
1125
|
});
|
|
1114
|
-
context.on("plugin:start", (plugin) => {
|
|
1126
|
+
context.on("kubb:plugin:start", (plugin) => {
|
|
1115
1127
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
1116
1128
|
const text = getMessage(`Generating ${plugin.name}`);
|
|
1117
1129
|
console.log(text);
|
|
1118
1130
|
});
|
|
1119
|
-
context.on("plugin:end", (plugin, { duration, success }) => {
|
|
1131
|
+
context.on("kubb:plugin:end", (plugin, { duration, success }) => {
|
|
1120
1132
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
1121
1133
|
const durationStr = formatMs(duration);
|
|
1122
1134
|
const text = getMessage(success ? `${plugin.name} completed in ${durationStr}` : `${plugin.name} failed in ${durationStr}`);
|
|
1123
1135
|
console.log(text);
|
|
1124
1136
|
});
|
|
1125
|
-
context.on("files:processing:start", (files) => {
|
|
1137
|
+
context.on("kubb:files:processing:start", (files) => {
|
|
1126
1138
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
1127
1139
|
const text = getMessage(`Writing ${files.length} files`);
|
|
1128
1140
|
console.log(text);
|
|
1129
1141
|
});
|
|
1130
|
-
context.on("file:processing:update", ({ file, config }) => {
|
|
1142
|
+
context.on("kubb:file:processing:update", ({ file, config }) => {
|
|
1131
1143
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
1132
1144
|
const text = getMessage(`Writing ${(0, node_path.relative)(config.root, file.path)}`);
|
|
1133
1145
|
console.log(text);
|
|
1134
1146
|
});
|
|
1135
|
-
context.on("files:processing:end", () => {
|
|
1147
|
+
context.on("kubb:files:processing:end", () => {
|
|
1136
1148
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
1137
1149
|
const text = getMessage("Files written successfully");
|
|
1138
1150
|
console.log(text);
|
|
1139
1151
|
});
|
|
1140
|
-
context.on("generation:end", (config) => {
|
|
1152
|
+
context.on("kubb:generation:end", (config) => {
|
|
1141
1153
|
const text = getMessage(config.name ? `Generation completed for ${config.name}` : "Generation completed");
|
|
1142
1154
|
console.log(text);
|
|
1143
1155
|
});
|
|
1144
|
-
context.on("format:start", () => {
|
|
1156
|
+
context.on("kubb:format:start", () => {
|
|
1145
1157
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
1146
1158
|
const text = getMessage("Format started");
|
|
1147
1159
|
console.log(text);
|
|
1148
1160
|
});
|
|
1149
|
-
context.on("format:end", () => {
|
|
1161
|
+
context.on("kubb:format:end", () => {
|
|
1150
1162
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
1151
1163
|
const text = getMessage("Format completed");
|
|
1152
1164
|
console.log(text);
|
|
1153
1165
|
});
|
|
1154
|
-
context.on("lint:start", () => {
|
|
1166
|
+
context.on("kubb:lint:start", () => {
|
|
1155
1167
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
1156
1168
|
const text = getMessage("Lint started");
|
|
1157
1169
|
console.log(text);
|
|
1158
1170
|
});
|
|
1159
|
-
context.on("lint:end", () => {
|
|
1171
|
+
context.on("kubb:lint:end", () => {
|
|
1160
1172
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
1161
1173
|
const text = getMessage("Lint completed");
|
|
1162
1174
|
console.log(text);
|
|
1163
1175
|
});
|
|
1164
|
-
context.on("hook:start", async ({ id, command, args }) => {
|
|
1176
|
+
context.on("kubb:hook:start", async ({ id, command, args }) => {
|
|
1165
1177
|
const commandWithArgs = formatCommandWithArgs(command, args);
|
|
1166
1178
|
const text = getMessage(`Hook ${commandWithArgs} started`);
|
|
1167
1179
|
if (logLevel > _kubb_core.logLevel.silent) console.log(text);
|
|
@@ -1178,12 +1190,12 @@ const plainLogger = (0, _kubb_core.defineLogger)({
|
|
|
1178
1190
|
}
|
|
1179
1191
|
});
|
|
1180
1192
|
});
|
|
1181
|
-
context.on("hook:end", ({ command, args }) => {
|
|
1193
|
+
context.on("kubb:hook:end", ({ command, args }) => {
|
|
1182
1194
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
1183
1195
|
const text = getMessage(`Hook ${formatCommandWithArgs(command, args)} completed`);
|
|
1184
1196
|
console.log(text);
|
|
1185
1197
|
});
|
|
1186
|
-
context.on("generation:summary", (config, { pluginTimings, status, hrStart, failedPlugins, filesCreated }) => {
|
|
1198
|
+
context.on("kubb:generation:summary", (config, { pluginTimings, status, hrStart, failedPlugins, filesCreated }) => {
|
|
1187
1199
|
const summary = getSummary({
|
|
1188
1200
|
failedPlugins,
|
|
1189
1201
|
filesCreated,
|
|
@@ -1256,8 +1268,8 @@ async function setupLogger(context, { logLevel }) {
|
|
|
1256
1268
|
}
|
|
1257
1269
|
//#endregion
|
|
1258
1270
|
//#region src/utils/executeHooks.ts
|
|
1259
|
-
async function executeHooks({
|
|
1260
|
-
const commands = Array.isArray(
|
|
1271
|
+
async function executeHooks({ configHooks, hooks }) {
|
|
1272
|
+
const commands = Array.isArray(configHooks.done) ? configHooks.done : [configHooks.done].filter(Boolean);
|
|
1261
1273
|
for (const command of commands) {
|
|
1262
1274
|
const [cmd, ...args] = require_shell.tokenize(command);
|
|
1263
1275
|
if (!cmd) continue;
|
|
@@ -1265,16 +1277,16 @@ async function executeHooks({ hooks, events }) {
|
|
|
1265
1277
|
const hookEndPromise = new Promise((resolve, reject) => {
|
|
1266
1278
|
const handler = ({ id, success, error }) => {
|
|
1267
1279
|
if (id !== hookId) return;
|
|
1268
|
-
|
|
1280
|
+
hooks.off("kubb:hook:end", handler);
|
|
1269
1281
|
if (!success) {
|
|
1270
1282
|
reject(error ?? /* @__PURE__ */ new Error(`Hook failed: ${command}`));
|
|
1271
1283
|
return;
|
|
1272
1284
|
}
|
|
1273
|
-
|
|
1285
|
+
hooks.emit("kubb:success", `${(0, node_util.styleText)("dim", command)} successfully executed`).then(resolve).catch(reject);
|
|
1274
1286
|
};
|
|
1275
|
-
|
|
1287
|
+
hooks.on("kubb:hook:end", handler);
|
|
1276
1288
|
});
|
|
1277
|
-
await
|
|
1289
|
+
await hooks.emit("kubb:hook:start", {
|
|
1278
1290
|
id: hookId,
|
|
1279
1291
|
command: cmd,
|
|
1280
1292
|
args
|
|
@@ -1283,6 +1295,15 @@ async function executeHooks({ hooks, events }) {
|
|
|
1283
1295
|
}
|
|
1284
1296
|
}
|
|
1285
1297
|
//#endregion
|
|
1298
|
+
//#region src/utils/getConfig.ts
|
|
1299
|
+
async function getConfigs(config, args) {
|
|
1300
|
+
const resolved = await (typeof config === "function" ? config(args) : config);
|
|
1301
|
+
return (Array.isArray(resolved) ? resolved : [resolved]).map((item) => ({
|
|
1302
|
+
...item,
|
|
1303
|
+
plugins: item.plugins ?? []
|
|
1304
|
+
}));
|
|
1305
|
+
}
|
|
1306
|
+
//#endregion
|
|
1286
1307
|
//#region src/utils/getCosmiConfig.ts
|
|
1287
1308
|
const jiti$1 = (0, jiti.createJiti)(require("url").pathToFileURL(__filename).href, {
|
|
1288
1309
|
jsx: {
|
|
@@ -1359,15 +1380,15 @@ async function startWatcher(path, cb) {
|
|
|
1359
1380
|
}
|
|
1360
1381
|
//#endregion
|
|
1361
1382
|
//#region src/runners/generate.ts
|
|
1362
|
-
async function runToolPass({ toolValue, detect, toolMap, toolLabel, successPrefix, noToolMessage, configName, outputPath, logLevel,
|
|
1383
|
+
async function runToolPass({ toolValue, detect, toolMap, toolLabel, successPrefix, noToolMessage, configName, outputPath, logLevel, hooks, onStart, onEnd }) {
|
|
1363
1384
|
await onStart();
|
|
1364
1385
|
let resolvedTool = toolValue;
|
|
1365
1386
|
if (resolvedTool === "auto") {
|
|
1366
1387
|
const detected = await detect();
|
|
1367
|
-
if (!detected) await
|
|
1388
|
+
if (!detected) await hooks.emit("kubb:warn", noToolMessage);
|
|
1368
1389
|
else {
|
|
1369
1390
|
resolvedTool = detected;
|
|
1370
|
-
await
|
|
1391
|
+
await hooks.emit("kubb:info", `Auto-detected ${toolLabel}: ${(0, node_util.styleText)("dim", resolvedTool)}`);
|
|
1371
1392
|
}
|
|
1372
1393
|
}
|
|
1373
1394
|
let toolError;
|
|
@@ -1378,20 +1399,20 @@ async function runToolPass({ toolValue, detect, toolMap, toolLabel, successPrefi
|
|
|
1378
1399
|
const hookEndPromise = new Promise((resolve, reject) => {
|
|
1379
1400
|
const handler = ({ id, success, error }) => {
|
|
1380
1401
|
if (id !== hookId) return;
|
|
1381
|
-
|
|
1402
|
+
hooks.off("kubb:hook:end", handler);
|
|
1382
1403
|
if (!success) {
|
|
1383
1404
|
reject(error ?? /* @__PURE__ */ new Error(`${toolConfig.errorMessage}`));
|
|
1384
1405
|
return;
|
|
1385
1406
|
}
|
|
1386
|
-
|
|
1407
|
+
hooks.emit("kubb:success", [
|
|
1387
1408
|
`${successPrefix} with ${(0, node_util.styleText)("dim", resolvedTool)}`,
|
|
1388
1409
|
logLevel >= _kubb_core.logLevel.info ? `on ${(0, node_util.styleText)("dim", outputPath)}` : void 0,
|
|
1389
1410
|
"successfully"
|
|
1390
1411
|
].filter(Boolean).join(" ")).then(resolve).catch(reject);
|
|
1391
1412
|
};
|
|
1392
|
-
|
|
1413
|
+
hooks.on("kubb:hook:end", handler);
|
|
1393
1414
|
});
|
|
1394
|
-
await
|
|
1415
|
+
await hooks.emit("kubb:hook:start", {
|
|
1395
1416
|
id: hookId,
|
|
1396
1417
|
command: toolConfig.command,
|
|
1397
1418
|
args: toolConfig.args(outputPath)
|
|
@@ -1400,7 +1421,7 @@ async function runToolPass({ toolValue, detect, toolMap, toolLabel, successPrefi
|
|
|
1400
1421
|
} catch (caughtError) {
|
|
1401
1422
|
const err = new Error(toolConfig.errorMessage);
|
|
1402
1423
|
err.cause = caughtError;
|
|
1403
|
-
await
|
|
1424
|
+
await hooks.emit("kubb:error", err);
|
|
1404
1425
|
toolError = err;
|
|
1405
1426
|
}
|
|
1406
1427
|
}
|
|
@@ -1408,34 +1429,32 @@ async function runToolPass({ toolValue, detect, toolMap, toolLabel, successPrefi
|
|
|
1408
1429
|
if (toolError) throw toolError;
|
|
1409
1430
|
}
|
|
1410
1431
|
async function generate(options) {
|
|
1411
|
-
const { input,
|
|
1432
|
+
const { input, hooks, logLevel } = options;
|
|
1412
1433
|
const hrStart = node_process.default.hrtime();
|
|
1413
1434
|
const inputPath = input ?? ("path" in options.config.input ? options.config.input.path : void 0);
|
|
1414
|
-
const
|
|
1415
|
-
config
|
|
1416
|
-
|
|
1417
|
-
input
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
events
|
|
1424
|
-
});
|
|
1425
|
-
const { sources, config, driver } = setupResult;
|
|
1426
|
-
await events.emit("generation:start", config);
|
|
1427
|
-
await events.emit("info", config.name ? `Setup generation ${(0, node_util.styleText)("bold", config.name)}` : "Setup generation", inputPath);
|
|
1428
|
-
await events.emit("info", config.name ? `Build generation ${(0, node_util.styleText)("bold", config.name)}` : "Build generation", inputPath);
|
|
1429
|
-
const { files, failedPlugins, pluginTimings, error } = await (0, _kubb_core.safeBuild)({
|
|
1435
|
+
const config = {
|
|
1436
|
+
...options.config,
|
|
1437
|
+
input: inputPath ? {
|
|
1438
|
+
...options.config.input,
|
|
1439
|
+
path: inputPath
|
|
1440
|
+
} : options.config.input,
|
|
1441
|
+
...options.config.output
|
|
1442
|
+
};
|
|
1443
|
+
const kubb = (0, _kubb_core.createKubb)({
|
|
1430
1444
|
config,
|
|
1431
|
-
|
|
1432
|
-
}
|
|
1433
|
-
await
|
|
1445
|
+
hooks
|
|
1446
|
+
});
|
|
1447
|
+
await kubb.setup();
|
|
1448
|
+
await hooks.emit("kubb:generation:start", config);
|
|
1449
|
+
await hooks.emit("kubb:info", config.name ? `Setup generation ${(0, node_util.styleText)("bold", config.name)}` : "Setup generation", inputPath);
|
|
1450
|
+
await hooks.emit("kubb:info", config.name ? `Build generation ${(0, node_util.styleText)("bold", config.name)}` : "Build generation", inputPath);
|
|
1451
|
+
const { files, failedPlugins, pluginTimings, error, driver } = await kubb.safeBuild();
|
|
1452
|
+
await hooks.emit("kubb:info", "Load summary");
|
|
1434
1453
|
if (failedPlugins.size > 0 || error) {
|
|
1435
1454
|
const allErrors = [error, ...Array.from(failedPlugins).filter((it) => it.error).map((it) => it.error)].filter(Boolean);
|
|
1436
|
-
for (const err of allErrors) await
|
|
1437
|
-
await
|
|
1438
|
-
await
|
|
1455
|
+
for (const err of allErrors) await hooks.emit("kubb:error", err);
|
|
1456
|
+
await hooks.emit("kubb:generation:end", config, files, kubb.sources);
|
|
1457
|
+
await hooks.emit("kubb:generation:summary", config, {
|
|
1439
1458
|
failedPlugins,
|
|
1440
1459
|
filesCreated: files.length,
|
|
1441
1460
|
status: "failed",
|
|
@@ -1455,8 +1474,8 @@ async function generate(options) {
|
|
|
1455
1474
|
}));
|
|
1456
1475
|
node_process.default.exit(1);
|
|
1457
1476
|
}
|
|
1458
|
-
await
|
|
1459
|
-
await
|
|
1477
|
+
await hooks.emit("kubb:success", "Generation successfully", inputPath);
|
|
1478
|
+
await hooks.emit("kubb:generation:end", config, files, kubb.sources);
|
|
1460
1479
|
const outputPath = node_path.default.resolve(config.root, config.output.path);
|
|
1461
1480
|
if (config.output.format) await runToolPass({
|
|
1462
1481
|
toolValue: config.output.format,
|
|
@@ -1468,9 +1487,9 @@ async function generate(options) {
|
|
|
1468
1487
|
configName: config.name,
|
|
1469
1488
|
outputPath,
|
|
1470
1489
|
logLevel,
|
|
1471
|
-
|
|
1472
|
-
onStart: () =>
|
|
1473
|
-
onEnd: () =>
|
|
1490
|
+
hooks,
|
|
1491
|
+
onStart: () => hooks.emit("kubb:format:start"),
|
|
1492
|
+
onEnd: () => hooks.emit("kubb:format:end")
|
|
1474
1493
|
});
|
|
1475
1494
|
if (config.output.lint) await runToolPass({
|
|
1476
1495
|
toolValue: config.output.lint,
|
|
@@ -1482,19 +1501,19 @@ async function generate(options) {
|
|
|
1482
1501
|
configName: config.name,
|
|
1483
1502
|
outputPath,
|
|
1484
1503
|
logLevel,
|
|
1485
|
-
|
|
1486
|
-
onStart: () =>
|
|
1487
|
-
onEnd: () =>
|
|
1504
|
+
hooks,
|
|
1505
|
+
onStart: () => hooks.emit("kubb:lint:start"),
|
|
1506
|
+
onEnd: () => hooks.emit("kubb:lint:end")
|
|
1488
1507
|
});
|
|
1489
1508
|
if (config.hooks) {
|
|
1490
|
-
await
|
|
1509
|
+
await hooks.emit("kubb:hooks:start");
|
|
1491
1510
|
await executeHooks({
|
|
1492
|
-
|
|
1493
|
-
|
|
1511
|
+
configHooks: config.hooks,
|
|
1512
|
+
hooks
|
|
1494
1513
|
});
|
|
1495
|
-
await
|
|
1514
|
+
await hooks.emit("kubb:hooks:end");
|
|
1496
1515
|
}
|
|
1497
|
-
await
|
|
1516
|
+
await hooks.emit("kubb:generation:summary", config, {
|
|
1498
1517
|
failedPlugins,
|
|
1499
1518
|
filesCreated: files.length,
|
|
1500
1519
|
status: "success",
|
|
@@ -1515,29 +1534,29 @@ async function generate(options) {
|
|
|
1515
1534
|
}
|
|
1516
1535
|
async function runGenerateCommand({ input, configPath, logLevel: logLevelKey, watch }) {
|
|
1517
1536
|
const logLevel = _kubb_core.logLevel[logLevelKey] ?? _kubb_core.logLevel.info;
|
|
1518
|
-
const
|
|
1519
|
-
await setupLogger(
|
|
1537
|
+
const hooks = new AsyncEventEmitter();
|
|
1538
|
+
await setupLogger(hooks, { logLevel });
|
|
1520
1539
|
await require_telemetry.executeIfOnline(async () => {
|
|
1521
1540
|
try {
|
|
1522
1541
|
const latestVersion = (await (await fetch(require_constants.KUBB_NPM_PACKAGE_URL)).json()).version;
|
|
1523
|
-
if (latestVersion && require_package.version < latestVersion) await
|
|
1542
|
+
if (latestVersion && require_package.version < latestVersion) await hooks.emit("kubb:version:new", require_package.version, latestVersion);
|
|
1524
1543
|
} catch {}
|
|
1525
1544
|
});
|
|
1526
1545
|
try {
|
|
1527
1546
|
const result = await getCosmiConfig("kubb", configPath);
|
|
1528
|
-
const configs = await
|
|
1529
|
-
await
|
|
1530
|
-
await
|
|
1531
|
-
await
|
|
1532
|
-
await
|
|
1533
|
-
await
|
|
1547
|
+
const configs = await getConfigs(result.config, { input });
|
|
1548
|
+
await hooks.emit("kubb:config:start");
|
|
1549
|
+
await hooks.emit("kubb:info", "Config loaded", node_path.default.relative(node_process.default.cwd(), result.filepath));
|
|
1550
|
+
await hooks.emit("kubb:success", "Config loaded successfully", node_path.default.relative(node_process.default.cwd(), result.filepath));
|
|
1551
|
+
await hooks.emit("kubb:config:end", configs);
|
|
1552
|
+
await hooks.emit("kubb:lifecycle:start", require_package.version);
|
|
1534
1553
|
for (const config of configs) if ((0, _kubb_core.isInputPath)(config) && watch) await startWatcher([input || config.input.path], async (paths) => {
|
|
1535
|
-
|
|
1554
|
+
hooks.removeAll();
|
|
1536
1555
|
await generate({
|
|
1537
1556
|
input,
|
|
1538
1557
|
config,
|
|
1539
1558
|
logLevel,
|
|
1540
|
-
|
|
1559
|
+
hooks
|
|
1541
1560
|
});
|
|
1542
1561
|
_clack_prompts.log.step((0, node_util.styleText)("yellow", `Watching for changes in ${paths.join(" and ")}`));
|
|
1543
1562
|
});
|
|
@@ -1545,15 +1564,15 @@ async function runGenerateCommand({ input, configPath, logLevel: logLevelKey, wa
|
|
|
1545
1564
|
input,
|
|
1546
1565
|
config,
|
|
1547
1566
|
logLevel,
|
|
1548
|
-
|
|
1567
|
+
hooks
|
|
1549
1568
|
});
|
|
1550
|
-
await
|
|
1569
|
+
await hooks.emit("kubb:lifecycle:end");
|
|
1551
1570
|
} catch (error) {
|
|
1552
|
-
await
|
|
1571
|
+
await hooks.emit("kubb:error", require_errors.toError(error));
|
|
1553
1572
|
node_process.default.exit(1);
|
|
1554
1573
|
}
|
|
1555
1574
|
}
|
|
1556
1575
|
//#endregion
|
|
1557
1576
|
exports.runGenerateCommand = runGenerateCommand;
|
|
1558
1577
|
|
|
1559
|
-
//# sourceMappingURL=generate-
|
|
1578
|
+
//# sourceMappingURL=generate-Cf1qSeSJ.cjs.map
|