@kubb/cli 4.12.6 → 4.12.8

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 (35) hide show
  1. package/dist/{generate-DrdKyOOH.cjs → generate-BIq4hG_7.cjs} +350 -176
  2. package/dist/generate-BIq4hG_7.cjs.map +1 -0
  3. package/dist/{generate-M-5j2zqa.js → generate-DbvDQY54.js} +351 -177
  4. package/dist/generate-DbvDQY54.js.map +1 -0
  5. package/dist/index.cjs +3 -5
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.js +3 -5
  8. package/dist/index.js.map +1 -1
  9. package/dist/mcp-B5FWDVjp.js.map +1 -1
  10. package/dist/mcp-D7d_8Bma.cjs.map +1 -1
  11. package/dist/{package-4h1lfDoB.cjs → package-DIKLcg4Q.cjs} +2 -2
  12. package/dist/package-DIKLcg4Q.cjs.map +1 -0
  13. package/dist/package-sWmJhaYS.js +6 -0
  14. package/dist/package-sWmJhaYS.js.map +1 -0
  15. package/dist/validate-Bt922JN-.js.map +1 -1
  16. package/dist/validate-D9LPzg3-.cjs.map +1 -1
  17. package/package.json +4 -4
  18. package/src/commands/generate.ts +10 -0
  19. package/src/commands/mcp.ts +1 -3
  20. package/src/commands/validate.ts +1 -3
  21. package/src/index.ts +0 -9
  22. package/src/loggers/clackLogger.ts +152 -86
  23. package/src/loggers/fileSystemLogger.ts +81 -15
  24. package/src/loggers/githubActionsLogger.ts +137 -57
  25. package/src/loggers/plainLogger.ts +33 -36
  26. package/src/runners/generate.ts +56 -45
  27. package/src/utils/Writables.ts +0 -8
  28. package/src/utils/executeHooks.ts +7 -4
  29. package/src/utils/getSummary.ts +3 -3
  30. package/dist/generate-DrdKyOOH.cjs.map +0 -1
  31. package/dist/generate-M-5j2zqa.js.map +0 -1
  32. package/dist/package-4h1lfDoB.cjs.map +0 -1
  33. package/dist/package-B857a-xb.js +0 -6
  34. package/dist/package-B857a-xb.js.map +0 -1
  35. package/src/utils/parseHrtimeToSeconds.ts +0 -4
@@ -1,5 +1,5 @@
1
1
  const require_chunk = require('./chunk-CbDLau6x.cjs');
2
- const require_package = require('./package-4h1lfDoB.cjs');
2
+ const require_package = require('./package-DIKLcg4Q.cjs');
3
3
  let citty = require("citty");
4
4
  let node_path = require("node:path");
5
5
  node_path = require_chunk.__toESM(node_path);
@@ -21,16 +21,11 @@ let seedrandom = require("seedrandom");
21
21
  seedrandom = require_chunk.__toESM(seedrandom);
22
22
  let node_stream = require("node:stream");
23
23
  let _kubb_core_fs = require("@kubb/core/fs");
24
+ let node_crypto = require("node:crypto");
24
25
  let string_argv = require("string-argv");
25
26
  let cosmiconfig = require("cosmiconfig");
26
27
  let jiti = require("jiti");
27
28
 
28
- //#region src/utils/parseHrtimeToSeconds.ts
29
- function parseHrtimeToSeconds(hrtime) {
30
- return (hrtime[0] + hrtime[1] / 1e9).toFixed(3);
31
- }
32
-
33
- //#endregion
34
29
  //#region src/utils/randomColour.ts
