@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.
Files changed (146) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +171 -51
  3. package/dist/constants-BQ8LZB1P.js +23 -0
  4. package/dist/constants-BQ8LZB1P.js.map +1 -0
  5. package/dist/constants-MzEjK668.cjs +40 -0
  6. package/dist/constants-MzEjK668.cjs.map +1 -0
  7. package/dist/{define-Bdn8j5VM.cjs → define-C4AB3POr.cjs} +2 -2
  8. package/dist/{define-Bdn8j5VM.cjs.map → define-C4AB3POr.cjs.map} +1 -1
  9. package/dist/{define-Ctii4bel.js → define-C63T4jp6.js} +2 -2
  10. package/dist/{define-Ctii4bel.js.map → define-C63T4jp6.js.map} +1 -1
  11. package/dist/{errors-CjPmyZHy.js → errors-BsemQCMn.js} +2 -2
  12. package/dist/{errors-CjPmyZHy.js.map → errors-BsemQCMn.js.map} +1 -1
  13. package/dist/{errors-CLCjoSg0.cjs → errors-DykI11xo.cjs} +2 -2
  14. package/dist/{errors-CLCjoSg0.cjs.map → errors-DykI11xo.cjs.map} +1 -1
  15. package/dist/generate-CKnn3tQa.js +83 -0
  16. package/dist/generate-CKnn3tQa.js.map +1 -0
  17. package/dist/generate-Q6GMu4L8.cjs +82 -0
  18. package/dist/generate-Q6GMu4L8.cjs.map +1 -0
  19. package/dist/index.cjs +22 -15
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.ts +1 -1
  22. package/dist/index.js +22 -15
  23. package/dist/index.js.map +1 -1
  24. package/dist/init-C5iCqBwA.cjs +53 -0
  25. package/dist/init-C5iCqBwA.cjs.map +1 -0
  26. package/dist/init-DyOF6CiQ.js +53 -0
  27. package/dist/init-DyOF6CiQ.js.map +1 -0
  28. package/dist/mcp-09FvxYWS.js +39 -0
  29. package/dist/mcp-09FvxYWS.js.map +1 -0
  30. package/dist/mcp-BN5HQYdK.cjs +39 -0
  31. package/dist/mcp-BN5HQYdK.cjs.map +1 -0
  32. package/dist/package-Bm6VUbtL.js +6 -0
  33. package/dist/package-Bm6VUbtL.js.map +1 -0
  34. package/dist/{package-BmYRU2hz.cjs → package-DOVOGEEY.cjs} +2 -2
  35. package/dist/package-DOVOGEEY.cjs.map +1 -0
  36. package/dist/run-BO7phoNN.js +51 -0
  37. package/dist/run-BO7phoNN.js.map +1 -0
  38. package/dist/{init-C5sZulT6.cjs → run-BtjzfTz3.cjs} +155 -85
  39. package/dist/run-BtjzfTz3.cjs.map +1 -0
  40. package/dist/run-BzaKz_nl.js +32 -0
  41. package/dist/run-BzaKz_nl.js.map +1 -0
  42. package/dist/{init-Cag3082g.js → run-C-omuksC.js} +147 -77
  43. package/dist/run-C-omuksC.js.map +1 -0
  44. package/dist/run-CkTpemme.cjs +52 -0
  45. package/dist/run-CkTpemme.cjs.map +1 -0
  46. package/dist/run-Cl4SrSob.cjs +33 -0
  47. package/dist/run-Cl4SrSob.cjs.map +1 -0
  48. package/dist/run-CrvmI4G2.cjs +1520 -0
  49. package/dist/run-CrvmI4G2.cjs.map +1 -0
  50. package/dist/run-DvZ5i2lT.js +1517 -0
  51. package/dist/run-DvZ5i2lT.js.map +1 -0
  52. package/dist/{shell-DLzN4fRo.js → shell-DsgkfUSW.js} +2 -2
  53. package/dist/{shell-DLzN4fRo.js.map → shell-DsgkfUSW.js.map} +1 -1
  54. package/dist/{shell-475fQKaX.cjs → shell-Lh-vLWwH.cjs} +2 -2
  55. package/dist/{shell-475fQKaX.cjs.map → shell-Lh-vLWwH.cjs.map} +1 -1
  56. package/dist/validate-5atkOC73.js +26 -0
  57. package/dist/validate-5atkOC73.js.map +1 -0
  58. package/dist/validate-C6KPFEex.cjs +26 -0
  59. package/dist/validate-C6KPFEex.cjs.map +1 -0
  60. package/package.json +14 -24
  61. package/src/commands/generate.ts +27 -13
  62. package/src/commands/init.ts +34 -3
  63. package/src/commands/mcp.ts +28 -4
  64. package/src/commands/validate.ts +6 -4
  65. package/src/constants.ts +1 -86
  66. package/src/index.ts +7 -6
  67. package/src/loggers/clackLogger.ts +137 -178
  68. package/src/loggers/plainLogger.ts +49 -102
  69. package/src/loggers/types.ts +6 -1
  70. package/src/loggers/utils.ts +141 -26
  71. package/src/runners/generate/run.ts +406 -0
  72. package/src/runners/generate/utils.ts +228 -0
  73. package/src/runners/init/run.ts +210 -0
  74. package/src/{utils/packageManager.ts → runners/init/utils.ts} +12 -2
  75. package/src/runners/mcp/run.ts +37 -0
  76. package/src/runners/validate/run.ts +63 -0
  77. package/dist/agent-BcUEl9yB.js +0 -56
  78. package/dist/agent-BcUEl9yB.js.map +0 -1
  79. package/dist/agent-CS45W0kL.cjs +0 -122
  80. package/dist/agent-CS45W0kL.cjs.map +0 -1
  81. package/dist/agent-CsMvXeqI.cjs +0 -58
  82. package/dist/agent-CsMvXeqI.cjs.map +0 -1
  83. package/dist/agent-IP0eLV3C.js +0 -118
  84. package/dist/agent-IP0eLV3C.js.map +0 -1
  85. package/dist/constants-B4iBDvCe.cjs +0 -148
  86. package/dist/constants-B4iBDvCe.cjs.map +0 -1
  87. package/dist/constants-DmPrkaz8.js +0 -95
  88. package/dist/constants-DmPrkaz8.js.map +0 -1
  89. package/dist/generate-7td_hs73.cjs +0 -65
  90. package/dist/generate-7td_hs73.cjs.map +0 -1
  91. package/dist/generate-BqeFFQGD.js +0 -66
  92. package/dist/generate-BqeFFQGD.js.map +0 -1
  93. package/dist/generate-CUd1dUY5.cjs +0 -1755
  94. package/dist/generate-CUd1dUY5.cjs.map +0 -1
  95. package/dist/generate-DVmGtwWe.js +0 -1752
  96. package/dist/generate-DVmGtwWe.js.map +0 -1
  97. package/dist/init-C5sZulT6.cjs.map +0 -1
  98. package/dist/init-Cag3082g.js.map +0 -1
  99. package/dist/init-CfAn19gC.js +0 -25
  100. package/dist/init-CfAn19gC.js.map +0 -1
  101. package/dist/init-CfsYoyGe.cjs +0 -25
  102. package/dist/init-CfsYoyGe.cjs.map +0 -1
  103. package/dist/mcp-BfORW-mY.cjs +0 -47
  104. package/dist/mcp-BfORW-mY.cjs.map +0 -1
  105. package/dist/mcp-BtOV6acy.js +0 -16
  106. package/dist/mcp-BtOV6acy.js.map +0 -1
  107. package/dist/mcp-CIbuLGMx.cjs +0 -16
  108. package/dist/mcp-CIbuLGMx.cjs.map +0 -1
  109. package/dist/mcp-DtQ5o0On.js +0 -46
  110. package/dist/mcp-DtQ5o0On.js.map +0 -1
  111. package/dist/package-BmYRU2hz.cjs.map +0 -1
  112. package/dist/package-DBU5ii-k.js +0 -6
  113. package/dist/package-DBU5ii-k.js.map +0 -1
  114. package/dist/telemetry-BU25EoI-.cjs +0 -282
  115. package/dist/telemetry-BU25EoI-.cjs.map +0 -1
  116. package/dist/telemetry-CaNU4-Bf.js +0 -245
  117. package/dist/telemetry-CaNU4-Bf.js.map +0 -1
  118. package/dist/validate-CQqM9siF.js +0 -25
  119. package/dist/validate-CQqM9siF.js.map +0 -1
  120. package/dist/validate-DBXLaLIn.cjs +0 -34
  121. package/dist/validate-DBXLaLIn.cjs.map +0 -1
  122. package/dist/validate-DI23zgmL.js +0 -33
  123. package/dist/validate-DI23zgmL.js.map +0 -1
  124. package/dist/validate-DwX4LzYq.cjs +0 -25
  125. package/dist/validate-DwX4LzYq.cjs.map +0 -1
  126. package/src/commands/agent/start.ts +0 -47
  127. package/src/commands/agent.ts +0 -8
  128. package/src/loggers/fileSystemLogger.ts +0 -138
  129. package/src/loggers/githubActionsLogger.ts +0 -379
  130. package/src/runners/agent.ts +0 -155
  131. package/src/runners/generate.ts +0 -333
  132. package/src/runners/init.ts +0 -296
  133. package/src/runners/mcp.ts +0 -51
  134. package/src/runners/validate.ts +0 -39
  135. package/src/types.ts +0 -11
  136. package/src/utils/Writables.ts +0 -17
  137. package/src/utils/executeHooks.ts +0 -45
  138. package/src/utils/flags.ts +0 -9
  139. package/src/utils/getConfig.ts +0 -10
  140. package/src/utils/getCosmiConfig.ts +0 -75
  141. package/src/utils/getSummary.ts +0 -68
  142. package/src/utils/runHook.ts +0 -91
  143. package/src/utils/telemetry.ts +0 -273
  144. package/src/utils/watcher.ts +0 -19
  145. /package/dist/{chunk-ByKO4r7w.cjs → chunk-Bx3C2hgW.cjs} +0 -0
  146. /package/dist/{chunk--u3MIqq1.js → chunk-C0LytTxp.js} +0 -0
