@kubb/cli 5.0.0-beta.6 → 5.0.0-beta.61
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 +170 -51
- package/dist/Telemetry-CVdyJarO.js +283 -0
- package/dist/Telemetry-CVdyJarO.js.map +1 -0
- package/dist/Telemetry-DrppRqqW.cjs +320 -0
- package/dist/Telemetry-DrppRqqW.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-BB2Q7I9s.cjs → generate-CJuBlTeJ.cjs} +22 -17
- package/dist/generate-CJuBlTeJ.cjs.map +1 -0
- package/dist/{generate-BmulGxIM.js → generate-DAePC4G2.js} +22 -17
- package/dist/generate-DAePC4G2.js.map +1 -0
- package/dist/index.cjs +10 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +10 -27
- package/dist/index.js.map +1 -1
- package/dist/{init-BTp9if7K.js → init-C8m7Z_W8.js} +6 -6
- package/dist/{init-BTp9if7K.js.map → init-C8m7Z_W8.js.map} +1 -1
- package/dist/{init-Dpg8e1HN.cjs → init-T1DC44PT.cjs} +6 -6
- package/dist/{init-Dpg8e1HN.cjs.map → init-T1DC44PT.cjs.map} +1 -1
- package/dist/{mcp-wpl6sYYR.cjs → mcp-B60MeTmD.cjs} +6 -6
- package/dist/{mcp-wpl6sYYR.cjs.map → mcp-B60MeTmD.cjs.map} +1 -1
- package/dist/{mcp-C9RoU-Dg.js → mcp-lEYflz1a.js} +6 -6
- package/dist/{mcp-C9RoU-Dg.js.map → mcp-lEYflz1a.js.map} +1 -1
- package/dist/package-BynuV_3t.js +6 -0
- package/dist/package-BynuV_3t.js.map +1 -0
- package/dist/{package-iheSdfas.cjs → package-QUV6JOtx.cjs} +2 -2
- package/dist/package-QUV6JOtx.cjs.map +1 -0
- package/dist/run-9ZhHuNZQ.cjs +33 -0
- package/dist/run-9ZhHuNZQ.cjs.map +1 -0
- package/dist/run-BG7Giryi.js +296 -0
- package/dist/run-BG7Giryi.js.map +1 -0
- package/dist/{validate-BU4fPTMc.cjs → run-BQO_tPlc.cjs} +25 -20
- package/dist/run-BQO_tPlc.cjs.map +1 -0
- package/dist/run-C-5oRB_f.cjs +1380 -0
- package/dist/run-C-5oRB_f.cjs.map +1 -0
- package/dist/run-CYnDu3ch.js +51 -0
- package/dist/run-CYnDu3ch.js.map +1 -0
- package/dist/run-Da0AZlgo.js +1377 -0
- package/dist/run-Da0AZlgo.js.map +1 -0
- package/dist/run-DpKny2hT.cjs +300 -0
- package/dist/run-DpKny2hT.cjs.map +1 -0
- package/dist/run-h8NTawHO.js +32 -0
- package/dist/run-h8NTawHO.js.map +1 -0
- package/dist/tools-BU99bhi8.js +152 -0
- package/dist/tools-BU99bhi8.js.map +1 -0
- package/dist/tools-_Xp8-_zy.cjs +175 -0
- package/dist/tools-_Xp8-_zy.cjs.map +1 -0
- package/dist/{validate-BfJoCxrC.js → validate-BhDi3x5e.js} +6 -6
- package/dist/{validate-BfJoCxrC.js.map → validate-BhDi3x5e.js.map} +1 -1
- package/dist/{validate-DIDBROB2.cjs → validate-CUEvWAyG.cjs} +6 -6
- package/dist/{validate-DIDBROB2.cjs.map → validate-CUEvWAyG.cjs.map} +1 -1
- package/package.json +12 -27
- package/src/Telemetry.ts +297 -0
- package/src/commands/generate.ts +18 -12
- package/src/commands/init.ts +2 -2
- package/src/commands/mcp.ts +2 -2
- package/src/commands/validate.ts +2 -2
- package/src/constants.ts +2 -35
- package/src/index.ts +5 -21
- package/src/loggers/clackLogger.ts +136 -202
- package/src/loggers/defineLogger.ts +59 -0
- package/src/loggers/plainLogger.ts +48 -103
- package/src/loggers/types.ts +6 -1
- package/src/loggers/utils.ts +167 -24
- package/src/runners/generate/run.ts +399 -0
- package/src/runners/generate/utils.ts +229 -0
- package/src/runners/{init.ts → init/run.ts} +81 -78
- package/src/runners/init/utils.ts +39 -0
- package/src/runners/mcp/run.ts +37 -0
- package/src/runners/{validate.ts → validate/run.ts} +25 -20
- package/dist/agent-BJEvbSiP.js +0 -68
- package/dist/agent-BJEvbSiP.js.map +0 -1
- package/dist/agent-CXNO6dgj.cjs +0 -70
- package/dist/agent-CXNO6dgj.cjs.map +0 -1
- package/dist/agent-D9CKYh4K.cjs +0 -122
- package/dist/agent-D9CKYh4K.cjs.map +0 -1
- package/dist/agent-VXKxLCho.js +0 -118
- package/dist/agent-VXKxLCho.js.map +0 -1
- package/dist/constants-BPJBMT_6.js +0 -45
- package/dist/constants-BPJBMT_6.js.map +0 -1
- package/dist/constants-BYGmiFs0.cjs +0 -139
- package/dist/constants-BYGmiFs0.cjs.map +0 -1
- package/dist/constants-DSJ-Xrbv.js +0 -116
- package/dist/constants-DSJ-Xrbv.js.map +0 -1
- package/dist/constants-Rcaqzyd-.cjs +0 -80
- package/dist/constants-Rcaqzyd-.cjs.map +0 -1
- package/dist/generate-BB2Q7I9s.cjs.map +0 -1
- package/dist/generate-B_p5dl68.cjs +0 -1755
- package/dist/generate-B_p5dl68.cjs.map +0 -1
- package/dist/generate-BmulGxIM.js.map +0 -1
- package/dist/generate-DAsdUw3z.js +0 -1752
- package/dist/generate-DAsdUw3z.js.map +0 -1
- package/dist/init-CJ80lKSP.cjs +0 -239
- package/dist/init-CJ80lKSP.cjs.map +0 -1
- package/dist/init-DCqcEq86.js +0 -235
- package/dist/init-DCqcEq86.js.map +0 -1
- package/dist/mcp-D1llTaRM.cjs +0 -50
- package/dist/mcp-D1llTaRM.cjs.map +0 -1
- package/dist/mcp-DNUw8nqb.js +0 -49
- package/dist/mcp-DNUw8nqb.js.map +0 -1
- package/dist/package-iheSdfas.cjs.map +0 -1
- package/dist/package-vLafMWCe.js +0 -6
- package/dist/package-vLafMWCe.js.map +0 -1
- package/dist/shell-475fQKaX.cjs +0 -62
- package/dist/shell-475fQKaX.cjs.map +0 -1
- package/dist/shell-DLzN4fRo.js +0 -51
- package/dist/shell-DLzN4fRo.js.map +0 -1
- package/dist/telemetry-BLX0NzRk.cjs +0 -282
- package/dist/telemetry-BLX0NzRk.cjs.map +0 -1
- package/dist/telemetry-juq4QBf7.js +0 -245
- package/dist/telemetry-juq4QBf7.js.map +0 -1
- package/dist/validate-BU4fPTMc.cjs.map +0 -1
- package/dist/validate-k9s_hFah.js +0 -46
- package/dist/validate-k9s_hFah.js.map +0 -1
- package/src/commands/agent/start.ts +0 -50
- package/src/commands/agent.ts +0 -10
- 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/mcp.ts +0 -56
- 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/packageManager.ts +0 -23
- 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
package/src/Telemetry.ts
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto'
|
|
2
|
+
import os from 'node:os'
|
|
3
|
+
import process from 'node:process'
|
|
4
|
+
import { isCIEnvironment, runtime } 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: Array<OtlpAnyValue> } }
|
|
17
|
+
type OtlpKvListValue = { kvlistValue: { values: Array<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: Array<OtlpKeyValue>
|
|
28
|
+
droppedAttributesCount?: number
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type OtlpInstrumentationScope = {
|
|
32
|
+
name: string
|
|
33
|
+
version?: string
|
|
34
|
+
attributes?: Array<OtlpKeyValue>
|
|
35
|
+
droppedAttributesCount?: number
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @see https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/trace/v1/trace.proto#L103
|
|
40
|
+
*/
|
|
41
|
+
type OtlpSpanKind = 0 | 1 | 2 | 3 | 4 | 5
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Span status code.
|
|
45
|
+
* - `0` is unset
|
|
46
|
+
* - `1` is OK
|
|
47
|
+
* - `2` is error
|
|
48
|
+
*/
|
|
49
|
+
type OtlpStatusCode = 0 | 1 | 2
|
|
50
|
+
|
|
51
|
+
type OtlpStatus = {
|
|
52
|
+
code: OtlpStatusCode
|
|
53
|
+
message?: string
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
type OtlpSpan = {
|
|
57
|
+
traceId: string
|
|
58
|
+
spanId: string
|
|
59
|
+
traceState?: string
|
|
60
|
+
parentSpanId?: string
|
|
61
|
+
name: string
|
|
62
|
+
kind: OtlpSpanKind
|
|
63
|
+
startTimeUnixNano: string
|
|
64
|
+
endTimeUnixNano: string
|
|
65
|
+
attributes?: Array<OtlpKeyValue>
|
|
66
|
+
droppedAttributesCount?: number
|
|
67
|
+
events?: Array<OtlpSpanEvent>
|
|
68
|
+
droppedEventsCount?: number
|
|
69
|
+
links?: Array<OtlpSpanLink>
|
|
70
|
+
droppedLinksCount?: number
|
|
71
|
+
status?: OtlpStatus
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
type OtlpSpanEvent = {
|
|
75
|
+
timeUnixNano: string
|
|
76
|
+
name: string
|
|
77
|
+
attributes?: Array<OtlpKeyValue>
|
|
78
|
+
droppedAttributesCount?: number
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
type OtlpSpanLink = {
|
|
82
|
+
traceId: string
|
|
83
|
+
spanId: string
|
|
84
|
+
traceState?: string
|
|
85
|
+
attributes?: Array<OtlpKeyValue>
|
|
86
|
+
droppedAttributesCount?: number
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
type OtlpScopeSpans = {
|
|
90
|
+
scope: OtlpInstrumentationScope
|
|
91
|
+
spans: Array<OtlpSpan>
|
|
92
|
+
schemaUrl?: string
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
type OtlpResourceSpans = {
|
|
96
|
+
resource: OtlpResource
|
|
97
|
+
scopeSpans: Array<OtlpScopeSpans>
|
|
98
|
+
schemaUrl?: string
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Root payload sent to POST /v1/traces.
|
|
103
|
+
*/
|
|
104
|
+
type OtlpExportTraceServiceRequest = {
|
|
105
|
+
resourceSpans: Array<OtlpResourceSpans>
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Anonymous plugin name and options snapshot sent with each telemetry event.
|
|
110
|
+
*/
|
|
111
|
+
export type TelemetryPlugin = {
|
|
112
|
+
/**
|
|
113
|
+
* Plugin name as registered in the Kubb config, e.g. `'@kubb/plugin-ts'`.
|
|
114
|
+
*/
|
|
115
|
+
name: string
|
|
116
|
+
/**
|
|
117
|
+
* Anonymized snapshot of the plugin options. Values are included but cannot be traced back to a user.
|
|
118
|
+
*/
|
|
119
|
+
options: Record<string, unknown>
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export type TelemetryEvent = {
|
|
123
|
+
command: string
|
|
124
|
+
kubbVersion: string
|
|
125
|
+
nodeVersion: string
|
|
126
|
+
/**
|
|
127
|
+
* Name of the JavaScript runtime that executed the run, `'bun'`, `'deno'`, or `'node'`.
|
|
128
|
+
*/
|
|
129
|
+
runtime: string
|
|
130
|
+
/**
|
|
131
|
+
* Major version of the active runtime, e.g. `'1'` under Bun or `'22'` under Node.
|
|
132
|
+
*/
|
|
133
|
+
runtimeVersion: string
|
|
134
|
+
platform: string
|
|
135
|
+
ci: boolean
|
|
136
|
+
plugins: Array<TelemetryPlugin>
|
|
137
|
+
duration: number
|
|
138
|
+
filesCreated: number
|
|
139
|
+
status: 'success' | 'failed'
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Anonymous OTLP usage telemetry for a Kubb run. The API is static, so call it as `Telemetry.build(...)`
|
|
144
|
+
* and `Telemetry.send(...)`. No file paths, OpenAPI specs, or secrets are sent, and sending fails
|
|
145
|
+
* silently so a failed request never breaks the run.
|
|
146
|
+
*/
|
|
147
|
+
export class Telemetry {
|
|
148
|
+
/**
|
|
149
|
+
* Returns `true` when telemetry is disabled via `DO_NOT_TRACK` or `KUBB_DISABLE_TELEMETRY`.
|
|
150
|
+
*/
|
|
151
|
+
static get isDisabled(): boolean {
|
|
152
|
+
return (
|
|
153
|
+
process.env['DO_NOT_TRACK'] === '1' ||
|
|
154
|
+
process.env['DO_NOT_TRACK'] === 'true' ||
|
|
155
|
+
process.env['KUBB_DISABLE_TELEMETRY'] === '1' ||
|
|
156
|
+
process.env['KUBB_DISABLE_TELEMETRY'] === 'true'
|
|
157
|
+
)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Build an anonymous telemetry payload from a completed generation run.
|
|
162
|
+
*/
|
|
163
|
+
static build(options: {
|
|
164
|
+
command: 'generate' | 'mcp' | 'validate' | 'agent'
|
|
165
|
+
kubbVersion: string
|
|
166
|
+
plugins?: Array<TelemetryPlugin>
|
|
167
|
+
hrStart: [number, number]
|
|
168
|
+
filesCreated?: number
|
|
169
|
+
status: 'success' | 'failed'
|
|
170
|
+
}): TelemetryEvent {
|
|
171
|
+
const [seconds, nanoseconds] = process.hrtime(options.hrStart)
|
|
172
|
+
const duration = Math.round(seconds * 1000 + nanoseconds / 1e6)
|
|
173
|
+
|
|
174
|
+
return {
|
|
175
|
+
command: options.command,
|
|
176
|
+
kubbVersion: options.kubbVersion,
|
|
177
|
+
nodeVersion: process.versions.node.split('.')[0] as string,
|
|
178
|
+
runtime: runtime.name,
|
|
179
|
+
runtimeVersion: runtime.version.split('.')[0] as string,
|
|
180
|
+
platform: os.platform(),
|
|
181
|
+
ci: isCIEnvironment(),
|
|
182
|
+
plugins: options.plugins ?? [],
|
|
183
|
+
duration,
|
|
184
|
+
filesCreated: options.filesCreated ?? 0,
|
|
185
|
+
status: options.status,
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Convert a {@link TelemetryEvent} into an OTLP-compatible JSON trace payload.
|
|
191
|
+
* See https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/
|
|
192
|
+
*/
|
|
193
|
+
static buildOtlpPayload(event: TelemetryEvent): OtlpExportTraceServiceRequest {
|
|
194
|
+
const traceId = randomBytes(16).toString('hex')
|
|
195
|
+
const spanId = randomBytes(8).toString('hex')
|
|
196
|
+
const endTimeNs = BigInt(Date.now()) * 1_000_000n
|
|
197
|
+
const startTimeNs = endTimeNs - BigInt(event.duration) * 1_000_000n
|
|
198
|
+
|
|
199
|
+
const attributes: Array<OtlpKeyValue> = [
|
|
200
|
+
{ key: 'kubb.command', value: { stringValue: event.command } },
|
|
201
|
+
{ key: 'kubb.version', value: { stringValue: event.kubbVersion } },
|
|
202
|
+
{ key: 'kubb.node_version', value: { stringValue: event.nodeVersion } },
|
|
203
|
+
{ key: 'kubb.runtime', value: { stringValue: event.runtime } },
|
|
204
|
+
{ key: 'kubb.runtime_version', value: { stringValue: event.runtimeVersion } },
|
|
205
|
+
{ key: 'kubb.platform', value: { stringValue: event.platform } },
|
|
206
|
+
{ key: 'kubb.ci', value: { boolValue: event.ci } },
|
|
207
|
+
{ key: 'kubb.files_created', value: { intValue: event.filesCreated } },
|
|
208
|
+
{ key: 'kubb.status', value: { stringValue: event.status } },
|
|
209
|
+
{
|
|
210
|
+
key: 'kubb.plugins',
|
|
211
|
+
value: {
|
|
212
|
+
arrayValue: {
|
|
213
|
+
values: event.plugins.map(
|
|
214
|
+
(p): OtlpKvListValue => ({
|
|
215
|
+
kvlistValue: {
|
|
216
|
+
values: [
|
|
217
|
+
{ key: 'name', value: { stringValue: p.name } },
|
|
218
|
+
{
|
|
219
|
+
key: 'options',
|
|
220
|
+
value: {
|
|
221
|
+
stringValue: JSON.stringify({
|
|
222
|
+
...p.options,
|
|
223
|
+
usedEnumNames: undefined,
|
|
224
|
+
}),
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
],
|
|
228
|
+
},
|
|
229
|
+
}),
|
|
230
|
+
),
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
},
|
|
234
|
+
]
|
|
235
|
+
|
|
236
|
+
return {
|
|
237
|
+
resourceSpans: [
|
|
238
|
+
{
|
|
239
|
+
resource: {
|
|
240
|
+
attributes: [
|
|
241
|
+
{ key: 'service.name', value: { stringValue: 'kubb-core' } },
|
|
242
|
+
{
|
|
243
|
+
key: 'service.version',
|
|
244
|
+
value: { stringValue: event.kubbVersion },
|
|
245
|
+
},
|
|
246
|
+
{ key: 'telemetry.sdk.language', value: { stringValue: 'nodejs' } },
|
|
247
|
+
],
|
|
248
|
+
},
|
|
249
|
+
scopeSpans: [
|
|
250
|
+
{
|
|
251
|
+
scope: { name: 'kubb-core', version: event.kubbVersion },
|
|
252
|
+
spans: [
|
|
253
|
+
{
|
|
254
|
+
traceId,
|
|
255
|
+
spanId,
|
|
256
|
+
name: event.command,
|
|
257
|
+
kind: 1 satisfies OtlpSpanKind,
|
|
258
|
+
startTimeUnixNano: String(startTimeNs),
|
|
259
|
+
endTimeUnixNano: String(endTimeNs),
|
|
260
|
+
attributes,
|
|
261
|
+
status: {
|
|
262
|
+
code: (event.status === 'success' ? 1 : 2) satisfies OtlpStatusCode,
|
|
263
|
+
},
|
|
264
|
+
},
|
|
265
|
+
],
|
|
266
|
+
},
|
|
267
|
+
],
|
|
268
|
+
},
|
|
269
|
+
],
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Send an anonymous telemetry event to the Kubb OTLP endpoint. Respects `DO_NOT_TRACK` and
|
|
275
|
+
* `KUBB_DISABLE_TELEMETRY`, and fails silently so telemetry never interrupts a run.
|
|
276
|
+
*/
|
|
277
|
+
static async send(event: TelemetryEvent): Promise<void> {
|
|
278
|
+
if (Telemetry.isDisabled) {
|
|
279
|
+
return
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
try {
|
|
283
|
+
await fetch(`${OTLP_ENDPOINT}/v1/traces`, {
|
|
284
|
+
method: 'POST',
|
|
285
|
+
headers: {
|
|
286
|
+
'Content-Type': 'application/json',
|
|
287
|
+
'Kubb-Telemetry-Version': '1',
|
|
288
|
+
'Kubb-Telemetry-Source': 'kubb-core',
|
|
289
|
+
},
|
|
290
|
+
body: JSON.stringify(Telemetry.buildOtlpPayload(event)),
|
|
291
|
+
signal: AbortSignal.timeout(5_000),
|
|
292
|
+
})
|
|
293
|
+
} catch (_e) {
|
|
294
|
+
// Fail silently, telemetry must never break the run
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
package/src/commands/generate.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { defineCommand } from '@internals/utils'
|
|
2
|
+
import type { ReporterName } from '@kubb/core'
|
|
2
3
|
|
|
3
4
|
export const command = defineCommand({
|
|
4
5
|
name: 'generate',
|
|
@@ -14,11 +15,11 @@ export const command = defineCommand({
|
|
|
14
15
|
},
|
|
15
16
|
logLevel: {
|
|
16
17
|
type: 'string',
|
|
17
|
-
description: 'Info, silent
|
|
18
|
+
description: 'Info, silent or verbose',
|
|
18
19
|
short: 'l',
|
|
19
20
|
default: 'info',
|
|
20
|
-
hint: 'silent|info|verbose
|
|
21
|
-
enum: ['silent', 'info', 'verbose'
|
|
21
|
+
hint: 'silent|info|verbose',
|
|
22
|
+
enum: ['silent', 'info', 'verbose'],
|
|
22
23
|
},
|
|
23
24
|
watch: {
|
|
24
25
|
type: 'boolean',
|
|
@@ -26,12 +27,6 @@ export const command = defineCommand({
|
|
|
26
27
|
short: 'w',
|
|
27
28
|
default: false,
|
|
28
29
|
},
|
|
29
|
-
debug: {
|
|
30
|
-
type: 'boolean',
|
|
31
|
-
description: 'Override logLevel to debug',
|
|
32
|
-
short: 'd',
|
|
33
|
-
default: false,
|
|
34
|
-
},
|
|
35
30
|
verbose: {
|
|
36
31
|
type: 'boolean',
|
|
37
32
|
description: 'Override logLevel to verbose',
|
|
@@ -44,16 +39,27 @@ export const command = defineCommand({
|
|
|
44
39
|
short: 's',
|
|
45
40
|
default: false,
|
|
46
41
|
},
|
|
42
|
+
reporter: {
|
|
43
|
+
type: 'string',
|
|
44
|
+
description: 'Reporters that render the run, comma-separated. Overrides config.reporters',
|
|
45
|
+
hint: 'cli|json|file',
|
|
46
|
+
enum: ['cli', 'json', 'file'],
|
|
47
|
+
},
|
|
47
48
|
},
|
|
48
49
|
async run({ values, positionals }) {
|
|
49
|
-
const logLevel = values.
|
|
50
|
-
const
|
|
50
|
+
const logLevel = values.verbose ? 'verbose' : values.silent ? 'silent' : values.logLevel
|
|
51
|
+
const reporters = values.reporter
|
|
52
|
+
?.split(',')
|
|
53
|
+
.map((name) => name.trim())
|
|
54
|
+
.filter(Boolean) as Array<ReporterName> | undefined
|
|
55
|
+
const { run } = await import('../runners/generate/run.ts')
|
|
51
56
|
|
|
52
|
-
await
|
|
57
|
+
await run({
|
|
53
58
|
input: positionals[0],
|
|
54
59
|
configPath: values.config,
|
|
55
60
|
logLevel,
|
|
56
61
|
watch: values.watch,
|
|
62
|
+
reporters,
|
|
57
63
|
})
|
|
58
64
|
},
|
|
59
65
|
})
|
package/src/commands/init.ts
CHANGED
|
@@ -38,9 +38,9 @@ export const command = defineCommand({
|
|
|
38
38
|
},
|
|
39
39
|
},
|
|
40
40
|
async run({ values }) {
|
|
41
|
-
const {
|
|
41
|
+
const { run } = await import('../runners/init/run.ts')
|
|
42
42
|
|
|
43
|
-
await
|
|
43
|
+
await run({
|
|
44
44
|
yes: values.yes,
|
|
45
45
|
version,
|
|
46
46
|
input: values.input,
|
package/src/commands/mcp.ts
CHANGED
|
@@ -25,9 +25,9 @@ export const command = defineCommand({
|
|
|
25
25
|
},
|
|
26
26
|
},
|
|
27
27
|
async run({ values }) {
|
|
28
|
-
const {
|
|
28
|
+
const { run } = await import('../runners/mcp/run.ts')
|
|
29
29
|
|
|
30
|
-
await
|
|
30
|
+
await run({
|
|
31
31
|
version,
|
|
32
32
|
port: values.port,
|
|
33
33
|
host: values.host,
|
package/src/commands/validate.ts
CHANGED
|
@@ -15,8 +15,8 @@ export const command = defineCommand({
|
|
|
15
15
|
},
|
|
16
16
|
},
|
|
17
17
|
async run({ values }) {
|
|
18
|
-
const {
|
|
18
|
+
const { run } = await import('../runners/validate/run.ts')
|
|
19
19
|
|
|
20
|
-
await
|
|
20
|
+
await run({ input: values.input, version })
|
|
21
21
|
},
|
|
22
22
|
})
|
package/src/constants.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { KUBB_CONFIG_FILENAME } from '@internals/shared'
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* NPM registry endpoint used to check for @kubb/cli updates.
|
|
5
3
|
*/
|
|
@@ -10,43 +8,12 @@ export const KUBB_NPM_PACKAGE_URL = 'https://registry.npmjs.org/@kubb/cli/latest
|
|
|
10
8
|
*/
|
|
11
9
|
export const OTLP_ENDPOINT = 'https://otlp.kubb.dev' as const
|
|
12
10
|
|
|
13
|
-
/**
|
|
14
|
-
* Horizontal rule rendered above/below the plain-logger generation summary.
|
|
15
|
-
*/
|
|
16
|
-
export const SUMMARY_SEPARATOR = '─'.repeat(27)
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Maximum number of █ characters in a plugin timing bar.
|
|
20
|
-
*/
|
|
21
|
-
export const SUMMARY_MAX_BAR_LENGTH = 10 as const
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Divides elapsed milliseconds into bar-length units (1 block per 100 ms).
|
|
25
|
-
*/
|
|
26
|
-
export const SUMMARY_TIME_SCALE_DIVISOR = 100 as const
|
|
27
|
-
|
|
28
11
|
/**
|
|
29
12
|
* Glob pattern for paths the file watcher ignores.
|
|
30
13
|
*/
|
|
31
14
|
export const WATCHER_IGNORED_PATHS = '**/{.git,node_modules}/**' as const
|
|
32
15
|
|
|
33
16
|
/**
|
|
34
|
-
* Flags that short-circuit execution (help
|
|
35
|
-
*/
|
|
36
|
-
export const QUIET_FLAGS = new Set(['--help', '-h', '--version', '-v'] as const)
|
|
37
|
-
|
|
38
|
-
export const agentDefaults = {
|
|
39
|
-
port: '3000',
|
|
40
|
-
host: 'localhost',
|
|
41
|
-
configFile: KUBB_CONFIG_FILENAME,
|
|
42
|
-
retryTimeout: '30000',
|
|
43
|
-
studioUrl: 'https://kubb.studio',
|
|
44
|
-
/**
|
|
45
|
-
* Relative path from the @kubb/agent package root to the server entry.
|
|
46
|
-
*/
|
|
47
|
-
serverEntryPath: '.output/server/index.mjs',
|
|
48
|
-
} as const
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Color palette used by randomCliColor() for deterministic plugin name coloring.
|
|
17
|
+
* Flags that short-circuit execution (help and version). The telemetry notice is suppressed for these.
|
|
52
18
|
*/
|
|
19
|
+
export const QUIET_FLAGS = new Set<string>(['--help', '-h', '--version', '-v'])
|
package/src/index.ts
CHANGED
|
@@ -1,29 +1,14 @@
|
|
|
1
1
|
import { styleText } from 'node:util'
|
|
2
2
|
import { createCLI } from '@internals/utils'
|
|
3
|
+
import { Telemetry } from './Telemetry.ts'
|
|
3
4
|
import { version } from '../package.json'
|
|
4
5
|
import { QUIET_FLAGS } from './constants.ts'
|
|
5
|
-
import { isFlag } from './utils/flags.ts'
|
|
6
|
-
import { isTelemetryDisabled } from './utils/telemetry.ts'
|
|
7
6
|
|
|
8
7
|
const cli = createCLI()
|
|
9
|
-
|
|
10
|
-
function shouldShowTelemetryNotice(argv: Array<string>): boolean {
|
|
11
|
-
if (isTelemetryDisabled()) {
|
|
12
|
-
return false
|
|
13
|
-
}
|
|
14
|
-
// Skip when the user is just asking for help or version info
|
|
15
|
-
if (argv.some((arg) => isFlag(QUIET_FLAGS, arg))) {
|
|
16
|
-
return false
|
|
17
|
-
}
|
|
18
|
-
// Skip in non-interactive / scripting contexts
|
|
19
|
-
if (!process.stdout.isTTY) {
|
|
20
|
-
return false
|
|
21
|
-
}
|
|
22
|
-
return true
|
|
23
|
-
}
|
|
24
|
-
|
|
25
8
|
export async function run(argv: Array<string> = process.argv): Promise<void> {
|
|
26
|
-
|
|
9
|
+
const isQuietFlag = argv.some((arg) => QUIET_FLAGS.has(arg))
|
|
10
|
+
|
|
11
|
+
if (!Telemetry.isDisabled && !isQuietFlag) {
|
|
27
12
|
console.log(
|
|
28
13
|
`${styleText('yellow', 'Notice:')} Kubb collects anonymous telemetry data to help improve the tool. No personal data or file contents are collected. \nTo disable, set ${styleText('cyan', 'KUBB_DISABLE_TELEMETRY=1')}.\n`,
|
|
29
14
|
)
|
|
@@ -32,10 +17,9 @@ export async function run(argv: Array<string> = process.argv): Promise<void> {
|
|
|
32
17
|
const { command: generateCommand } = await import('./commands/generate.ts')
|
|
33
18
|
const { command: validateCommand } = await import('./commands/validate.ts')
|
|
34
19
|
const { command: mcpCommand } = await import('./commands/mcp.ts')
|
|
35
|
-
const { command: agentCommand } = await import('./commands/agent.ts')
|
|
36
20
|
const { command: initCommand } = await import('./commands/init.ts')
|
|
37
21
|
|
|
38
|
-
await cli.run([generateCommand, validateCommand, mcpCommand,
|
|
22
|
+
await cli.run([generateCommand, validateCommand, mcpCommand, initCommand], argv, {
|
|
39
23
|
programName: 'kubb',
|
|
40
24
|
defaultCommandName: 'generate',
|
|
41
25
|
version,
|