@kubb/cli 5.0.0-beta.5 → 5.0.0-beta.51
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/Telemetry-BG80bcoQ.cjs +350 -0
- package/dist/Telemetry-BG80bcoQ.cjs.map +1 -0
- package/dist/Telemetry-CyBqvgcj.js +313 -0
- package/dist/Telemetry-CyBqvgcj.js.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-BRpukupe.cjs +82 -0
- package/dist/generate-BRpukupe.cjs.map +1 -0
- package/dist/generate-XeCSLYWp.js +83 -0
- package/dist/generate-XeCSLYWp.js.map +1 -0
- package/dist/index.cjs +22 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +21 -15
- package/dist/index.js.map +1 -1
- package/dist/init-C156kkn3.cjs +53 -0
- package/dist/init-C156kkn3.cjs.map +1 -0
- package/dist/init-Djx-xXm2.js +53 -0
- package/dist/init-Djx-xXm2.js.map +1 -0
- package/dist/mcp--t_K4yMF.js +39 -0
- package/dist/mcp--t_K4yMF.js.map +1 -0
- package/dist/mcp-D4ZwcNDD.cjs +39 -0
- package/dist/mcp-D4ZwcNDD.cjs.map +1 -0
- package/dist/package-_PDiS5qW.js +6 -0
- package/dist/package-_PDiS5qW.js.map +1 -0
- package/dist/{package-BmYRU2hz.cjs → package-aN3cIOkh.cjs} +2 -2
- package/dist/package-aN3cIOkh.cjs.map +1 -0
- package/dist/run-7yQQ3lIR.js +51 -0
- package/dist/run-7yQQ3lIR.js.map +1 -0
- package/dist/{init-C5sZulT6.cjs → run-BtjzfTz3.cjs} +155 -85
- package/dist/run-BtjzfTz3.cjs.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-CDs_ebOt.cjs +1458 -0
- package/dist/run-CDs_ebOt.cjs.map +1 -0
- package/dist/run-CZEf3B3A.cjs +33 -0
- package/dist/run-CZEf3B3A.cjs.map +1 -0
- package/dist/run-CsBW0NRp.js +32 -0
- package/dist/run-CsBW0NRp.js.map +1 -0
- package/dist/run-YYlwMdeu.cjs +52 -0
- package/dist/run-YYlwMdeu.cjs.map +1 -0
- package/dist/run-aODbKkaY.js +1455 -0
- package/dist/run-aODbKkaY.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-DWdTJLGF.js +26 -0
- package/dist/validate-DWdTJLGF.js.map +1 -0
- package/dist/validate-sOD68Kma.cjs +26 -0
- package/dist/validate-sOD68Kma.cjs.map +1 -0
- package/package.json +14 -24
- package/src/Telemetry.ts +290 -0
- 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 -81
- package/src/index.ts +7 -6
- package/src/loggers/clackLogger.ts +135 -201
- package/src/loggers/defineLogger.ts +59 -0
- package/src/loggers/plainLogger.ts +47 -102
- package/src/loggers/types.ts +6 -1
- package/src/loggers/utils.ts +164 -23
- package/src/runners/generate/run.ts +403 -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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Telemetry-BG80bcoQ.cjs","names":["dnsPromises","process","os"],"sources":["../../../internals/utils/src/env.ts","../../../internals/utils/src/network.ts","../../../internals/utils/src/runtime.ts","../src/constants.ts","../src/Telemetry.ts"],"sourcesContent":["/**\n * Returns `true` when the process is running in a CI environment.\n * Covers GitHub Actions, GitLab CI, CircleCI, Travis CI, Jenkins, Bitbucket,\n * TeamCity, Buildkite, and Azure Pipelines.\n *\n * @example\n * ```ts\n * if (isCIEnvironment()) {\n * logger.level = 'error'\n * }\n * ```\n */\nexport function isCIEnvironment(): boolean {\n return !!(\n process.env.CI ||\n process.env.GITHUB_ACTIONS ||\n process.env.GITLAB_CI ||\n process.env.BITBUCKET_BUILD_NUMBER ||\n process.env.JENKINS_URL ||\n process.env.CIRCLECI ||\n process.env.TRAVIS ||\n process.env.TEAMCITY_VERSION ||\n process.env.BUILDKITE ||\n process.env.TF_BUILD\n )\n}\n\n/**\n * Returns `true` when the process has an interactive TTY with a valid terminal\n * width and is not running in CI.\n *\n * Some IDE-embedded terminals report `isTTY = true` but set `columns` to `0`,\n * which breaks clack's box-drawing helpers (they call `String.prototype.repeat`\n * with a negative count and throw a `RangeError`). We therefore require a\n * positive column count before declaring the TTY usable.\n *\n * @example\n * ```ts\n * if (canUseTTY()) {\n * renderProgressBar()\n * }\n * ```\n */\nexport function canUseTTY(): boolean {\n return !!process.stdout.isTTY && (process.stdout.columns ?? 0) > 0 && !isCIEnvironment()\n}\n","import { promises as dnsPromises } from 'node:dns'\n\n/**\n * Well-known stable domains used as DNS probes to check internet connectivity.\n */\nconst TEST_DOMAINS = ['dns.google.com', 'cloudflare.com', 'one.one.one.one'] as const\n\n/**\n * Returns `true` when the system has internet connectivity.\n * Probes DNS resolution against well-known stable domains.\n *\n * @example\n * ```ts\n * if (await isOnline()) {\n * await fetchLatestVersion()\n * }\n * ```\n */\nexport async function isOnline(): Promise<boolean> {\n for (const domain of TEST_DOMAINS) {\n try {\n await dnsPromises.resolve(domain)\n return true\n } catch {\n // Try next domain\n }\n }\n\n return false\n}\n\n/**\n * Executes `fn` only when the system is online. Returns `null` when offline or on error.\n *\n * @example\n * ```ts\n * const version = await executeIfOnline(() => fetchLatestVersion('kubb'))\n * // null when offline\n * ```\n */\nexport async function executeIfOnline<T>(fn: () => Promise<T>): Promise<T | null> {\n if (!(await isOnline())) return null\n\n try {\n return await fn()\n } catch {\n return null\n }\n}\n","/**\n * Name of the JavaScript runtime executing the current process.\n */\nexport type RuntimeName = 'bun' | 'deno' | 'node'\n\n/**\n * Returns `true` when the current process is running under Bun.\n *\n * Detection keys off the global `Bun` object rather than `process.versions`,\n * because Bun polyfills `process.versions.node` for Node compatibility and would\n * otherwise look like Node.\n *\n * @example\n * ```ts\n * if (isBun()) {\n * await Bun.write(path, data)\n * }\n * ```\n */\nexport function isBun(): boolean {\n return typeof Bun !== 'undefined'\n}\n\n/**\n * Returns `true` when the current process is running under Deno.\n */\nexport function isDeno(): boolean {\n return typeof (globalThis as { Deno?: unknown }).Deno !== 'undefined'\n}\n\n/**\n * Returns `true` when the current process is running under Node.\n *\n * Bun and Deno are excluded first so a polyfilled `process` does not register as Node.\n */\nexport function isNode(): boolean {\n return !isBun() && !isDeno() && typeof process !== 'undefined' && process.versions?.node != null\n}\n\n/**\n * Returns the name of the runtime executing the current process.\n *\n * @example\n * ```ts\n * getRuntimeName() // 'bun' when run with `bun kubb`, 'node' otherwise\n * ```\n */\nexport function getRuntimeName(): RuntimeName {\n if (isBun()) return 'bun'\n if (isDeno()) return 'deno'\n return 'node'\n}\n\n/**\n * Returns the version of the active runtime, or an empty string when it cannot be read.\n *\n * @example\n * ```ts\n * getRuntimeVersion() // '1.3.11' under Bun, '22.22.2' under Node\n * ```\n */\nexport function getRuntimeVersion(): string {\n if (isBun()) return process.versions.bun ?? ''\n if (isDeno()) return (globalThis as { Deno?: { version?: { deno?: string } } }).Deno?.version?.deno ?? ''\n return process.versions?.node ?? ''\n}\n","/**\n * NPM registry endpoint used to check for @kubb/cli updates.\n */\nexport const KUBB_NPM_PACKAGE_URL = 'https://registry.npmjs.org/@kubb/cli/latest' as const\n\n/**\n * OpenTelemetry ingestion endpoint for anonymous usage telemetry.\n */\nexport const OTLP_ENDPOINT = 'https://otlp.kubb.dev' as const\n\n/**\n * Horizontal rule rendered above/below the plain-logger generation summary.\n */\nexport const SUMMARY_SEPARATOR = '─'.repeat(27)\n\n/**\n * Glob pattern for paths the file watcher ignores.\n */\nexport const WATCHER_IGNORED_PATHS = '**/{.git,node_modules}/**' as const\n\n/**\n * Flags that short-circuit execution (help/version), no telemetry notice is shown.\n */\nexport const QUIET_FLAGS = new Set(['--help', '-h', '--version', '-v'] as const)\n","import { randomBytes } from 'node:crypto'\nimport os from 'node:os'\nimport process from 'node:process'\nimport { executeIfOnline, getRuntimeName, getRuntimeVersion, isCIEnvironment, type RuntimeName } from '@internals/utils'\nimport { OTLP_ENDPOINT } from './constants.ts'\n\n// OpenTelemetry OTLP JSON types\n// https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/trace/v1/trace.proto\n// https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/common/v1/common.proto\n\ntype OtlpStringValue = { stringValue: string }\ntype OtlpBoolValue = { boolValue: boolean }\ntype OtlpIntValue = { intValue: number }\ntype OtlpDoubleValue = { doubleValue: number }\ntype OtlpBytesValue = { bytesValue: string }\ntype OtlpArrayValue = { arrayValue: { values: Array<OtlpAnyValue> } }\ntype OtlpKvListValue = { kvlistValue: { values: Array<OtlpKeyValue> } }\n\ntype OtlpAnyValue = OtlpStringValue | OtlpBoolValue | OtlpIntValue | OtlpDoubleValue | OtlpBytesValue | OtlpArrayValue | OtlpKvListValue\n\ntype OtlpKeyValue = {\n key: string\n value: OtlpAnyValue\n}\n\ntype OtlpResource = {\n attributes: Array<OtlpKeyValue>\n droppedAttributesCount?: number\n}\n\ntype OtlpInstrumentationScope = {\n name: string\n version?: string\n attributes?: Array<OtlpKeyValue>\n droppedAttributesCount?: number\n}\n\n/** https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/trace/v1/trace.proto#L103 */\ntype OtlpSpanKind = 0 | 1 | 2 | 3 | 4 | 5\n\n/** 0 = STATUS_CODE_UNSET, 1 = STATUS_CODE_OK, 2 = STATUS_CODE_ERROR */\ntype OtlpStatusCode = 0 | 1 | 2\n\ntype OtlpStatus = {\n code: OtlpStatusCode\n message?: string\n}\n\ntype OtlpSpan = {\n traceId: string\n spanId: string\n traceState?: string\n parentSpanId?: string\n name: string\n kind: OtlpSpanKind\n startTimeUnixNano: string\n endTimeUnixNano: string\n attributes?: Array<OtlpKeyValue>\n droppedAttributesCount?: number\n events?: Array<OtlpSpanEvent>\n droppedEventsCount?: number\n links?: Array<OtlpSpanLink>\n droppedLinksCount?: number\n status?: OtlpStatus\n}\n\ntype OtlpSpanEvent = {\n timeUnixNano: string\n name: string\n attributes?: Array<OtlpKeyValue>\n droppedAttributesCount?: number\n}\n\ntype OtlpSpanLink = {\n traceId: string\n spanId: string\n traceState?: string\n attributes?: Array<OtlpKeyValue>\n droppedAttributesCount?: number\n}\n\ntype OtlpScopeSpans = {\n scope: OtlpInstrumentationScope\n spans: Array<OtlpSpan>\n schemaUrl?: string\n}\n\ntype OtlpResourceSpans = {\n resource: OtlpResource\n scopeSpans: Array<OtlpScopeSpans>\n schemaUrl?: string\n}\n\n/** Root payload sent to POST /v1/traces */\ntype OtlpExportTraceServiceRequest = {\n resourceSpans: Array<OtlpResourceSpans>\n}\n\n/**\n * Anonymous plugin name and options snapshot sent with each telemetry event.\n */\nexport type TelemetryPlugin = {\n /**\n * Plugin name as registered in the Kubb config, e.g. `'@kubb/plugin-ts'`.\n */\n name: string\n /**\n * anonymized plugin options snapshot, values are included but cannot be traced back to the user.\n */\n options: Record<string, unknown>\n}\n\nexport type TelemetryEvent = {\n command: string\n kubbVersion: string\n nodeVersion: string\n /**\n * Name of the JavaScript runtime that executed the run, `'bun'`, `'deno'`, or `'node'`.\n */\n runtime: RuntimeName\n /**\n * Major version of the active runtime, e.g. `'1'` under Bun or `'22'` under Node.\n */\n runtimeVersion: string\n platform: string\n ci: boolean\n plugins: Array<TelemetryPlugin>\n duration: number\n filesCreated: number\n status: 'success' | 'failed'\n}\n\n/**\n * Anonymous OTLP usage telemetry for the Kubb run. All methods are static, so call them as\n * `Telemetry.build(...)`, `Telemetry.send(...)`, and `Telemetry.isDisabled()`. No file paths,\n * OpenAPI specs, or secrets are ever included, and sending fails silently to never break a run.\n */\nexport class Telemetry {\n /**\n * Returns `true` when telemetry is disabled via `DO_NOT_TRACK` or `KUBB_DISABLE_TELEMETRY`.\n */\n static isDisabled(): boolean {\n return (\n process.env['DO_NOT_TRACK'] === '1' ||\n process.env['DO_NOT_TRACK'] === 'true' ||\n process.env['KUBB_DISABLE_TELEMETRY'] === '1' ||\n process.env['KUBB_DISABLE_TELEMETRY'] === 'true'\n )\n }\n\n /**\n * Build an anonymous telemetry payload from a completed generation run.\n */\n static build(options: {\n command: 'generate' | 'mcp' | 'validate' | 'agent'\n kubbVersion: string\n plugins?: Array<TelemetryPlugin>\n hrStart: [number, number]\n filesCreated?: number\n status: 'success' | 'failed'\n }): TelemetryEvent {\n const [seconds, nanoseconds] = process.hrtime(options.hrStart)\n const duration = Math.round(seconds * 1000 + nanoseconds / 1e6)\n\n return {\n command: options.command,\n kubbVersion: options.kubbVersion,\n nodeVersion: process.versions.node.split('.')[0] as string,\n runtime: getRuntimeName(),\n runtimeVersion: getRuntimeVersion().split('.')[0] as string,\n platform: os.platform(),\n ci: isCIEnvironment(),\n plugins: options.plugins ?? [],\n duration,\n filesCreated: options.filesCreated ?? 0,\n status: options.status,\n }\n }\n\n /**\n * Convert a {@link TelemetryEvent} into an OTLP-compatible JSON trace payload.\n * See https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/\n */\n static buildOtlpPayload(event: TelemetryEvent): OtlpExportTraceServiceRequest {\n const traceId = randomBytes(16).toString('hex')\n const spanId = randomBytes(8).toString('hex')\n const endTimeNs = BigInt(Date.now()) * 1_000_000n\n const startTimeNs = endTimeNs - BigInt(event.duration) * 1_000_000n\n\n const attributes: Array<OtlpKeyValue> = [\n { key: 'kubb.command', value: { stringValue: event.command } },\n { key: 'kubb.version', value: { stringValue: event.kubbVersion } },\n { key: 'kubb.node_version', value: { stringValue: event.nodeVersion } },\n { key: 'kubb.runtime', value: { stringValue: event.runtime } },\n { key: 'kubb.runtime_version', value: { stringValue: event.runtimeVersion } },\n { key: 'kubb.platform', value: { stringValue: event.platform } },\n { key: 'kubb.ci', value: { boolValue: event.ci } },\n { key: 'kubb.files_created', value: { intValue: event.filesCreated } },\n { key: 'kubb.status', value: { stringValue: event.status } },\n {\n key: 'kubb.plugins',\n value: {\n arrayValue: {\n values: event.plugins.map(\n (p): OtlpKvListValue => ({\n kvlistValue: {\n values: [\n { key: 'name', value: { stringValue: p.name } },\n {\n key: 'options',\n value: {\n stringValue: JSON.stringify({\n ...p.options,\n usedEnumNames: undefined,\n }),\n },\n },\n ],\n },\n }),\n ),\n },\n },\n },\n ]\n\n return {\n resourceSpans: [\n {\n resource: {\n attributes: [\n { key: 'service.name', value: { stringValue: 'kubb-core' } },\n {\n key: 'service.version',\n value: { stringValue: event.kubbVersion },\n },\n { key: 'telemetry.sdk.language', value: { stringValue: 'nodejs' } },\n ],\n },\n scopeSpans: [\n {\n scope: { name: 'kubb-core', version: event.kubbVersion },\n spans: [\n {\n traceId,\n spanId,\n name: event.command,\n kind: 1 satisfies OtlpSpanKind,\n startTimeUnixNano: String(startTimeNs),\n endTimeUnixNano: String(endTimeNs),\n attributes,\n status: {\n code: (event.status === 'success' ? 1 : 2) satisfies OtlpStatusCode,\n },\n },\n ],\n },\n ],\n },\n ],\n }\n }\n\n /**\n * Send an anonymous telemetry event to the Kubb OTLP endpoint. Respects `DO_NOT_TRACK` and\n * `KUBB_DISABLE_TELEMETRY`, and fails silently so telemetry never interrupts a run.\n */\n static async send(event: TelemetryEvent): Promise<void> {\n if (Telemetry.isDisabled()) {\n return\n }\n\n await executeIfOnline(async () => {\n try {\n await fetch(`${OTLP_ENDPOINT}/v1/traces`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Kubb-Telemetry-Version': '1',\n 'Kubb-Telemetry-Source': 'kubb-core',\n },\n body: JSON.stringify(Telemetry.buildOtlpPayload(event)),\n signal: AbortSignal.timeout(5_000),\n })\n } catch (_e) {\n // Fail silently, telemetry must never break the run\n }\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAYA,SAAgB,kBAA2B;CACzC,OAAO,CAAC,EACN,QAAQ,IAAI,MACZ,QAAQ,IAAI,kBACZ,QAAQ,IAAI,aACZ,QAAQ,IAAI,0BACZ,QAAQ,IAAI,eACZ,QAAQ,IAAI,YACZ,QAAQ,IAAI,UACZ,QAAQ,IAAI,oBACZ,QAAQ,IAAI,aACZ,QAAQ,IAAI;AAEhB;;;;;;;;;;;;;;;;;AAkBA,SAAgB,YAAqB;CACnC,OAAO,CAAC,CAAC,QAAQ,OAAO,UAAU,QAAQ,OAAO,WAAW,KAAK,KAAK,CAAC,gBAAgB;AACzF;;;;;;ACxCA,MAAM,eAAe;CAAC;CAAkB;CAAkB;AAAiB;;;;;;;;;;;;AAa3E,eAAsB,WAA6B;CACjD,KAAK,MAAM,UAAU,cACnB,IAAI;EACF,MAAMA,SAAAA,SAAY,QAAQ,MAAM;EAChC,OAAO;CACT,QAAQ,CAER;CAGF,OAAO;AACT;;;;;;;;;;AAWA,eAAsB,gBAAmB,IAAyC;CAChF,IAAI,CAAE,MAAM,SAAS,GAAI,OAAO;CAEhC,IAAI;EACF,OAAO,MAAM,GAAG;CAClB,QAAQ;EACN,OAAO;CACT;AACF;;;;;;;;;;;;;;;;;AC7BA,SAAgB,QAAiB;CAC/B,OAAO,OAAO,QAAQ;AACxB;;;;AAKA,SAAgB,SAAkB;CAChC,OAAO,OAAQ,WAAkC,SAAS;AAC5D;;;;;;;;;AAmBA,SAAgB,iBAA8B;CAC5C,IAAI,MAAM,GAAG,OAAO;CACpB,IAAI,OAAO,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aAAa,SAAS;IAAE;GACpE,EACF;GACA,YAAY,CACV;IACE,OAAO;KAAE,MAAM;KAAa,SAAS,MAAM;IAAY;IACvD,OAAO,CACL;KACE;KACA;KACA,MAAM,MAAM;KACZ,MAAM;KACN,mBAAmB,OAAO,WAAW;KACrC,iBAAiB,OAAO,SAAS;KACjC;KACA,QAAQ,EACN,MAAO,MAAM,WAAW,YAAY,IAAI,EAC1C;IACF,CACF;GACF,CACF;EACF,CACF,EACF;CACF;;;;;CAMA,aAAa,KAAK,OAAsC;EACtD,IAAI,UAAU,WAAW,GACvB;EAGF,MAAM,gBAAgB,YAAY;GAChC,IAAI;IACF,MAAM,MAAM,GAAG,cAAc,aAAa;KACxC,QAAQ;KACR,SAAS;MACP,gBAAgB;MAChB,0BAA0B;MAC1B,yBAAyB;KAC3B;KACA,MAAM,KAAK,UAAU,UAAU,iBAAiB,KAAK,CAAC;KACtD,QAAQ,YAAY,QAAQ,GAAK;IACnC,CAAC;GACH,SAAS,IAAI,CAEb;EACF,CAAC;CACH;AACF"}
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import "./chunk-C0LytTxp.js";
|
|
2
|
+
import { randomBytes } from "node:crypto";
|
|
3
|
+
import { promises } from "node:dns";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import process$1 from "node:process";
|
|
6
|
+
//#region ../../internals/utils/src/env.ts
|
|
7
|
+
/**
|
|
8
|
+
* Returns `true` when the process is running in a CI environment.
|
|
9
|
+
* Covers GitHub Actions, GitLab CI, CircleCI, Travis CI, Jenkins, Bitbucket,
|
|
10
|
+
* TeamCity, Buildkite, and Azure Pipelines.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* if (isCIEnvironment()) {
|
|
15
|
+
* logger.level = 'error'
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
function isCIEnvironment() {
|
|
20
|
+
return !!(process.env.CI || process.env.GITHUB_ACTIONS || process.env.GITLAB_CI || process.env.BITBUCKET_BUILD_NUMBER || process.env.JENKINS_URL || process.env.CIRCLECI || process.env.TRAVIS || process.env.TEAMCITY_VERSION || process.env.BUILDKITE || process.env.TF_BUILD);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Returns `true` when the process has an interactive TTY with a valid terminal
|
|
24
|
+
* width and is not running in CI.
|
|
25
|
+
*
|
|
26
|
+
* Some IDE-embedded terminals report `isTTY = true` but set `columns` to `0`,
|
|
27
|
+
* which breaks clack's box-drawing helpers (they call `String.prototype.repeat`
|
|
28
|
+
* with a negative count and throw a `RangeError`). We therefore require a
|
|
29
|
+
* positive column count before declaring the TTY usable.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* if (canUseTTY()) {
|
|
34
|
+
* renderProgressBar()
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
function canUseTTY() {
|
|
39
|
+
return !!process.stdout.isTTY && (process.stdout.columns ?? 0) > 0 && !isCIEnvironment();
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region ../../internals/utils/src/network.ts
|
|
43
|
+
/**
|
|
44
|
+
* Well-known stable domains used as DNS probes to check internet connectivity.
|
|
45
|
+
*/
|
|
46
|
+
const TEST_DOMAINS = [
|
|
47
|
+
"dns.google.com",
|
|
48
|
+
"cloudflare.com",
|
|
49
|
+
"one.one.one.one"
|
|
50
|
+
];
|
|
51
|
+
/**
|
|
52
|
+
* Returns `true` when the system has internet connectivity.
|
|
53
|
+
* Probes DNS resolution against well-known stable domains.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* if (await isOnline()) {
|
|
58
|
+
* await fetchLatestVersion()
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
async function isOnline() {
|
|
63
|
+
for (const domain of TEST_DOMAINS) try {
|
|
64
|
+
await promises.resolve(domain);
|
|
65
|
+
return true;
|
|
66
|
+
} catch {}
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Executes `fn` only when the system is online. Returns `null` when offline or on error.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* const version = await executeIfOnline(() => fetchLatestVersion('kubb'))
|
|
75
|
+
* // null when offline
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
async function executeIfOnline(fn) {
|
|
79
|
+
if (!await isOnline()) return null;
|
|
80
|
+
try {
|
|
81
|
+
return await fn();
|
|
82
|
+
} catch {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region ../../internals/utils/src/runtime.ts
|
|
88
|
+
/**
|
|
89
|
+
* Returns `true` when the current process is running under Bun.
|
|
90
|
+
*
|
|
91
|
+
* Detection keys off the global `Bun` object rather than `process.versions`,
|
|
92
|
+
* because Bun polyfills `process.versions.node` for Node compatibility and would
|
|
93
|
+
* otherwise look like Node.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* if (isBun()) {
|
|
98
|
+
* await Bun.write(path, data)
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
function isBun() {
|
|
103
|
+
return typeof Bun !== "undefined";
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Returns `true` when the current process is running under Deno.
|
|
107
|
+
*/
|
|
108
|
+
function isDeno() {
|
|
109
|
+
return typeof globalThis.Deno !== "undefined";
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Returns the name of the runtime executing the current process.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```ts
|
|
116
|
+
* getRuntimeName() // 'bun' when run with `bun kubb`, 'node' otherwise
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
function getRuntimeName() {
|
|
120
|
+
if (isBun()) return "bun";
|
|
121
|
+
if (isDeno()) return "deno";
|
|
122
|
+
return "node";
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Returns the version of the active runtime, or an empty string when it cannot be read.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```ts
|
|
129
|
+
* getRuntimeVersion() // '1.3.11' under Bun, '22.22.2' under Node
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
function getRuntimeVersion() {
|
|
133
|
+
if (isBun()) return process.versions.bun ?? "";
|
|
134
|
+
if (isDeno()) return globalThis.Deno?.version?.deno ?? "";
|
|
135
|
+
return process.versions?.node ?? "";
|
|
136
|
+
}
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region src/constants.ts
|
|
139
|
+
/**
|
|
140
|
+
* NPM registry endpoint used to check for @kubb/cli updates.
|
|
141
|
+
*/
|
|
142
|
+
const KUBB_NPM_PACKAGE_URL = "https://registry.npmjs.org/@kubb/cli/latest";
|
|
143
|
+
/**
|
|
144
|
+
* OpenTelemetry ingestion endpoint for anonymous usage telemetry.
|
|
145
|
+
*/
|
|
146
|
+
const OTLP_ENDPOINT = "https://otlp.kubb.dev";
|
|
147
|
+
"─".repeat(27);
|
|
148
|
+
/**
|
|
149
|
+
* Glob pattern for paths the file watcher ignores.
|
|
150
|
+
*/
|
|
151
|
+
const WATCHER_IGNORED_PATHS = "**/{.git,node_modules}/**";
|
|
152
|
+
/**
|
|
153
|
+
* Flags that short-circuit execution (help/version), no telemetry notice is shown.
|
|
154
|
+
*/
|
|
155
|
+
const QUIET_FLAGS = new Set([
|
|
156
|
+
"--help",
|
|
157
|
+
"-h",
|
|
158
|
+
"--version",
|
|
159
|
+
"-v"
|
|
160
|
+
]);
|
|
161
|
+
//#endregion
|
|
162
|
+
//#region src/Telemetry.ts
|
|
163
|
+
/**
|
|
164
|
+
* Anonymous OTLP usage telemetry for the Kubb run. All methods are static, so call them as
|
|
165
|
+
* `Telemetry.build(...)`, `Telemetry.send(...)`, and `Telemetry.isDisabled()`. No file paths,
|
|
166
|
+
* OpenAPI specs, or secrets are ever included, and sending fails silently to never break a run.
|
|
167
|
+
*/
|
|
168
|
+
var Telemetry = class Telemetry {
|
|
169
|
+
/**
|
|
170
|
+
* Returns `true` when telemetry is disabled via `DO_NOT_TRACK` or `KUBB_DISABLE_TELEMETRY`.
|
|
171
|
+
*/
|
|
172
|
+
static isDisabled() {
|
|
173
|
+
return process$1.env["DO_NOT_TRACK"] === "1" || process$1.env["DO_NOT_TRACK"] === "true" || process$1.env["KUBB_DISABLE_TELEMETRY"] === "1" || process$1.env["KUBB_DISABLE_TELEMETRY"] === "true";
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Build an anonymous telemetry payload from a completed generation run.
|
|
177
|
+
*/
|
|
178
|
+
static build(options) {
|
|
179
|
+
const [seconds, nanoseconds] = process$1.hrtime(options.hrStart);
|
|
180
|
+
const duration = Math.round(seconds * 1e3 + nanoseconds / 1e6);
|
|
181
|
+
return {
|
|
182
|
+
command: options.command,
|
|
183
|
+
kubbVersion: options.kubbVersion,
|
|
184
|
+
nodeVersion: process$1.versions.node.split(".")[0],
|
|
185
|
+
runtime: getRuntimeName(),
|
|
186
|
+
runtimeVersion: getRuntimeVersion().split(".")[0],
|
|
187
|
+
platform: os.platform(),
|
|
188
|
+
ci: isCIEnvironment(),
|
|
189
|
+
plugins: options.plugins ?? [],
|
|
190
|
+
duration,
|
|
191
|
+
filesCreated: options.filesCreated ?? 0,
|
|
192
|
+
status: options.status
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Convert a {@link TelemetryEvent} into an OTLP-compatible JSON trace payload.
|
|
197
|
+
* See https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/
|
|
198
|
+
*/
|
|
199
|
+
static buildOtlpPayload(event) {
|
|
200
|
+
const traceId = randomBytes(16).toString("hex");
|
|
201
|
+
const spanId = randomBytes(8).toString("hex");
|
|
202
|
+
const endTimeNs = BigInt(Date.now()) * 1000000n;
|
|
203
|
+
const startTimeNs = endTimeNs - BigInt(event.duration) * 1000000n;
|
|
204
|
+
const attributes = [
|
|
205
|
+
{
|
|
206
|
+
key: "kubb.command",
|
|
207
|
+
value: { stringValue: event.command }
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
key: "kubb.version",
|
|
211
|
+
value: { stringValue: event.kubbVersion }
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
key: "kubb.node_version",
|
|
215
|
+
value: { stringValue: event.nodeVersion }
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
key: "kubb.runtime",
|
|
219
|
+
value: { stringValue: event.runtime }
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
key: "kubb.runtime_version",
|
|
223
|
+
value: { stringValue: event.runtimeVersion }
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
key: "kubb.platform",
|
|
227
|
+
value: { stringValue: event.platform }
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
key: "kubb.ci",
|
|
231
|
+
value: { boolValue: event.ci }
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
key: "kubb.files_created",
|
|
235
|
+
value: { intValue: event.filesCreated }
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
key: "kubb.status",
|
|
239
|
+
value: { stringValue: event.status }
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
key: "kubb.plugins",
|
|
243
|
+
value: { arrayValue: { values: event.plugins.map((p) => ({ kvlistValue: { values: [{
|
|
244
|
+
key: "name",
|
|
245
|
+
value: { stringValue: p.name }
|
|
246
|
+
}, {
|
|
247
|
+
key: "options",
|
|
248
|
+
value: { stringValue: JSON.stringify({
|
|
249
|
+
...p.options,
|
|
250
|
+
usedEnumNames: void 0
|
|
251
|
+
}) }
|
|
252
|
+
}] } })) } }
|
|
253
|
+
}
|
|
254
|
+
];
|
|
255
|
+
return { resourceSpans: [{
|
|
256
|
+
resource: { attributes: [
|
|
257
|
+
{
|
|
258
|
+
key: "service.name",
|
|
259
|
+
value: { stringValue: "kubb-core" }
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
key: "service.version",
|
|
263
|
+
value: { stringValue: event.kubbVersion }
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
key: "telemetry.sdk.language",
|
|
267
|
+
value: { stringValue: "nodejs" }
|
|
268
|
+
}
|
|
269
|
+
] },
|
|
270
|
+
scopeSpans: [{
|
|
271
|
+
scope: {
|
|
272
|
+
name: "kubb-core",
|
|
273
|
+
version: event.kubbVersion
|
|
274
|
+
},
|
|
275
|
+
spans: [{
|
|
276
|
+
traceId,
|
|
277
|
+
spanId,
|
|
278
|
+
name: event.command,
|
|
279
|
+
kind: 1,
|
|
280
|
+
startTimeUnixNano: String(startTimeNs),
|
|
281
|
+
endTimeUnixNano: String(endTimeNs),
|
|
282
|
+
attributes,
|
|
283
|
+
status: { code: event.status === "success" ? 1 : 2 }
|
|
284
|
+
}]
|
|
285
|
+
}]
|
|
286
|
+
}] };
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Send an anonymous telemetry event to the Kubb OTLP endpoint. Respects `DO_NOT_TRACK` and
|
|
290
|
+
* `KUBB_DISABLE_TELEMETRY`, and fails silently so telemetry never interrupts a run.
|
|
291
|
+
*/
|
|
292
|
+
static async send(event) {
|
|
293
|
+
if (Telemetry.isDisabled()) return;
|
|
294
|
+
await executeIfOnline(async () => {
|
|
295
|
+
try {
|
|
296
|
+
await fetch(`${OTLP_ENDPOINT}/v1/traces`, {
|
|
297
|
+
method: "POST",
|
|
298
|
+
headers: {
|
|
299
|
+
"Content-Type": "application/json",
|
|
300
|
+
"Kubb-Telemetry-Version": "1",
|
|
301
|
+
"Kubb-Telemetry-Source": "kubb-core"
|
|
302
|
+
},
|
|
303
|
+
body: JSON.stringify(Telemetry.buildOtlpPayload(event)),
|
|
304
|
+
signal: AbortSignal.timeout(5e3)
|
|
305
|
+
});
|
|
306
|
+
} catch (_e) {}
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
//#endregion
|
|
311
|
+
export { executeIfOnline as a, WATCHER_IGNORED_PATHS as i, KUBB_NPM_PACKAGE_URL as n, canUseTTY as o, QUIET_FLAGS as r, Telemetry as t };
|
|
312
|
+
|
|
313
|
+
//# sourceMappingURL=Telemetry-CyBqvgcj.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Telemetry-CyBqvgcj.js","names":["dnsPromises","process"],"sources":["../../../internals/utils/src/env.ts","../../../internals/utils/src/network.ts","../../../internals/utils/src/runtime.ts","../src/constants.ts","../src/Telemetry.ts"],"sourcesContent":["/**\n * Returns `true` when the process is running in a CI environment.\n * Covers GitHub Actions, GitLab CI, CircleCI, Travis CI, Jenkins, Bitbucket,\n * TeamCity, Buildkite, and Azure Pipelines.\n *\n * @example\n * ```ts\n * if (isCIEnvironment()) {\n * logger.level = 'error'\n * }\n * ```\n */\nexport function isCIEnvironment(): boolean {\n return !!(\n process.env.CI ||\n process.env.GITHUB_ACTIONS ||\n process.env.GITLAB_CI ||\n process.env.BITBUCKET_BUILD_NUMBER ||\n process.env.JENKINS_URL ||\n process.env.CIRCLECI ||\n process.env.TRAVIS ||\n process.env.TEAMCITY_VERSION ||\n process.env.BUILDKITE ||\n process.env.TF_BUILD\n )\n}\n\n/**\n * Returns `true` when the process has an interactive TTY with a valid terminal\n * width and is not running in CI.\n *\n * Some IDE-embedded terminals report `isTTY = true` but set `columns` to `0`,\n * which breaks clack's box-drawing helpers (they call `String.prototype.repeat`\n * with a negative count and throw a `RangeError`). We therefore require a\n * positive column count before declaring the TTY usable.\n *\n * @example\n * ```ts\n * if (canUseTTY()) {\n * renderProgressBar()\n * }\n * ```\n */\nexport function canUseTTY(): boolean {\n return !!process.stdout.isTTY && (process.stdout.columns ?? 0) > 0 && !isCIEnvironment()\n}\n","import { promises as dnsPromises } from 'node:dns'\n\n/**\n * Well-known stable domains used as DNS probes to check internet connectivity.\n */\nconst TEST_DOMAINS = ['dns.google.com', 'cloudflare.com', 'one.one.one.one'] as const\n\n/**\n * Returns `true` when the system has internet connectivity.\n * Probes DNS resolution against well-known stable domains.\n *\n * @example\n * ```ts\n * if (await isOnline()) {\n * await fetchLatestVersion()\n * }\n * ```\n */\nexport async function isOnline(): Promise<boolean> {\n for (const domain of TEST_DOMAINS) {\n try {\n await dnsPromises.resolve(domain)\n return true\n } catch {\n // Try next domain\n }\n }\n\n return false\n}\n\n/**\n * Executes `fn` only when the system is online. Returns `null` when offline or on error.\n *\n * @example\n * ```ts\n * const version = await executeIfOnline(() => fetchLatestVersion('kubb'))\n * // null when offline\n * ```\n */\nexport async function executeIfOnline<T>(fn: () => Promise<T>): Promise<T | null> {\n if (!(await isOnline())) return null\n\n try {\n return await fn()\n } catch {\n return null\n }\n}\n","/**\n * Name of the JavaScript runtime executing the current process.\n */\nexport type RuntimeName = 'bun' | 'deno' | 'node'\n\n/**\n * Returns `true` when the current process is running under Bun.\n *\n * Detection keys off the global `Bun` object rather than `process.versions`,\n * because Bun polyfills `process.versions.node` for Node compatibility and would\n * otherwise look like Node.\n *\n * @example\n * ```ts\n * if (isBun()) {\n * await Bun.write(path, data)\n * }\n * ```\n */\nexport function isBun(): boolean {\n return typeof Bun !== 'undefined'\n}\n\n/**\n * Returns `true` when the current process is running under Deno.\n */\nexport function isDeno(): boolean {\n return typeof (globalThis as { Deno?: unknown }).Deno !== 'undefined'\n}\n\n/**\n * Returns `true` when the current process is running under Node.\n *\n * Bun and Deno are excluded first so a polyfilled `process` does not register as Node.\n */\nexport function isNode(): boolean {\n return !isBun() && !isDeno() && typeof process !== 'undefined' && process.versions?.node != null\n}\n\n/**\n * Returns the name of the runtime executing the current process.\n *\n * @example\n * ```ts\n * getRuntimeName() // 'bun' when run with `bun kubb`, 'node' otherwise\n * ```\n */\nexport function getRuntimeName(): RuntimeName {\n if (isBun()) return 'bun'\n if (isDeno()) return 'deno'\n return 'node'\n}\n\n/**\n * Returns the version of the active runtime, or an empty string when it cannot be read.\n *\n * @example\n * ```ts\n * getRuntimeVersion() // '1.3.11' under Bun, '22.22.2' under Node\n * ```\n */\nexport function getRuntimeVersion(): string {\n if (isBun()) return process.versions.bun ?? ''\n if (isDeno()) return (globalThis as { Deno?: { version?: { deno?: string } } }).Deno?.version?.deno ?? ''\n return process.versions?.node ?? ''\n}\n","/**\n * NPM registry endpoint used to check for @kubb/cli updates.\n */\nexport const KUBB_NPM_PACKAGE_URL = 'https://registry.npmjs.org/@kubb/cli/latest' as const\n\n/**\n * OpenTelemetry ingestion endpoint for anonymous usage telemetry.\n */\nexport const OTLP_ENDPOINT = 'https://otlp.kubb.dev' as const\n\n/**\n * Horizontal rule rendered above/below the plain-logger generation summary.\n */\nexport const SUMMARY_SEPARATOR = '─'.repeat(27)\n\n/**\n * Glob pattern for paths the file watcher ignores.\n */\nexport const WATCHER_IGNORED_PATHS = '**/{.git,node_modules}/**' as const\n\n/**\n * Flags that short-circuit execution (help/version), no telemetry notice is shown.\n */\nexport const QUIET_FLAGS = new Set(['--help', '-h', '--version', '-v'] as const)\n","import { randomBytes } from 'node:crypto'\nimport os from 'node:os'\nimport process from 'node:process'\nimport { executeIfOnline, getRuntimeName, getRuntimeVersion, isCIEnvironment, type RuntimeName } from '@internals/utils'\nimport { OTLP_ENDPOINT } from './constants.ts'\n\n// OpenTelemetry OTLP JSON types\n// https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/trace/v1/trace.proto\n// https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/common/v1/common.proto\n\ntype OtlpStringValue = { stringValue: string }\ntype OtlpBoolValue = { boolValue: boolean }\ntype OtlpIntValue = { intValue: number }\ntype OtlpDoubleValue = { doubleValue: number }\ntype OtlpBytesValue = { bytesValue: string }\ntype OtlpArrayValue = { arrayValue: { values: Array<OtlpAnyValue> } }\ntype OtlpKvListValue = { kvlistValue: { values: Array<OtlpKeyValue> } }\n\ntype OtlpAnyValue = OtlpStringValue | OtlpBoolValue | OtlpIntValue | OtlpDoubleValue | OtlpBytesValue | OtlpArrayValue | OtlpKvListValue\n\ntype OtlpKeyValue = {\n key: string\n value: OtlpAnyValue\n}\n\ntype OtlpResource = {\n attributes: Array<OtlpKeyValue>\n droppedAttributesCount?: number\n}\n\ntype OtlpInstrumentationScope = {\n name: string\n version?: string\n attributes?: Array<OtlpKeyValue>\n droppedAttributesCount?: number\n}\n\n/** https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/trace/v1/trace.proto#L103 */\ntype OtlpSpanKind = 0 | 1 | 2 | 3 | 4 | 5\n\n/** 0 = STATUS_CODE_UNSET, 1 = STATUS_CODE_OK, 2 = STATUS_CODE_ERROR */\ntype OtlpStatusCode = 0 | 1 | 2\n\ntype OtlpStatus = {\n code: OtlpStatusCode\n message?: string\n}\n\ntype OtlpSpan = {\n traceId: string\n spanId: string\n traceState?: string\n parentSpanId?: string\n name: string\n kind: OtlpSpanKind\n startTimeUnixNano: string\n endTimeUnixNano: string\n attributes?: Array<OtlpKeyValue>\n droppedAttributesCount?: number\n events?: Array<OtlpSpanEvent>\n droppedEventsCount?: number\n links?: Array<OtlpSpanLink>\n droppedLinksCount?: number\n status?: OtlpStatus\n}\n\ntype OtlpSpanEvent = {\n timeUnixNano: string\n name: string\n attributes?: Array<OtlpKeyValue>\n droppedAttributesCount?: number\n}\n\ntype OtlpSpanLink = {\n traceId: string\n spanId: string\n traceState?: string\n attributes?: Array<OtlpKeyValue>\n droppedAttributesCount?: number\n}\n\ntype OtlpScopeSpans = {\n scope: OtlpInstrumentationScope\n spans: Array<OtlpSpan>\n schemaUrl?: string\n}\n\ntype OtlpResourceSpans = {\n resource: OtlpResource\n scopeSpans: Array<OtlpScopeSpans>\n schemaUrl?: string\n}\n\n/** Root payload sent to POST /v1/traces */\ntype OtlpExportTraceServiceRequest = {\n resourceSpans: Array<OtlpResourceSpans>\n}\n\n/**\n * Anonymous plugin name and options snapshot sent with each telemetry event.\n */\nexport type TelemetryPlugin = {\n /**\n * Plugin name as registered in the Kubb config, e.g. `'@kubb/plugin-ts'`.\n */\n name: string\n /**\n * anonymized plugin options snapshot, values are included but cannot be traced back to the user.\n */\n options: Record<string, unknown>\n}\n\nexport type TelemetryEvent = {\n command: string\n kubbVersion: string\n nodeVersion: string\n /**\n * Name of the JavaScript runtime that executed the run, `'bun'`, `'deno'`, or `'node'`.\n */\n runtime: RuntimeName\n /**\n * Major version of the active runtime, e.g. `'1'` under Bun or `'22'` under Node.\n */\n runtimeVersion: string\n platform: string\n ci: boolean\n plugins: Array<TelemetryPlugin>\n duration: number\n filesCreated: number\n status: 'success' | 'failed'\n}\n\n/**\n * Anonymous OTLP usage telemetry for the Kubb run. All methods are static, so call them as\n * `Telemetry.build(...)`, `Telemetry.send(...)`, and `Telemetry.isDisabled()`. No file paths,\n * OpenAPI specs, or secrets are ever included, and sending fails silently to never break a run.\n */\nexport class Telemetry {\n /**\n * Returns `true` when telemetry is disabled via `DO_NOT_TRACK` or `KUBB_DISABLE_TELEMETRY`.\n */\n static isDisabled(): boolean {\n return (\n process.env['DO_NOT_TRACK'] === '1' ||\n process.env['DO_NOT_TRACK'] === 'true' ||\n process.env['KUBB_DISABLE_TELEMETRY'] === '1' ||\n process.env['KUBB_DISABLE_TELEMETRY'] === 'true'\n )\n }\n\n /**\n * Build an anonymous telemetry payload from a completed generation run.\n */\n static build(options: {\n command: 'generate' | 'mcp' | 'validate' | 'agent'\n kubbVersion: string\n plugins?: Array<TelemetryPlugin>\n hrStart: [number, number]\n filesCreated?: number\n status: 'success' | 'failed'\n }): TelemetryEvent {\n const [seconds, nanoseconds] = process.hrtime(options.hrStart)\n const duration = Math.round(seconds * 1000 + nanoseconds / 1e6)\n\n return {\n command: options.command,\n kubbVersion: options.kubbVersion,\n nodeVersion: process.versions.node.split('.')[0] as string,\n runtime: getRuntimeName(),\n runtimeVersion: getRuntimeVersion().split('.')[0] as string,\n platform: os.platform(),\n ci: isCIEnvironment(),\n plugins: options.plugins ?? [],\n duration,\n filesCreated: options.filesCreated ?? 0,\n status: options.status,\n }\n }\n\n /**\n * Convert a {@link TelemetryEvent} into an OTLP-compatible JSON trace payload.\n * See https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/\n */\n static buildOtlpPayload(event: TelemetryEvent): OtlpExportTraceServiceRequest {\n const traceId = randomBytes(16).toString('hex')\n const spanId = randomBytes(8).toString('hex')\n const endTimeNs = BigInt(Date.now()) * 1_000_000n\n const startTimeNs = endTimeNs - BigInt(event.duration) * 1_000_000n\n\n const attributes: Array<OtlpKeyValue> = [\n { key: 'kubb.command', value: { stringValue: event.command } },\n { key: 'kubb.version', value: { stringValue: event.kubbVersion } },\n { key: 'kubb.node_version', value: { stringValue: event.nodeVersion } },\n { key: 'kubb.runtime', value: { stringValue: event.runtime } },\n { key: 'kubb.runtime_version', value: { stringValue: event.runtimeVersion } },\n { key: 'kubb.platform', value: { stringValue: event.platform } },\n { key: 'kubb.ci', value: { boolValue: event.ci } },\n { key: 'kubb.files_created', value: { intValue: event.filesCreated } },\n { key: 'kubb.status', value: { stringValue: event.status } },\n {\n key: 'kubb.plugins',\n value: {\n arrayValue: {\n values: event.plugins.map(\n (p): OtlpKvListValue => ({\n kvlistValue: {\n values: [\n { key: 'name', value: { stringValue: p.name } },\n {\n key: 'options',\n value: {\n stringValue: JSON.stringify({\n ...p.options,\n usedEnumNames: undefined,\n }),\n },\n },\n ],\n },\n }),\n ),\n },\n },\n },\n ]\n\n return {\n resourceSpans: [\n {\n resource: {\n attributes: [\n { key: 'service.name', value: { stringValue: 'kubb-core' } },\n {\n key: 'service.version',\n value: { stringValue: event.kubbVersion },\n },\n { key: 'telemetry.sdk.language', value: { stringValue: 'nodejs' } },\n ],\n },\n scopeSpans: [\n {\n scope: { name: 'kubb-core', version: event.kubbVersion },\n spans: [\n {\n traceId,\n spanId,\n name: event.command,\n kind: 1 satisfies OtlpSpanKind,\n startTimeUnixNano: String(startTimeNs),\n endTimeUnixNano: String(endTimeNs),\n attributes,\n status: {\n code: (event.status === 'success' ? 1 : 2) satisfies OtlpStatusCode,\n },\n },\n ],\n },\n ],\n },\n ],\n }\n }\n\n /**\n * Send an anonymous telemetry event to the Kubb OTLP endpoint. Respects `DO_NOT_TRACK` and\n * `KUBB_DISABLE_TELEMETRY`, and fails silently so telemetry never interrupts a run.\n */\n static async send(event: TelemetryEvent): Promise<void> {\n if (Telemetry.isDisabled()) {\n return\n }\n\n await executeIfOnline(async () => {\n try {\n await fetch(`${OTLP_ENDPOINT}/v1/traces`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Kubb-Telemetry-Version': '1',\n 'Kubb-Telemetry-Source': 'kubb-core',\n },\n body: JSON.stringify(Telemetry.buildOtlpPayload(event)),\n signal: AbortSignal.timeout(5_000),\n })\n } catch (_e) {\n // Fail silently, telemetry must never break the run\n }\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAYA,SAAgB,kBAA2B;CACzC,OAAO,CAAC,EACN,QAAQ,IAAI,MACZ,QAAQ,IAAI,kBACZ,QAAQ,IAAI,aACZ,QAAQ,IAAI,0BACZ,QAAQ,IAAI,eACZ,QAAQ,IAAI,YACZ,QAAQ,IAAI,UACZ,QAAQ,IAAI,oBACZ,QAAQ,IAAI,aACZ,QAAQ,IAAI;AAEhB;;;;;;;;;;;;;;;;;AAkBA,SAAgB,YAAqB;CACnC,OAAO,CAAC,CAAC,QAAQ,OAAO,UAAU,QAAQ,OAAO,WAAW,KAAK,KAAK,CAAC,gBAAgB;AACzF;;;;;;ACxCA,MAAM,eAAe;CAAC;CAAkB;CAAkB;AAAiB;;;;;;;;;;;;AAa3E,eAAsB,WAA6B;CACjD,KAAK,MAAM,UAAU,cACnB,IAAI;EACF,MAAMA,SAAY,QAAQ,MAAM;EAChC,OAAO;CACT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a,KAAK,UAAU;MAC1B,GAAG,EAAE;MACL,eAAe,KAAA;KACjB,CAAC,EACH;IACF,CACF,EACF,EACF,EACF,EACF,EACF;GACF;EACF;EAEA,OAAO,EACL,eAAe,CACb;GACE,UAAU,EACR,YAAY;IACV;KAAE,KAAK;KAAgB,OAAO,EAAE,aAAa,YAAY;IAAE;IAC3D;KACE,KAAK;KACL,OAAO,EAAE,aAAa,MAAM,YAAY;IAC1C;IACA;KAAE,KAAK;KAA0B,OAAO,EAAE,aAAa,SAAS;IAAE;GACpE,EACF;GACA,YAAY,CACV;IACE,OAAO;KAAE,MAAM;KAAa,SAAS,MAAM;IAAY;IACvD,OAAO,CACL;KACE;KACA;KACA,MAAM,MAAM;KACZ,MAAM;KACN,mBAAmB,OAAO,WAAW;KACrC,iBAAiB,OAAO,SAAS;KACjC;KACA,QAAQ,EACN,MAAO,MAAM,WAAW,YAAY,IAAI,EAC1C;IACF,CACF;GACF,CACF;EACF,CACF,EACF;CACF;;;;;CAMA,aAAa,KAAK,OAAsC;EACtD,IAAI,UAAU,WAAW,GACvB;EAGF,MAAM,gBAAgB,YAAY;GAChC,IAAI;IACF,MAAM,MAAM,GAAG,cAAc,aAAa;KACxC,QAAQ;KACR,SAAS;MACP,gBAAgB;MAChB,0BAA0B;MAC1B,yBAAyB;KAC3B;KACA,MAAM,KAAK,UAAU,UAAU,iBAAiB,KAAK,CAAC;KACtD,QAAQ,YAAY,QAAQ,GAAK;IACnC,CAAC;GACH,SAAS,IAAI,CAEb;EACF,CAAC;CACH;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require("./chunk-
|
|
1
|
+
require("./chunk-Bx3C2hgW.cjs");
|
|
2
2
|
//#region ../../internals/utils/src/cli/define.ts
|
|
3
3
|
/**
|
|
4
4
|
* Returns a `CLIAdapter` as-is with full type inference. Pass a custom adapter to `createCLI` to swap the CLI engine.
|
|
@@ -51,4 +51,4 @@ Object.defineProperty(exports, "defineCommand", {
|
|
|
51
51
|
}
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
-
//# sourceMappingURL=define-
|
|
54
|
+
//# sourceMappingURL=define-C4AB3POr.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-
|
|
1
|
+
{"version":3,"file":"define-C4AB3POr.cjs","names":[],"sources":["../../../internals/utils/src/cli/define.ts"],"sourcesContent":["import type { CLIAdapter, CommandDefinition, OptionDefinition } from './types.ts'\n\ntype OptionTypeMap = { string: string; boolean: boolean }\n\ntype IsRequired<O extends OptionDefinition> = O['default'] extends string | boolean ? true : O['required'] extends true ? true : false\n\n/**\n * Infers typed values from an options record. Options with a `default` or `required: true` are always defined.\n */\ntype InferValues<O extends Record<string, OptionDefinition>> = {\n [K in keyof O as IsRequired<O[K]> extends true ? K : never]: OptionTypeMap[O[K]['type']]\n} & {\n [K in keyof O as IsRequired<O[K]> extends true ? never : K]?: OptionTypeMap[O[K]['type']]\n}\n\n/**\n * Returns a `CLIAdapter` as-is with full type inference. Pass a custom adapter to `createCLI` to swap the CLI engine.\n *\n * @example\n * ```ts\n * const adapter = defineCLIAdapter({ run: myRun, renderHelp: myHelp })\n * createCLI({ adapter }).run(commands, argv, opts)\n * ```\n */\nexport function defineCLIAdapter(adapter: CLIAdapter): CLIAdapter {\n return adapter\n}\n\n/**\n * Returns a `CommandDefinition` with typed `values` in `run()`.\n * The callback receives `values` inferred from the declared options — no casts needed.\n *\n * @example\n * ```ts\n * const generate = defineCommand({\n * name: 'generate',\n * description: 'Generate client code',\n * options: { config: { type: 'string', description: 'Config path' } },\n * async run({ values }) { console.log(values.config) },\n * })\n * ```\n */\nexport function defineCommand<O extends Record<string, OptionDefinition>>(def: {\n name: string\n description: string\n arguments?: string[]\n examples?: string[]\n options?: O\n subCommands?: CommandDefinition[]\n run?: (args: { values: InferValues<O>; positionals: string[] }) => Promise<void>\n}): CommandDefinition {\n const { run, ...rest } = def\n if (!run) return rest\n return {\n ...rest,\n run: (args) =>\n run({\n values: args.values as InferValues<O>,\n positionals: args.positionals,\n }),\n }\n}\n"],"mappings":";;;;;;;;;;;AAwBA,SAAgB,iBAAiB,SAAiC;CAChE,OAAO;AACT;;;;;;;;;;;;;;;AAgBA,SAAgB,cAA0D,KAQpD;CACpB,MAAM,EAAE,KAAK,GAAG,SAAS;CACzB,IAAI,CAAC,KAAK,OAAO;CACjB,OAAO;EACL,GAAG;EACH,MAAM,SACJ,IAAI;GACF,QAAQ,KAAK;GACb,aAAa,KAAK;EACpB,CAAC;CACL;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./chunk
|
|
1
|
+
import "./chunk-C0LytTxp.js";
|
|
2
2
|
//#region ../../internals/utils/src/cli/define.ts
|
|
3
3
|
/**
|
|
4
4
|
* Returns a `CLIAdapter` as-is with full type inference. Pass a custom adapter to `createCLI` to swap the CLI engine.
|
|
@@ -40,4 +40,4 @@ function defineCommand(def) {
|
|
|
40
40
|
//#endregion
|
|
41
41
|
export { defineCommand as n, defineCLIAdapter as t };
|
|
42
42
|
|
|
43
|
-
//# sourceMappingURL=define-
|
|
43
|
+
//# sourceMappingURL=define-C63T4jp6.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-
|
|
1
|
+
{"version":3,"file":"define-C63T4jp6.js","names":[],"sources":["../../../internals/utils/src/cli/define.ts"],"sourcesContent":["import type { CLIAdapter, CommandDefinition, OptionDefinition } from './types.ts'\n\ntype OptionTypeMap = { string: string; boolean: boolean }\n\ntype IsRequired<O extends OptionDefinition> = O['default'] extends string | boolean ? true : O['required'] extends true ? true : false\n\n/**\n * Infers typed values from an options record. Options with a `default` or `required: true` are always defined.\n */\ntype InferValues<O extends Record<string, OptionDefinition>> = {\n [K in keyof O as IsRequired<O[K]> extends true ? K : never]: OptionTypeMap[O[K]['type']]\n} & {\n [K in keyof O as IsRequired<O[K]> extends true ? never : K]?: OptionTypeMap[O[K]['type']]\n}\n\n/**\n * Returns a `CLIAdapter` as-is with full type inference. Pass a custom adapter to `createCLI` to swap the CLI engine.\n *\n * @example\n * ```ts\n * const adapter = defineCLIAdapter({ run: myRun, renderHelp: myHelp })\n * createCLI({ adapter }).run(commands, argv, opts)\n * ```\n */\nexport function defineCLIAdapter(adapter: CLIAdapter): CLIAdapter {\n return adapter\n}\n\n/**\n * Returns a `CommandDefinition` with typed `values` in `run()`.\n * The callback receives `values` inferred from the declared options — no casts needed.\n *\n * @example\n * ```ts\n * const generate = defineCommand({\n * name: 'generate',\n * description: 'Generate client code',\n * options: { config: { type: 'string', description: 'Config path' } },\n * async run({ values }) { console.log(values.config) },\n * })\n * ```\n */\nexport function defineCommand<O extends Record<string, OptionDefinition>>(def: {\n name: string\n description: string\n arguments?: string[]\n examples?: string[]\n options?: O\n subCommands?: CommandDefinition[]\n run?: (args: { values: InferValues<O>; positionals: string[] }) => Promise<void>\n}): CommandDefinition {\n const { run, ...rest } = def\n if (!run) return rest\n return {\n ...rest,\n run: (args) =>\n run({\n values: args.values as InferValues<O>,\n positionals: args.positionals,\n }),\n }\n}\n"],"mappings":";;;;;;;;;;;AAwBA,SAAgB,iBAAiB,SAAiC;CAChE,OAAO;AACT;;;;;;;;;;;;;;;AAgBA,SAAgB,cAA0D,KAQpD;CACpB,MAAM,EAAE,KAAK,GAAG,SAAS;CACzB,IAAI,CAAC,KAAK,OAAO;CACjB,OAAO;EACL,GAAG;EACH,MAAM,SACJ,IAAI;GACF,QAAQ,KAAK;GACb,aAAa,KAAK;EACpB,CAAC;CACL;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./chunk
|
|
1
|
+
import "./chunk-C0LytTxp.js";
|
|
2
2
|
//#region ../../internals/utils/src/errors.ts
|
|
3
3
|
/**
|
|
4
4
|
* Coerces an unknown thrown value to an `Error` instance.
|
|
@@ -40,4 +40,4 @@ function toCause(error) {
|
|
|
40
40
|
//#endregion
|
|
41
41
|
export { toCause as n, toError as r, getErrorMessage as t };
|
|
42
42
|
|
|
43
|
-
//# sourceMappingURL=errors-
|
|
43
|
+
//# sourceMappingURL=errors-BsemQCMn.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors-
|
|
1
|
+
{"version":3,"file":"errors-BsemQCMn.js","names":[],"sources":["../../../internals/utils/src/errors.ts"],"sourcesContent":["/**\n * Thrown when one or more errors occur during a Kubb build.\n * Carries the full list of underlying errors on `errors`.\n *\n * @example\n * ```ts\n * throw new BuildError('Build failed', { errors: [err1, err2] })\n * ```\n */\nexport class BuildError extends Error {\n errors: Array<Error>\n\n constructor(message: string, options: { cause?: Error; errors: Array<Error> }) {\n super(message, { cause: options.cause })\n this.name = 'BuildError'\n this.errors = options.errors\n }\n}\n\n/**\n * Coerces an unknown thrown value to an `Error` instance.\n * Returns the value as-is when it is already an `Error`; otherwise wraps it with `String(value)`.\n *\n * @example\n * ```ts\n * try { ... } catch(err) {\n * throw new BuildError('Build failed', { cause: toError(err), errors: [] })\n * }\n * ```\n */\nexport function toError(value: unknown): Error {\n return value instanceof Error ? value : new Error(String(value))\n}\n\n/**\n * Extracts a human-readable message from any thrown value.\n *\n * @example\n * ```ts\n * getErrorMessage(new Error('oops')) // 'oops'\n * getErrorMessage('plain string') // 'plain string'\n * ```\n */\nexport function getErrorMessage(value: unknown): string {\n return value instanceof Error ? value.message : String(value)\n}\n\n/**\n * Extracts the `.cause` of an `Error` as an `Error`, or `undefined` when absent or not an `Error`.\n *\n * @example\n * ```ts\n * const cause = toCause(buildError) // Error | undefined\n * ```\n */\nexport function toCause(error: Error): Error | undefined {\n return error.cause instanceof Error ? error.cause : undefined\n}\n"],"mappings":";;;;;;;;;;;;;AA8BA,SAAgB,QAAQ,OAAuB;CAC7C,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;AACjE;;;;;;;;;;AAWA,SAAgB,gBAAgB,OAAwB;CACtD,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAC9D;;;;;;;;;AAUA,SAAgB,QAAQ,OAAiC;CACvD,OAAO,MAAM,iBAAiB,QAAQ,MAAM,QAAQ,KAAA;AACtD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require("./chunk-
|
|
1
|
+
require("./chunk-Bx3C2hgW.cjs");
|
|
2
2
|
//#region ../../internals/utils/src/errors.ts
|
|
3
3
|
/**
|
|
4
4
|
* Coerces an unknown thrown value to an `Error` instance.
|
|
@@ -57,4 +57,4 @@ Object.defineProperty(exports, "toError", {
|
|
|
57
57
|
}
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
-
//# sourceMappingURL=errors-
|
|
60
|
+
//# sourceMappingURL=errors-DykI11xo.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors-
|
|
1
|
+
{"version":3,"file":"errors-DykI11xo.cjs","names":[],"sources":["../../../internals/utils/src/errors.ts"],"sourcesContent":["/**\n * Thrown when one or more errors occur during a Kubb build.\n * Carries the full list of underlying errors on `errors`.\n *\n * @example\n * ```ts\n * throw new BuildError('Build failed', { errors: [err1, err2] })\n * ```\n */\nexport class BuildError extends Error {\n errors: Array<Error>\n\n constructor(message: string, options: { cause?: Error; errors: Array<Error> }) {\n super(message, { cause: options.cause })\n this.name = 'BuildError'\n this.errors = options.errors\n }\n}\n\n/**\n * Coerces an unknown thrown value to an `Error` instance.\n * Returns the value as-is when it is already an `Error`; otherwise wraps it with `String(value)`.\n *\n * @example\n * ```ts\n * try { ... } catch(err) {\n * throw new BuildError('Build failed', { cause: toError(err), errors: [] })\n * }\n * ```\n */\nexport function toError(value: unknown): Error {\n return value instanceof Error ? value : new Error(String(value))\n}\n\n/**\n * Extracts a human-readable message from any thrown value.\n *\n * @example\n * ```ts\n * getErrorMessage(new Error('oops')) // 'oops'\n * getErrorMessage('plain string') // 'plain string'\n * ```\n */\nexport function getErrorMessage(value: unknown): string {\n return value instanceof Error ? value.message : String(value)\n}\n\n/**\n * Extracts the `.cause` of an `Error` as an `Error`, or `undefined` when absent or not an `Error`.\n *\n * @example\n * ```ts\n * const cause = toCause(buildError) // Error | undefined\n * ```\n */\nexport function toCause(error: Error): Error | undefined {\n return error.cause instanceof Error ? error.cause : undefined\n}\n"],"mappings":";;;;;;;;;;;;;AA8BA,SAAgB,QAAQ,OAAuB;CAC7C,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;AACjE;;;;;;;;;;AAWA,SAAgB,gBAAgB,OAAwB;CACtD,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAC9D;;;;;;;;;AAUA,SAAgB,QAAQ,OAAiC;CACvD,OAAO,MAAM,iBAAiB,QAAQ,MAAM,QAAQ,KAAA;AACtD"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
require("./chunk-Bx3C2hgW.cjs");
|
|
2
|
+
//#region src/commands/generate.ts
|
|
3
|
+
const command = require("./define-C4AB3POr.cjs").defineCommand({
|
|
4
|
+
name: "generate",
|
|
5
|
+
description: "Generate TypeScript types, API clients, React Query hooks, Zod schemas, and more from an OpenAPI specification. Reads kubb.config.ts by default. Pass an OpenAPI file path as the first argument to override the input without editing the config.",
|
|
6
|
+
arguments: ["[input]"],
|
|
7
|
+
examples: [
|
|
8
|
+
"kubb generate",
|
|
9
|
+
"kubb generate ./openapi.yaml",
|
|
10
|
+
"kubb generate --config kubb.config.ts",
|
|
11
|
+
"kubb generate --watch"
|
|
12
|
+
],
|
|
13
|
+
options: {
|
|
14
|
+
config: {
|
|
15
|
+
type: "string",
|
|
16
|
+
description: "Path to the Kubb config",
|
|
17
|
+
short: "c"
|
|
18
|
+
},
|
|
19
|
+
logLevel: {
|
|
20
|
+
type: "string",
|
|
21
|
+
description: "Info, silent or verbose",
|
|
22
|
+
short: "l",
|
|
23
|
+
default: "info",
|
|
24
|
+
hint: "silent|info|verbose",
|
|
25
|
+
enum: [
|
|
26
|
+
"silent",
|
|
27
|
+
"info",
|
|
28
|
+
"verbose"
|
|
29
|
+
]
|
|
30
|
+
},
|
|
31
|
+
watch: {
|
|
32
|
+
type: "boolean",
|
|
33
|
+
description: "Watch mode based on the input file",
|
|
34
|
+
short: "w",
|
|
35
|
+
default: false
|
|
36
|
+
},
|
|
37
|
+
verbose: {
|
|
38
|
+
type: "boolean",
|
|
39
|
+
description: "Override logLevel to verbose",
|
|
40
|
+
short: "v",
|
|
41
|
+
default: false
|
|
42
|
+
},
|
|
43
|
+
silent: {
|
|
44
|
+
type: "boolean",
|
|
45
|
+
description: "Override logLevel to silent",
|
|
46
|
+
short: "s",
|
|
47
|
+
default: false
|
|
48
|
+
},
|
|
49
|
+
reporter: {
|
|
50
|
+
type: "string",
|
|
51
|
+
description: "Reporters that render the run, comma-separated. Overrides config.reporters",
|
|
52
|
+
hint: "cli|json|file",
|
|
53
|
+
enum: [
|
|
54
|
+
"cli",
|
|
55
|
+
"json",
|
|
56
|
+
"file"
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
"no-cache": {
|
|
60
|
+
type: "boolean",
|
|
61
|
+
description: "Disable the incremental build cache and force a full regeneration",
|
|
62
|
+
default: false
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
async run({ values, positionals }) {
|
|
66
|
+
const logLevel = values.verbose ? "verbose" : values.silent ? "silent" : values.logLevel;
|
|
67
|
+
const reporters = values.reporter?.split(",").map((name) => name.trim()).filter(Boolean);
|
|
68
|
+
const { run } = await Promise.resolve().then(() => require("./run-CDs_ebOt.cjs"));
|
|
69
|
+
await run({
|
|
70
|
+
input: positionals[0],
|
|
71
|
+
configPath: values.config,
|
|
72
|
+
logLevel,
|
|
73
|
+
watch: values.watch,
|
|
74
|
+
reporters,
|
|
75
|
+
noCache: values["no-cache"]
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
//#endregion
|
|
80
|
+
exports.command = command;
|
|
81
|
+
|
|
82
|
+
//# sourceMappingURL=generate-BRpukupe.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-BRpukupe.cjs","names":["defineCommand"],"sources":["../src/commands/generate.ts"],"sourcesContent":["import { defineCommand } from '@internals/utils'\nimport type { ReporterName } from '@kubb/core'\n\nexport const command = defineCommand({\n name: 'generate',\n description:\n 'Generate TypeScript types, API clients, React Query hooks, Zod schemas, and more from an OpenAPI specification. Reads kubb.config.ts by default. Pass an OpenAPI file path as the first argument to override the input without editing the config.',\n arguments: ['[input]'],\n examples: ['kubb generate', 'kubb generate ./openapi.yaml', 'kubb generate --config kubb.config.ts', 'kubb generate --watch'],\n options: {\n config: {\n type: 'string',\n description: 'Path to the Kubb config',\n short: 'c',\n },\n logLevel: {\n type: 'string',\n description: 'Info, silent or verbose',\n short: 'l',\n default: 'info',\n hint: 'silent|info|verbose',\n enum: ['silent', 'info', 'verbose'],\n },\n watch: {\n type: 'boolean',\n description: 'Watch mode based on the input file',\n short: 'w',\n default: false,\n },\n verbose: {\n type: 'boolean',\n description: 'Override logLevel to verbose',\n short: 'v',\n default: false,\n },\n silent: {\n type: 'boolean',\n description: 'Override logLevel to silent',\n short: 's',\n default: false,\n },\n reporter: {\n type: 'string',\n description: 'Reporters that render the run, comma-separated. Overrides config.reporters',\n hint: 'cli|json|file',\n enum: ['cli', 'json', 'file'],\n },\n 'no-cache': {\n type: 'boolean',\n description: 'Disable the incremental build cache and force a full regeneration',\n default: false,\n },\n },\n async run({ values, positionals }) {\n const logLevel = values.verbose ? 'verbose' : values.silent ? 'silent' : values.logLevel\n const reporters = values.reporter\n ?.split(',')\n .map((name) => name.trim())\n .filter(Boolean) as Array<ReporterName> | undefined\n const { run } = await import('../runners/generate/run.ts')\n\n await run({\n input: positionals[0],\n configPath: values.config,\n logLevel,\n watch: values.watch,\n reporters,\n noCache: values['no-cache'],\n })\n },\n})\n"],"mappings":";;AAGA,MAAa,yCAAUA,CAAAA,CAAAA,cAAc;CACnC,MAAM;CACN,aACE;CACF,WAAW,CAAC,SAAS;CACrB,UAAU;EAAC;EAAiB;EAAgC;EAAyC;CAAuB;CAC5H,SAAS;EACP,QAAQ;GACN,MAAM;GACN,aAAa;GACb,OAAO;EACT;EACA,UAAU;GACR,MAAM;GACN,aAAa;GACb,OAAO;GACP,SAAS;GACT,MAAM;GACN,MAAM;IAAC;IAAU;IAAQ;GAAS;EACpC;EACA,OAAO;GACL,MAAM;GACN,aAAa;GACb,OAAO;GACP,SAAS;EACX;EACA,SAAS;GACP,MAAM;GACN,aAAa;GACb,OAAO;GACP,SAAS;EACX;EACA,QAAQ;GACN,MAAM;GACN,aAAa;GACb,OAAO;GACP,SAAS;EACX;EACA,UAAU;GACR,MAAM;GACN,aAAa;GACb,MAAM;GACN,MAAM;IAAC;IAAO;IAAQ;GAAM;EAC9B;EACA,YAAY;GACV,MAAM;GACN,aAAa;GACb,SAAS;EACX;CACF;CACA,MAAM,IAAI,EAAE,QAAQ,eAAe;EACjC,MAAM,WAAW,OAAO,UAAU,YAAY,OAAO,SAAS,WAAW,OAAO;EAChF,MAAM,YAAY,OAAO,UACrB,MAAM,GAAG,CAAC,CACX,KAAK,SAAS,KAAK,KAAK,CAAC,CAAC,CAC1B,OAAO,OAAO;EACjB,MAAM,EAAE,QAAQ,MAAA,QAAA,QAAA,CAAA,CAAA,WAAA,QAAM,oBAAA,CAAA;EAEtB,MAAM,IAAI;GACR,OAAO,YAAY;GACnB,YAAY,OAAO;GACnB;GACA,OAAO,OAAO;GACd;GACA,SAAS,OAAO;EAClB,CAAC;CACH;AACF,CAAC"}
|