@kubb/cli 5.0.0-beta.5 → 5.0.0-beta.50
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/LICENSE +17 -10
- package/README.md +171 -51
- package/dist/constants-BQ8LZB1P.js +23 -0
- package/dist/constants-BQ8LZB1P.js.map +1 -0
- package/dist/constants-MzEjK668.cjs +40 -0
- package/dist/constants-MzEjK668.cjs.map +1 -0
- package/dist/{define-Bdn8j5VM.cjs → define-C4AB3POr.cjs} +2 -2
- package/dist/{define-Bdn8j5VM.cjs.map → define-C4AB3POr.cjs.map} +1 -1
- package/dist/{define-Ctii4bel.js → define-C63T4jp6.js} +2 -2
- package/dist/{define-Ctii4bel.js.map → define-C63T4jp6.js.map} +1 -1
- package/dist/{errors-CjPmyZHy.js → errors-BsemQCMn.js} +2 -2
- package/dist/{errors-CjPmyZHy.js.map → errors-BsemQCMn.js.map} +1 -1
- package/dist/{errors-CLCjoSg0.cjs → errors-DykI11xo.cjs} +2 -2
- package/dist/{errors-CLCjoSg0.cjs.map → errors-DykI11xo.cjs.map} +1 -1
- package/dist/generate-CKnn3tQa.js +83 -0
- package/dist/generate-CKnn3tQa.js.map +1 -0
- package/dist/generate-Q6GMu4L8.cjs +82 -0
- package/dist/generate-Q6GMu4L8.cjs.map +1 -0
- package/dist/index.cjs +22 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +22 -15
- package/dist/index.js.map +1 -1
- package/dist/init-C5iCqBwA.cjs +53 -0
- package/dist/init-C5iCqBwA.cjs.map +1 -0
- package/dist/init-DyOF6CiQ.js +53 -0
- package/dist/init-DyOF6CiQ.js.map +1 -0
- package/dist/mcp-09FvxYWS.js +39 -0
- package/dist/mcp-09FvxYWS.js.map +1 -0
- package/dist/mcp-BN5HQYdK.cjs +39 -0
- package/dist/mcp-BN5HQYdK.cjs.map +1 -0
- package/dist/package-Bm6VUbtL.js +6 -0
- package/dist/package-Bm6VUbtL.js.map +1 -0
- package/dist/{package-BmYRU2hz.cjs → package-DOVOGEEY.cjs} +2 -2
- package/dist/package-DOVOGEEY.cjs.map +1 -0
- package/dist/run-BO7phoNN.js +51 -0
- package/dist/run-BO7phoNN.js.map +1 -0
- package/dist/{init-C5sZulT6.cjs → run-BtjzfTz3.cjs} +155 -85
- package/dist/run-BtjzfTz3.cjs.map +1 -0
- package/dist/run-BzaKz_nl.js +32 -0
- package/dist/run-BzaKz_nl.js.map +1 -0
- package/dist/{init-Cag3082g.js → run-C-omuksC.js} +147 -77
- package/dist/run-C-omuksC.js.map +1 -0
- package/dist/run-CkTpemme.cjs +52 -0
- package/dist/run-CkTpemme.cjs.map +1 -0
- package/dist/run-Cl4SrSob.cjs +33 -0
- package/dist/run-Cl4SrSob.cjs.map +1 -0
- package/dist/run-CrvmI4G2.cjs +1520 -0
- package/dist/run-CrvmI4G2.cjs.map +1 -0
- package/dist/run-DvZ5i2lT.js +1517 -0
- package/dist/run-DvZ5i2lT.js.map +1 -0
- package/dist/{shell-DLzN4fRo.js → shell-DsgkfUSW.js} +2 -2
- package/dist/{shell-DLzN4fRo.js.map → shell-DsgkfUSW.js.map} +1 -1
- package/dist/{shell-475fQKaX.cjs → shell-Lh-vLWwH.cjs} +2 -2
- package/dist/{shell-475fQKaX.cjs.map → shell-Lh-vLWwH.cjs.map} +1 -1
- package/dist/validate-5atkOC73.js +26 -0
- package/dist/validate-5atkOC73.js.map +1 -0
- package/dist/validate-C6KPFEex.cjs +26 -0
- package/dist/validate-C6KPFEex.cjs.map +1 -0
- package/package.json +14 -24
- package/src/commands/generate.ts +27 -13
- package/src/commands/init.ts +34 -3
- package/src/commands/mcp.ts +28 -4
- package/src/commands/validate.ts +6 -4
- package/src/constants.ts +1 -86
- package/src/index.ts +7 -6
- package/src/loggers/clackLogger.ts +137 -178
- package/src/loggers/plainLogger.ts +49 -102
- package/src/loggers/types.ts +6 -1
- package/src/loggers/utils.ts +141 -26
- package/src/runners/generate/run.ts +406 -0
- package/src/runners/generate/utils.ts +228 -0
- package/src/runners/init/run.ts +210 -0
- package/src/{utils/packageManager.ts → runners/init/utils.ts} +12 -2
- package/src/runners/mcp/run.ts +37 -0
- package/src/runners/validate/run.ts +63 -0
- package/dist/agent-BcUEl9yB.js +0 -56
- package/dist/agent-BcUEl9yB.js.map +0 -1
- package/dist/agent-CS45W0kL.cjs +0 -122
- package/dist/agent-CS45W0kL.cjs.map +0 -1
- package/dist/agent-CsMvXeqI.cjs +0 -58
- package/dist/agent-CsMvXeqI.cjs.map +0 -1
- package/dist/agent-IP0eLV3C.js +0 -118
- package/dist/agent-IP0eLV3C.js.map +0 -1
- package/dist/constants-B4iBDvCe.cjs +0 -148
- package/dist/constants-B4iBDvCe.cjs.map +0 -1
- package/dist/constants-DmPrkaz8.js +0 -95
- package/dist/constants-DmPrkaz8.js.map +0 -1
- package/dist/generate-7td_hs73.cjs +0 -65
- package/dist/generate-7td_hs73.cjs.map +0 -1
- package/dist/generate-BqeFFQGD.js +0 -66
- package/dist/generate-BqeFFQGD.js.map +0 -1
- package/dist/generate-CUd1dUY5.cjs +0 -1755
- package/dist/generate-CUd1dUY5.cjs.map +0 -1
- package/dist/generate-DVmGtwWe.js +0 -1752
- package/dist/generate-DVmGtwWe.js.map +0 -1
- package/dist/init-C5sZulT6.cjs.map +0 -1
- package/dist/init-Cag3082g.js.map +0 -1
- package/dist/init-CfAn19gC.js +0 -25
- package/dist/init-CfAn19gC.js.map +0 -1
- package/dist/init-CfsYoyGe.cjs +0 -25
- package/dist/init-CfsYoyGe.cjs.map +0 -1
- package/dist/mcp-BfORW-mY.cjs +0 -47
- package/dist/mcp-BfORW-mY.cjs.map +0 -1
- package/dist/mcp-BtOV6acy.js +0 -16
- package/dist/mcp-BtOV6acy.js.map +0 -1
- package/dist/mcp-CIbuLGMx.cjs +0 -16
- package/dist/mcp-CIbuLGMx.cjs.map +0 -1
- package/dist/mcp-DtQ5o0On.js +0 -46
- package/dist/mcp-DtQ5o0On.js.map +0 -1
- package/dist/package-BmYRU2hz.cjs.map +0 -1
- package/dist/package-DBU5ii-k.js +0 -6
- package/dist/package-DBU5ii-k.js.map +0 -1
- package/dist/telemetry-BU25EoI-.cjs +0 -282
- package/dist/telemetry-BU25EoI-.cjs.map +0 -1
- package/dist/telemetry-CaNU4-Bf.js +0 -245
- package/dist/telemetry-CaNU4-Bf.js.map +0 -1
- package/dist/validate-CQqM9siF.js +0 -25
- package/dist/validate-CQqM9siF.js.map +0 -1
- package/dist/validate-DBXLaLIn.cjs +0 -34
- package/dist/validate-DBXLaLIn.cjs.map +0 -1
- package/dist/validate-DI23zgmL.js +0 -33
- package/dist/validate-DI23zgmL.js.map +0 -1
- package/dist/validate-DwX4LzYq.cjs +0 -25
- package/dist/validate-DwX4LzYq.cjs.map +0 -1
- package/src/commands/agent/start.ts +0 -47
- package/src/commands/agent.ts +0 -8
- package/src/loggers/fileSystemLogger.ts +0 -138
- package/src/loggers/githubActionsLogger.ts +0 -379
- package/src/runners/agent.ts +0 -155
- package/src/runners/generate.ts +0 -333
- package/src/runners/init.ts +0 -296
- package/src/runners/mcp.ts +0 -51
- package/src/runners/validate.ts +0 -39
- package/src/types.ts +0 -11
- package/src/utils/Writables.ts +0 -17
- package/src/utils/executeHooks.ts +0 -45
- package/src/utils/flags.ts +0 -9
- package/src/utils/getConfig.ts +0 -10
- package/src/utils/getCosmiConfig.ts +0 -75
- package/src/utils/getSummary.ts +0 -68
- package/src/utils/runHook.ts +0 -91
- package/src/utils/telemetry.ts +0 -273
- package/src/utils/watcher.ts +0 -19
- /package/dist/{chunk-ByKO4r7w.cjs → chunk-Bx3C2hgW.cjs} +0 -0
- /package/dist/{chunk--u3MIqq1.js → chunk-C0LytTxp.js} +0 -0
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { relative } from 'node:path'
|
|
2
2
|
import { formatMs, toCause } from '@internals/utils'
|
|
3
|
-
import { defineLogger, logLevel as logLevelMap } from '@kubb/core'
|
|
4
|
-
import {
|
|
5
|
-
import { getSummary } from '../utils/getSummary.ts'
|
|
6
|
-
import { runHook } from '../utils/runHook.ts'
|
|
7
|
-
import { formatCommandWithArgs, formatMessage } from './utils.ts'
|
|
3
|
+
import { defineLogger, Diagnostics, type KubbHooks, logLevel as logLevelMap } from '@kubb/core'
|
|
4
|
+
import { createHookTimer, formatCommandWithArgs, formatMessage } from './utils.ts'
|
|
8
5
|
|
|
9
6
|
/**
|
|
10
7
|
* Plain console adapter for non-TTY environments with simple `console.log` output.
|
|
@@ -13,11 +10,22 @@ export const plainLogger = defineLogger({
|
|
|
13
10
|
name: 'plain',
|
|
14
11
|
install(context, options) {
|
|
15
12
|
const logLevel = options?.logLevel ?? logLevelMap.info
|
|
13
|
+
const hookTimer = createHookTimer()
|
|
16
14
|
|
|
17
15
|
function getMessage(message: string): string {
|
|
18
16
|
return formatMessage(message, logLevel)
|
|
19
17
|
}
|
|
20
18
|
|
|
19
|
+
// Registers a handler that logs a fixed message, skipped at silent level.
|
|
20
|
+
function onStep<E extends keyof KubbHooks>(event: E, message: string): void {
|
|
21
|
+
context.on(event, () => {
|
|
22
|
+
if (logLevel <= logLevelMap.silent) {
|
|
23
|
+
return
|
|
24
|
+
}
|
|
25
|
+
console.log(getMessage(message))
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
21
29
|
context.on('kubb:info', ({ message, info }) => {
|
|
22
30
|
if (logLevel <= logLevelMap.silent) {
|
|
23
31
|
return
|
|
@@ -55,8 +63,8 @@ export const plainLogger = defineLogger({
|
|
|
55
63
|
|
|
56
64
|
console.log(text)
|
|
57
65
|
|
|
58
|
-
// Show stack trace in
|
|
59
|
-
if (logLevel >= logLevelMap.
|
|
66
|
+
// Show stack trace in verbose mode (first 3 frames)
|
|
67
|
+
if (logLevel >= logLevelMap.verbose && error.stack) {
|
|
60
68
|
const frames = error.stack.split('\n').slice(1, 4)
|
|
61
69
|
for (const frame of frames) {
|
|
62
70
|
console.log(getMessage(frame.trim()))
|
|
@@ -73,30 +81,21 @@ export const plainLogger = defineLogger({
|
|
|
73
81
|
}
|
|
74
82
|
})
|
|
75
83
|
|
|
76
|
-
context.on('kubb:
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
context.on('kubb:config:start', () => {
|
|
81
|
-
if (logLevel <= logLevelMap.silent) {
|
|
84
|
+
context.on('kubb:diagnostic', ({ diagnostic }) => {
|
|
85
|
+
// Silent still surfaces errors so failures stay visible. It drops warnings and info.
|
|
86
|
+
if (logLevel <= logLevelMap.silent && diagnostic.severity !== 'error') {
|
|
82
87
|
return
|
|
83
88
|
}
|
|
84
|
-
|
|
85
|
-
const text = getMessage('Configuration started')
|
|
86
|
-
|
|
87
|
-
console.log(text)
|
|
89
|
+
console.log(getMessage(Diagnostics.formatLines(diagnostic).join('\n')))
|
|
88
90
|
})
|
|
89
91
|
|
|
90
|
-
context.on('kubb:
|
|
91
|
-
|
|
92
|
-
return
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const text = getMessage('Configuration completed')
|
|
96
|
-
|
|
97
|
-
console.log(text)
|
|
92
|
+
context.on('kubb:lifecycle:start', ({ version }) => {
|
|
93
|
+
console.log(`Kubb CLI v${version}`)
|
|
98
94
|
})
|
|
99
95
|
|
|
96
|
+
onStep('kubb:config:start', 'Configuration started')
|
|
97
|
+
onStep('kubb:config:end', 'Configuration completed')
|
|
98
|
+
|
|
100
99
|
context.on('kubb:generation:start', () => {
|
|
101
100
|
const text = getMessage('Generation started')
|
|
102
101
|
|
|
@@ -133,14 +132,14 @@ export const plainLogger = defineLogger({
|
|
|
133
132
|
console.log(text)
|
|
134
133
|
})
|
|
135
134
|
|
|
136
|
-
context.on('kubb:
|
|
135
|
+
context.on('kubb:files:processing:update', ({ files }) => {
|
|
137
136
|
if (logLevel <= logLevelMap.silent) {
|
|
138
137
|
return
|
|
139
138
|
}
|
|
140
139
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
140
|
+
for (const { file, config } of files) {
|
|
141
|
+
console.log(getMessage(`Writing ${relative(config.root, file.path)}`))
|
|
142
|
+
}
|
|
144
143
|
})
|
|
145
144
|
|
|
146
145
|
context.on('kubb:files:processing:end', () => {
|
|
@@ -159,96 +158,44 @@ export const plainLogger = defineLogger({
|
|
|
159
158
|
console.log(text)
|
|
160
159
|
})
|
|
161
160
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
161
|
+
onStep('kubb:format:start', 'Format started')
|
|
162
|
+
onStep('kubb:format:end', 'Format completed')
|
|
163
|
+
onStep('kubb:lint:start', 'Lint started')
|
|
164
|
+
onStep('kubb:lint:end', 'Lint completed')
|
|
165
|
+
onStep('kubb:hooks:start', 'Hooks started')
|
|
166
|
+
onStep('kubb:hooks:end', 'Hooks completed')
|
|
168
167
|
|
|
169
|
-
|
|
170
|
-
})
|
|
171
|
-
|
|
172
|
-
context.on('kubb:format:end', () => {
|
|
168
|
+
context.on('kubb:hook:start', ({ id, command, args }) => {
|
|
173
169
|
if (logLevel <= logLevelMap.silent) {
|
|
174
170
|
return
|
|
175
171
|
}
|
|
176
172
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
console.log(text)
|
|
180
|
-
})
|
|
181
|
-
|
|
182
|
-
context.on('kubb:lint:start', () => {
|
|
183
|
-
if (logLevel <= logLevelMap.silent) {
|
|
184
|
-
return
|
|
173
|
+
if (id) {
|
|
174
|
+
hookTimer.start(id)
|
|
185
175
|
}
|
|
186
176
|
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
console.log(text)
|
|
177
|
+
const commandWithArgs = formatCommandWithArgs(command, args)
|
|
178
|
+
console.log(getMessage(`Hook ${commandWithArgs} started`))
|
|
190
179
|
})
|
|
191
180
|
|
|
192
|
-
context.on('kubb:
|
|
181
|
+
context.on('kubb:hook:end', ({ id, command, args, success, error, stdout, stderr }) => {
|
|
193
182
|
if (logLevel <= logLevelMap.silent) {
|
|
194
183
|
return
|
|
195
184
|
}
|
|
196
185
|
|
|
197
|
-
const
|
|
186
|
+
const ms = id ? hookTimer.end(id) : undefined
|
|
187
|
+
const durationStr = ms !== undefined ? ` in ${formatMs(ms)}` : ''
|
|
198
188
|
|
|
199
|
-
console.log(text)
|
|
200
|
-
})
|
|
201
|
-
|
|
202
|
-
context.on('kubb:hook:start', async ({ id, command, args }) => {
|
|
203
189
|
const commandWithArgs = formatCommandWithArgs(command, args)
|
|
204
|
-
const text = getMessage(`Hook ${commandWithArgs} started`)
|
|
205
|
-
|
|
206
|
-
if (logLevel > logLevelMap.silent) {
|
|
207
|
-
console.log(text)
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// Skip hook execution if no id is provided (e.g., during benchmarks or tests)
|
|
211
|
-
if (!id) {
|
|
212
|
-
return
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
await runHook({
|
|
216
|
-
id,
|
|
217
|
-
command,
|
|
218
|
-
args,
|
|
219
|
-
commandWithArgs,
|
|
220
|
-
context,
|
|
221
|
-
sink: {
|
|
222
|
-
onStdout: logLevel > logLevelMap.silent ? (s) => console.log(s) : undefined,
|
|
223
|
-
onStderr: logLevel > logLevelMap.silent ? (s) => console.error(s) : undefined,
|
|
224
|
-
},
|
|
225
|
-
})
|
|
226
|
-
})
|
|
227
190
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
191
|
+
if (success) {
|
|
192
|
+
console.log(getMessage(`✓ Hook ${commandWithArgs} completed${durationStr}`))
|
|
193
|
+
} else {
|
|
194
|
+
if (stdout) console.log(stdout)
|
|
195
|
+
if (stderr) console.error(stderr)
|
|
196
|
+
const reason = error?.message ? ` (${error.message})` : ''
|
|
197
|
+
console.log(getMessage(`✗ Hook ${commandWithArgs} failed${durationStr}${reason}`))
|
|
231
198
|
}
|
|
232
|
-
|
|
233
|
-
const commandWithArgs = formatCommandWithArgs(command, args)
|
|
234
|
-
const text = getMessage(`Hook ${commandWithArgs} completed`)
|
|
235
|
-
|
|
236
|
-
console.log(text)
|
|
237
|
-
})
|
|
238
|
-
|
|
239
|
-
context.on('kubb:generation:summary', ({ config, pluginTimings, status, hrStart, failedPlugins, filesCreated }) => {
|
|
240
|
-
const summary = getSummary({
|
|
241
|
-
failedPlugins,
|
|
242
|
-
filesCreated,
|
|
243
|
-
config,
|
|
244
|
-
status,
|
|
245
|
-
hrStart,
|
|
246
|
-
pluginTimings: logLevel >= logLevelMap.verbose ? pluginTimings : undefined,
|
|
247
|
-
})
|
|
248
|
-
|
|
249
|
-
console.log(SUMMARY_SEPARATOR)
|
|
250
|
-
console.log(summary.join('\n'))
|
|
251
|
-
console.log(SUMMARY_SEPARATOR)
|
|
252
199
|
})
|
|
253
200
|
},
|
|
254
201
|
})
|
package/src/loggers/types.ts
CHANGED
|
@@ -1 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Logger adapter selected by `setupReporters` based on the runtime environment.
|
|
3
|
+
* - `'clack'`: TTY-aware output with spinners and progress bars.
|
|
4
|
+
* - `'plain'`: Plain `console.log` output for non-TTY environments.
|
|
5
|
+
*/
|
|
6
|
+
export type LoggerType = 'clack' | 'plain'
|
package/src/loggers/utils.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
+
import process from 'node:process'
|
|
1
2
|
import { styleText } from 'node:util'
|
|
2
|
-
import { canUseTTY, formatHrtime,
|
|
3
|
-
import type { Logger, LoggerContext, LoggerOptions } from '@kubb/core'
|
|
3
|
+
import { canUseTTY, formatHrtime, getElapsedMs } from '@internals/utils'
|
|
4
|
+
import type { Logger, LoggerContext, LoggerOptions, Reporter, ReporterContext } from '@kubb/core'
|
|
4
5
|
import { logLevel as logLevelMap } from '@kubb/core'
|
|
5
6
|
import { clackLogger } from './clackLogger.ts'
|
|
6
|
-
import { fileSystemLogger } from './fileSystemLogger.ts'
|
|
7
|
-
import { githubActionsLogger } from './githubActionsLogger.ts'
|
|
8
7
|
import { plainLogger } from './plainLogger.ts'
|
|
9
8
|
import type { LoggerType } from './types.ts'
|
|
10
9
|
|
|
@@ -26,20 +25,38 @@ export function formatMessage(message: string, logLevel: number): string {
|
|
|
26
25
|
}
|
|
27
26
|
|
|
28
27
|
type ProgressState = {
|
|
28
|
+
/**
|
|
29
|
+
* Total number of plugins scheduled for this generation run.
|
|
30
|
+
*/
|
|
29
31
|
totalPlugins: number
|
|
32
|
+
/**
|
|
33
|
+
* Number of plugins that have finished without error.
|
|
34
|
+
*/
|
|
30
35
|
completedPlugins: number
|
|
36
|
+
/**
|
|
37
|
+
* Number of plugins that exited with an error.
|
|
38
|
+
*/
|
|
31
39
|
failedPlugins: number
|
|
40
|
+
/**
|
|
41
|
+
* Total number of files expected to be written.
|
|
42
|
+
*/
|
|
32
43
|
totalFiles: number
|
|
44
|
+
/**
|
|
45
|
+
* Number of files written so far.
|
|
46
|
+
*/
|
|
33
47
|
processedFiles: number
|
|
48
|
+
/**
|
|
49
|
+
* `process.hrtime()` snapshot taken at the start of generation, used to compute elapsed time.
|
|
50
|
+
*/
|
|
34
51
|
hrStart: [number, number]
|
|
35
52
|
}
|
|
36
53
|
|
|
37
54
|
/**
|
|
38
|
-
* Build the progress summary line
|
|
55
|
+
* Build the progress summary line shown by the clack logger.
|
|
39
56
|
* Returns null when there is nothing to display.
|
|
40
57
|
*/
|
|
41
58
|
export function buildProgressLine(state: ProgressState): string | null {
|
|
42
|
-
const parts: string
|
|
59
|
+
const parts: Array<string> = []
|
|
43
60
|
const duration = formatHrtime(state.hrStart)
|
|
44
61
|
|
|
45
62
|
if (state.totalPlugins > 0) {
|
|
@@ -62,45 +79,143 @@ export function buildProgressLine(state: ProgressState): string | null {
|
|
|
62
79
|
return parts.join(styleText('dim', ' | '))
|
|
63
80
|
}
|
|
64
81
|
|
|
82
|
+
/**
|
|
83
|
+
* Creates the per-run progress counters used by the clack logger.
|
|
84
|
+
*/
|
|
85
|
+
export function createProgressCounters(): ProgressState {
|
|
86
|
+
return {
|
|
87
|
+
totalPlugins: 0,
|
|
88
|
+
completedPlugins: 0,
|
|
89
|
+
failedPlugins: 0,
|
|
90
|
+
totalFiles: 0,
|
|
91
|
+
processedFiles: 0,
|
|
92
|
+
hrStart: process.hrtime(),
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Resets the progress counters in place at the start/end of a generation run.
|
|
98
|
+
*/
|
|
99
|
+
export function resetProgressCounters(state: ProgressState): void {
|
|
100
|
+
state.totalPlugins = 0
|
|
101
|
+
state.completedPlugins = 0
|
|
102
|
+
state.failedPlugins = 0
|
|
103
|
+
state.totalFiles = 0
|
|
104
|
+
state.processedFiles = 0
|
|
105
|
+
state.hrStart = process.hrtime()
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Records a finished plugin against the progress counters.
|
|
110
|
+
*/
|
|
111
|
+
export function recordPluginResult(state: ProgressState, success: boolean): void {
|
|
112
|
+
if (success) {
|
|
113
|
+
state.completedPlugins++
|
|
114
|
+
} else {
|
|
115
|
+
state.failedPlugins++
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Tracks per-hook start times so a logger can report a hook's elapsed duration.
|
|
121
|
+
* Used by the plain logger, which keys timing by hook `id`.
|
|
122
|
+
*/
|
|
123
|
+
export type HookTimer = {
|
|
124
|
+
start(id: string): void
|
|
125
|
+
/**
|
|
126
|
+
* Returns the elapsed milliseconds since `start(id)`, or `undefined` when no start was recorded.
|
|
127
|
+
*/
|
|
128
|
+
end(id: string): number | undefined
|
|
129
|
+
clear(): void
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Creates a {@link HookTimer} backed by a private `id → hrtime` map.
|
|
134
|
+
*/
|
|
135
|
+
export function createHookTimer(): HookTimer {
|
|
136
|
+
const starts = new Map<string, [number, number]>()
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
start(id: string): void {
|
|
140
|
+
starts.set(id, process.hrtime())
|
|
141
|
+
},
|
|
142
|
+
end(id: string): number | undefined {
|
|
143
|
+
const hrStart = starts.get(id)
|
|
144
|
+
if (!hrStart) {
|
|
145
|
+
return undefined
|
|
146
|
+
}
|
|
147
|
+
starts.delete(id)
|
|
148
|
+
return getElapsedMs(hrStart)
|
|
149
|
+
},
|
|
150
|
+
clear(): void {
|
|
151
|
+
starts.clear()
|
|
152
|
+
},
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
65
156
|
/**
|
|
66
157
|
* Join a command and its optional args into a single display string.
|
|
67
158
|
* e.g. ("prettier", ["--write", "."]) → "prettier --write ."
|
|
68
159
|
*/
|
|
69
|
-
export function formatCommandWithArgs(command: string, args?:
|
|
160
|
+
export function formatCommandWithArgs(command: string, args?: ReadonlyArray<string>): string {
|
|
70
161
|
return args?.length ? `${command} ${args.join(' ')}` : command
|
|
71
162
|
}
|
|
72
163
|
|
|
73
164
|
function detectLogger(): LoggerType {
|
|
74
|
-
if (isGitHubActions()) {
|
|
75
|
-
return 'github-actions'
|
|
76
|
-
}
|
|
77
165
|
if (canUseTTY()) {
|
|
78
166
|
return 'clack'
|
|
79
167
|
}
|
|
80
168
|
return 'plain'
|
|
81
169
|
}
|
|
82
170
|
|
|
83
|
-
const logMapper = {
|
|
171
|
+
const logMapper: Record<LoggerType, Logger> = {
|
|
84
172
|
clack: clackLogger,
|
|
85
173
|
plain: plainLogger,
|
|
86
|
-
|
|
87
|
-
} as const satisfies Record<LoggerType, Logger>
|
|
88
|
-
|
|
89
|
-
export async function setupLogger(context: LoggerContext, { logLevel }: LoggerOptions): Promise<void> {
|
|
90
|
-
const type = detectLogger()
|
|
174
|
+
}
|
|
91
175
|
|
|
92
|
-
|
|
176
|
+
/**
|
|
177
|
+
* Bridges a {@link Reporter} onto the run's event emitter: calls `report` with each config's
|
|
178
|
+
* {@link GenerationResult} on `kubb:generation:end`. The reporter never touches the emitter.
|
|
179
|
+
*/
|
|
180
|
+
export function installReporter(context: LoggerContext, reporter: Reporter, ctx: ReporterContext): void {
|
|
181
|
+
context.on('kubb:generation:end', async ({ config, diagnostics = [], filesCreated = 0, status = 'success', hrStart = process.hrtime() }) => {
|
|
182
|
+
await reporter.report({ config, diagnostics, filesCreated, status, hrStart }, ctx)
|
|
183
|
+
})
|
|
93
184
|
|
|
94
|
-
if (
|
|
95
|
-
|
|
185
|
+
if (reporter.drain) {
|
|
186
|
+
context.on('kubb:lifecycle:end', () => reporter.drain?.(ctx))
|
|
96
187
|
}
|
|
188
|
+
}
|
|
97
189
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
190
|
+
/**
|
|
191
|
+
* Installs the live logger (the TUI view) and the given reporters (the output). The reporters are
|
|
192
|
+
* already selected by the caller (the CLI maps `--reporter` to names via `selectReporters`); this
|
|
193
|
+
* only wires them. Loggers receive hook subprocess output through `kubb:hook:line` and the
|
|
194
|
+
* `stdout`/`stderr` on `kubb:hook:end`, so nothing is returned here.
|
|
195
|
+
*
|
|
196
|
+
* Loggers and reporters are independent: the `cli` reporter also activates the env logger summary.
|
|
197
|
+
* The `json` reporter owns stdout, so the live logger and the `cli` summary are suppressed whenever
|
|
198
|
+
* `json` is among the reporters, even if `cli` is also listed.
|
|
199
|
+
*/
|
|
200
|
+
async function setupReporters(context: LoggerContext, { logLevel, reporters }: LoggerOptions & { reporters: ReadonlyArray<Reporter> }): Promise<void> {
|
|
201
|
+
const hasJson = reporters.some((reporter) => reporter.name === 'json')
|
|
202
|
+
const ctx: ReporterContext = { logLevel }
|
|
203
|
+
|
|
204
|
+
for (const reporter of reporters) {
|
|
205
|
+
if (reporter.name === 'cli') {
|
|
206
|
+
if (hasJson) {
|
|
207
|
+
continue
|
|
208
|
+
}
|
|
209
|
+
const type = detectLogger()
|
|
210
|
+
const logger = logMapper[type]
|
|
211
|
+
if (!logger) {
|
|
212
|
+
throw new Error(`Unknown adapter type: ${type}`)
|
|
213
|
+
}
|
|
214
|
+
await logger.install(context, { logLevel })
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
installReporter(context, reporter, ctx)
|
|
103
218
|
}
|
|
104
|
-
|
|
105
|
-
return cleanup
|
|
106
219
|
}
|
|
220
|
+
|
|
221
|
+
export default setupReporters
|