@kubb/cli 5.5.6 → 5.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/dist/{Telemetry-CMXOVUKB.js → Telemetry-RBcAjNxj.js} +18 -43
  2. package/dist/Telemetry-RBcAjNxj.js.map +1 -0
  3. package/dist/{Telemetry-DDHXBdEz.cjs → Telemetry-bGdFBaGt.cjs} +27 -89
  4. package/dist/Telemetry-bGdFBaGt.cjs.map +1 -0
  5. package/dist/agent-BPIqnEl2.js +59 -0
  6. package/dist/agent-BPIqnEl2.js.map +1 -0
  7. package/dist/agent-DElUuYuy.cjs +120 -0
  8. package/dist/agent-DElUuYuy.cjs.map +1 -0
  9. package/dist/{background-DxlRE9O5.js → background-0PMj56FJ.js} +6 -5
  10. package/dist/background-0PMj56FJ.js.map +1 -0
  11. package/dist/background-BqS01QDb.js +2 -0
  12. package/dist/{background-Bbcc2TdN.cjs → background-R0T_7Szu.cjs} +8 -7
  13. package/dist/background-R0T_7Szu.cjs.map +1 -0
  14. package/dist/commands-BAgGrcvc.js +65 -0
  15. package/dist/commands-BAgGrcvc.js.map +1 -0
  16. package/dist/commands-Si-RFAS6.cjs +71 -0
  17. package/dist/commands-Si-RFAS6.cjs.map +1 -0
  18. package/dist/config-8Xl4yZmw.js +146 -0
  19. package/dist/config-8Xl4yZmw.js.map +1 -0
  20. package/dist/config-ByfJSj3q.cjs +164 -0
  21. package/dist/config-ByfJSj3q.cjs.map +1 -0
  22. package/dist/constants-CdxpgX3_.cjs.map +1 -1
  23. package/dist/constants-DHRspBTo.js.map +1 -1
  24. package/dist/{errors-C-wEou02.cjs → errors-CMbMAwyW.cjs} +2 -2
  25. package/dist/{errors-C-wEou02.cjs.map → errors-CMbMAwyW.cjs.map} +1 -1
  26. package/dist/index.cjs +431 -22
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.js +429 -20
  29. package/dist/index.js.map +1 -1
  30. package/dist/output-B6Ondw0g.js +776 -0
  31. package/dist/output-B6Ondw0g.js.map +1 -0
  32. package/dist/output-i3s5c4Xu.cjs +878 -0
  33. package/dist/output-i3s5c4Xu.cjs.map +1 -0
  34. package/dist/run-3I2NPeXG.cjs +31 -0
  35. package/dist/run-3I2NPeXG.cjs.map +1 -0
  36. package/dist/{run-C-jBKNbI.cjs → run-BkLJ5mXn.cjs} +22 -43
  37. package/dist/run-BkLJ5mXn.cjs.map +1 -0
  38. package/dist/run-CZlkqkDc.js +30 -0
  39. package/dist/run-CZlkqkDc.js.map +1 -0
  40. package/dist/run-CmNDNEjR.js +346 -0
  41. package/dist/run-CmNDNEjR.js.map +1 -0
  42. package/dist/{run-BdTwxLCW.js → run-D5AeacqK.js} +9 -23
  43. package/dist/run-D5AeacqK.js.map +1 -0
  44. package/dist/{run-y6LRyWdS.cjs → run-D8Wz_17X.cjs} +41 -60
  45. package/dist/run-D8Wz_17X.cjs.map +1 -0
  46. package/dist/{run-Dn8HVjnM.js → run-DQoKTiGk.js} +23 -44
  47. package/dist/run-DQoKTiGk.js.map +1 -0
  48. package/dist/{run-BDaZPU-1.js → run-Dgph0WYk.js} +25 -49
  49. package/dist/run-Dgph0WYk.js.map +1 -0
  50. package/dist/run-t8nm7zcT.cjs +348 -0
  51. package/dist/run-t8nm7zcT.cjs.map +1 -0
  52. package/dist/{run-CZz_GbE4.cjs → run-yvuot2N9.cjs} +12 -26
  53. package/dist/run-yvuot2N9.cjs.map +1 -0
  54. package/dist/{snapshot-B5mc4gpC.js → snapshot-CkHXR0Nl.js} +5 -5
  55. package/dist/snapshot-CkHXR0Nl.js.map +1 -0
  56. package/dist/{snapshot-DnCxZfmM.cjs → snapshot-D4nKbwkw.cjs} +9 -9
  57. package/dist/snapshot-D4nKbwkw.cjs.map +1 -0
  58. package/dist/studioWorker.js +2 -2
  59. package/package.json +7 -7
  60. package/dist/Telemetry-CMXOVUKB.js.map +0 -1
  61. package/dist/Telemetry-DDHXBdEz.cjs.map +0 -1
  62. package/dist/agent-DiB4CRre.cjs +0 -38
  63. package/dist/agent-DiB4CRre.cjs.map +0 -1
  64. package/dist/agent-yA5vrXJB.js +0 -26
  65. package/dist/agent-yA5vrXJB.js.map +0 -1
  66. package/dist/background-Bbcc2TdN.cjs.map +0 -1
  67. package/dist/background-CFNncNYT.js +0 -2
  68. package/dist/background-DxlRE9O5.js.map +0 -1
  69. package/dist/connect-C9tTngda.js +0 -11
  70. package/dist/connect-C9tTngda.js.map +0 -1
  71. package/dist/connect-CJ7BhOcs.cjs +0 -11
  72. package/dist/connect-CJ7BhOcs.cjs.map +0 -1
  73. package/dist/generate-BUqZ_7GB.cjs +0 -92
  74. package/dist/generate-BUqZ_7GB.cjs.map +0 -1
  75. package/dist/generate-q2m01zRd.js +0 -92
  76. package/dist/generate-q2m01zRd.js.map +0 -1
  77. package/dist/gunshiDryRun-DdKJuVn1.js +0 -2
  78. package/dist/init-Ckpwkfvz.cjs +0 -58
  79. package/dist/init-Ckpwkfvz.cjs.map +0 -1
  80. package/dist/init-DukE9Uw4.js +0 -58
  81. package/dist/init-DukE9Uw4.js.map +0 -1
  82. package/dist/login-Bc19oiFE.cjs +0 -11
  83. package/dist/login-Bc19oiFE.cjs.map +0 -1
  84. package/dist/login-Do3nns0B.js +0 -11
  85. package/dist/login-Do3nns0B.js.map +0 -1
  86. package/dist/logout-BvHFvCeI.cjs +0 -16
  87. package/dist/logout-BvHFvCeI.cjs.map +0 -1
  88. package/dist/logout-COxoIMum.js +0 -16
  89. package/dist/logout-COxoIMum.js.map +0 -1
  90. package/dist/mcp-B-GxGgVr.js +0 -19
  91. package/dist/mcp-B-GxGgVr.js.map +0 -1
  92. package/dist/mcp-B3B-rE7W.cjs +0 -18
  93. package/dist/mcp-B3B-rE7W.cjs.map +0 -1
  94. package/dist/output-CVLosNZq.cjs +0 -411
  95. package/dist/output-CVLosNZq.cjs.map +0 -1
  96. package/dist/output-FDo-db-w.js +0 -321
  97. package/dist/output-FDo-db-w.js.map +0 -1
  98. package/dist/package-Ci2fcoOV.js +0 -6
  99. package/dist/package-Ci2fcoOV.js.map +0 -1
  100. package/dist/package-Do9rJ7D3.cjs +0 -11
  101. package/dist/package-Do9rJ7D3.cjs.map +0 -1
  102. package/dist/rolldown-runtime-qbf5tadS.cjs +0 -38
  103. package/dist/run-BDaZPU-1.js.map +0 -1
  104. package/dist/run-BdTwxLCW.js.map +0 -1
  105. package/dist/run-C-jBKNbI.cjs.map +0 -1
  106. package/dist/run-CAcQlhub.js +0 -295
  107. package/dist/run-CAcQlhub.js.map +0 -1
  108. package/dist/run-CSoFhDyK.cjs +0 -297
  109. package/dist/run-CSoFhDyK.cjs.map +0 -1
  110. package/dist/run-CZz_GbE4.cjs.map +0 -1
  111. package/dist/run-CaEbo-te.js +0 -40
  112. package/dist/run-CaEbo-te.js.map +0 -1
  113. package/dist/run-CihzLZmR.cjs +0 -41
  114. package/dist/run-CihzLZmR.cjs.map +0 -1
  115. package/dist/run-Dn8HVjnM.js.map +0 -1
  116. package/dist/run-y6LRyWdS.cjs.map +0 -1
  117. package/dist/shared-Cl-OLpNh.cjs +0 -81
  118. package/dist/shared-Cl-OLpNh.cjs.map +0 -1
  119. package/dist/shared-DaHA7QFQ.js +0 -58
  120. package/dist/shared-DaHA7QFQ.js.map +0 -1
  121. package/dist/snapshot-B5mc4gpC.js.map +0 -1
  122. package/dist/snapshot-DnCxZfmM.cjs.map +0 -1
  123. package/dist/start-B-GXO8tS.cjs +0 -12
  124. package/dist/start-B-GXO8tS.cjs.map +0 -1
  125. package/dist/start-Dbfx_8zG.js +0 -12
  126. package/dist/start-Dbfx_8zG.js.map +0 -1
  127. package/dist/status-DDajNc8w.js +0 -17
  128. package/dist/status-DDajNc8w.js.map +0 -1
  129. package/dist/status-DusS7DfO.cjs +0 -17
  130. package/dist/status-DusS7DfO.cjs.map +0 -1
  131. package/dist/stop-C5t7Yx0t.js +0 -11
  132. package/dist/stop-C5t7Yx0t.js.map +0 -1
  133. package/dist/stop-zmM3A0Re.cjs +0 -11
  134. package/dist/stop-zmM3A0Re.cjs.map +0 -1
  135. package/dist/studio--IOOl_VB.js +0 -174
  136. package/dist/studio--IOOl_VB.js.map +0 -1
  137. package/dist/studio-CJ2XhtRd.cjs +0 -174
  138. package/dist/studio-CJ2XhtRd.cjs.map +0 -1
  139. package/dist/utils-C3HZOWL_.js +0 -1107
  140. package/dist/utils-C3HZOWL_.js.map +0 -1
  141. package/dist/utils-ClRbJfxu.cjs +0 -1210
  142. package/dist/utils-ClRbJfxu.cjs.map +0 -1
  143. package/dist/validate-BcB0tFQ6.cjs +0 -19
  144. package/dist/validate-BcB0tFQ6.cjs.map +0 -1
  145. package/dist/validate-QpkCbIFJ.js +0 -20
  146. package/dist/validate-QpkCbIFJ.js.map +0 -1