35
30
  function randomColour(text) {
36
31
  if (!text) return "white";
@@ -58,14 +53,14 @@ function randomCliColour(text) {
58
53
  //#endregion
59
54
  //#region src/utils/getSummary.ts
60
55
  function getSummary({ failedPlugins, filesCreated, status, hrStart, config, pluginTimings }) {
61
- const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(hrStart));
56
+ const duration = (0, _kubb_core_utils.formatHrtime)(hrStart);
62
57
  const pluginsCount = config.plugins?.length || 0;
63
58
  const successCount = pluginsCount - failedPlugins.size;
64
59
  const meta = {
65
60
  plugins: status === "success" ? `${picocolors.default.green(`${successCount} successful`)}, ${pluginsCount} total` : `${picocolors.default.green(`${successCount} successful`)}, ${picocolors.default.red(`${failedPlugins.size} failed`)}, ${pluginsCount} total`,
66
61
  pluginsFailed: status === "failed" ? [...failedPlugins]?.map(({ plugin }) => randomCliColour(plugin.name))?.join(", ") : void 0,
67
62
  filesCreated,
68
- time: `${elapsedSeconds}s`,
63
+ time: picocolors.default.green(duration),
69
64
  output: node_path.default.isAbsolute(config.root) ? node_path.default.resolve(config.root, config.output.path) : config.root
70
65
  };
71
66
  const labels = {
@@ -122,9 +117,46 @@ const clackLogger = (0, _kubb_core.defineLogger)({
122
117
  name: "clack",
123
118
  install(context, options) {
124
119
  const logLevel = options?.logLevel || _kubb_core.LogLevel.info;
125
- const activeProgress = /* @__PURE__ */ new Map();
126
- const spinner = _clack_prompts.spinner();
127
- let isSpinning = false;
120
+ const state = {
121
+ totalPlugins: 0,
122
+ completedPlugins: 0,
123
+ failedPlugins: 0,
124
+ totalFiles: 0,
125
+ processedFiles: 0,
126
+ hrStart: node_process.default.hrtime(),
127
+ spinner: _clack_prompts.spinner(),
128
+ isSpinning: false,
129
+ activeProgress: /* @__PURE__ */ new Map()
130
+ };
131
+ function reset() {
132
+ for (const [_key, active] of state.activeProgress) {
133
+ if (active.interval) clearInterval(active.interval);
134
+ active.progressBar?.stop();
135
+ }
136
+ state.totalPlugins = 0;
137
+ state.completedPlugins = 0;
138
+ state.failedPlugins = 0;
139
+ state.totalFiles = 0;
140
+ state.processedFiles = 0;
141
+ state.hrStart = node_process.default.hrtime();
142
+ state.spinner = _clack_prompts.spinner();
143
+ state.isSpinning = false;
144
+ state.activeProgress.clear();
145
+ }
146
+ function showProgressStep() {
147
+ if (logLevel <= _kubb_core.LogLevel.silent) return;
148
+ const parts = [];
149
+ const duration = (0, _kubb_core_utils.formatHrtime)(state.hrStart);
150
+ if (state.totalPlugins > 0) {
151
+ const pluginStr = state.failedPlugins > 0 ? `Plugins ${picocolors.default.green(state.completedPlugins.toString())}/${state.totalPlugins} ${picocolors.default.red(`(${state.failedPlugins} failed)`)}` : `Plugins ${picocolors.default.green(state.completedPlugins.toString())}/${state.totalPlugins}`;
152
+ parts.push(pluginStr);
153
+ }
154
+ if (state.totalFiles > 0) parts.push(`Files ${picocolors.default.green(state.processedFiles.toString())}/${state.totalFiles}`);
155
+ if (parts.length > 0) {
156
+ parts.push(`${picocolors.default.green(duration)} elapsed`);
157
+ _clack_prompts.log.step(getMessage(parts.join(picocolors.default.dim(" | "))));
158
+ }
159
+ }
128
160
  function getMessage(message) {
129
161
  if (logLevel >= _kubb_core.LogLevel.verbose) {
130
162
  const timestamp = (/* @__PURE__ */ new Date()).toLocaleTimeString("en-US", {
@@ -138,12 +170,12 @@ const clackLogger = (0, _kubb_core.defineLogger)({
138
170
  return message;
139
171
  }
140
172
  function startSpinner(text) {
141
- spinner.start(text);
142
- isSpinning = true;
173
+ state.spinner.start(text);
174
+ state.isSpinning = true;
143
175
  }
144
176
  function stopSpinner(text) {
145
- spinner.stop(text);
146
- isSpinning = false;
177
+ state.spinner.stop(text);
178
+ state.isSpinning = false;
147
179
  }
148
180
  context.on("info", (message, info = "") => {
149
181
  if (logLevel <= _kubb_core.LogLevel.silent) return;
@@ -152,7 +184,7 @@ const clackLogger = (0, _kubb_core.defineLogger)({
152
184
  message,
153
185
  picocolors.default.dim(info)
154
186
  ].join(" "));
155
- if (isSpinning) spinner.message(text);
187
+ if (state.isSpinning) state.spinner.message(text);
156
188
  else _clack_prompts.log.info(text);
157
189
  });
158
190
  context.on("success", (message, info = "") => {
@@ -162,7 +194,7 @@ const clackLogger = (0, _kubb_core.defineLogger)({
162
194
  message,
163
195
  logLevel >= _kubb_core.LogLevel.info ? picocolors.default.dim(info) : void 0
164
196
  ].filter(Boolean).join(" "));
165
- if (isSpinning) stopSpinner(text);
197
+ if (state.isSpinning) stopSpinner(text);
166
198
  else _clack_prompts.log.success(text);
167
199
  });
168
200
  context.on("warn", (message, info) => {
@@ -177,7 +209,7 @@ const clackLogger = (0, _kubb_core.defineLogger)({
177
209
  context.on("error", (error) => {
178
210
  const caused = error.cause;
179
211
  const text = [picocolors.default.red("✗"), error.message].join(" ");
180
- if (isSpinning) stopSpinner(getMessage(text));
212
+ if (state.isSpinning) stopSpinner(getMessage(text));
181
213
  else _clack_prompts.log.error(getMessage(text));
182
214
  if (logLevel >= _kubb_core.LogLevel.debug && error.stack) {
183
215
  const frames = error.stack.split("\n").slice(1, 4);
@@ -207,6 +239,7 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
207
239
  "#F5A217",
208
240
  "#F55A17"
209
241
  ])(`Kubb ${version$1} 🧩`));
242
+ reset();
210
243
  });
211
244
  context.on("config:start", () => {
212
245
  if (logLevel <= _kubb_core.LogLevel.silent) return;
@@ -214,14 +247,16 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
214
247
  _clack_prompts.intro(text);
215
248
  startSpinner(getMessage("Configuration loading"));
216
249
  });
217
- context.on("config:end", () => {
250
+ context.on("config:end", (_configs) => {
218
251
  if (logLevel <= _kubb_core.LogLevel.silent) return;
219
252
  const text = getMessage("Configuration completed");
220
253
  _clack_prompts.outro(text);
221
254
  });
222
255
  context.on("generation:start", (config) => {
256
+ state.totalPlugins = config.plugins?.length || 0;
223
257
  const text = getMessage(["Generation started", config.name ? `for ${picocolors.default.dim(config.name)}` : void 0].filter(Boolean).join(" "));
224
258
  _clack_prompts.intro(text);
259
+ reset();
225
260
  });
226
261
  context.on("plugin:start", (plugin) => {
227
262
  if (logLevel <= _kubb_core.LogLevel.silent) return;
@@ -235,25 +270,30 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
235
270
  progressBar.start(text);
236
271
  const interval = setInterval(() => {
237
272
  progressBar.advance();
238
- }, 50);
239
- activeProgress.set(plugin.name, {
273
+ }, 100);
274
+ state.activeProgress.set(plugin.name, {
240
275
  progressBar,
241
276
  interval
242
277
  });
243
278
  });
244
- context.on("plugin:end", (plugin, duration) => {
279
+ context.on("plugin:end", (plugin, { duration, success }) => {
245
280
  stopSpinner();
246
- const active = activeProgress.get(plugin.name);
281
+ const active = state.activeProgress.get(plugin.name);
247
282
  if (!active || logLevel === _kubb_core.LogLevel.silent) return;
248
283
  clearInterval(active.interval);
249
- const durationStr = duration >= 1e3 ? `${(duration / 1e3).toFixed(2)}s` : `${duration}ms`;
250
- const text = getMessage(`${picocolors.default.bold(plugin.name)} completed in ${picocolors.default.green(durationStr)}`);
284
+ if (success) state.completedPlugins++;
285
+ else state.failedPlugins++;
286
+ const durationStr = (0, _kubb_core_utils.formatMs)(duration);
287
+ const text = getMessage(success ? `${picocolors.default.bold(plugin.name)} completed in ${picocolors.default.green(durationStr)}` : `${picocolors.default.bold(plugin.name)} failed in ${picocolors.default.red(durationStr)}`);
251
288
  active.progressBar.stop(text);
252
- activeProgress.delete(plugin.name);
289
+ state.activeProgress.delete(plugin.name);
290
+ showProgressStep();
253
291
  });
254
292
  context.on("files:processing:start", (files) => {
255
293
  if (logLevel <= _kubb_core.LogLevel.silent) return;
256
294
  stopSpinner();
295
+ state.totalFiles = files.length;
296
+ state.processedFiles = 0;
257
297
  const text = `Writing ${files.length} files`;
258
298
  const progressBar = _clack_prompts.progress({
259
299
  style: "block",
@@ -262,13 +302,14 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
262
302
  });
263
303
  context.emit("info", text);
264
304
  progressBar.start(getMessage(text));
265
- activeProgress.set("files", { progressBar });
305
+ state.activeProgress.set("files", { progressBar });
266
306
  });
267
307
  context.on("file:processing:update", ({ file, config }) => {
268
308
  if (logLevel <= _kubb_core.LogLevel.silent) return;
269
309
  stopSpinner();
310
+ state.processedFiles++;
270
311
  const text = `Writing ${(0, node_path.relative)(config.root, file.path)}`;
271
- const active = activeProgress.get("files");
312
+ const active = state.activeProgress.get("files");
272
313
  if (!active) return;
273
314
  active.progressBar.advance(void 0, text);
274
315
  });
@@ -276,16 +317,38 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
276
317
  if (logLevel <= _kubb_core.LogLevel.silent) return;
277
318
  stopSpinner();
278
319
  const text = getMessage("Files written successfully");
279
- const active = activeProgress.get("files");
320
+ const active = state.activeProgress.get("files");
280
321
  if (!active) return;
281
322
  active.progressBar.stop(text);
282
- activeProgress.delete("files");
323
+ state.activeProgress.delete("files");
324
+ showProgressStep();
283
325
  });
284
326
  context.on("generation:end", (config) => {
285
327
  const text = getMessage(config.name ? `Generation completed for ${picocolors.default.dim(config.name)}` : "Generation completed");
286
328
  _clack_prompts.outro(text);
287
329
  });
288
- context.on("hook:execute", async ({ command: command$1, args }, cb) => {
330
+ context.on("format:start", () => {
331
+ if (logLevel <= _kubb_core.LogLevel.silent) return;
332
+ const text = getMessage("Format started");
333
+ _clack_prompts.intro(text);
334
+ });
335
+ context.on("format:end", () => {
336
+ if (logLevel <= _kubb_core.LogLevel.silent) return;
337
+ const text = getMessage("Format completed");
338
+ _clack_prompts.outro(text);
339
+ });
340
+ context.on("lint:start", () => {
341
+ if (logLevel <= _kubb_core.LogLevel.silent) return;
342
+ const text = getMessage("Lint started");
343
+ _clack_prompts.intro(text);
344
+ });
345
+ context.on("lint:end", () => {
346
+ if (logLevel <= _kubb_core.LogLevel.silent) return;
347
+ const text = getMessage("Lint completed");
348
+ _clack_prompts.outro(text);
349
+ });
350
+ context.on("hook:start", async ({ id, command: command$1, args }) => {
351
+ const text = getMessage(`Hook ${picocolors.default.dim(command$1)} started`);
289
352
  if (logLevel <= _kubb_core.LogLevel.silent) {
290
353
  try {
291
354
  const result = await (0, execa.execa)(command$1, args, {
@@ -296,7 +359,10 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
296
359
  date: /* @__PURE__ */ new Date(),
297
360
  logs: [result.stdout]
298
361
  });
299
- cb();
362
+ await context.emit("hook:end", {
363
+ command: command$1,
364
+ id
365
+ });
300
366
  } catch (err) {
301
367
  const error = /* @__PURE__ */ new Error("Hook execute failed");
302
368
  error.cause = err;
@@ -308,6 +374,7 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
308
374
  }
309
375
  return;
310
376
  }
377
+ _clack_prompts.intro(text);
311
378
  const writable = new ClackWritable(_clack_prompts.taskLog({ title: getMessage(["Executing hook", logLevel >= _kubb_core.LogLevel.info ? picocolors.default.dim(`${command$1} ${args?.join(" ")}`) : void 0].filter(Boolean).join(" ")) }));
312
379
  try {
313
380
  const result = await (0, execa.execa)(command$1, args, {
@@ -319,7 +386,10 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
319
386
  date: /* @__PURE__ */ new Date(),
320
387
  logs: [result.stdout]
321
388
  });
322
- cb();
389
+ await context.emit("hook:end", {
390
+ command: command$1,
391
+ id
392
+ });
323
393
  } catch (err) {
324
394
  const error = /* @__PURE__ */ new Error("Hook execute failed");
325
395
  error.cause = err;
@@ -330,34 +400,9 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
330
400
  await context.emit("error", error);
331
401
  }
332
402
  });
333
- context.on("format:start", () => {
334
- if (logLevel <= _kubb_core.LogLevel.silent) return;
335
- const text = getMessage("Format started");
336
- _clack_prompts.intro(text);
337
- });
338
- context.on("format:end", () => {
339
- if (logLevel <= _kubb_core.LogLevel.silent) return;
340
- const text = getMessage("Format completed");
341
- _clack_prompts.outro(text);
342
- });
343
- context.on("lint:start", () => {
344
- if (logLevel <= _kubb_core.LogLevel.silent) return;
345
- const text = getMessage("Lint started");
346
- _clack_prompts.intro(text);
347
- });
348
- context.on("lint:end", () => {
403
+ context.on("hook:end", ({ command: command$1 }) => {
349
404
  if (logLevel <= _kubb_core.LogLevel.silent) return;
350
- const text = getMessage("Lint completed");
351
- _clack_prompts.outro(text);
352
- });
353
- context.on("hook:start", (command$1) => {
354
- if (logLevel <= _kubb_core.LogLevel.silent) return;
355
- const text = getMessage(`Hook ${picocolors.default.dim(command$1)} started`);
356
- _clack_prompts.intro(text);
357
- });
358
- context.on("hook:end", (command$1) => {
359
- if (logLevel <= _kubb_core.LogLevel.silent) return;
360
- const text = getMessage(`Hook ${picocolors.default.dim(command$1)} completed`);
405
+ const text = getMessage(`Hook ${picocolors.default.dim(command$1)} successfully executed`);
361
406
  _clack_prompts.outro(text);
362
407
  });
363
408
  context.on("generation:summary", (config, { pluginTimings, failedPlugins, filesCreated, status, hrStart }) => {
@@ -393,11 +438,7 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
393
438
  });
394
439
  });
395
440
  context.on("lifecycle:end", () => {
396
- for (const [_key, active] of activeProgress) {
397
- if (active.interval) clearInterval(active.interval);
398
- active.progressBar?.stop();
399
- }
400
- activeProgress.clear();
441
+ reset();
401
442
  });
402
443
  }
403
444
  });
@@ -435,36 +476,97 @@ function canUseTTY() {
435
476
  const fileSystemLogger = (0, _kubb_core.defineLogger)({
436
477
  name: "filesystem",
437
478
  install(context) {
438
- const cachedLogs = /* @__PURE__ */ new Set();
439
- const startDate = Date.now();
440
- async function writeLogs() {
441
- if (cachedLogs.size === 0) return;
479
+ const state = {
480
+ cachedLogs: /* @__PURE__ */ new Set(),
481
+ startDate: Date.now()
482
+ };
483
+ function reset() {
484
+ state.cachedLogs = /* @__PURE__ */ new Set();
485
+ state.startDate = Date.now();
486
+ }
487
+ async function writeLogs(name) {
488
+ if (state.cachedLogs.size === 0) return;
442
489
  const files = {};
443
- for (const log of cachedLogs) {
444
- const fileName = (0, node_path.resolve)(process.cwd(), ".kubb", log.fileName || `kubb-${startDate}.log`);
445
- if (!files[fileName]) files[fileName] = [];
490
+ for (const log of state.cachedLogs) {
491
+ const baseName = log.fileName || `${[
492
+ "kubb",
493
+ name,
494
+ state.startDate
495
+ ].filter(Boolean).join("-")}.log`;
496
+ const pathName = (0, node_path.resolve)(process.cwd(), ".kubb", baseName);
497
+ if (!files[pathName]) files[pathName] = [];
446
498
  if (log.logs.length > 0) {
447
499
  const timestamp = log.date.toLocaleString();
448
- files[fileName].push(`[${timestamp}]\n${log.logs.join("\n")}`);
500
+ files[pathName].push(`[${timestamp}]\n${log.logs.join("\n")}`);
449
501
  }
450
502
  }
451
503
  await Promise.all(Object.entries(files).map(async ([fileName, logs]) => {
452
504
  return (0, _kubb_core_fs.write)(fileName, logs.join("\n\n"));
453
505
  }));
454
- cachedLogs.clear();
455
506
  }
507
+ context.on("info", (message, info) => {
508
+ state.cachedLogs.add({
509
+ date: /* @__PURE__ */ new Date(),
510
+ logs: [`ℹ ${message} ${info}`],
511
+ fileName: void 0
512
+ });
513
+ });
514
+ context.on("success", (message, info) => {
515
+ state.cachedLogs.add({
516
+ date: /* @__PURE__ */ new Date(),
517
+ logs: [`✓ ${message} ${info}`],
518
+ fileName: void 0
519
+ });
520
+ });
521
+ context.on("warn", (message, info) => {
522
+ state.cachedLogs.add({
523
+ date: /* @__PURE__ */ new Date(),
524
+ logs: [`⚠ ${message} ${info}`],
525
+ fileName: void 0
526
+ });
527
+ });
528
+ context.on("error", (error) => {
529
+ state.cachedLogs.add({
530
+ date: /* @__PURE__ */ new Date(),
531
+ logs: [`✗ ${error.message}`, error.stack || "unknown stack"],
532
+ fileName: void 0
533
+ });
534
+ });
456
535
  context.on("debug", (message) => {
457
- cachedLogs.add({
536
+ state.cachedLogs.add({
458
537
  date: /* @__PURE__ */ new Date(),
459
538
  logs: message.logs,
460
539
  fileName: void 0
461
540
  });
462
541
  });
463
- context.on("lifecycle:end", async () => {
464
- await writeLogs();
542
+ context.on("plugin:start", (plugin) => {
543
+ state.cachedLogs.add({
544
+ date: /* @__PURE__ */ new Date(),
545
+ logs: [`Generating ${plugin.name}`],
546
+ fileName: void 0
547
+ });
548
+ });
549
+ context.on("plugin:end", (plugin, { duration, success }) => {
550
+ const durationStr = (0, _kubb_core_utils.formatMs)(duration);
551
+ state.cachedLogs.add({
552
+ date: /* @__PURE__ */ new Date(),
553
+ logs: [success ? `${plugin.name} completed in ${durationStr}` : `${plugin.name} failed in ${durationStr}`],
554
+ fileName: void 0
555
+ });
556
+ });
557
+ context.on("files:processing:start", (files) => {
558
+ state.cachedLogs.add({
559
+ date: /* @__PURE__ */ new Date(),
560
+ logs: [`Start ${files.length} writing:`, ...files.map((file) => file.path)],
561
+ fileName: void 0
562
+ });
563
+ });
564
+ context.on("generation:end", async (config) => {
565
+ await writeLogs(config.name);
566
+ reset();
465
567
  });
466
568
  const exitHandler = () => {
467
- if (cachedLogs.size > 0) writeLogs().catch(() => {});
569
+ if (state.cachedLogs.size > 0) writeLogs().catch(() => {});
468
570
  };
469
571
  process.once("exit", exitHandler);
470
572
  process.once("SIGINT", exitHandler);
@@ -482,7 +584,37 @@ const githubActionsLogger = (0, _kubb_core.defineLogger)({
482
584
  name: "github-actions",
483
585
  install(context, options) {
484
586
  const logLevel = options?.logLevel || _kubb_core.LogLevel.info;
485
- let currentConfigs = [];
587
+ const state = {
588
+ totalPlugins: 0,
589
+ completedPlugins: 0,
590
+ failedPlugins: 0,
591
+ totalFiles: 0,
592
+ processedFiles: 0,
593
+ hrStart: process.hrtime(),
594
+ currentConfigs: []
595
+ };
596
+ function reset() {
597
+ state.totalPlugins = 0;
598
+ state.completedPlugins = 0;
599
+ state.failedPlugins = 0;
600
+ state.totalFiles = 0;
601
+ state.processedFiles = 0;
602
+ state.hrStart = process.hrtime();
603
+ }
604
+ function showProgressStep() {
605
+ if (logLevel <= _kubb_core.LogLevel.silent) return;
606
+ const parts = [];
607
+ const duration = (0, _kubb_core_utils.formatHrtime)(state.hrStart);
608
+ if (state.totalPlugins > 0) {
609
+ const pluginStr = state.failedPlugins > 0 ? `Plugins ${picocolors.default.green(state.completedPlugins.toString())}/${state.totalPlugins} ${picocolors.default.red(`(${state.failedPlugins} failed)`)}` : `Plugins ${picocolors.default.green(state.completedPlugins.toString())}/${state.totalPlugins}`;
610
+ parts.push(pluginStr);
611
+ }
612
+ if (state.totalFiles > 0) parts.push(`Files ${picocolors.default.green(state.processedFiles.toString())}/${state.totalFiles}`);
613
+ if (parts.length > 0) {
614
+ parts.push(`${picocolors.default.green(duration)} elapsed`);
615
+ console.log(getMessage(parts.join(picocolors.default.dim(" | "))));
616
+ }
617
+ }
486
618
  function getMessage(message) {
487
619
  if (logLevel >= _kubb_core.LogLevel.verbose) {
488
620
  const timestamp = (/* @__PURE__ */ new Date()).toLocaleTimeString("en-US", {
@@ -535,6 +667,7 @@ const githubActionsLogger = (0, _kubb_core.defineLogger)({
535
667
  });
536
668
  context.on("lifecycle:start", (version$1) => {
537
669
  console.log(picocolors.default.yellow(`Kubb ${version$1} 🧩`));
670
+ reset();
538
671
  });
539
672
  context.on("config:start", () => {
540
673
  if (logLevel <= _kubb_core.LogLevel.silent) return;
@@ -543,34 +676,41 @@ const githubActionsLogger = (0, _kubb_core.defineLogger)({
543
676
  console.log(text);
544
677
  });
545
678
  context.on("config:end", (configs) => {
546
- currentConfigs = configs;
679
+ state.currentConfigs = configs;
547
680
  if (logLevel <= _kubb_core.LogLevel.silent) return;
548
681
  const text = getMessage("Configuration completed");
549
682
  console.log(text);
550
683
  closeGroup("Configuration");
551
684
  });
552
685
  context.on("generation:start", (config) => {
686
+ state.totalPlugins = config.plugins?.length || 0;
553
687
  const text = config.name ? `Generation for ${picocolors.default.bold(config.name)}` : "Generation";
554
- if (currentConfigs.length > 1) openGroup(text);
555
- if (currentConfigs.length === 1) console.log(getMessage(text));
688
+ if (state.currentConfigs.length > 1) openGroup(text);
689
+ if (state.currentConfigs.length === 1) console.log(getMessage(text));
690
+ reset();
556
691
  });
557
692
  context.on("plugin:start", (plugin) => {
558
693
  if (logLevel <= _kubb_core.LogLevel.silent) return;
559
694
  const text = getMessage(`Generating ${picocolors.default.bold(plugin.name)}`);
560
- if (currentConfigs.length === 1) openGroup(`Plugin: ${plugin.name}`);
695
+ if (state.currentConfigs.length === 1) openGroup(`Plugin: ${plugin.name}`);
561
696
  console.log(text);
562
697
  });
563
- context.on("plugin:end", (plugin, duration) => {
698
+ context.on("plugin:end", (plugin, { duration, success }) => {
564
699
  if (logLevel <= _kubb_core.LogLevel.silent) return;
565
- const durationStr = duration >= 1e3 ? `${(duration / 1e3).toFixed(2)}s` : `${duration}ms`;
566
- const text = getMessage(`${picocolors.default.bold(plugin.name)} completed in ${picocolors.default.green(durationStr)}`);
700
+ if (success) state.completedPlugins++;
701
+ else state.failedPlugins++;
702
+ const durationStr = (0, _kubb_core_utils.formatMs)(duration);
703
+ const text = getMessage(success ? `${picocolors.default.bold(plugin.name)} completed in ${picocolors.default.green(durationStr)}` : `${picocolors.default.bold(plugin.name)} failed in ${picocolors.default.red(durationStr)}`);
567
704
  console.log(text);
568
- if (currentConfigs.length > 1) console.log(" ");
569
- if (currentConfigs.length === 1) closeGroup(`Plugin: ${plugin.name}`);
705
+ if (state.currentConfigs.length > 1) console.log(" ");
706
+ if (state.currentConfigs.length === 1) closeGroup(`Plugin: ${plugin.name}`);
707
+ showProgressStep();
570
708
  });
571
709
  context.on("files:processing:start", (files) => {
572
710
  if (logLevel <= _kubb_core.LogLevel.silent) return;
573
- if (currentConfigs.length === 1) openGroup("File Generation");
711
+ state.totalFiles = files.length;
712
+ state.processedFiles = 0;
713
+ if (state.currentConfigs.length === 1) openGroup("File Generation");
574
714
  const text = getMessage(`Writing ${files.length} files`);
575
715
  console.log(text);
576
716
  });
@@ -578,76 +718,87 @@ const githubActionsLogger = (0, _kubb_core.defineLogger)({
578
718
  if (logLevel <= _kubb_core.LogLevel.silent) return;
579
719
  const text = getMessage("Files written successfully");
580
720
  console.log(text);
581
- if (currentConfigs.length === 1) closeGroup("File Generation");
721
+ if (state.currentConfigs.length === 1) closeGroup("File Generation");
722
+ });
723
+ context.on("file:processing:update", () => {
724
+ if (logLevel <= _kubb_core.LogLevel.silent) return;
725
+ state.processedFiles++;
726
+ });
727
+ context.on("files:processing:end", () => {
728
+ if (logLevel <= _kubb_core.LogLevel.silent) return;
729
+ showProgressStep();
582
730
  });
583
731
  context.on("generation:end", (config) => {
584
732
  const text = getMessage(config.name ? `${picocolors.default.blue("✓")} Generation completed for ${picocolors.default.dim(config.name)}` : `${picocolors.default.blue("✓")} Generation completed`);
585
733
  console.log(text);
586
734
  });
587
- context.on("hook:execute", async ({ command: command$1, args }, cb) => {
588
- try {
589
- const result = await (0, execa.execa)(command$1, args, {
590
- detached: true,
591
- stripFinalNewline: true
592
- });
593
- await context.emit("debug", {
594
- date: /* @__PURE__ */ new Date(),
595
- logs: [result.stdout]
596
- });
597
- console.log(result.stdout);
598
- cb();
599
- } catch (err) {
600
- const error = /* @__PURE__ */ new Error("Hook execute failed");
601
- error.cause = err;
602
- await context.emit("debug", {
603
- date: /* @__PURE__ */ new Date(),
604
- logs: [err.stdout]
605
- });
606
- await context.emit("error", error);
607
- }
608
- });
609
735
  context.on("format:start", () => {
610
736
  if (logLevel <= _kubb_core.LogLevel.silent) return;
611
737
  const text = getMessage("Format started");
612
- if (currentConfigs.length === 1) openGroup("Formatting");
738
+ if (state.currentConfigs.length === 1) openGroup("Formatting");
613
739
  console.log(text);
614
740
  });
615
741
  context.on("format:end", () => {
616
742
  if (logLevel <= _kubb_core.LogLevel.silent) return;
617
743
  const text = getMessage("Format completed");
618
744
  console.log(text);
619
- if (currentConfigs.length === 1) closeGroup("Formatting");
745
+ if (state.currentConfigs.length === 1) closeGroup("Formatting");
620
746
  });
621
747
  context.on("lint:start", () => {
622
748
  if (logLevel <= _kubb_core.LogLevel.silent) return;
623
749
  const text = getMessage("Lint started");
624
- if (currentConfigs.length === 1) openGroup("Linting");
750
+ if (state.currentConfigs.length === 1) openGroup("Linting");
625
751
  console.log(text);
626
752
  });
627
753
  context.on("lint:end", () => {
628
754
  if (logLevel <= _kubb_core.LogLevel.silent) return;
629
755
  const text = getMessage("Lint completed");
630
756
  console.log(text);
631
- if (currentConfigs.length === 1) closeGroup("Linting");
757
+ if (state.currentConfigs.length === 1) closeGroup("Linting");
632
758
  });
633
- context.on("hook:start", (command$1) => {
634
- if (logLevel <= _kubb_core.LogLevel.silent) return;
759
+ context.on("hook:start", async ({ id, command: command$1, args }) => {
635
760
  const text = getMessage(`Hook ${picocolors.default.dim(command$1)} started`);
636
- if (currentConfigs.length === 1) openGroup(`Hook ${command$1}`);
637
- console.log(text);
761
+ if (logLevel > _kubb_core.LogLevel.silent) {
762
+ if (state.currentConfigs.length === 1) openGroup(`Hook ${command$1}`);
763
+ console.log(text);
764
+ }
765
+ try {
766
+ const result = await (0, execa.execa)(command$1, args, {
767
+ detached: true,
768
+ stripFinalNewline: true
769
+ });
770
+ await context.emit("debug", {
771
+ date: /* @__PURE__ */ new Date(),
772
+ logs: [result.stdout]
773
+ });
774
+ console.log(result.stdout);
775
+ await context.emit("hook:end", {
776
+ command: command$1,
777
+ id
778
+ });
779
+ } catch (err) {
780
+ const error = /* @__PURE__ */ new Error("Hook execute failed");
781
+ error.cause = err;
782
+ await context.emit("debug", {
783
+ date: /* @__PURE__ */ new Date(),
784
+ logs: [err.stdout]
785
+ });
786
+ await context.emit("error", error);
787
+ }
638
788
  });
639
- context.on("hook:end", (command$1) => {
789
+ context.on("hook:end", ({ command: command$1 }) => {
640
790
  if (logLevel <= _kubb_core.LogLevel.silent) return;
641
791
  const text = getMessage(`Hook ${picocolors.default.dim(command$1)} completed`);
642
792
  console.log(text);
643
- if (currentConfigs.length === 1) closeGroup(`Hook ${command$1}`);
793
+ if (state.currentConfigs.length === 1) closeGroup(`Hook ${command$1}`);
644
794
  });
645
- context.on("generation:summary", (config, { status, failedPlugins }) => {
795
+ context.on("generation:summary", (config, { status, hrStart, failedPlugins }) => {
646
796
  const pluginsCount = config.plugins?.length || 0;
647
797
  const successCount = pluginsCount - failedPlugins.size;
648
- if (currentConfigs.length > 1) console.log(" ");
649
- console.log(status === "success" ? `Kubb Summary: ${picocolors.default.blue("✓")} ${`${successCount} successful`}, ${pluginsCount} total` : `Kubb Summary: ${picocolors.default.blue("")} ${`${successCount} successful`}, ✗ ${`${failedPlugins.size} failed`}, ${pluginsCount} total`);
650
- if (currentConfigs.length > 1) closeGroup(config.name ? `Generation for ${picocolors.default.bold(config.name)}` : "Generation");
798
+ const duration = (0, _kubb_core_utils.formatHrtime)(hrStart);
799
+ if (state.currentConfigs.length > 1) console.log(" ");
800
+ console.log(status === "success" ? `Kubb Summary: ${picocolors.default.blue("✓")} ${`${successCount} successful`}, ${pluginsCount} total, ${picocolors.default.green(duration)}` : `Kubb Summary: ${picocolors.default.blue("")} ${`${successCount} successful`}, ✗ ${`${failedPlugins.size} failed`}, ${pluginsCount} total, ${picocolors.default.green(duration)}`);
801
+ if (state.currentConfigs.length > 1) closeGroup(config.name ? `Generation for ${picocolors.default.bold(config.name)}` : "Generation");
651
802
  });
652
803
  }
653
804
  });
@@ -734,10 +885,10 @@ const plainLogger = (0, _kubb_core.defineLogger)({
734
885
  const text = getMessage(`Generating ${plugin.name}`);
735
886
  console.log(text);
736
887
  });
737
- context.on("plugin:end", (plugin, duration) => {
888
+ context.on("plugin:end", (plugin, { duration, success }) => {
738
889
  if (logLevel <= _kubb_core.LogLevel.silent) return;
739
- const durationStr = duration >= 1e3 ? `${(duration / 1e3).toFixed(2)}s` : `${duration}ms`;
740
- const text = getMessage(`${plugin.name} completed in ${durationStr}`);
890
+ const durationStr = (0, _kubb_core_utils.formatMs)(duration);
891
+ const text = getMessage(success ? `${plugin.name} completed in ${durationStr}` : `${plugin.name} failed in ${durationStr}`);
741
892
  console.log(text);
742
893
  });
743
894
  context.on("files:processing:start", (files) => {
@@ -759,28 +910,6 @@ const plainLogger = (0, _kubb_core.defineLogger)({
759
910
  const text = getMessage(config.name ? `Generation completed for ${config.name}` : "Generation completed");
760
911
  console.log(text);
761
912
  });
762
- context.on("hook:execute", async ({ command: command$1, args }, cb) => {
763
- try {
764
- const result = await (0, execa.execa)(command$1, args, {
765
- detached: true,
766
- stripFinalNewline: true
767
- });
768
- await context.emit("debug", {
769
- date: /* @__PURE__ */ new Date(),
770
- logs: [result.stdout]
771
- });
772
- console.log(result.stdout);
773
- cb();
774
- } catch (err) {
775
- const error = /* @__PURE__ */ new Error("Hook execute failed");
776
- error.cause = err;
777
- await context.emit("debug", {
778
- date: /* @__PURE__ */ new Date(),
779
- logs: [err.stdout]
780
- });
781
- await context.emit("error", error);
782
- }
783
- });
784
913
  context.on("format:start", () => {
785
914
  if (logLevel <= _kubb_core.LogLevel.silent) return;
786
915
  const text = getMessage("Format started");
@@ -801,10 +930,32 @@ const plainLogger = (0, _kubb_core.defineLogger)({
801
930
  const text = getMessage("Lint completed");
802
931
  console.log(text);
803
932
  });
804
- context.on("hook:start", (command$1) => {
805
- if (logLevel <= _kubb_core.LogLevel.silent) return;
933
+ context.on("hook:start", async ({ id, command: command$1, args }) => {
806
934
  const text = getMessage(`Hook ${command$1} started`);
807
- console.log(text);
935
+ if (logLevel > _kubb_core.LogLevel.silent) console.log(text);
936
+ try {
937
+ const result = await (0, execa.execa)(command$1, args, {
938
+ detached: true,
939
+ stripFinalNewline: true
940
+ });
941
+ await context.emit("debug", {
942
+ date: /* @__PURE__ */ new Date(),
943
+ logs: [result.stdout]
944
+ });
945
+ console.log(result.stdout);
946
+ await context.emit("hook:end", {
947
+ command: command$1,
948
+ id
949
+ });
950
+ } catch (err) {
951
+ const error = /* @__PURE__ */ new Error("Hook execute failed");
952
+ error.cause = err;
953
+ await context.emit("debug", {
954
+ date: /* @__PURE__ */ new Date(),
955
+ logs: [err.stdout]
956
+ });
957
+ await context.emit("error", error);
958
+ }
808
959
  });
809
960
  context.on("hook:end", (command$1) => {
810
961
  if (logLevel <= _kubb_core.LogLevel.silent) return;
@@ -855,13 +1006,14 @@ async function executeHooks({ hooks, events }) {
855
1006
  for (const command$1 of commands) {
856
1007
  const [cmd, ...args] = [...(0, string_argv.parseArgsStringToArgv)(command$1)];
857
1008
  if (!cmd) continue;
858
- await events.emit("hook:start", command$1);
859
- await events.emit("hook:execute", {
1009
+ const hookId = (0, node_crypto.createHash)("sha256").update(command$1).digest("hex");
1010
+ await events.emit("hook:start", {
1011
+ id: hookId,
860
1012
  command: cmd,
861
1013
  args
862
- }, async () => {
863
- await events.emit("success", `${picocolors.default.dim(command$1)} successfully executed`);
864
- await events.emit("hook:end", command$1);
1014
+ });
1015
+ await events.on("hook:end", async ({ id }) => {
1016
+ if (id === hookId) await events.emit("success", `${picocolors.default.dim(command$1)} successfully executed`);
865
1017
  });
866
1018
  }
867
1019
  }
@@ -924,15 +1076,18 @@ async function generate({ input, config, events, logLevel }) {
924
1076
  await events.emit("info", [`Formatting with ${picocolors.default.dim(config.output.format)}`, logLevel >= _kubb_core.LogLevel.info ? `on ${picocolors.default.dim(node_path.default.resolve(definedConfig.root, definedConfig.output.path))}` : void 0].filter(Boolean).join(" "));
925
1077
  if (config.output.format === "prettier") {
926
1078
  try {
927
- await events.emit("hook:execute", {
1079
+ const hookId = (0, node_crypto.createHash)("sha256").update(config.output.format).digest("hex");
1080
+ await events.emit("hook:start", {
1081
+ id: hookId,
928
1082
  command: "prettier",
929
1083
  args: [
930
1084
  "--ignore-unknown",
931
1085
  "--write",
932
1086
  node_path.default.resolve(definedConfig.root, definedConfig.output.path)
933
1087
  ]
934
- }, async () => {
935
- await events.emit("success", [
1088
+ });
1089
+ await events.on("hook:end", async ({ id }) => {
1090
+ if (id === hookId) await events.emit("success", [
936
1091
  `Formatting with ${picocolors.default.dim(config.output.format)}`,
937
1092
  logLevel >= _kubb_core.LogLevel.info ? `on ${picocolors.default.dim(node_path.default.resolve(definedConfig.root, definedConfig.output.path))}` : void 0,
938
1093
  "successfully"
@@ -944,15 +1099,18 @@ async function generate({ input, config, events, logLevel }) {
944
1099
  await events.emit("success", `Formatted with ${config.output.format}`);
945
1100
  }
946
1101
  if (config.output.format === "biome") try {
947
- await events.emit("hook:execute", {
1102
+ const hookId = (0, node_crypto.createHash)("sha256").update(config.output.format).digest("hex");
1103
+ await events.emit("hook:start", {
1104
+ id: hookId,
948
1105
  command: "biome",
949
1106
  args: [
950
1107
  "format",
951
1108
  "--write",
952
1109
  node_path.default.resolve(definedConfig.root, definedConfig.output.path)
953
1110
  ]
954
- }, async () => {
955
- await events.emit("success", [
1111
+ });
1112
+ await events.on("hook:end", async ({ id }) => {
1113
+ if (id === hookId) await events.emit("success", [
956
1114
  `Formatting with ${picocolors.default.dim(config.output.format)}`,
957
1115
  logLevel >= _kubb_core.LogLevel.info ? `on ${picocolors.default.dim(node_path.default.resolve(definedConfig.root, definedConfig.output.path))}` : void 0,
958
1116
  "successfully"
@@ -969,11 +1127,14 @@ async function generate({ input, config, events, logLevel }) {
969
1127
  await events.emit("lint:start");
970
1128
  await events.emit("info", [`Linting with ${picocolors.default.dim(config.output.lint)}`, logLevel >= _kubb_core.LogLevel.info ? `on ${picocolors.default.dim(node_path.default.resolve(definedConfig.root, definedConfig.output.path))}` : void 0].filter(Boolean).join(" "));
971
1129
  if (config.output.lint === "eslint") try {
972
- await events.emit("hook:execute", {
1130
+ const hookId = (0, node_crypto.createHash)("sha256").update(config.output.lint).digest("hex");
1131
+ await events.emit("hook:start", {
1132
+ id: hookId,
973
1133
  command: "eslint",
974
1134
  args: [node_path.default.resolve(definedConfig.root, definedConfig.output.path), "--fix"]
975
- }, async () => {
976
- await events.emit("success", [
1135
+ });
1136
+ await events.on("hook:end", async ({ id }) => {
1137
+ if (id === hookId) await events.emit("success", [
977
1138
  `Linted with ${picocolors.default.dim(config.output.lint)}`,
978
1139
  logLevel >= _kubb_core.LogLevel.info ? `on ${picocolors.default.dim(node_path.default.resolve(definedConfig.root, definedConfig.output.path))}` : void 0,
979
1140
  "successfully"
@@ -985,15 +1146,18 @@ async function generate({ input, config, events, logLevel }) {
985
1146
  await events.emit("error", error$1);
986
1147
  }
987
1148
  if (config.output.lint === "biome") try {
988
- await events.emit("hook:execute", {
1149
+ const hookId = (0, node_crypto.createHash)("sha256").update(config.output.lint).digest("hex");
1150
+ await events.emit("hook:start", {
1151
+ id: hookId,
989
1152
  command: "biome",
990
1153
  args: [
991
1154
  "lint",
992
1155
  "--fix",
993
1156
  node_path.default.resolve(definedConfig.root, definedConfig.output.path)
994
1157
  ]
995
- }, async () => {
996
- await events.emit("success", [
1158
+ });
1159
+ await events.on("hook:end", async ({ id }) => {
1160
+ if (id === hookId) await events.emit("success", [
997
1161
  `Linted with ${picocolors.default.dim(config.output.lint)}`,
998
1162
  logLevel >= _kubb_core.LogLevel.info ? `on ${picocolors.default.dim(node_path.default.resolve(definedConfig.root, definedConfig.output.path))}` : void 0,
999
1163
  "successfully"
@@ -1005,11 +1169,14 @@ async function generate({ input, config, events, logLevel }) {
1005
1169
  await events.emit("error", error$1);
1006
1170
  }
1007
1171
  if (config.output.lint === "oxlint") try {
1008
- await events.emit("hook:execute", {
1172
+ const hookId = (0, node_crypto.createHash)("sha256").update(config.output.lint).digest("hex");
1173
+ await events.emit("hook:start", {
1174
+ id: hookId,
1009
1175
  command: "oxlint",
1010
1176
  args: ["--fix", node_path.default.resolve(definedConfig.root, definedConfig.output.path)]
1011
- }, async () => {
1012
- await events.emit("success", [
1177
+ });
1178
+ await events.on("hook:end", async ({ id }) => {
1179
+ if (id === hookId) await events.emit("success", [
1013
1180
  `Linted with ${picocolors.default.dim(config.output.lint)}`,
1014
1181
  logLevel >= _kubb_core.LogLevel.info ? `on ${picocolors.default.dim(node_path.default.resolve(definedConfig.root, definedConfig.output.path))}` : void 0,
1015
1182
  "successfully"
@@ -1192,6 +1359,12 @@ const command = (0, citty.defineCommand)({
1192
1359
  alias: "v",
1193
1360
  default: false
1194
1361
  },
1362
+ silent: {
1363
+ type: "boolean",
1364
+ description: "Override logLevel to silent",
1365
+ alias: "s",
1366
+ default: false
1367
+ },
1195
1368
  help: {
1196
1369
  type: "boolean",
1197
1370
  description: "Show help",
@@ -1207,6 +1380,7 @@ const command = (0, citty.defineCommand)({
1207
1380
  if (args.help) return (0, citty.showUsage)(command);
1208
1381
  if (args.debug) args.logLevel = "debug";
1209
1382
  if (args.verbose) args.logLevel = "verbose";
1383
+ if (args.silent) args.logLevel = "silent";
1210
1384
  const logLevel = _kubb_core.LogLevel[args.logLevel] || 3;
1211
1385
  await setupLogger(events, { logLevel });
1212
1386
  const latestVersion = await (0, latest_version.default)("@kubb/cli");
@@ -1253,4 +1427,4 @@ var generate_default = command;
1253
1427
 
1254
1428
  //#endregion
1255
1429
  exports.default = generate_default;
1256
- //# sourceMappingURL=generate-DrdKyOOH.cjs.map
1430
+ //# sourceMappingURL=generate-BIq4hG_7.cjs.map