@kubb/cli 5.0.0-beta.40 → 5.0.0-beta.41
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 +11 -15
- package/dist/{agent-ZKJkTTGN.js → agent-D3K_-kiv.js} +2 -2
- package/dist/{agent-ZKJkTTGN.js.map → agent-D3K_-kiv.js.map} +1 -1
- package/dist/{agent-DQerNyd8.cjs → agent-DTqKBULa.cjs} +2 -2
- package/dist/{agent-DQerNyd8.cjs.map → agent-DTqKBULa.cjs.map} +1 -1
- package/dist/{generate-DQLvFw4z.cjs → generate-CZYIOngX.cjs} +2 -2
- package/dist/{generate-DQLvFw4z.cjs.map → generate-CZYIOngX.cjs.map} +1 -1
- package/dist/{generate-40x9PP4o.js → generate-HcvbU80u.js} +2 -2
- package/dist/{generate-40x9PP4o.js.map → generate-HcvbU80u.js.map} +1 -1
- package/dist/index.cjs +6 -6
- package/dist/index.js +6 -6
- package/dist/{init-CT9RChdK.js → init-BMtuczv8.js} +2 -2
- package/dist/{init-CT9RChdK.js.map → init-BMtuczv8.js.map} +1 -1
- package/dist/{init-sEaUN7Dj.cjs → init-DybfkgNy.cjs} +2 -2
- package/dist/{init-sEaUN7Dj.cjs.map → init-DybfkgNy.cjs.map} +1 -1
- package/dist/{mcp-cjPrOeot.js → mcp-BF9dnH_F.js} +2 -2
- package/dist/{mcp-cjPrOeot.js.map → mcp-BF9dnH_F.js.map} +1 -1
- package/dist/{mcp-Siyb6fTT.cjs → mcp-YzKoU6_l.cjs} +2 -2
- package/dist/{mcp-Siyb6fTT.cjs.map → mcp-YzKoU6_l.cjs.map} +1 -1
- package/dist/package-BCwMApnr.js +6 -0
- package/dist/package-BCwMApnr.js.map +1 -0
- package/dist/{package-BJ6qam2Y.cjs → package-DPe5CA4S.cjs} +2 -2
- package/dist/package-DPe5CA4S.cjs.map +1 -0
- package/dist/{run-CHZKHTv0.js → run-DaV_NiKR.js} +68 -316
- package/dist/run-DaV_NiKR.js.map +1 -0
- package/dist/{run-CcQawFNK.cjs → run-UWQ9wImP.cjs} +48 -296
- package/dist/run-UWQ9wImP.cjs.map +1 -0
- package/dist/{validate-8pgfxUTy.js → validate-BHc3lUKB.js} +2 -2
- package/dist/{validate-8pgfxUTy.js.map → validate-BHc3lUKB.js.map} +1 -1
- package/dist/{validate-CstV7Pc2.cjs → validate-CqRqJxmQ.cjs} +2 -2
- package/dist/{validate-CstV7Pc2.cjs.map → validate-CqRqJxmQ.cjs.map} +1 -1
- package/package.json +6 -6
- package/src/loggers/clackLogger.ts +22 -25
- package/src/loggers/plainLogger.ts +3 -6
- package/src/loggers/types.ts +1 -2
- package/src/loggers/utils.ts +11 -68
- package/src/runners/generate/run.ts +7 -14
- package/src/runners/generate/utils.ts +15 -18
- package/dist/package-BJ6qam2Y.cjs.map +0 -1
- package/dist/package-CR5vEK4K.js +0 -6
- package/dist/package-CR5vEK4K.js.map +0 -1
- package/dist/run-CHZKHTv0.js.map +0 -1
- package/dist/run-CcQawFNK.cjs.map +0 -1
- package/src/loggers/githubActionsLogger.ts +0 -377
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const require_chunk = require("./chunk-Bx3C2hgW.cjs");
|
|
2
2
|
const require_errors = require("./errors-DykI11xo.cjs");
|
|
3
3
|
const require_shell = require("./shell-Lh-vLWwH.cjs");
|
|
4
|
-
const require_package = require("./package-
|
|
4
|
+
const require_package = require("./package-DPe5CA4S.cjs");
|
|
5
5
|
const require_constants = require("./constants-BtmponZ3.cjs");
|
|
6
6
|
let node_util = require("node:util");
|
|
7
7
|
let node_events = require("node:events");
|
|
@@ -306,19 +306,6 @@ function formatMsWithColor(ms) {
|
|
|
306
306
|
//#endregion
|
|
307
307
|
//#region ../../internals/utils/src/env.ts
|
|
308
308
|
/**
|
|
309
|
-
* Returns `true` when running inside a GitHub Actions workflow.
|
|
310
|
-
*
|
|
311
|
-
* @example
|
|
312
|
-
* ```ts
|
|
313
|
-
* if (isGitHubActions()) {
|
|
314
|
-
* core.setOutput('result', 'ok')
|
|
315
|
-
* }
|
|
316
|
-
* ```
|
|
317
|
-
*/
|
|
318
|
-
function isGitHubActions() {
|
|
319
|
-
return !!process.env.GITHUB_ACTIONS;
|
|
320
|
-
}
|
|
321
|
-
/**
|
|
322
309
|
* Returns `true` when the process is running in a CI environment.
|
|
323
310
|
* Covers GitHub Actions, GitLab CI, CircleCI, Travis CI, Jenkins, Bitbucket,
|
|
324
311
|
* TeamCity, Buildkite, and Azure Pipelines.
|
|
@@ -766,8 +753,18 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
|
|
|
766
753
|
hrStart: node_process.default.hrtime()
|
|
767
754
|
});
|
|
768
755
|
});
|
|
769
|
-
context.on("kubb:hook:
|
|
770
|
-
|
|
756
|
+
if (logLevel > _kubb_core.logLevel.silent) context.on("kubb:hook:line", ({ id, line }) => {
|
|
757
|
+
state.activeHookLogs.get(id)?.taskLog.message((0, node_util.styleText)("dim", line));
|
|
758
|
+
});
|
|
759
|
+
context.on("kubb:hook:end", ({ id, command, args, success, error, stdout, stderr }) => {
|
|
760
|
+
if (!id) return;
|
|
761
|
+
if (logLevel <= _kubb_core.logLevel.silent) {
|
|
762
|
+
if (!success) {
|
|
763
|
+
if (stdout) console.log(stdout);
|
|
764
|
+
if (stderr) console.error(stderr);
|
|
765
|
+
}
|
|
766
|
+
return;
|
|
767
|
+
}
|
|
771
768
|
const active = state.activeHookLogs.get(id);
|
|
772
769
|
if (!active) return;
|
|
773
770
|
state.activeHookLogs.delete(id);
|
|
@@ -782,233 +779,6 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
|
|
|
782
779
|
context.on("kubb:lifecycle:end", () => {
|
|
783
780
|
reset();
|
|
784
781
|
});
|
|
785
|
-
return (_commandWithArgs, hookId) => {
|
|
786
|
-
if (logLevel <= _kubb_core.logLevel.silent) return {
|
|
787
|
-
onStdout: (s) => console.log(s),
|
|
788
|
-
onStderr: (s) => console.error(s)
|
|
789
|
-
};
|
|
790
|
-
const active = state.activeHookLogs.get(hookId);
|
|
791
|
-
if (!active) return null;
|
|
792
|
-
const { taskLog } = active;
|
|
793
|
-
return {
|
|
794
|
-
stream: true,
|
|
795
|
-
onLine: (line) => taskLog.message((0, node_util.styleText)("dim", line)),
|
|
796
|
-
onStdout: (s) => taskLog.message(s),
|
|
797
|
-
onStderr: (s) => taskLog.message((0, node_util.styleText)("red", s))
|
|
798
|
-
};
|
|
799
|
-
};
|
|
800
|
-
}
|
|
801
|
-
});
|
|
802
|
-
//#endregion
|
|
803
|
-
//#region src/loggers/githubActionsLogger.ts
|
|
804
|
-
/**
|
|
805
|
-
* GitHub Actions logger using group annotations for collapsible sections in CI.
|
|
806
|
-
*/
|
|
807
|
-
const githubActionsLogger = (0, _kubb_core.defineLogger)({
|
|
808
|
-
name: "github-actions",
|
|
809
|
-
install(context, options) {
|
|
810
|
-
const logLevel = options?.logLevel ?? _kubb_core.logLevel.info;
|
|
811
|
-
const state = {
|
|
812
|
-
...createProgressCounters(),
|
|
813
|
-
currentConfigs: [],
|
|
814
|
-
openGroupDepth: 0
|
|
815
|
-
};
|
|
816
|
-
const hookTimer = createHookTimer();
|
|
817
|
-
function reset() {
|
|
818
|
-
closeAllGroups();
|
|
819
|
-
resetProgressCounters(state);
|
|
820
|
-
state.currentConfigs = [];
|
|
821
|
-
hookTimer.clear();
|
|
822
|
-
}
|
|
823
|
-
function showProgressStep() {
|
|
824
|
-
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
825
|
-
const line = buildProgressLine(state);
|
|
826
|
-
if (line) console.log(getMessage(line));
|
|
827
|
-
}
|
|
828
|
-
function getMessage(message) {
|
|
829
|
-
return formatMessage(message, logLevel);
|
|
830
|
-
}
|
|
831
|
-
function openGroup(name) {
|
|
832
|
-
console.log(`::group::${name}`);
|
|
833
|
-
state.openGroupDepth++;
|
|
834
|
-
}
|
|
835
|
-
function closeGroup(_name) {
|
|
836
|
-
console.log("::endgroup::");
|
|
837
|
-
if (state.openGroupDepth > 0) state.openGroupDepth--;
|
|
838
|
-
}
|
|
839
|
-
function closeAllGroups() {
|
|
840
|
-
while (state.openGroupDepth > 0) {
|
|
841
|
-
console.log("::endgroup::");
|
|
842
|
-
state.openGroupDepth--;
|
|
843
|
-
}
|
|
844
|
-
}
|
|
845
|
-
function onGroupStart(event, message, group) {
|
|
846
|
-
context.on(event, () => {
|
|
847
|
-
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
848
|
-
if (state.currentConfigs.length === 1) openGroup(group);
|
|
849
|
-
console.log(getMessage(message));
|
|
850
|
-
});
|
|
851
|
-
}
|
|
852
|
-
function onGroupEnd(event, message, group) {
|
|
853
|
-
context.on(event, () => {
|
|
854
|
-
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
855
|
-
console.log(getMessage(message));
|
|
856
|
-
if (state.currentConfigs.length === 1) closeGroup(group);
|
|
857
|
-
});
|
|
858
|
-
}
|
|
859
|
-
context.on("kubb:info", ({ message, info = "" }) => {
|
|
860
|
-
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
861
|
-
const text = getMessage([
|
|
862
|
-
(0, node_util.styleText)("blue", "ℹ"),
|
|
863
|
-
message,
|
|
864
|
-
(0, node_util.styleText)("dim", info)
|
|
865
|
-
].join(" "));
|
|
866
|
-
console.log(text);
|
|
867
|
-
});
|
|
868
|
-
context.on("kubb:success", ({ message, info = "" }) => {
|
|
869
|
-
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
870
|
-
const text = getMessage([
|
|
871
|
-
(0, node_util.styleText)("blue", "✓"),
|
|
872
|
-
message,
|
|
873
|
-
logLevel >= _kubb_core.logLevel.info ? (0, node_util.styleText)("dim", info) : void 0
|
|
874
|
-
].filter(Boolean).join(" "));
|
|
875
|
-
console.log(text);
|
|
876
|
-
});
|
|
877
|
-
context.on("kubb:warn", ({ message, info = "" }) => {
|
|
878
|
-
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
879
|
-
const text = getMessage([
|
|
880
|
-
(0, node_util.styleText)("yellow", "⚠"),
|
|
881
|
-
message,
|
|
882
|
-
logLevel >= _kubb_core.logLevel.info ? (0, node_util.styleText)("dim", info) : void 0
|
|
883
|
-
].filter(Boolean).join(" "));
|
|
884
|
-
console.warn(`::warning::${text}`);
|
|
885
|
-
});
|
|
886
|
-
context.on("kubb:error", ({ error }) => {
|
|
887
|
-
const caused = require_errors.toCause(error);
|
|
888
|
-
closeAllGroups();
|
|
889
|
-
const message = error.message || String(error);
|
|
890
|
-
console.error(`::error::${message}`);
|
|
891
|
-
if (logLevel >= _kubb_core.logLevel.verbose && error.stack) {
|
|
892
|
-
const frames = error.stack.split("\n").slice(1, 4);
|
|
893
|
-
for (const frame of frames) console.log(getMessage((0, node_util.styleText)("dim", frame.trim())));
|
|
894
|
-
if (caused?.stack) {
|
|
895
|
-
console.log((0, node_util.styleText)("dim", `└─ caused by ${caused.message}`));
|
|
896
|
-
const frames = caused.stack.split("\n").slice(1, 4);
|
|
897
|
-
for (const frame of frames) console.log(getMessage(` ${(0, node_util.styleText)("dim", frame.trim())}`));
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
});
|
|
901
|
-
context.on("kubb:diagnostic", ({ diagnostic }) => {
|
|
902
|
-
closeAllGroups();
|
|
903
|
-
if (logLevel <= _kubb_core.logLevel.silent && diagnostic.severity !== "error") return;
|
|
904
|
-
if (!_kubb_core.Diagnostics.isProblem(diagnostic)) {
|
|
905
|
-
console.log(`::notice::${diagnostic.message}`);
|
|
906
|
-
return;
|
|
907
|
-
}
|
|
908
|
-
const parts = [`${diagnostic.code} ${diagnostic.message}`];
|
|
909
|
-
if (diagnostic.location && "pointer" in diagnostic.location) parts.push(`(at ${diagnostic.location.pointer})`);
|
|
910
|
-
if (diagnostic.plugin) parts.push(`[plugin: ${diagnostic.plugin}]`);
|
|
911
|
-
if (diagnostic.help) parts.push(`help: ${diagnostic.help}`);
|
|
912
|
-
if (diagnostic.code !== _kubb_core.Diagnostics.code.unknown) parts.push(`docs: ${_kubb_core.Diagnostics.docsUrl(diagnostic.code)}`);
|
|
913
|
-
console.error(`::error::${parts.join(" ")}`);
|
|
914
|
-
});
|
|
915
|
-
context.on("kubb:lifecycle:start", ({ version }) => {
|
|
916
|
-
console.log((0, node_util.styleText)("yellow", `Kubb ${version} 🧩`));
|
|
917
|
-
reset();
|
|
918
|
-
});
|
|
919
|
-
context.on("kubb:config:start", () => {
|
|
920
|
-
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
921
|
-
const text = getMessage("Configuration started");
|
|
922
|
-
openGroup("Configuration");
|
|
923
|
-
console.log(text);
|
|
924
|
-
});
|
|
925
|
-
context.on("kubb:config:end", ({ configs }) => {
|
|
926
|
-
state.currentConfigs = configs;
|
|
927
|
-
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
928
|
-
const text = getMessage("Configuration completed");
|
|
929
|
-
console.log(text);
|
|
930
|
-
closeGroup("Configuration");
|
|
931
|
-
});
|
|
932
|
-
context.on("kubb:generation:start", ({ config }) => {
|
|
933
|
-
reset();
|
|
934
|
-
state.totalPlugins = config.plugins?.length ?? 0;
|
|
935
|
-
const text = config.name ? `Generation for ${(0, node_util.styleText)("bold", config.name)}` : "Generation";
|
|
936
|
-
if (state.currentConfigs.length > 1) openGroup(text);
|
|
937
|
-
if (state.currentConfigs.length === 1) console.log(getMessage(text));
|
|
938
|
-
});
|
|
939
|
-
context.on("kubb:plugin:start", ({ plugin }) => {
|
|
940
|
-
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
941
|
-
const text = getMessage(`Generating ${(0, node_util.styleText)("bold", plugin.name)}`);
|
|
942
|
-
if (state.currentConfigs.length === 1) openGroup(`Plugin: ${plugin.name}`);
|
|
943
|
-
console.log(text);
|
|
944
|
-
});
|
|
945
|
-
context.on("kubb:plugin:end", ({ plugin, duration, success }) => {
|
|
946
|
-
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
947
|
-
recordPluginResult(state, success);
|
|
948
|
-
const durationStr = formatMsWithColor(duration);
|
|
949
|
-
const text = getMessage(success ? `${(0, node_util.styleText)("bold", plugin.name)} completed in ${durationStr}` : `${(0, node_util.styleText)("bold", plugin.name)} failed in ${(0, node_util.styleText)("red", formatMs(duration))}`);
|
|
950
|
-
console.log(text);
|
|
951
|
-
if (state.currentConfigs.length > 1) console.log(" ");
|
|
952
|
-
if (state.currentConfigs.length === 1) closeGroup(`Plugin: ${plugin.name}`);
|
|
953
|
-
showProgressStep();
|
|
954
|
-
});
|
|
955
|
-
context.on("kubb:files:processing:start", ({ files }) => {
|
|
956
|
-
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
957
|
-
state.totalFiles = files.length;
|
|
958
|
-
state.processedFiles = 0;
|
|
959
|
-
if (state.currentConfigs.length === 1) openGroup("File Generation");
|
|
960
|
-
const text = getMessage(`Writing ${files.length} files`);
|
|
961
|
-
console.log(text);
|
|
962
|
-
});
|
|
963
|
-
context.on("kubb:files:processing:end", () => {
|
|
964
|
-
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
965
|
-
const text = getMessage("Files written successfully");
|
|
966
|
-
console.log(text);
|
|
967
|
-
if (state.currentConfigs.length === 1) closeGroup("File Generation");
|
|
968
|
-
showProgressStep();
|
|
969
|
-
});
|
|
970
|
-
context.on("kubb:files:processing:update", ({ files }) => {
|
|
971
|
-
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
972
|
-
state.processedFiles += files.length;
|
|
973
|
-
});
|
|
974
|
-
context.on("kubb:generation:end", ({ config }) => {
|
|
975
|
-
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`);
|
|
976
|
-
console.log(text);
|
|
977
|
-
if (state.currentConfigs.length > 1) closeGroup(config.name ? `Generation for ${(0, node_util.styleText)("bold", config.name)}` : "Generation");
|
|
978
|
-
});
|
|
979
|
-
onGroupStart("kubb:format:start", "Format started", "Formatting");
|
|
980
|
-
onGroupEnd("kubb:format:end", "Format completed", "Formatting");
|
|
981
|
-
onGroupStart("kubb:lint:start", "Lint started", "Linting");
|
|
982
|
-
onGroupEnd("kubb:lint:end", "Lint completed", "Linting");
|
|
983
|
-
onGroupStart("kubb:hooks:start", "Hooks started", "Hooks");
|
|
984
|
-
onGroupEnd("kubb:hooks:end", "Hooks completed", "Hooks");
|
|
985
|
-
context.on("kubb:hook:start", ({ id, command, args }) => {
|
|
986
|
-
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
987
|
-
if (id) hookTimer.start(id);
|
|
988
|
-
const commandWithArgs = formatCommandWithArgs(command, args);
|
|
989
|
-
const text = getMessage(`Hook ${(0, node_util.styleText)("dim", commandWithArgs)} started`);
|
|
990
|
-
if (state.currentConfigs.length === 1) openGroup(`Hook ${commandWithArgs}`);
|
|
991
|
-
console.log(text);
|
|
992
|
-
});
|
|
993
|
-
context.on("kubb:hook:end", ({ id, command, args, success, error }) => {
|
|
994
|
-
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
995
|
-
const ms = id ? hookTimer.end(id) : void 0;
|
|
996
|
-
const durationStr = ms !== void 0 ? ` in ${formatMsWithColor(ms)}` : "";
|
|
997
|
-
const commandWithArgs = formatCommandWithArgs(command, args);
|
|
998
|
-
if (success) console.log(getMessage(`${(0, node_util.styleText)("green", "✓")} Hook ${(0, node_util.styleText)("dim", commandWithArgs)} completed${durationStr}`));
|
|
999
|
-
else {
|
|
1000
|
-
const reason = error?.message ? ` (${error.message})` : "";
|
|
1001
|
-
console.log(`::error::Hook ${commandWithArgs} failed${durationStr}${reason}`);
|
|
1002
|
-
}
|
|
1003
|
-
if (state.currentConfigs.length === 1) closeGroup(`Hook ${commandWithArgs}`);
|
|
1004
|
-
});
|
|
1005
|
-
context.on("kubb:lifecycle:end", () => {
|
|
1006
|
-
reset();
|
|
1007
|
-
});
|
|
1008
|
-
return (_commandWithArgs, _hookId) => ({
|
|
1009
|
-
onStdout: logLevel > _kubb_core.logLevel.silent ? (s) => console.log(s) : void 0,
|
|
1010
|
-
onStderr: logLevel > _kubb_core.logLevel.silent ? (s) => console.error(`::error::${s}`) : void 0
|
|
1011
|
-
});
|
|
1012
782
|
}
|
|
1013
783
|
});
|
|
1014
784
|
//#endregion
|
|
@@ -1125,21 +895,19 @@ const plainLogger = (0, _kubb_core.defineLogger)({
|
|
|
1125
895
|
const commandWithArgs = formatCommandWithArgs(command, args);
|
|
1126
896
|
console.log(getMessage(`Hook ${commandWithArgs} started`));
|
|
1127
897
|
});
|
|
1128
|
-
context.on("kubb:hook:end", ({ id, command, args, success, error }) => {
|
|
898
|
+
context.on("kubb:hook:end", ({ id, command, args, success, error, stdout, stderr }) => {
|
|
1129
899
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
1130
900
|
const ms = id ? hookTimer.end(id) : void 0;
|
|
1131
901
|
const durationStr = ms !== void 0 ? ` in ${formatMs(ms)}` : "";
|
|
1132
902
|
const commandWithArgs = formatCommandWithArgs(command, args);
|
|
1133
903
|
if (success) console.log(getMessage(`✓ Hook ${commandWithArgs} completed${durationStr}`));
|
|
1134
904
|
else {
|
|
905
|
+
if (stdout) console.log(stdout);
|
|
906
|
+
if (stderr) console.error(stderr);
|
|
1135
907
|
const reason = error?.message ? ` (${error.message})` : "";
|
|
1136
908
|
console.log(getMessage(`✗ Hook ${commandWithArgs} failed${durationStr}${reason}`));
|
|
1137
909
|
}
|
|
1138
910
|
});
|
|
1139
|
-
return (_commandWithArgs, _hookId) => ({
|
|
1140
|
-
onStdout: logLevel > _kubb_core.logLevel.silent ? (s) => console.log(s) : void 0,
|
|
1141
|
-
onStderr: logLevel > _kubb_core.logLevel.silent ? (s) => console.error(s) : void 0
|
|
1142
|
-
});
|
|
1143
911
|
}
|
|
1144
912
|
});
|
|
1145
913
|
//#endregion
|
|
@@ -1158,7 +926,7 @@ function formatMessage(message, logLevel) {
|
|
|
1158
926
|
return message;
|
|
1159
927
|
}
|
|
1160
928
|
/**
|
|
1161
|
-
* Build the progress summary line
|
|
929
|
+
* Build the progress summary line shown by the clack logger.
|
|
1162
930
|
* Returns null when there is nothing to display.
|
|
1163
931
|
*/
|
|
1164
932
|
function buildProgressLine(state) {
|
|
@@ -1174,7 +942,7 @@ function buildProgressLine(state) {
|
|
|
1174
942
|
return parts.join((0, node_util.styleText)("dim", " | "));
|
|
1175
943
|
}
|
|
1176
944
|
/**
|
|
1177
|
-
* Creates the per-run progress counters
|
|
945
|
+
* Creates the per-run progress counters used by the clack logger.
|
|
1178
946
|
*/
|
|
1179
947
|
function createProgressCounters() {
|
|
1180
948
|
return {
|
|
@@ -1232,14 +1000,12 @@ function formatCommandWithArgs(command, args) {
|
|
|
1232
1000
|
return args?.length ? `${command} ${args.join(" ")}` : command;
|
|
1233
1001
|
}
|
|
1234
1002
|
function detectLogger() {
|
|
1235
|
-
if (isGitHubActions()) return "github-actions";
|
|
1236
1003
|
if (canUseTTY()) return "clack";
|
|
1237
1004
|
return "plain";
|
|
1238
1005
|
}
|
|
1239
1006
|
const logMapper = {
|
|
1240
1007
|
clack: clackLogger,
|
|
1241
|
-
plain: plainLogger
|
|
1242
|
-
"github-actions": githubActionsLogger
|
|
1008
|
+
plain: plainLogger
|
|
1243
1009
|
};
|
|
1244
1010
|
/**
|
|
1245
1011
|
* Bridges a {@link Reporter} onto the run's event emitter: calls `report` with each config's
|
|
@@ -1258,9 +1024,10 @@ function installReporter(context, reporter, ctx) {
|
|
|
1258
1024
|
if (reporter.drain) context.on("kubb:lifecycle:end", () => reporter.drain?.(ctx));
|
|
1259
1025
|
}
|
|
1260
1026
|
/**
|
|
1261
|
-
* Installs the live logger (the TUI view) and the given reporters (the output)
|
|
1262
|
-
*
|
|
1263
|
-
*
|
|
1027
|
+
* Installs the live logger (the TUI view) and the given reporters (the output). The reporters are
|
|
1028
|
+
* already selected by the caller (the CLI maps `--reporter` to names via `selectReporters`); this
|
|
1029
|
+
* only wires them. Loggers receive hook subprocess output through `kubb:hook:line` and the
|
|
1030
|
+
* `stdout`/`stderr` on `kubb:hook:end`, so nothing is returned here.
|
|
1264
1031
|
*
|
|
1265
1032
|
* Loggers and reporters are independent: the `cli` reporter also activates the env logger summary.
|
|
1266
1033
|
* The `json` reporter owns stdout, so the live logger and the `cli` summary are suppressed whenever
|
|
@@ -1269,19 +1036,16 @@ function installReporter(context, reporter, ctx) {
|
|
|
1269
1036
|
async function setupReporters(context, { logLevel, reporters }) {
|
|
1270
1037
|
const hasJson = reporters.some((reporter) => reporter.name === "json");
|
|
1271
1038
|
const ctx = { logLevel };
|
|
1272
|
-
let makeSink = null;
|
|
1273
1039
|
for (const reporter of reporters) {
|
|
1274
1040
|
if (reporter.name === "cli") {
|
|
1275
1041
|
if (hasJson) continue;
|
|
1276
1042
|
const type = detectLogger();
|
|
1277
1043
|
const logger = logMapper[type];
|
|
1278
1044
|
if (!logger) throw new Error(`Unknown adapter type: ${type}`);
|
|
1279
|
-
|
|
1280
|
-
makeSink = typeof sink === "function" ? sink : null;
|
|
1045
|
+
await logger.install(context, { logLevel });
|
|
1281
1046
|
}
|
|
1282
1047
|
installReporter(context, reporter, ctx);
|
|
1283
1048
|
}
|
|
1284
|
-
return makeSink;
|
|
1285
1049
|
}
|
|
1286
1050
|
//#endregion
|
|
1287
1051
|
//#region src/runners/generate/utils.ts
|
|
@@ -1362,7 +1126,7 @@ async function getConfigs({ configPath, input, watch, logLevel }) {
|
|
|
1362
1126
|
/**
|
|
1363
1127
|
* Runs the `done` hooks defined in a Kubb config in sequence.
|
|
1364
1128
|
*/
|
|
1365
|
-
async function executeHooks({ configHooks, hooks
|
|
1129
|
+
async function executeHooks({ configHooks, hooks }) {
|
|
1366
1130
|
const commands = Array.isArray(configHooks.done) ? configHooks.done : [configHooks.done].filter(Boolean);
|
|
1367
1131
|
for (const command of commands) {
|
|
1368
1132
|
const [cmd, ...args] = require_shell.tokenize(command);
|
|
@@ -1374,36 +1138,34 @@ async function executeHooks({ configHooks, hooks, makeSink }) {
|
|
|
1374
1138
|
command: cmd,
|
|
1375
1139
|
args
|
|
1376
1140
|
});
|
|
1377
|
-
const { stream = false, onLine, onStdout, onStderr } = makeSink?.(commandWithArgs, hookId) ?? {};
|
|
1378
1141
|
await runHook({
|
|
1379
1142
|
id: hookId,
|
|
1380
1143
|
command: cmd,
|
|
1381
1144
|
args,
|
|
1382
1145
|
commandWithArgs,
|
|
1383
|
-
hooks
|
|
1384
|
-
stream,
|
|
1385
|
-
sink: {
|
|
1386
|
-
onLine,
|
|
1387
|
-
onStdout,
|
|
1388
|
-
onStderr
|
|
1389
|
-
}
|
|
1146
|
+
hooks
|
|
1390
1147
|
});
|
|
1391
1148
|
}
|
|
1392
1149
|
}
|
|
1393
|
-
async function runHook({ id, command, args, commandWithArgs, hooks
|
|
1394
|
-
const emitEnd = (success, error) => hooks.emit("kubb:hook:end", {
|
|
1150
|
+
async function runHook({ id, command, args, commandWithArgs, hooks }) {
|
|
1151
|
+
const emitEnd = (success, error, output) => hooks.emit("kubb:hook:end", {
|
|
1395
1152
|
command,
|
|
1396
1153
|
args,
|
|
1397
1154
|
id,
|
|
1398
1155
|
success,
|
|
1399
|
-
error
|
|
1156
|
+
error,
|
|
1157
|
+
...output
|
|
1400
1158
|
});
|
|
1159
|
+
const stream = hooks.listenerCount("kubb:hook:line") > 0;
|
|
1401
1160
|
try {
|
|
1402
1161
|
const proc = (0, tinyexec.x)(command, [...args ?? []], {
|
|
1403
1162
|
nodeOptions: { detached: process.platform !== "win32" },
|
|
1404
1163
|
throwOnError: true
|
|
1405
1164
|
});
|
|
1406
|
-
if (stream
|
|
1165
|
+
if (stream) for await (const line of proc) await hooks.emit("kubb:hook:line", {
|
|
1166
|
+
id,
|
|
1167
|
+
line
|
|
1168
|
+
});
|
|
1407
1169
|
await proc;
|
|
1408
1170
|
await hooks.emit("kubb:success", { message: `${(0, node_util.styleText)("dim", commandWithArgs)} successfully executed` });
|
|
1409
1171
|
await emitEnd(true, null);
|
|
@@ -1414,9 +1176,10 @@ async function runHook({ id, command, args, commandWithArgs, hooks, stream = fal
|
|
|
1414
1176
|
}
|
|
1415
1177
|
const stderr = err.output?.stderr ?? "";
|
|
1416
1178
|
const stdout = err.output?.stdout ?? "";
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1179
|
+
await emitEnd(false, /* @__PURE__ */ new Error(`Hook execute failed: ${commandWithArgs}`), {
|
|
1180
|
+
stdout,
|
|
1181
|
+
stderr
|
|
1182
|
+
});
|
|
1420
1183
|
}
|
|
1421
1184
|
}
|
|
1422
1185
|
/**
|
|
@@ -1467,7 +1230,7 @@ function waitForHookEnd(hooks, hookId, onSuccess, fallbackErrorMessage) {
|
|
|
1467
1230
|
hooks.on("kubb:hook:end", handler);
|
|
1468
1231
|
});
|
|
1469
1232
|
}
|
|
1470
|
-
async function runToolPass({ toolValue, detect, toolMap, toolLabel, successPrefix, noToolMessage, configName, outputPath, logLevel, hooks,
|
|
1233
|
+
async function runToolPass({ toolValue, detect, toolMap, toolLabel, successPrefix, noToolMessage, configName, outputPath, logLevel, hooks, onStart, onEnd }) {
|
|
1471
1234
|
await onStart();
|
|
1472
1235
|
let resolvedTool = toolValue;
|
|
1473
1236
|
if (resolvedTool === "auto") {
|
|
@@ -1496,19 +1259,12 @@ async function runToolPass({ toolValue, detect, toolMap, toolLabel, successPrefi
|
|
|
1496
1259
|
command: toolConfig.command,
|
|
1497
1260
|
args: hookArgs
|
|
1498
1261
|
});
|
|
1499
|
-
const { stream = false, onLine, onStdout, onStderr } = makeSink?.(commandWithArgs, hookId) ?? {};
|
|
1500
1262
|
runHook({
|
|
1501
1263
|
id: hookId,
|
|
1502
1264
|
command: toolConfig.command,
|
|
1503
1265
|
args: hookArgs,
|
|
1504
1266
|
commandWithArgs,
|
|
1505
|
-
hooks
|
|
1506
|
-
stream,
|
|
1507
|
-
sink: {
|
|
1508
|
-
onLine,
|
|
1509
|
-
onStdout,
|
|
1510
|
-
onStderr
|
|
1511
|
-
}
|
|
1267
|
+
hooks
|
|
1512
1268
|
}).catch(() => {});
|
|
1513
1269
|
await hookEndPromise;
|
|
1514
1270
|
} catch (caughtError) {
|
|
@@ -1519,7 +1275,7 @@ async function runToolPass({ toolValue, detect, toolMap, toolLabel, successPrefi
|
|
|
1519
1275
|
if (toolError) throw toolError;
|
|
1520
1276
|
}
|
|
1521
1277
|
async function generate(options) {
|
|
1522
|
-
const { input, hooks, logLevel
|
|
1278
|
+
const { input, hooks, logLevel } = options;
|
|
1523
1279
|
const hrStart = node_process.default.hrtime();
|
|
1524
1280
|
const inputPath = input ?? (options.config.input && "path" in options.config.input ? options.config.input.path : void 0);
|
|
1525
1281
|
const config = {
|
|
@@ -1602,8 +1358,7 @@ async function generate(options) {
|
|
|
1602
1358
|
configName: config.name,
|
|
1603
1359
|
outputPath,
|
|
1604
1360
|
logLevel,
|
|
1605
|
-
hooks
|
|
1606
|
-
makeSink
|
|
1361
|
+
hooks
|
|
1607
1362
|
});
|
|
1608
1363
|
} catch (caughtError) {
|
|
1609
1364
|
const diagnostic = outputDiagnostic(code, pass.toolLabel, caughtError);
|
|
@@ -1620,8 +1375,7 @@ async function generate(options) {
|
|
|
1620
1375
|
try {
|
|
1621
1376
|
await executeHooks({
|
|
1622
1377
|
configHooks: config.hooks,
|
|
1623
|
-
hooks
|
|
1624
|
-
makeSink
|
|
1378
|
+
hooks
|
|
1625
1379
|
});
|
|
1626
1380
|
} finally {
|
|
1627
1381
|
hooks.off("kubb:hook:end", onHookEnd);
|
|
@@ -1703,7 +1457,7 @@ async function run({ input, configPath, logLevel: logLevelKey, watch, reporters:
|
|
|
1703
1457
|
node_process.default.exit(1);
|
|
1704
1458
|
}
|
|
1705
1459
|
const requestedNames = cliReporters?.length ? cliReporters : ["cli"];
|
|
1706
|
-
|
|
1460
|
+
await setupReporters(hooks, {
|
|
1707
1461
|
logLevel,
|
|
1708
1462
|
reporters: (0, _kubb_core.selectReporters)(configs[0]?.reporters ?? [], requestedNames)
|
|
1709
1463
|
});
|
|
@@ -1727,8 +1481,7 @@ async function run({ input, configPath, logLevel: logLevelKey, watch, reporters:
|
|
|
1727
1481
|
input,
|
|
1728
1482
|
config,
|
|
1729
1483
|
logLevel,
|
|
1730
|
-
hooks
|
|
1731
|
-
makeSink
|
|
1484
|
+
hooks
|
|
1732
1485
|
});
|
|
1733
1486
|
_clack_prompts.log.step((0, node_util.styleText)("yellow", `Watching for changes in ${paths.join(" and ")}`));
|
|
1734
1487
|
}, {
|
|
@@ -1740,8 +1493,7 @@ async function run({ input, configPath, logLevel: logLevelKey, watch, reporters:
|
|
|
1740
1493
|
input,
|
|
1741
1494
|
config,
|
|
1742
1495
|
logLevel,
|
|
1743
|
-
hooks
|
|
1744
|
-
makeSink
|
|
1496
|
+
hooks
|
|
1745
1497
|
})) anyFailed = true;
|
|
1746
1498
|
} catch (configError) {
|
|
1747
1499
|
await hooks.emit("kubb:error", { error: require_errors.toError(configError) });
|
|
@@ -1757,4 +1509,4 @@ async function run({ input, configPath, logLevel: logLevelKey, watch, reporters:
|
|
|
1757
1509
|
//#endregion
|
|
1758
1510
|
exports.run = run;
|
|
1759
1511
|
|
|
1760
|
-
//# sourceMappingURL=run-
|
|
1512
|
+
//# sourceMappingURL=run-UWQ9wImP.cjs.map
|