@@ -1,295 +0,0 @@
1
- import "./rolldown-runtime-CRm0XQPb.js";
2
- import { t as toError } from "./errors-BQJzaUwP.js";
3
- import { i as KUBB_NPM_PACKAGE_URL, o as UPDATE_CHECK_TIMEOUT_MS, r as sendTelemetry, t as buildTelemetryEvent } from "./Telemetry-CMXOVUKB.js";
4
- import { _ as linters, a as runPostGenerate, d as selectReporters, f as setupReporters, g as formatters, h as detectTool, i as runHook, m as LINTER_PREFERENCE, n as getConfigs, o as startUrlWatcher, p as FORMATTER_PREFERENCE, r as isNewerVersion, s as startWatcher, t as fetchUrlBody, u as pluralize } from "./utils-C3HZOWL_.js";
5
- import { a as logInfo, c as logSpacer, i as logError, l as logStep, n as logBanner, o as logIntro, s as logOutro, t as createSpinner, u as logTip } from "./output-FDo-db-w.js";
6
- import { t as version } from "./package-Ci2fcoOV.js";
7
- import { styleText } from "node:util";
8
- import { randomUUID } from "node:crypto";
9
- import process from "node:process";
10
- import path from "node:path";
11
- import { existsSync } from "node:fs";
12
- import { Diagnostics, Hookable, cliReporter, createKubb, fileReporter, getInputKind, htmlReporter, jsonReporter, logLevel, memoryStorage } from "@kubb/core";
13
- //#region src/runners/generate/run.ts
14
- /**
15
- * Runs one formatter or linter pass over the output directory. Returns the failure instead of
16
- * throwing, so the caller can turn it into a coded diagnostic. Failures never render here:
17
- * the caller emits them through `Diagnostics.emit`, like every other diagnostic.
18
- */
19
- async function runToolPass({ toolValue, tool, outputPath, logLevel: logLevel$1, hooks, onStart, onEnd }) {
20
- await onStart();
21
- let resolvedTool = toolValue;
22
- if (resolvedTool === "auto") {
23
- const detected = await tool.detect();
24
- if (!detected) await hooks.callHook("kubb:warn", { message: tool.noToolMessage });
25
- else {
26
- resolvedTool = detected;
27
- await hooks.callHook("kubb:info", { message: `Auto-detected ${tool.label}: ${styleText("dim", resolvedTool)}` });
28
- }
29
- }
30
- let toolError = null;
31
- if (resolvedTool && resolvedTool !== "auto" && resolvedTool in tool.map && existsSync(outputPath)) {
32
- const toolConfig = tool.map[resolvedTool];
33
- const successMessage = [
34
- `${tool.successPrefix} with ${styleText("dim", resolvedTool)}`,
35
- logLevel$1 >= logLevel.info ? `on ${styleText("dim", outputPath)}` : void 0,
36
- "successfully"
37
- ].filter(Boolean).join(" ");
38
- try {
39
- const hookId = randomUUID();
40
- const hookArgs = toolConfig.args(outputPath);
41
- const commandWithArgs = [toolConfig.command, ...hookArgs].join(" ");
42
- await hooks.callHook("kubb:hook:start", {
43
- id: hookId,
44
- command: toolConfig.command,
45
- args: hookArgs
46
- });
47
- const result = await runHook({
48
- id: hookId,
49
- command: toolConfig.command,
50
- args: hookArgs,
51
- commandWithArgs,
52
- hooks
53
- });
54
- if (result.success) await hooks.callHook("kubb:success", { message: successMessage });
55
- else toolError = result.error ?? new Error(toolConfig.errorMessage);
56
- } catch (caughtError) {
57
- toolError = toError(caughtError);
58
- }
59
- }
60
- await onEnd();
61
- return toolError;
62
- }
63
- async function generate(options) {
64
- const { input, hooks, logLevel, dryRun = false } = options;
65
- const hrStart = process.hrtime();
66
- const config = {
67
- ...options.config,
68
- input: input ?? options.config.input,
69
- storage: dryRun ? memoryStorage() : options.config.storage,
70
- output: dryRun ? {
71
- ...options.config.output,
72
- format: false,
73
- lint: false,
74
- postGenerate: []
75
- } : options.config.output
76
- };
77
- const processOutput = async ({ config: resolvedConfig, outputPath }) => {
78
- if (dryRun) return [];
79
- const outputDiagnostics = [];
80
- const reportOutputFailure = async (code, label, error) => {
81
- const diagnostic = outputDiagnostic(code, label, error);
82
- outputDiagnostics.push(diagnostic);
83
- await Diagnostics.emit(hooks, diagnostic);
84
- };
85
- const toolPasses = [{
86
- value: resolvedConfig.output.format,
87
- code: Diagnostics.code.formatFailed,
88
- tool: {
89
- label: "formatter",
90
- map: formatters,
91
- detect: () => detectTool(FORMATTER_PREFERENCE),
92
- successPrefix: "Formatting",
93
- noToolMessage: `No formatter found (${FORMATTER_PREFERENCE.join(", ")}). Skipping formatting.`
94
- },
95
- onStart: () => hooks.callHook("kubb:format:start"),
96
- onEnd: () => hooks.callHook("kubb:format:end")
97
- }, {
98
- value: resolvedConfig.output.lint,
99
- code: Diagnostics.code.lintFailed,
100
- tool: {
101
- label: "linter",
102
- map: linters,
103
- detect: () => detectTool(LINTER_PREFERENCE),
104
- successPrefix: "Linting",
105
- noToolMessage: `No linter found (${LINTER_PREFERENCE.join(", ")}). Skipping linting.`
106
- },
107
- onStart: () => hooks.callHook("kubb:lint:start"),
108
- onEnd: () => hooks.callHook("kubb:lint:end")
109
- }];
110
- for (const pass of toolPasses) {
111
- if (!pass.value) continue;
112
- const error = await runToolPass({
113
- toolValue: pass.value,
114
- tool: pass.tool,
115
- onStart: pass.onStart,
116
- onEnd: pass.onEnd,
117
- outputPath,
118
- logLevel,
119
- hooks
120
- });
121
- if (error) await reportOutputFailure(pass.code, pass.tool.label, error);
122
- }
123
- if (resolvedConfig.output.postGenerate?.length) {
124
- await hooks.callHook("kubb:hooks:start");
125
- const hookResults = await runPostGenerate({
126
- commands: resolvedConfig.output.postGenerate,
127
- hooks
128
- });
129
- for (const hookResult of hookResults) {
130
- if (hookResult.success) continue;
131
- await reportOutputFailure(Diagnostics.code.postGenerateFailed, "Post-generate command", hookResult.error ?? /* @__PURE__ */ new Error("Post-generate command failed"));
132
- }
133
- await hooks.callHook("kubb:hooks:end");
134
- }
135
- return outputDiagnostics;
136
- };
137
- const kubb = createKubb(config, { hooks });
138
- const result = await kubb.generate({ processOutput });
139
- if (dryRun) await hooks.callHook("kubb:info", {
140
- message: "Dry run: no files were written",
141
- info: `${result.files.length} file(s) would be generated`
142
- });
143
- const telemetryPlugins = Array.from(kubb.driver.plugins.values(), (p) => ({
144
- name: p.name,
145
- options: p.options
146
- }));
147
- await sendTelemetry(buildTelemetryEvent({
148
- command: "generate",
149
- kubbVersion: version,
150
- plugins: telemetryPlugins,
151
- hrStart,
152
- filesCreated: result.files.length,
153
- status: result.success ? "success" : "failed"
154
- }));
155
- return result.success;
156
- }
157
- /**
158
- * Builds a coded diagnostic for an output-phase failure (formatter, linter, or `done` hook).
159
- */
160
- function outputDiagnostic(code, label, caughtError) {
161
- const error = toError(caughtError);
162
- return {
163
- code,
164
- severity: "error",
165
- message: `${label} failed: ${error.message}`,
166
- help: "Check that the tool is installed and that the command and its config are correct.",
167
- location: { kind: "config" },
168
- cause: error
169
- };
170
- }
171
- async function checkForUpdate(hooks) {
172
- try {
173
- const data = await (await fetch(KUBB_NPM_PACKAGE_URL, { signal: AbortSignal.timeout(UPDATE_CHECK_TIMEOUT_MS) })).json();
174
- if (data.version && isNewerVersion(version, data.version)) await Diagnostics.emit(hooks, Diagnostics.update({
175
- currentVersion: version,
176
- latestVersion: data.version
177
- }));
178
- } catch {}
179
- }
180
- /**
181
- * Runs the full Kubb generation lifecycle for the given CLI options.
182
- * Loads configs, sets up the reporters (CLI `--reporter` picks which of `config.reporters` to trigger),
183
- * checks for a newer version, and calls `generate` for each config entry.
184
- */
185
- async function run({ input, configPath, logLevel: logLevelKey, watch, reporters: cliReporters, dryRun }) {
186
- const logLevel$2 = logLevel[logLevelKey] ?? logLevel.info;
187
- const hooks = new Hookable();
188
- const requestedNames = cliReporters?.length ? cliReporters : ["cli"];
189
- const quiet = logLevel$2 <= logLevel.silent || requestedNames.includes("json");
190
- if (!quiet) {
191
- logBanner(version);
192
- logIntro({ title: "Configuration" });
193
- }
194
- const configSpinner = createSpinner();
195
- let configs;
196
- let resolvedConfigPath;
197
- try {
198
- if (!quiet) configSpinner.start("Loading config");
199
- const loaded = await getConfigs({
200
- configPath,
201
- input,
202
- watch,
203
- logLevel: logLevelKey
204
- });
205
- configs = loaded.configs;
206
- resolvedConfigPath = loaded.configPath;
207
- if (!quiet) configSpinner.stop(`Loaded ${styleText("dim", path.relative(process.cwd(), resolvedConfigPath))}`);
208
- } catch (error) {
209
- if (!quiet) configSpinner.error("Config failed loading");
210
- await setupReporters(hooks, {
211
- logLevel: logLevel$2,
212
- reporters: [cliReporter]
213
- });
214
- await hooks.callHook("kubb:error", { error: toError(error) });
215
- if (!quiet) logOutro(styleText("red", "✗ Configuration failed"));
216
- process.exit(1);
217
- }
218
- const available = configs[0]?.reporters?.length ? configs[0].reporters : [
219
- cliReporter,
220
- jsonReporter,
221
- fileReporter,
222
- htmlReporter
223
- ];
224
- const reporters = selectReporters(available, requestedNames);
225
- await setupReporters(hooks, {
226
- logLevel: logLevel$2,
227
- reporters
228
- });
229
- await hooks.callHook("kubb:lifecycle:start", { version });
230
- await checkForUpdate(hooks);
231
- if (!quiet) logOutro(`${pluralize(configs.length, "config")} ready`);
232
- try {
233
- let anyFailed = false;
234
- for (const config of configs) {
235
- const effectiveInput = input ?? config.input;
236
- const inputKind = typeof effectiveInput === "string" ? getInputKind(effectiveInput) : void 0;
237
- const watchPath = inputKind === "file" || inputKind === "url" ? effectiveInput : void 0;
238
- if (watchPath && watch) {
239
- const watchedPaths = [watchPath];
240
- const build = async (paths) => {
241
- const succeeded = await generate({
242
- input,
243
- config,
244
- logLevel: logLevel$2,
245
- hooks,
246
- dryRun
247
- });
248
- logStep(styleText("yellow", `Watching for changes in ${paths.join(" and ")}`));
249
- if (succeeded) {
250
- logSpacer();
251
- logTip();
252
- }
253
- };
254
- const initialBody = inputKind === "url" ? await fetchUrlBody(watchPath) : void 0;
255
- try {
256
- await build(watchedPaths);
257
- } catch (buildError) {
258
- await hooks.callHook("kubb:error", { error: toError(buildError) });
259
- }
260
- if (inputKind === "url") startUrlWatcher(watchPath, build, {
261
- log: {
262
- info: logInfo,
263
- error: logError
264
- },
265
- initialBody
266
- });
267
- else await startWatcher(watchedPaths, build, {
268
- info: logInfo,
269
- error: logError
270
- });
271
- } else try {
272
- if (!await generate({
273
- input,
274
- config,
275
- logLevel: logLevel$2,
276
- hooks,
277
- dryRun
278
- })) anyFailed = true;
279
- } catch (configError) {
280
- await hooks.callHook("kubb:error", { error: toError(configError) });
281
- anyFailed = true;
282
- }
283
- }
284
- await hooks.callHook("kubb:lifecycle:end");
285
- if (!quiet && !watch && !anyFailed) logTip();
286
- if (anyFailed) process.exit(1);
287
- } catch (error) {
288
- await hooks.callHook("kubb:error", { error: toError(error) });
289
- process.exit(1);
290
- }
291
- }
292
- //#endregion
293
- export { run };
294
-
295
- //# sourceMappingURL=run-CAcQlhub.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"run-CAcQlhub.js","names":["logLevel","logLevelMap"],"sources":["../src/runners/generate/run.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto'\nimport { existsSync } from 'node:fs'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { styleText } from 'node:util'\nimport { toError } from '@internals/utils'\nimport {\n Hookable,\n type CLIOptions,\n cliReporter,\n type Config,\n createKubb,\n type Diagnostic,\n Diagnostics,\n fileReporter,\n getInputKind,\n htmlReporter,\n jsonReporter,\n type KubbHooks,\n logLevel as logLevelMap,\n memoryStorage,\n type ProblemDiagnostic,\n type ReporterName,\n} from '@kubb/core'\nimport { version } from '../../../package.json'\nimport { KUBB_NPM_PACKAGE_URL, UPDATE_CHECK_TIMEOUT_MS } from '../../constants.ts'\nimport { buildTelemetryEvent, sendTelemetry } from '../../Telemetry.ts'\nimport setupReporters, { pluralize, selectReporters } from '../../loggers/utils.ts'\nimport { createSpinner, logBanner, logError, logInfo, logIntro, logOutro, logSpacer, logStep, logTip } from '../../loggers/output.ts'\nimport { fetchUrlBody, getConfigs, isNewerVersion, runHook, runPostGenerate, startUrlWatcher, startWatcher } from './utils.ts'\nimport { FORMATTER_PREFERENCE, LINTER_PREFERENCE } from '@internals/utils'\nimport { detectTool, formatters, linters } from '../../tools.ts'\n\ntype GenerateProps = {\n input?: string\n config: Config\n hooks: Hookable<KubbHooks>\n logLevel: number\n /**\n * When `true`, generates in memory instead of writing to disk, and skips formatting, linting,\n * and post-generate commands.\n */\n dryRun?: boolean\n}\n\ntype ToolMap = typeof formatters | typeof linters\n\n/**\n * Static description of one output tool: its command table, the label and messages the pass logs,\n * and how to auto-detect it. Format and lint differ only in these values.\n */\ntype Tool = {\n label: string\n map: ToolMap\n detect: () => Promise<string | null>\n successPrefix: string\n noToolMessage: string\n}\n\ntype RunToolPassOptions = {\n toolValue: string\n tool: Tool\n outputPath: string\n logLevel: number\n hooks: Hookable<KubbHooks>\n onStart: () => Promise<void> | void\n onEnd: () => Promise<void> | void\n}\n\n/**\n * Runs one formatter or linter pass over the output directory. Returns the failure instead of\n * throwing, so the caller can turn it into a coded diagnostic. Failures never render here:\n * the caller emits them through `Diagnostics.emit`, like every other diagnostic.\n */\nasync function runToolPass({ toolValue, tool, outputPath, logLevel, hooks, onStart, onEnd }: RunToolPassOptions): Promise<Error | null> {\n await onStart()\n\n let resolvedTool = toolValue\n if (resolvedTool === 'auto') {\n const detected = await tool.detect()\n if (!detected) {\n await hooks.callHook('kubb:warn', { message: tool.noToolMessage })\n } else {\n resolvedTool = detected\n await hooks.callHook('kubb:info', { message: `Auto-detected ${tool.label}: ${styleText('dim', resolvedTool)}` })\n }\n }\n\n let toolError: Error | null = null\n\n // Nothing to lint or format when the output dir was never written. Skip so the tool\n // (e.g. oxlint with --no-ignore) doesn't fail with \"No files found to lint\".\n if (resolvedTool && resolvedTool !== 'auto' && resolvedTool in tool.map && existsSync(outputPath)) {\n const toolConfig = tool.map[resolvedTool as keyof ToolMap]\n\n const successMessage = [\n `${tool.successPrefix} with ${styleText('dim', resolvedTool)}`,\n logLevel >= logLevelMap.info ? `on ${styleText('dim', outputPath)}` : undefined,\n 'successfully',\n ]\n .filter(Boolean)\n .join(' ')\n\n try {\n const hookId = randomUUID()\n const hookArgs = toolConfig.args(outputPath)\n const commandWithArgs = [toolConfig.command, ...hookArgs].join(' ')\n\n await hooks.callHook('kubb:hook:start', { id: hookId, command: toolConfig.command, args: hookArgs })\n\n const result = await runHook({ id: hookId, command: toolConfig.command, args: hookArgs, commandWithArgs, hooks })\n\n if (result.success) {\n await hooks.callHook('kubb:success', { message: successMessage })\n } else {\n toolError = result.error ?? new Error(toolConfig.errorMessage)\n }\n } catch (caughtError) {\n toolError = toError(caughtError)\n }\n }\n\n await onEnd()\n\n return toolError\n}\n\nasync function generate(options: GenerateProps): Promise<boolean> {\n const { input, hooks, logLevel, dryRun = false } = options\n\n const hrStart = process.hrtime()\n\n const config: Config = {\n ...options.config,\n input: input ?? options.config.input,\n // Dry-run never touches disk, regardless of the config's own storage driver.\n storage: dryRun ? memoryStorage() : options.config.storage,\n // Also keeps core's `hasOutputPasses` false, so dry-run skips the output manifest write too.\n output: dryRun ? { ...options.config.output, format: false, lint: false, postGenerate: [] } : options.config.output,\n }\n\n // The formatter, linter, and post-generate commands run after a successful build. Collect their\n // failures as coded diagnostics so they reach the summary, the json report, and the exit code.\n const processOutput = async ({ config: resolvedConfig, outputPath }: { config: Config; outputPath: string }): Promise<Array<Diagnostic>> => {\n if (dryRun) return []\n\n const outputDiagnostics: Array<Diagnostic> = []\n const reportOutputFailure = async (code: ProblemDiagnostic['code'], label: string, error: Error) => {\n const diagnostic = outputDiagnostic(code, label, error)\n outputDiagnostics.push(diagnostic)\n await Diagnostics.emit(hooks, diagnostic)\n }\n\n // Format and lint are the same pass over the output directory, differing only in the tool\n // table and the hooks they announce themselves with, so run them from one descriptor list.\n const toolPasses = [\n {\n value: resolvedConfig.output.format,\n code: Diagnostics.code.formatFailed,\n tool: {\n label: 'formatter',\n map: formatters,\n detect: () => detectTool(FORMATTER_PREFERENCE),\n successPrefix: 'Formatting',\n noToolMessage: `No formatter found (${FORMATTER_PREFERENCE.join(', ')}). Skipping formatting.`,\n },\n onStart: () => hooks.callHook('kubb:format:start'),\n onEnd: () => hooks.callHook('kubb:format:end'),\n },\n {\n value: resolvedConfig.output.lint,\n code: Diagnostics.code.lintFailed,\n tool: {\n label: 'linter',\n map: linters,\n detect: () => detectTool(LINTER_PREFERENCE),\n successPrefix: 'Linting',\n noToolMessage: `No linter found (${LINTER_PREFERENCE.join(', ')}). Skipping linting.`,\n },\n onStart: () => hooks.callHook('kubb:lint:start'),\n onEnd: () => hooks.callHook('kubb:lint:end'),\n },\n ]\n\n for (const pass of toolPasses) {\n if (!pass.value) continue\n const error = await runToolPass({\n toolValue: pass.value,\n tool: pass.tool,\n onStart: pass.onStart,\n onEnd: pass.onEnd,\n outputPath,\n logLevel,\n hooks,\n })\n if (error) await reportOutputFailure(pass.code, pass.tool.label, error)\n }\n\n if (resolvedConfig.output.postGenerate?.length) {\n await hooks.callHook('kubb:hooks:start')\n const hookResults = await runPostGenerate({ commands: resolvedConfig.output.postGenerate, hooks })\n for (const hookResult of hookResults) {\n if (hookResult.success) continue\n await reportOutputFailure(Diagnostics.code.postGenerateFailed, 'Post-generate command', hookResult.error ?? new Error('Post-generate command failed'))\n }\n await hooks.callHook('kubb:hooks:end')\n }\n\n return outputDiagnostics\n }\n\n const kubb = createKubb(config, { hooks })\n const result = await kubb.generate({ processOutput })\n\n if (dryRun) {\n await hooks.callHook('kubb:info', { message: 'Dry run: no files were written', info: `${result.files.length} file(s) would be generated` })\n }\n\n const telemetryPlugins = Array.from(kubb.driver.plugins.values(), (p) => ({ name: p.name, options: p.options as Record<string, unknown> }))\n await sendTelemetry(\n buildTelemetryEvent({\n command: 'generate',\n kubbVersion: version,\n plugins: telemetryPlugins,\n hrStart,\n filesCreated: result.files.length,\n status: result.success ? 'success' : 'failed',\n }),\n )\n\n return result.success\n}\n\n/**\n * Builds a coded diagnostic for an output-phase failure (formatter, linter, or `done` hook).\n */\nfunction outputDiagnostic(code: ProblemDiagnostic['code'], label: string, caughtError: unknown): ProblemDiagnostic {\n const error = toError(caughtError)\n return {\n code,\n severity: 'error',\n message: `${label} failed: ${error.message}`,\n help: 'Check that the tool is installed and that the command and its config are correct.',\n location: { kind: 'config' },\n cause: error,\n }\n}\n\ntype GenerateCommandOptions = {\n input?: string\n configPath?: string\n logLevel: string\n watch: boolean\n reporters?: Array<ReporterName>\n dryRun?: boolean\n}\n\nasync function checkForUpdate(hooks: Hookable<KubbHooks>): Promise<void> {\n try {\n const res = await fetch(KUBB_NPM_PACKAGE_URL, { signal: AbortSignal.timeout(UPDATE_CHECK_TIMEOUT_MS) })\n const data = (await res.json()) as { version: string }\n if (data.version && isNewerVersion(version, data.version)) {\n await Diagnostics.emit(hooks, Diagnostics.update({ currentVersion: version, latestVersion: data.version }))\n }\n } catch {\n // Ignore network errors\n }\n}\n\n/**\n * Runs the full Kubb generation lifecycle for the given CLI options.\n * Loads configs, sets up the reporters (CLI `--reporter` picks which of `config.reporters` to trigger),\n * checks for a newer version, and calls `generate` for each config entry.\n */\nexport async function run({ input, configPath, logLevel: logLevelKey, watch, reporters: cliReporters, dryRun }: GenerateCommandOptions): Promise<void> {\n const logLevel = logLevelMap[logLevelKey as keyof typeof logLevelMap] ?? logLevelMap.info\n const hooks = new Hookable<KubbHooks>()\n\n // CLI `--reporter` selects which reporters to trigger by name, defaulting to `cli`. `defineConfig`\n // registers the built-in reporters on the config; a config exported without it falls back to them below.\n const requestedNames: Array<ReporterName> = cliReporters?.length ? cliReporters : ['cli']\n\n // The `json` reporter owns stdout, so the command writes nothing of its own around it.\n const quiet = logLevel <= logLevelMap.silent || requestedNames.includes('json')\n\n if (!quiet) {\n logBanner(version)\n logIntro({ title: 'Configuration' })\n }\n\n // Load the config first so `config.reporters` can pick the reporters. A failure here has no\n // reporter installed yet, so fall back to the default `cli` reporter to surface it.\n const configSpinner = createSpinner()\n let configs: Array<Config>\n let resolvedConfigPath: string\n try {\n if (!quiet) configSpinner.start('Loading config')\n\n const loaded = await getConfigs({\n configPath,\n input,\n watch,\n logLevel: logLevelKey as CLIOptions['logLevel'],\n })\n configs = loaded.configs\n resolvedConfigPath = loaded.configPath\n\n if (!quiet) configSpinner.stop(`Loaded ${styleText('dim', path.relative(process.cwd(), resolvedConfigPath))}`)\n } catch (error) {\n if (!quiet) configSpinner.error('Config failed loading')\n\n await setupReporters(hooks, { logLevel, reporters: [cliReporter] })\n await hooks.callHook('kubb:error', { error: toError(error) })\n\n if (!quiet) logOutro(styleText('red', '✗ Configuration failed'))\n process.exit(1)\n }\n\n // Without a reporter nothing is printed, not even an error, so a config written without\n // `defineConfig` gets the same built-ins it would have registered.\n const available = configs[0]?.reporters?.length ? configs[0].reporters : [cliReporter, jsonReporter, fileReporter, htmlReporter]\n const reporters = selectReporters(available, requestedNames)\n await setupReporters(hooks, { logLevel, reporters })\n\n await hooks.callHook('kubb:lifecycle:start', { version })\n\n // Inside the bootstrap group, so an update notice reads as part of the setup rather than as part\n // of the first config's generation.\n await checkForUpdate(hooks)\n\n if (!quiet) logOutro(`${pluralize(configs.length, 'config')} ready`)\n\n try {\n let anyFailed = false\n for (const config of configs) {\n const effectiveInput = input ?? config.input\n const inputKind = typeof effectiveInput === 'string' ? getInputKind(effectiveInput) : undefined\n const watchPath = inputKind === 'file' || inputKind === 'url' ? (effectiveInput as string) : undefined\n if (watchPath && watch) {\n const watchedPaths = [watchPath]\n // Don't removeAll() between builds, that would also drop logger and lifecycle\n // listeners. Plugin listeners are already disposed by safeBuild's dispose()\n // in its finally block, so re-running generate() on the same hooks emitter is safe.\n const build = async (paths: Array<string>) => {\n const succeeded = await generate({ input, config, logLevel, hooks, dryRun })\n logStep(styleText('yellow', `Watching for changes in ${paths.join(' and ')}`))\n if (succeeded) {\n logSpacer()\n logTip()\n }\n }\n\n // For a URL input, capture the document before the build: it becomes the watcher's\n // change-detection baseline, so an edit landing before the first poll still rebuilds.\n // When the server is down the baseline stays undefined and the watcher rebuilds on its\n // first successful poll, so recovery with an unchanged document still generates output.\n const initialBody = inputKind === 'url' ? await fetchUrlBody(watchPath) : undefined\n\n // The watchers ignore their startup state (chokidar's initial events, the baseline\n // above), so run the first build here. A failing first build keeps watching, since\n // the user can fix the input and save.\n try {\n await build(watchedPaths)\n } catch (buildError) {\n await hooks.callHook('kubb:error', { error: toError(buildError) })\n }\n\n if (inputKind === 'url') {\n startUrlWatcher(watchPath, build, { log: { info: logInfo, error: logError }, initialBody })\n } else {\n await startWatcher(watchedPaths, build, { info: logInfo, error: logError })\n }\n } else {\n try {\n const succeeded = await generate({ input, config, logLevel, hooks, dryRun })\n if (!succeeded) anyFailed = true\n } catch (configError) {\n await hooks.callHook('kubb:error', { error: toError(configError) })\n anyFailed = true\n }\n }\n }\n\n await hooks.callHook('kubb:lifecycle:end')\n\n // Watch mode prints a tip after each successful build. Regular generate commands need to\n // print one explicitly after the lifecycle group has closed so it stays outside the group.\n if (!quiet && !watch && !anyFailed) {\n logTip()\n }\n\n if (anyFailed) {\n process.exit(1)\n }\n } catch (error) {\n await hooks.callHook('kubb:error', { error: toError(error) })\n process.exit(1)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA0EA,eAAe,YAAY,EAAE,WAAW,MAAM,YAAY,UAAA,YAAU,OAAO,SAAS,SAAoD;CACtI,MAAM,QAAQ;CAEd,IAAI,eAAe;CACnB,IAAI,iBAAiB,QAAQ;EAC3B,MAAM,WAAW,MAAM,KAAK,OAAO;EACnC,IAAI,CAAC,UACH,MAAM,MAAM,SAAS,aAAa,EAAE,SAAS,KAAK,cAAc,CAAC;OAC5D;GACL,eAAe;GACf,MAAM,MAAM,SAAS,aAAa,EAAE,SAAS,iBAAiB,KAAK,MAAM,IAAI,UAAU,OAAO,YAAY,IAAI,CAAC;EACjH;CACF;CAEA,IAAI,YAA0B;CA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ACd,MAAM,MAAM,SAAS,cAAc,EAAE,OAAO,QAAQ,KAAK,EAAE,CAAC;EAC5D,QAAQ,KAAK,CAAC;CAChB;AACF"}
@@ -1,297 +0,0 @@
1
- const require_rolldown_runtime = require("./rolldown-runtime-qbf5tadS.cjs");
2
- const require_errors = require("./errors-C-wEou02.cjs");
3
- const require_Telemetry = require("./Telemetry-DDHXBdEz.cjs");
4
- const require_utils = require("./utils-ClRbJfxu.cjs");
5
- const require_output = require("./output-CVLosNZq.cjs");
6
- const require_package = require("./package-Do9rJ7D3.cjs");
7
- let node_util = require("node:util");
8
- let node_crypto = require("node:crypto");
9
- let node_process = require("node:process");
10
- node_process = require_rolldown_runtime.__toESM(node_process, 1);
11
- let node_path = require("node:path");
12
- node_path = require_rolldown_runtime.__toESM(node_path, 1);
13
- let node_fs = require("node:fs");
14
- let _kubb_core = require("@kubb/core");
15
- //#region src/runners/generate/run.ts
16
- /**
17
- * Runs one formatter or linter pass over the output directory. Returns the failure instead of
18
- * throwing, so the caller can turn it into a coded diagnostic. Failures never render here:
19
- * the caller emits them through `Diagnostics.emit`, like every other diagnostic.
20
- */
21
- async function runToolPass({ toolValue, tool, outputPath, logLevel, hooks, onStart, onEnd }) {
22
- await onStart();
23
- let resolvedTool = toolValue;
24
- if (resolvedTool === "auto") {
25
- const detected = await tool.detect();
26
- if (!detected) await hooks.callHook("kubb:warn", { message: tool.noToolMessage });
27
- else {
28
- resolvedTool = detected;
29
- await hooks.callHook("kubb:info", { message: `Auto-detected ${tool.label}: ${(0, node_util.styleText)("dim", resolvedTool)}` });
30
- }
31
- }
32
- let toolError = null;
33
- if (resolvedTool && resolvedTool !== "auto" && resolvedTool in tool.map && (0, node_fs.existsSync)(outputPath)) {
34
- const toolConfig = tool.map[resolvedTool];
35
- const successMessage = [
36
- `${tool.successPrefix} with ${(0, node_util.styleText)("dim", resolvedTool)}`,
37
- logLevel >= _kubb_core.logLevel.info ? `on ${(0, node_util.styleText)("dim", outputPath)}` : void 0,
38
- "successfully"
39
- ].filter(Boolean).join(" ");
40
- try {
41
- const hookId = (0, node_crypto.randomUUID)();
42
- const hookArgs = toolConfig.args(outputPath);
43
- const commandWithArgs = [toolConfig.command, ...hookArgs].join(" ");
44
- await hooks.callHook("kubb:hook:start", {
45
- id: hookId,
46
- command: toolConfig.command,
47
- args: hookArgs
48
- });
49
- const result = await require_utils.runHook({
50
- id: hookId,
51
- command: toolConfig.command,
52
- args: hookArgs,
53
- commandWithArgs,
54
- hooks
55
- });
56
- if (result.success) await hooks.callHook("kubb:success", { message: successMessage });
57
- else toolError = result.error ?? new Error(toolConfig.errorMessage);
58
- } catch (caughtError) {
59
- toolError = require_errors.toError(caughtError);
60
- }
61
- }
62
- await onEnd();
63
- return toolError;
64
- }
65
- async function generate(options) {
66
- const { input, hooks, logLevel, dryRun = false } = options;
67
- const hrStart = node_process.default.hrtime();
68
- const config = {
69
- ...options.config,
70
- input: input ?? options.config.input,
71
- storage: dryRun ? (0, _kubb_core.memoryStorage)() : options.config.storage,
72
- output: dryRun ? {
73
- ...options.config.output,
74
- format: false,
75
- lint: false,
76
- postGenerate: []
77
- } : options.config.output
78
- };
79
- const processOutput = async ({ config: resolvedConfig, outputPath }) => {
80
- if (dryRun) return [];
81
- const outputDiagnostics = [];
82
- const reportOutputFailure = async (code, label, error) => {
83
- const diagnostic = outputDiagnostic(code, label, error);
84
- outputDiagnostics.push(diagnostic);
85
- await _kubb_core.Diagnostics.emit(hooks, diagnostic);
86
- };
87
- const toolPasses = [{
88
- value: resolvedConfig.output.format,
89
- code: _kubb_core.Diagnostics.code.formatFailed,
90
- tool: {
91
- label: "formatter",
92
- map: require_utils.formatters,
93
- detect: () => require_utils.detectTool(require_utils.FORMATTER_PREFERENCE),
94
- successPrefix: "Formatting",
95
- noToolMessage: `No formatter found (${require_utils.FORMATTER_PREFERENCE.join(", ")}). Skipping formatting.`
96
- },
97
- onStart: () => hooks.callHook("kubb:format:start"),
98
- onEnd: () => hooks.callHook("kubb:format:end")
99
- }, {
100
- value: resolvedConfig.output.lint,
101
- code: _kubb_core.Diagnostics.code.lintFailed,
102
- tool: {
103
- label: "linter",
104
- map: require_utils.linters,
105
- detect: () => require_utils.detectTool(require_utils.LINTER_PREFERENCE),
106
- successPrefix: "Linting",
107
- noToolMessage: `No linter found (${require_utils.LINTER_PREFERENCE.join(", ")}). Skipping linting.`
108
- },
109
- onStart: () => hooks.callHook("kubb:lint:start"),
110
- onEnd: () => hooks.callHook("kubb:lint:end")
111
- }];
112
- for (const pass of toolPasses) {
113
- if (!pass.value) continue;
114
- const error = await runToolPass({
115
- toolValue: pass.value,
116
- tool: pass.tool,
117
- onStart: pass.onStart,
118
- onEnd: pass.onEnd,
119
- outputPath,
120
- logLevel,
121
- hooks
122
- });
123
- if (error) await reportOutputFailure(pass.code, pass.tool.label, error);
124
- }
125
- if (resolvedConfig.output.postGenerate?.length) {
126
- await hooks.callHook("kubb:hooks:start");
127
- const hookResults = await require_utils.runPostGenerate({
128
- commands: resolvedConfig.output.postGenerate,
129
- hooks
130
- });
131
- for (const hookResult of hookResults) {
132
- if (hookResult.success) continue;
133
- await reportOutputFailure(_kubb_core.Diagnostics.code.postGenerateFailed, "Post-generate command", hookResult.error ?? /* @__PURE__ */ new Error("Post-generate command failed"));
134
- }
135
- await hooks.callHook("kubb:hooks:end");
136
- }
137
- return outputDiagnostics;
138
- };
139
- const kubb = (0, _kubb_core.createKubb)(config, { hooks });
140
- const result = await kubb.generate({ processOutput });
141
- if (dryRun) await hooks.callHook("kubb:info", {
142
- message: "Dry run: no files were written",
143
- info: `${result.files.length} file(s) would be generated`
144
- });
145
- const telemetryPlugins = Array.from(kubb.driver.plugins.values(), (p) => ({
146
- name: p.name,
147
- options: p.options
148
- }));
149
- await require_Telemetry.sendTelemetry(require_Telemetry.buildTelemetryEvent({
150
- command: "generate",
151
- kubbVersion: require_package.version,
152
- plugins: telemetryPlugins,
153
- hrStart,
154
- filesCreated: result.files.length,
155
- status: result.success ? "success" : "failed"
156
- }));
157
- return result.success;
158
- }
159
- /**
160
- * Builds a coded diagnostic for an output-phase failure (formatter, linter, or `done` hook).
161
- */
162
- function outputDiagnostic(code, label, caughtError) {
163
- const error = require_errors.toError(caughtError);
164
- return {
165
- code,
166
- severity: "error",
167
- message: `${label} failed: ${error.message}`,
168
- help: "Check that the tool is installed and that the command and its config are correct.",
169
- location: { kind: "config" },
170
- cause: error
171
- };
172
- }
173
- async function checkForUpdate(hooks) {
174
- try {
175
- const data = await (await fetch(require_Telemetry.KUBB_NPM_PACKAGE_URL, { signal: AbortSignal.timeout(require_Telemetry.UPDATE_CHECK_TIMEOUT_MS) })).json();
176
- if (data.version && require_utils.isNewerVersion(require_package.version, data.version)) await _kubb_core.Diagnostics.emit(hooks, _kubb_core.Diagnostics.update({
177
- currentVersion: require_package.version,
178
- latestVersion: data.version
179
- }));
180
- } catch {}
181
- }
182
- /**
183
- * Runs the full Kubb generation lifecycle for the given CLI options.
184
- * Loads configs, sets up the reporters (CLI `--reporter` picks which of `config.reporters` to trigger),
185
- * checks for a newer version, and calls `generate` for each config entry.
186
- */
187
- async function run({ input, configPath, logLevel: logLevelKey, watch, reporters: cliReporters, dryRun }) {
188
- const logLevel = _kubb_core.logLevel[logLevelKey] ?? _kubb_core.logLevel.info;
189
- const hooks = new _kubb_core.Hookable();
190
- const requestedNames = cliReporters?.length ? cliReporters : ["cli"];
191
- const quiet = logLevel <= _kubb_core.logLevel.silent || requestedNames.includes("json");
192
- if (!quiet) {
193
- require_output.logBanner(require_package.version);
194
- require_output.logIntro({ title: "Configuration" });
195
- }
196
- const configSpinner = require_output.createSpinner();
197
- let configs;
198
- let resolvedConfigPath;
199
- try {
200
- if (!quiet) configSpinner.start("Loading config");
201
- const loaded = await require_utils.getConfigs({
202
- configPath,
203
- input,
204
- watch,
205
- logLevel: logLevelKey
206
- });
207
- configs = loaded.configs;
208
- resolvedConfigPath = loaded.configPath;
209
- if (!quiet) configSpinner.stop(`Loaded ${(0, node_util.styleText)("dim", node_path.default.relative(node_process.default.cwd(), resolvedConfigPath))}`);
210
- } catch (error) {
211
- if (!quiet) configSpinner.error("Config failed loading");
212
- await require_utils.setupReporters(hooks, {
213
- logLevel,
214
- reporters: [_kubb_core.cliReporter]
215
- });
216
- await hooks.callHook("kubb:error", { error: require_errors.toError(error) });
217
- if (!quiet) require_output.logOutro((0, node_util.styleText)("red", "✗ Configuration failed"));
218
- node_process.default.exit(1);
219
- }
220
- const available = configs[0]?.reporters?.length ? configs[0].reporters : [
221
- _kubb_core.cliReporter,
222
- _kubb_core.jsonReporter,
223
- _kubb_core.fileReporter,
224
- _kubb_core.htmlReporter
225
- ];
226
- const reporters = require_utils.selectReporters(available, requestedNames);
227
- await require_utils.setupReporters(hooks, {
228
- logLevel,
229
- reporters
230
- });
231
- await hooks.callHook("kubb:lifecycle:start", { version: require_package.version });
232
- await checkForUpdate(hooks);
233
- if (!quiet) require_output.logOutro(`${require_utils.pluralize(configs.length, "config")} ready`);
234
- try {
235
- let anyFailed = false;
236
- for (const config of configs) {
237
- const effectiveInput = input ?? config.input;
238
- const inputKind = typeof effectiveInput === "string" ? (0, _kubb_core.getInputKind)(effectiveInput) : void 0;
239
- const watchPath = inputKind === "file" || inputKind === "url" ? effectiveInput : void 0;
240
- if (watchPath && watch) {
241
- const watchedPaths = [watchPath];
242
- const build = async (paths) => {
243
- const succeeded = await generate({
244
- input,
245
- config,
246
- logLevel,
247
- hooks,
248
- dryRun
249
- });
250
- require_output.logStep((0, node_util.styleText)("yellow", `Watching for changes in ${paths.join(" and ")}`));
251
- if (succeeded) {
252
- require_output.logSpacer();
253
- require_output.logTip();
254
- }
255
- };
256
- const initialBody = inputKind === "url" ? await require_utils.fetchUrlBody(watchPath) : void 0;
257
- try {
258
- await build(watchedPaths);
259
- } catch (buildError) {
260
- await hooks.callHook("kubb:error", { error: require_errors.toError(buildError) });
261
- }
262
- if (inputKind === "url") require_utils.startUrlWatcher(watchPath, build, {
263
- log: {
264
- info: require_output.logInfo,
265
- error: require_output.logError
266
- },
267
- initialBody
268
- });
269
- else await require_utils.startWatcher(watchedPaths, build, {
270
- info: require_output.logInfo,
271
- error: require_output.logError
272
- });
273
- } else try {
274
- if (!await generate({
275
- input,
276
- config,
277
- logLevel,
278
- hooks,
279
- dryRun
280
- })) anyFailed = true;
281
- } catch (configError) {
282
- await hooks.callHook("kubb:error", { error: require_errors.toError(configError) });
283
- anyFailed = true;
284
- }
285
- }
286
- await hooks.callHook("kubb:lifecycle:end");
287
- if (!quiet && !watch && !anyFailed) require_output.logTip();
288
- if (anyFailed) node_process.default.exit(1);
289
- } catch (error) {
290
- await hooks.callHook("kubb:error", { error: require_errors.toError(error) });
291
- node_process.default.exit(1);
292
- }
293
- }
294
- //#endregion
295
- exports.run = run;
296
-
297
- //# sourceMappingURL=run-CSoFhDyK.cjs.map