@@ -1,91 +0,0 @@
1
- import type { AsyncEventEmitter } from '@internals/utils'
2
- import { toError } from '@internals/utils'
3
- import type { KubbHooks } from '@kubb/core'
4
- import { NonZeroExitError, x } from 'tinyexec'
5
-
6
- type HookOutputSink = {
7
- /** Called for each streamed stdout line while the hook runs (optional). */
8
- onLine?: (line: string) => void
9
- /** Called on stderr after failure (optional). */
10
- onStderr?: (text: string) => void
11
- /** Called on stdout after failure (optional). */
12
- onStdout?: (text: string) => void
13
- }
14
-
15
- type RunHookOptions = {
16
- id: string
17
- command: string
18
- args?: readonly string[]
19
- commandWithArgs: string
20
- context: AsyncEventEmitter<KubbHooks>
21
- /** When true the process output is streamed line-by-line via onLine. */
22
- stream?: boolean
23
- sink?: HookOutputSink
24
- }
25
-
26
- /**
27
- * Executes a hook command, emits debug and completion events, and forwards output to an optional sink.
28
- */
29
- export async function runHook({ id, command, args, commandWithArgs, context, stream = false, sink }: RunHookOptions): Promise<void> {
30
- try {
31
- const proc = x(command, [...(args ?? [])], {
32
- nodeOptions: { detached: process.platform !== 'win32' },
33
- throwOnError: true,
34
- })
35
-
36
- if (stream && sink?.onLine) {
37
- for await (const line of proc) {
38
- sink.onLine(line)
39
- }
40
- }
41
-
42
- const result = await proc
43
-
44
- await context.emit('kubb:debug', {
45
- date: new Date(),
46
- logs: [result.stdout.trimEnd()],
47
- })
48
-
49
- await context.emit('kubb:hook:end', {
50
- command,
51
- args,
52
- id,
53
- success: true,
54
- error: null,
55
- })
56
- } catch (err) {
57
- if (!(err instanceof NonZeroExitError)) {
58
- await context.emit('kubb:hook:end', {
59
- command,
60
- args,
61
- id,
62
- success: false,
63
- error: toError(err),
64
- })
65
- await context.emit('kubb:error', { error: toError(err) })
66
- return
67
- }
68
-
69
- const stderr = err.output?.stderr ?? ''
70
- const stdout = err.output?.stdout ?? ''
71
-
72
- await context.emit('kubb:debug', {
73
- date: new Date(),
74
- logs: [stdout, stderr].filter(Boolean),
75
- })
76
-
77
- if (stderr) sink?.onStderr?.(stderr)
78
- if (stdout) sink?.onStdout?.(stdout)
79
-
80
- const errorMessage = new Error(`Hook execute failed: ${commandWithArgs}`)
81
-
82
- await context.emit('kubb:hook:end', {
83
- command,
84
- args,
85
- id,
86
- success: false,
87
- error: errorMessage,
88
- })
89
- await context.emit('kubb:error', { error: errorMessage })
90
- }
91
- }
@@ -1,273 +0,0 @@
1
- import { randomBytes } from 'node:crypto'
2
- import os from 'node:os'
3
- import process from 'node:process'
4
- import { executeIfOnline, isCIEnvironment } from '@internals/utils'
5
- import { OTLP_ENDPOINT } from '../constants.ts'
6
-
7
- // OpenTelemetry OTLP JSON types
8
- // https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/trace/v1/trace.proto
9
- // https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/common/v1/common.proto
10
-
11
- type OtlpStringValue = { stringValue: string }
12
- type OtlpBoolValue = { boolValue: boolean }
13
- type OtlpIntValue = { intValue: number }
14
- type OtlpDoubleValue = { doubleValue: number }
15
- type OtlpBytesValue = { bytesValue: string }
16
- type OtlpArrayValue = { arrayValue: { values: OtlpAnyValue[] } }
17
- type OtlpKvListValue = { kvlistValue: { values: OtlpKeyValue[] } }
18
-
19
- type OtlpAnyValue = OtlpStringValue | OtlpBoolValue | OtlpIntValue | OtlpDoubleValue | OtlpBytesValue | OtlpArrayValue | OtlpKvListValue
20
-
21
- type OtlpKeyValue = {
22
- key: string
23
- value: OtlpAnyValue
24
- }
25
-
26
- type OtlpResource = {
27
- attributes: OtlpKeyValue[]
28
- droppedAttributesCount?: number
29
- }
30
-
31
- type OtlpInstrumentationScope = {
32
- name: string
33
- version?: string
34
- attributes?: OtlpKeyValue[]
35
- droppedAttributesCount?: number
36
- }
37
-
38
- /** https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/trace/v1/trace.proto#L103 */
39
- type OtlpSpanKind = 0 | 1 | 2 | 3 | 4 | 5
40
-
41
- /** 0 = STATUS_CODE_UNSET, 1 = STATUS_CODE_OK, 2 = STATUS_CODE_ERROR */
42
- type OtlpStatusCode = 0 | 1 | 2
43
-
44
- type OtlpStatus = {
45
- code: OtlpStatusCode
46
- message?: string
47
- }
48
-
49
- type OtlpSpan = {
50
- traceId: string
51
- spanId: string
52
- traceState?: string
53
- parentSpanId?: string
54
- name: string
55
- kind: OtlpSpanKind
56
- startTimeUnixNano: string
57
- endTimeUnixNano: string
58
- attributes?: OtlpKeyValue[]
59
- droppedAttributesCount?: number
60
- events?: OtlpSpanEvent[]
61
- droppedEventsCount?: number
62
- links?: OtlpSpanLink[]
63
- droppedLinksCount?: number
64
- status?: OtlpStatus
65
- }
66
-
67
- type OtlpSpanEvent = {
68
- timeUnixNano: string
69
- name: string
70
- attributes?: OtlpKeyValue[]
71
- droppedAttributesCount?: number
72
- }
73
-
74
- type OtlpSpanLink = {
75
- traceId: string
76
- spanId: string
77
- traceState?: string
78
- attributes?: OtlpKeyValue[]
79
- droppedAttributesCount?: number
80
- }
81
-
82
- type OtlpScopeSpans = {
83
- scope: OtlpInstrumentationScope
84
- spans: OtlpSpan[]
85
- schemaUrl?: string
86
- }
87
-
88
- type OtlpResourceSpans = {
89
- resource: OtlpResource
90
- scopeSpans: OtlpScopeSpans[]
91
- schemaUrl?: string
92
- }
93
-
94
- /** Root payload sent to POST /v1/traces */
95
- type OtlpExportTraceServiceRequest = {
96
- resourceSpans: OtlpResourceSpans[]
97
- }
98
-
99
- export type TelemetryPlugin = {
100
- name: string
101
- options: Record<string, unknown>
102
- }
103
-
104
- type TelemetryEvent = {
105
- command: string
106
- kubbVersion: string
107
- nodeVersion: string
108
- platform: string
109
- ci: boolean
110
- plugins: TelemetryPlugin[]
111
- duration: number
112
- filesCreated: number
113
- status: 'success' | 'failed'
114
- }
115
-
116
- /**
117
- * Detect whether the current process is running inside a CI environment.
118
- * Delegates to the canonical isCIEnvironment() from envDetection.
119
- */
120
- export function isCi(): boolean {
121
- return isCIEnvironment()
122
- }
123
-
124
- /**
125
- * Check if telemetry is disabled via DO_NOT_TRACK or KUBB_DISABLE_TELEMETRY.
126
- * Respects the standard DO_NOT_TRACK convention used across development tools.
127
- */
128
- export function isTelemetryDisabled(): boolean {
129
- return (
130
- process.env['DO_NOT_TRACK'] === '1' ||
131
- process.env['DO_NOT_TRACK'] === 'true' ||
132
- process.env['KUBB_DISABLE_TELEMETRY'] === '1' ||
133
- process.env['KUBB_DISABLE_TELEMETRY'] === 'true'
134
- )
135
- }
136
-
137
- /**
138
- * Convert a TelemetryEvent into an OTLP-compatible JSON trace payload.
139
- * See https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/
140
- */
141
- export function buildOtlpPayload(event: TelemetryEvent): OtlpExportTraceServiceRequest {
142
- const traceId = randomBytes(16).toString('hex')
143
- const spanId = randomBytes(8).toString('hex')
144
- const endTimeNs = BigInt(Date.now()) * 1_000_000n
145
- const startTimeNs = endTimeNs - BigInt(event.duration) * 1_000_000n
146
-
147
- const attributes: OtlpKeyValue[] = [
148
- { key: 'kubb.command', value: { stringValue: event.command } },
149
- { key: 'kubb.version', value: { stringValue: event.kubbVersion } },
150
- { key: 'kubb.node_version', value: { stringValue: event.nodeVersion } },
151
- { key: 'kubb.platform', value: { stringValue: event.platform } },
152
- { key: 'kubb.ci', value: { boolValue: event.ci } },
153
- { key: 'kubb.files_created', value: { intValue: event.filesCreated } },
154
- { key: 'kubb.status', value: { stringValue: event.status } },
155
- {
156
- key: 'kubb.plugins',
157
- value: {
158
- arrayValue: {
159
- values: event.plugins.map(
160
- (p): OtlpKvListValue => ({
161
- kvlistValue: {
162
- values: [
163
- { key: 'name', value: { stringValue: p.name } },
164
- {
165
- key: 'options',
166
- value: {
167
- stringValue: JSON.stringify({
168
- ...p.options,
169
- usedEnumNames: undefined,
170
- }),
171
- },
172
- },
173
- ],
174
- },
175
- }),
176
- ),
177
- },
178
- },
179
- },
180
- ]
181
-
182
- return {
183
- resourceSpans: [
184
- {
185
- resource: {
186
- attributes: [
187
- { key: 'service.name', value: { stringValue: 'kubb-cli' } },
188
- {
189
- key: 'service.version',
190
- value: { stringValue: event.kubbVersion },
191
- },
192
- { key: 'telemetry.sdk.language', value: { stringValue: 'nodejs' } },
193
- ],
194
- },
195
- scopeSpans: [
196
- {
197
- scope: { name: 'kubb-cli', version: event.kubbVersion },
198
- spans: [
199
- {
200
- traceId,
201
- spanId,
202
- name: event.command,
203
- kind: 1 satisfies OtlpSpanKind,
204
- startTimeUnixNano: String(startTimeNs),
205
- endTimeUnixNano: String(endTimeNs),
206
- attributes,
207
- status: {
208
- code: (event.status === 'success' ? 1 : 2) satisfies OtlpStatusCode,
209
- },
210
- },
211
- ],
212
- },
213
- ],
214
- },
215
- ],
216
- }
217
- }
218
-
219
- /**
220
- * Send an anonymous telemetry event to the Kubb OTLP endpoint.
221
- * Respects DO_NOT_TRACK and KUBB_DISABLE_TELEMETRY environment variables.
222
- * Fails silently to never interrupt the generation process.
223
- */
224
- export async function sendTelemetry(event: TelemetryEvent): Promise<void> {
225
- if (isTelemetryDisabled()) {
226
- return
227
- }
228
-
229
- await executeIfOnline(async () => {
230
- try {
231
- await fetch(`${OTLP_ENDPOINT}/v1/traces`, {
232
- method: 'POST',
233
- headers: {
234
- 'Content-Type': 'application/json',
235
- 'Kubb-Telemetry-Version': '1',
236
- 'Kubb-Telemetry-Source': 'kubb-cli',
237
- },
238
- body: JSON.stringify(buildOtlpPayload(event)),
239
- signal: AbortSignal.timeout(5_000),
240
- })
241
- } catch (_e) {
242
- // Fail silently – telemetry must never break the CLI
243
- }
244
- })
245
- }
246
-
247
- /**
248
- * Build an anonymous telemetry payload from a completed generation run.
249
- * No file paths, OpenAPI specs, or secrets are included.
250
- */
251
- export function buildTelemetryEvent(options: {
252
- command: 'generate' | 'mcp' | 'validate' | 'agent'
253
- kubbVersion: string
254
- plugins?: TelemetryPlugin[]
255
- hrStart: [number, number]
256
- filesCreated?: number
257
- status: 'success' | 'failed'
258
- }): TelemetryEvent {
259
- const [seconds, nanoseconds] = process.hrtime(options.hrStart)
260
- const duration = Math.round(seconds * 1000 + nanoseconds / 1e6)
261
-
262
- return {
263
- command: options.command,
264
- kubbVersion: options.kubbVersion,
265
- nodeVersion: process.versions.node.split('.')[0] as string,
266
- platform: os.platform(),
267
- ci: isCi(),
268
- plugins: options.plugins ?? [],
269
- duration,
270
- filesCreated: options.filesCreated ?? 0,
271
- status: options.status,
272
- }
273
- }
@@ -1,19 +0,0 @@
1
- import { styleText } from 'node:util'
2
- import { WATCHER_IGNORED_PATHS } from '../constants.ts'
3
-
4
- export async function startWatcher(path: string[], cb: (path: string[]) => Promise<void>): Promise<void> {
5
- const { watch } = await import('chokidar')
6
- const watcher = watch(path, {
7
- ignorePermissionErrors: true,
8
- ignored: WATCHER_IGNORED_PATHS,
9
- })
10
- watcher.on('all', async (type, file) => {
11
- console.log(styleText('yellow', styleText('bold', `Change detected: ${type} ${file}`)))
12
-
13
- try {
14
- await cb(path)
15
- } catch (_e) {
16
- console.log(styleText('red', 'Watcher failed'))
17
- }
18
- })
19
- }
File without changes
File without changes