@kubb/cli 5.0.0-beta.62 → 5.0.0-beta.64
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/bin/kubb.js +9 -3
- package/dist/{Telemetry-DrppRqqW.cjs → Telemetry-CfPP7MYq.cjs} +6 -5
- package/dist/Telemetry-CfPP7MYq.cjs.map +1 -0
- package/dist/{Telemetry-CVdyJarO.js → Telemetry-uAr3lK_-.js} +4 -3
- package/dist/Telemetry-uAr3lK_-.js.map +1 -0
- package/dist/{define-C4AB3POr.cjs → define-Cq9hOxpK.cjs} +2 -2
- package/dist/{define-C4AB3POr.cjs.map → define-Cq9hOxpK.cjs.map} +1 -1
- package/dist/{define-C63T4jp6.js → define-GYXr00ky.js} +2 -2
- package/dist/{define-C63T4jp6.js.map → define-GYXr00ky.js.map} +1 -1
- package/dist/{errors-BsemQCMn.js → errors-Dc_d7BfX.js} +2 -2
- package/dist/{errors-BsemQCMn.js.map → errors-Dc_d7BfX.js.map} +1 -1
- package/dist/{errors-DykI11xo.cjs → errors-gxFK0vrp.cjs} +2 -2
- package/dist/{errors-DykI11xo.cjs.map → errors-gxFK0vrp.cjs.map} +1 -1
- package/dist/{generate-BI0qGM4M.js → generate-DHQnl_F1.js} +4 -4
- package/dist/{generate-BI0qGM4M.js.map → generate-DHQnl_F1.js.map} +1 -1
- package/dist/{generate-C4BcNMRq.cjs → generate-svfhwhEK.cjs} +4 -4
- package/dist/{generate-C4BcNMRq.cjs.map → generate-svfhwhEK.cjs.map} +1 -1
- package/dist/index.cjs +13 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +13 -8
- package/dist/index.js.map +1 -1
- package/dist/{init-BzS2oVRl.js → init-B02NN_88.js} +5 -5
- package/dist/{init-BzS2oVRl.js.map → init-B02NN_88.js.map} +1 -1
- package/dist/{init-DbmOhX2-.cjs → init-Bg_68Ok6.cjs} +5 -5
- package/dist/{init-DbmOhX2-.cjs.map → init-Bg_68Ok6.cjs.map} +1 -1
- package/dist/{mcp-AyUriTgO.cjs → mcp-DUzIXdRV.cjs} +7 -25
- package/dist/mcp-DUzIXdRV.cjs.map +1 -0
- package/dist/mcp-ZJQksVUU.js +21 -0
- package/dist/mcp-ZJQksVUU.js.map +1 -0
- package/dist/package-BoXPsuNH.js +6 -0
- package/dist/package-BoXPsuNH.js.map +1 -0
- package/dist/{package-DXJ46ia8.cjs → package-Cdu8eJMb.cjs} +2 -2
- package/dist/package-Cdu8eJMb.cjs.map +1 -0
- package/dist/{run-DpKny2hT.cjs → run-B4rIAnch.cjs} +7 -7
- package/dist/run-B4rIAnch.cjs.map +1 -0
- package/dist/{run-9ZhHuNZQ.cjs → run-BM1t8CSM.cjs} +10 -10
- package/dist/run-BM1t8CSM.cjs.map +1 -0
- package/dist/{run-h8NTawHO.js → run-BlFVmIJl.js} +9 -9
- package/dist/run-BlFVmIJl.js.map +1 -0
- package/dist/{run-BQO_tPlc.cjs → run-CBc896in.cjs} +5 -5
- package/dist/{run-BQO_tPlc.cjs.map → run-CBc896in.cjs.map} +1 -1
- package/dist/{run-Drs-S6sa.cjs → run-CD3BE8yP.cjs} +70 -70
- package/dist/run-CD3BE8yP.cjs.map +1 -0
- package/dist/{run-CYnDu3ch.js → run-D_dWNFhX.js} +4 -4
- package/dist/{run-CYnDu3ch.js.map → run-D_dWNFhX.js.map} +1 -1
- package/dist/{run-C_7kOXnc.js → run-DkW2VQBq.js} +68 -68
- package/dist/run-DkW2VQBq.js.map +1 -0
- package/dist/{run-BG7Giryi.js → run-DzYeru-0.js} +3 -3
- package/dist/run-DzYeru-0.js.map +1 -0
- package/dist/{tools-_Xp8-_zy.cjs → tools-CZT9wSA6.cjs} +2 -2
- package/dist/{tools-_Xp8-_zy.cjs.map → tools-CZT9wSA6.cjs.map} +1 -1
- package/dist/{tools-BU99bhi8.js → tools-D0UogMU3.js} +2 -2
- package/dist/{tools-BU99bhi8.js.map → tools-D0UogMU3.js.map} +1 -1
- package/dist/{validate-CfdPbbz_.cjs → validate-B3EwltHu.cjs} +5 -5
- package/dist/{validate-CfdPbbz_.cjs.map → validate-B3EwltHu.cjs.map} +1 -1
- package/dist/{validate-jZWMwN4r.js → validate-DXYcZCm_.js} +5 -5
- package/dist/{validate-jZWMwN4r.js.map → validate-DXYcZCm_.js.map} +1 -1
- package/package.json +7 -8
- package/dist/Telemetry-CVdyJarO.js.map +0 -1
- package/dist/Telemetry-DrppRqqW.cjs.map +0 -1
- package/dist/mcp-AyUriTgO.cjs.map +0 -1
- package/dist/mcp-BY4D1lHt.js +0 -39
- package/dist/mcp-BY4D1lHt.js.map +0 -1
- package/dist/package-BSv0yWfQ.js +0 -6
- package/dist/package-BSv0yWfQ.js.map +0 -1
- package/dist/package-DXJ46ia8.cjs.map +0 -1
- package/dist/run-9ZhHuNZQ.cjs.map +0 -1
- package/dist/run-BG7Giryi.js.map +0 -1
- package/dist/run-C_7kOXnc.js.map +0 -1
- package/dist/run-DpKny2hT.cjs.map +0 -1
- package/dist/run-Drs-S6sa.cjs.map +0 -1
- package/dist/run-h8NTawHO.js.map +0 -1
- package/src/Telemetry.ts +0 -297
- package/src/commands/generate.ts +0 -65
- package/src/commands/init.ts +0 -51
- package/src/commands/mcp.ts +0 -36
- package/src/commands/validate.ts +0 -22
- package/src/constants.ts +0 -19
- package/src/index.ts +0 -27
- package/src/loggers/clackLogger.ts +0 -392
- package/src/loggers/defineLogger.ts +0 -59
- package/src/loggers/plainLogger.ts +0 -199
- package/src/loggers/types.ts +0 -6
- package/src/loggers/utils.ts +0 -249
- package/src/runners/generate/run.ts +0 -399
- package/src/runners/generate/utils.ts +0 -229
- package/src/runners/init/run.ts +0 -210
- package/src/runners/init/utils.ts +0 -39
- package/src/runners/mcp/run.ts +0 -37
- package/src/runners/validate/run.ts +0 -63
- /package/dist/{chunk-Bx3C2hgW.cjs → rolldown-runtime-Bx3C2hgW.cjs} +0 -0
- /package/dist/{chunk-C0LytTxp.js → rolldown-runtime-C0LytTxp.js} +0 -0
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import { relative } from 'node:path'
|
|
2
|
-
import { formatMs, toCause } from '@internals/utils'
|
|
3
|
-
import { Diagnostics, type KubbHooks, logLevel as logLevelMap } from '@kubb/core'
|
|
4
|
-
import { defineLogger } from './defineLogger.ts'
|
|
5
|
-
import { createHookTimer, formatCommandWithArgs, formatMessage } from './utils.ts'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Plain console adapter for non-TTY environments, built on `console.log`.
|
|
9
|
-
*/
|
|
10
|
-
export const plainLogger = defineLogger({
|
|
11
|
-
name: 'plain',
|
|
12
|
-
install(context, options) {
|
|
13
|
-
const logLevel = options?.logLevel ?? logLevelMap.info
|
|
14
|
-
const hookTimer = createHookTimer()
|
|
15
|
-
|
|
16
|
-
function getMessage(message: string): string {
|
|
17
|
-
return formatMessage(message, logLevel)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Registers a handler that logs a fixed message, skipped at silent level.
|
|
21
|
-
function onStep<E extends keyof KubbHooks>(event: E, message: string): void {
|
|
22
|
-
context.on(event, () => {
|
|
23
|
-
if (logLevel <= logLevelMap.silent) {
|
|
24
|
-
return
|
|
25
|
-
}
|
|
26
|
-
console.log(getMessage(message))
|
|
27
|
-
})
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
context.on('kubb:info', ({ message, info }) => {
|
|
31
|
-
if (logLevel <= logLevelMap.silent) {
|
|
32
|
-
return
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const text = getMessage(['ℹ', message, info].join(' '))
|
|
36
|
-
|
|
37
|
-
console.log(text)
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
context.on('kubb:success', ({ message, info = '' }) => {
|
|
41
|
-
if (logLevel <= logLevelMap.silent) {
|
|
42
|
-
return
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const text = getMessage(['✓', message, logLevel >= logLevelMap.info ? info : undefined].filter(Boolean).join(' '))
|
|
46
|
-
|
|
47
|
-
console.log(text)
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
context.on('kubb:warn', ({ message, info }) => {
|
|
51
|
-
if (logLevel < logLevelMap.warn) {
|
|
52
|
-
return
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const text = getMessage(['⚠', message, logLevel >= logLevelMap.info ? info : undefined].filter(Boolean).join(' '))
|
|
56
|
-
|
|
57
|
-
console.log(text)
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
context.on('kubb:error', ({ error }) => {
|
|
61
|
-
const caused = toCause(error)
|
|
62
|
-
|
|
63
|
-
const text = getMessage(['✗', error.message].join(' '))
|
|
64
|
-
|
|
65
|
-
console.log(text)
|
|
66
|
-
|
|
67
|
-
// Show stack trace in verbose mode (first 3 frames)
|
|
68
|
-
if (logLevel >= logLevelMap.verbose && error.stack) {
|
|
69
|
-
const frames = error.stack.split('\n').slice(1, 4)
|
|
70
|
-
for (const frame of frames) {
|
|
71
|
-
console.log(getMessage(frame.trim()))
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (caused?.stack) {
|
|
75
|
-
console.log(`└─ caused by ${caused.message}`)
|
|
76
|
-
|
|
77
|
-
const frames = caused.stack.split('\n').slice(1, 4)
|
|
78
|
-
for (const frame of frames) {
|
|
79
|
-
console.log(getMessage(` ${frame.trim()}`))
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
context.on('kubb:diagnostic', ({ diagnostic }) => {
|
|
86
|
-
// Silent still surfaces errors so failures stay visible. It drops warnings and info.
|
|
87
|
-
if (logLevel <= logLevelMap.silent && diagnostic.severity !== 'error') {
|
|
88
|
-
return
|
|
89
|
-
}
|
|
90
|
-
console.log(getMessage(Diagnostics.formatLines(diagnostic).join('\n')))
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
context.on('kubb:lifecycle:start', ({ version }) => {
|
|
94
|
-
console.log(`Kubb CLI v${version}`)
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
context.on('kubb:generation:start', () => {
|
|
98
|
-
const text = getMessage('Generation started')
|
|
99
|
-
|
|
100
|
-
console.log(text)
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
context.on('kubb:plugin:start', ({ plugin }) => {
|
|
104
|
-
if (logLevel <= logLevelMap.silent) {
|
|
105
|
-
return
|
|
106
|
-
}
|
|
107
|
-
const text = getMessage(`Generating ${plugin.name}`)
|
|
108
|
-
|
|
109
|
-
console.log(text)
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
context.on('kubb:plugin:end', ({ plugin, duration, success }) => {
|
|
113
|
-
if (logLevel <= logLevelMap.silent) {
|
|
114
|
-
return
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const durationStr = formatMs(duration)
|
|
118
|
-
const text = getMessage(success ? `${plugin.name} completed in ${durationStr}` : `${plugin.name} failed in ${durationStr}`)
|
|
119
|
-
|
|
120
|
-
console.log(text)
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
context.on('kubb:files:processing:start', ({ files }) => {
|
|
124
|
-
if (logLevel <= logLevelMap.silent) {
|
|
125
|
-
return
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const text = getMessage(`Writing ${files.length} files`)
|
|
129
|
-
|
|
130
|
-
console.log(text)
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
context.on('kubb:files:processing:update', ({ files }) => {
|
|
134
|
-
if (logLevel <= logLevelMap.silent) {
|
|
135
|
-
return
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
for (const { file, config } of files) {
|
|
139
|
-
console.log(getMessage(`Writing ${relative(config.root, file.path)}`))
|
|
140
|
-
}
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
context.on('kubb:files:processing:end', () => {
|
|
144
|
-
if (logLevel <= logLevelMap.silent) {
|
|
145
|
-
return
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
const text = getMessage('Files written successfully')
|
|
149
|
-
|
|
150
|
-
console.log(text)
|
|
151
|
-
})
|
|
152
|
-
|
|
153
|
-
context.on('kubb:generation:end', ({ config }) => {
|
|
154
|
-
const text = getMessage(config.name ? `Generation completed for ${config.name}` : 'Generation completed')
|
|
155
|
-
|
|
156
|
-
console.log(text)
|
|
157
|
-
})
|
|
158
|
-
|
|
159
|
-
onStep('kubb:format:start', 'Format started')
|
|
160
|
-
onStep('kubb:format:end', 'Format completed')
|
|
161
|
-
onStep('kubb:lint:start', 'Lint started')
|
|
162
|
-
onStep('kubb:lint:end', 'Lint completed')
|
|
163
|
-
onStep('kubb:hooks:start', 'Hooks started')
|
|
164
|
-
onStep('kubb:hooks:end', 'Hooks completed')
|
|
165
|
-
|
|
166
|
-
context.on('kubb:hook:start', ({ id, command, args }) => {
|
|
167
|
-
if (logLevel <= logLevelMap.silent) {
|
|
168
|
-
return
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
if (id) {
|
|
172
|
-
hookTimer.start(id)
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const commandWithArgs = formatCommandWithArgs(command, args)
|
|
176
|
-
console.log(getMessage(`Hook ${commandWithArgs} started`))
|
|
177
|
-
})
|
|
178
|
-
|
|
179
|
-
context.on('kubb:hook:end', ({ id, command, args, success, error, stdout, stderr }) => {
|
|
180
|
-
if (logLevel <= logLevelMap.silent) {
|
|
181
|
-
return
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
const ms = id ? hookTimer.end(id) : undefined
|
|
185
|
-
const durationStr = ms !== undefined ? ` in ${formatMs(ms)}` : ''
|
|
186
|
-
|
|
187
|
-
const commandWithArgs = formatCommandWithArgs(command, args)
|
|
188
|
-
|
|
189
|
-
if (success) {
|
|
190
|
-
console.log(getMessage(`✓ Hook ${commandWithArgs} completed${durationStr}`))
|
|
191
|
-
} else {
|
|
192
|
-
if (stdout) console.log(stdout)
|
|
193
|
-
if (stderr) console.error(stderr)
|
|
194
|
-
const reason = error?.message ? ` (${error.message})` : ''
|
|
195
|
-
console.log(getMessage(`✗ Hook ${commandWithArgs} failed${durationStr}${reason}`))
|
|
196
|
-
}
|
|
197
|
-
})
|
|
198
|
-
},
|
|
199
|
-
})
|
package/src/loggers/types.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
import process from 'node:process'
|
|
2
|
-
import { styleText } from 'node:util'
|
|
3
|
-
import { canUseTTY, formatHrtime, getElapsedMs } from '@internals/utils'
|
|
4
|
-
import type { Reporter, ReporterContext } from '@kubb/core'
|
|
5
|
-
import { logLevel as logLevelMap } from '@kubb/core'
|
|
6
|
-
import type { Logger, LoggerContext, LoggerOptions } from './defineLogger.ts'
|
|
7
|
-
import { clackLogger } from './clackLogger.ts'
|
|
8
|
-
import { plainLogger } from './plainLogger.ts'
|
|
9
|
-
import type { LoggerType } from './types.ts'
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Optionally prefix a message with a [HH:MM:SS] timestamp when logLevel >= verbose.
|
|
13
|
-
* Shared across all logger adapters to avoid duplication.
|
|
14
|
-
*/
|
|
15
|
-
export function formatMessage(message: string, logLevel: number): string {
|
|
16
|
-
if (logLevel >= logLevelMap.verbose) {
|
|
17
|
-
const timestamp = new Date().toLocaleTimeString('en-US', {
|
|
18
|
-
hour12: false,
|
|
19
|
-
hour: '2-digit',
|
|
20
|
-
minute: '2-digit',
|
|
21
|
-
second: '2-digit',
|
|
22
|
-
})
|
|
23
|
-
return `${styleText('dim', `[${timestamp}]`)} ${message}`
|
|
24
|
-
}
|
|
25
|
-
return message
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
type ProgressState = {
|
|
29
|
-
/**
|
|
30
|
-
* Total number of plugins scheduled for this generation run.
|
|
31
|
-
*/
|
|
32
|
-
totalPlugins: number
|
|
33
|
-
/**
|
|
34
|
-
* Number of plugins that have finished without error.
|
|
35
|
-
*/
|
|
36
|
-
completedPlugins: number
|
|
37
|
-
/**
|
|
38
|
-
* Number of plugins that exited with an error.
|
|
39
|
-
*/
|
|
40
|
-
failedPlugins: number
|
|
41
|
-
/**
|
|
42
|
-
* Total number of files expected to be written.
|
|
43
|
-
*/
|
|
44
|
-
totalFiles: number
|
|
45
|
-
/**
|
|
46
|
-
* Number of files written so far.
|
|
47
|
-
*/
|
|
48
|
-
processedFiles: number
|
|
49
|
-
/**
|
|
50
|
-
* `process.hrtime()` snapshot taken at the start of generation, used to compute elapsed time.
|
|
51
|
-
*/
|
|
52
|
-
hrStart: [number, number]
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Build the progress summary line shown by the clack logger.
|
|
57
|
-
* Returns null when there is nothing to display.
|
|
58
|
-
*/
|
|
59
|
-
export function buildProgressLine(state: ProgressState): string | null {
|
|
60
|
-
const parts: Array<string> = []
|
|
61
|
-
const duration = formatHrtime(state.hrStart)
|
|
62
|
-
|
|
63
|
-
if (state.totalPlugins > 0) {
|
|
64
|
-
const pluginStr =
|
|
65
|
-
state.failedPlugins > 0
|
|
66
|
-
? `Plugins ${styleText('green', state.completedPlugins.toString())}/${state.totalPlugins} ${styleText('red', `(${state.failedPlugins} failed)`)}`
|
|
67
|
-
: `Plugins ${styleText('green', state.completedPlugins.toString())}/${state.totalPlugins}`
|
|
68
|
-
parts.push(pluginStr)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (state.totalFiles > 0) {
|
|
72
|
-
parts.push(`Files ${styleText('green', state.processedFiles.toString())}/${state.totalFiles}`)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (parts.length === 0) {
|
|
76
|
-
return null
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
parts.push(`${styleText('green', duration)} elapsed`)
|
|
80
|
-
return parts.join(styleText('dim', ' | '))
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Creates the per-run progress counters used by the clack logger.
|
|
85
|
-
*/
|
|
86
|
-
export function createProgressCounters(): ProgressState {
|
|
87
|
-
return {
|
|
88
|
-
totalPlugins: 0,
|
|
89
|
-
completedPlugins: 0,
|
|
90
|
-
failedPlugins: 0,
|
|
91
|
-
totalFiles: 0,
|
|
92
|
-
processedFiles: 0,
|
|
93
|
-
hrStart: process.hrtime(),
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Resets the progress counters in place at the start/end of a generation run.
|
|
99
|
-
*/
|
|
100
|
-
export function resetProgressCounters(state: ProgressState): void {
|
|
101
|
-
state.totalPlugins = 0
|
|
102
|
-
state.completedPlugins = 0
|
|
103
|
-
state.failedPlugins = 0
|
|
104
|
-
state.totalFiles = 0
|
|
105
|
-
state.processedFiles = 0
|
|
106
|
-
state.hrStart = process.hrtime()
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Records a finished plugin against the progress counters.
|
|
111
|
-
*/
|
|
112
|
-
export function recordPluginResult(state: ProgressState, success: boolean): void {
|
|
113
|
-
if (success) {
|
|
114
|
-
state.completedPlugins++
|
|
115
|
-
} else {
|
|
116
|
-
state.failedPlugins++
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Tracks per-hook start times so a logger can report a hook's elapsed duration.
|
|
122
|
-
* Used by the plain logger, which keys timing by hook `id`.
|
|
123
|
-
*/
|
|
124
|
-
export type HookTimer = {
|
|
125
|
-
start(id: string): void
|
|
126
|
-
/**
|
|
127
|
-
* Returns the elapsed milliseconds since `start(id)`, or `undefined` when no start was recorded.
|
|
128
|
-
*/
|
|
129
|
-
end(id: string): number | undefined
|
|
130
|
-
clear(): void
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Creates a {@link HookTimer} backed by a private `id → hrtime` map.
|
|
135
|
-
*/
|
|
136
|
-
export function createHookTimer(): HookTimer {
|
|
137
|
-
const starts = new Map<string, [number, number]>()
|
|
138
|
-
|
|
139
|
-
return {
|
|
140
|
-
start(id: string): void {
|
|
141
|
-
starts.set(id, process.hrtime())
|
|
142
|
-
},
|
|
143
|
-
end(id: string): number | undefined {
|
|
144
|
-
const hrStart = starts.get(id)
|
|
145
|
-
if (!hrStart) {
|
|
146
|
-
return undefined
|
|
147
|
-
}
|
|
148
|
-
starts.delete(id)
|
|
149
|
-
return getElapsedMs(hrStart)
|
|
150
|
-
},
|
|
151
|
-
clear(): void {
|
|
152
|
-
starts.clear()
|
|
153
|
-
},
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Join a command and its optional args into a single display string.
|
|
159
|
-
*
|
|
160
|
-
* @example
|
|
161
|
-
* `formatCommandWithArgs('prettier', ['--write', '.']) → 'prettier --write .'`
|
|
162
|
-
*/
|
|
163
|
-
export function formatCommandWithArgs(command: string, args?: ReadonlyArray<string>): string {
|
|
164
|
-
return args?.length ? `${command} ${args.join(' ')}` : command
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function detectLogger(): LoggerType {
|
|
168
|
-
if (canUseTTY()) {
|
|
169
|
-
return 'clack'
|
|
170
|
-
}
|
|
171
|
-
return 'plain'
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
const logMapper: Record<LoggerType, Logger> = {
|
|
175
|
-
clack: clackLogger,
|
|
176
|
-
plain: plainLogger,
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Bridges a {@link Reporter} onto the run's event emitter: calls `report` with each config's
|
|
181
|
-
* {@link GenerationResult} on `kubb:generation:end`. The reporter never touches the emitter.
|
|
182
|
-
*/
|
|
183
|
-
export function installReporter(context: LoggerContext, reporter: Reporter, ctx: ReporterContext): void {
|
|
184
|
-
context.on('kubb:generation:end', async ({ config, diagnostics = [], filesCreated = 0, status = 'success', hrStart = process.hrtime() }) => {
|
|
185
|
-
await reporter.report({ config, diagnostics, filesCreated, status, hrStart }, ctx)
|
|
186
|
-
})
|
|
187
|
-
|
|
188
|
-
if (reporter.drain) {
|
|
189
|
-
context.on('kubb:lifecycle:end', () => reporter.drain?.(ctx))
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Installs the live logger (the TUI view) and the given reporters (the output). The reporters are
|
|
195
|
-
* already selected by the caller (the CLI maps `--reporter` to names via `selectReporters`). This
|
|
196
|
-
* only wires them. Loggers receive hook subprocess output through `kubb:hook:line` and the
|
|
197
|
-
* `stdout`/`stderr` on `kubb:hook:end`, so nothing is returned here.
|
|
198
|
-
*
|
|
199
|
-
* Loggers and reporters are independent: the `cli` reporter also activates the env logger summary.
|
|
200
|
-
* The `json` reporter owns stdout, so the live logger and the `cli` summary are suppressed whenever
|
|
201
|
-
* `json` is among the reporters, even if `cli` is also listed.
|
|
202
|
-
*/
|
|
203
|
-
async function setupReporters(context: LoggerContext, { logLevel, reporters }: LoggerOptions & { reporters: ReadonlyArray<Reporter> }): Promise<void> {
|
|
204
|
-
const hasJson = reporters.some((reporter) => reporter.name === 'json')
|
|
205
|
-
const ctx: ReporterContext = { logLevel }
|
|
206
|
-
|
|
207
|
-
for (const reporter of reporters) {
|
|
208
|
-
if (reporter.name === 'cli') {
|
|
209
|
-
if (hasJson) {
|
|
210
|
-
continue
|
|
211
|
-
}
|
|
212
|
-
const type = detectLogger()
|
|
213
|
-
const logger = logMapper[type]
|
|
214
|
-
if (!logger) {
|
|
215
|
-
throw new Error(`Unknown adapter type: ${type}`)
|
|
216
|
-
}
|
|
217
|
-
await logger.install(context, { logLevel })
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
installReporter(context, reporter, ctx)
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
export default setupReporters
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* Picks the reporters whose `name` matches one of `names`, in the order the names are given.
|
|
228
|
-
* The config carries every available reporter, and the host selects which to activate by name
|
|
229
|
-
* (the CLI maps `--reporter` to this). Duplicate names and names without a matching reporter are
|
|
230
|
-
* skipped.
|
|
231
|
-
*/
|
|
232
|
-
export function selectReporters(reporters: ReadonlyArray<Reporter>, names: ReadonlyArray<string>): Array<Reporter> {
|
|
233
|
-
const seen = new Set<string>()
|
|
234
|
-
const selected: Array<Reporter> = []
|
|
235
|
-
|
|
236
|
-
for (const name of names) {
|
|
237
|
-
if (seen.has(name)) {
|
|
238
|
-
continue
|
|
239
|
-
}
|
|
240
|
-
seen.add(name)
|
|
241
|
-
|
|
242
|
-
const reporter = reporters.find((candidate) => candidate.name === name)
|
|
243
|
-
if (reporter) {
|
|
244
|
-
selected.push(reporter)
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
return selected
|
|
249
|
-
}
|