@kubb/cli 5.0.0-beta.53 → 5.0.0-beta.55
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/README.md +0 -1
- package/dist/{Telemetry-DC5WVMB9.cjs → Telemetry-BuDSora3.cjs} +83 -112
- package/dist/Telemetry-BuDSora3.cjs.map +1 -0
- package/dist/{Telemetry-BZH4YIxq.js → Telemetry-C66uYyC2.js} +82 -111
- package/dist/Telemetry-C66uYyC2.js.map +1 -0
- package/dist/define-C4AB3POr.cjs.map +1 -1
- package/dist/define-C63T4jp6.js.map +1 -1
- package/dist/{generate-w8nvAG7i.js → generate-CByoI4cQ.js} +3 -9
- package/dist/generate-CByoI4cQ.js.map +1 -0
- package/dist/{generate-DzULb5D8.cjs → generate-Dg9jZ8xa.cjs} +3 -9
- package/dist/generate-Dg9jZ8xa.cjs.map +1 -0
- package/dist/index.cjs +8 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +8 -22
- package/dist/index.js.map +1 -1
- package/dist/{init-BtYgNYSH.js → init-C7KqFbJT.js} +3 -3
- package/dist/{init-BtYgNYSH.js.map → init-C7KqFbJT.js.map} +1 -1
- package/dist/{init-Dptxcf7c.cjs → init-Cptp_SSW.cjs} +3 -3
- package/dist/{init-Dptxcf7c.cjs.map → init-Cptp_SSW.cjs.map} +1 -1
- package/dist/{mcp-CccZq-lH.cjs → mcp-CM19f7rG.cjs} +3 -3
- package/dist/{mcp-CccZq-lH.cjs.map → mcp-CM19f7rG.cjs.map} +1 -1
- package/dist/{mcp-7cxItivW.js → mcp-ClbeosGy.js} +3 -3
- package/dist/{mcp-7cxItivW.js.map → mcp-ClbeosGy.js.map} +1 -1
- package/dist/{package-C5Egcs3F.cjs → package-dLlE0LgE.cjs} +2 -2
- package/dist/package-dLlE0LgE.cjs.map +1 -0
- package/dist/package-scFCPMiP.js +6 -0
- package/dist/package-scFCPMiP.js.map +1 -0
- package/dist/{run-C-omuksC.js → run-BG7Giryi.js} +36 -99
- package/dist/run-BG7Giryi.js.map +1 -0
- package/dist/{run-DMWGLJUx.cjs → run-Bj64iPU_.cjs} +2 -2
- package/dist/{run-DMWGLJUx.cjs.map → run-Bj64iPU_.cjs.map} +1 -1
- package/dist/{run-CmW3AT37.cjs → run-BoR5nxtV.cjs} +86 -168
- package/dist/run-BoR5nxtV.cjs.map +1 -0
- package/dist/{run-C7cr0qhi.js → run-CUkZ6gnP.js} +2 -2
- package/dist/{run-C7cr0qhi.js.map → run-CUkZ6gnP.js.map} +1 -1
- package/dist/{run-DJP6fr9w.js → run-CY0htF8O.js} +83 -165
- package/dist/run-CY0htF8O.js.map +1 -0
- package/dist/{run-DGMgkbD3.cjs → run-DCXY-eRK.cjs} +2 -2
- package/dist/{run-DGMgkbD3.cjs.map → run-DCXY-eRK.cjs.map} +1 -1
- package/dist/{run-BtjzfTz3.cjs → run-DpKny2hT.cjs} +30 -93
- package/dist/run-DpKny2hT.cjs.map +1 -0
- package/dist/{run-DLVIbuN0.js → run-OWQyNzZx.js} +2 -2
- package/dist/{run-DLVIbuN0.js.map → run-OWQyNzZx.js.map} +1 -1
- 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-DNzxpCMJ.js → validate-BtKwM4zb.js} +3 -3
- package/dist/{validate-DNzxpCMJ.js.map → validate-BtKwM4zb.js.map} +1 -1
- package/dist/{validate-CiL4bco7.cjs → validate-Cj5IIh1M.cjs} +3 -3
- package/dist/{validate-CiL4bco7.cjs.map → validate-Cj5IIh1M.cjs.map} +1 -1
- package/package.json +5 -5
- package/src/Telemetry.ts +20 -22
- package/src/commands/generate.ts +0 -6
- package/src/constants.ts +1 -1
- package/src/index.ts +4 -21
- package/src/runners/generate/run.ts +12 -16
- package/src/runners/generate/utils.ts +18 -19
- package/src/runners/init/utils.ts +9 -3
- package/dist/Telemetry-BZH4YIxq.js.map +0 -1
- package/dist/Telemetry-DC5WVMB9.cjs.map +0 -1
- package/dist/generate-DzULb5D8.cjs.map +0 -1
- package/dist/generate-w8nvAG7i.js.map +0 -1
- package/dist/package-C5Egcs3F.cjs.map +0 -1
- package/dist/package-DJCeuUrP.js +0 -6
- package/dist/package-DJCeuUrP.js.map +0 -1
- package/dist/run-BtjzfTz3.cjs.map +0 -1
- package/dist/run-C-omuksC.js.map +0 -1
- package/dist/run-CmW3AT37.cjs.map +0 -1
- package/dist/run-DJP6fr9w.js.map +0 -1
- package/dist/shell-DsgkfUSW.js +0 -51
- package/dist/shell-DsgkfUSW.js.map +0 -1
- package/dist/shell-Lh-vLWwH.cjs +0 -62
- package/dist/shell-Lh-vLWwH.cjs.map +0 -1
package/README.md
CHANGED
|
@@ -110,7 +110,6 @@ npx kubb generate
|
|
|
110
110
|
| `--verbose` | `-v` | boolean | `false` | Override log level to `verbose` |
|
|
111
111
|
| `--silent` | `-s` | boolean | `false` | Override log level to `silent` |
|
|
112
112
|
| `--reporter <names>` | | string | `cli` | Reporters that render the run, comma-separated: `cli`, `json`, `file`. Overrides `config.reporters` |
|
|
113
|
-
| `--no-cache` | | boolean | `false` | Disable the incremental build cache and regenerate everything |
|
|
114
113
|
|
|
115
114
|
#### Examples
|
|
116
115
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const require_chunk = require("./chunk-Bx3C2hgW.cjs");
|
|
2
2
|
let node_crypto = require("node:crypto");
|
|
3
|
-
let node_dns = require("node:dns");
|
|
4
3
|
let node_os = require("node:os");
|
|
5
4
|
node_os = require_chunk.__toESM(node_os, 1);
|
|
6
5
|
let node_process = require("node:process");
|
|
@@ -38,104 +37,78 @@ function isCIEnvironment() {
|
|
|
38
37
|
* ```
|
|
39
38
|
*/
|
|
40
39
|
function canUseTTY() {
|
|
41
|
-
return
|
|
42
|
-
}
|
|
43
|
-
//#endregion
|
|
44
|
-
//#region ../../internals/utils/src/network.ts
|
|
45
|
-
/**
|
|
46
|
-
* Well-known stable domains used as DNS probes to check internet connectivity.
|
|
47
|
-
*/
|
|
48
|
-
const TEST_DOMAINS = [
|
|
49
|
-
"dns.google.com",
|
|
50
|
-
"cloudflare.com",
|
|
51
|
-
"one.one.one.one"
|
|
52
|
-
];
|
|
53
|
-
/**
|
|
54
|
-
* Returns `true` when the system has internet connectivity.
|
|
55
|
-
* Probes DNS resolution against well-known stable domains.
|
|
56
|
-
*
|
|
57
|
-
* @example
|
|
58
|
-
* ```ts
|
|
59
|
-
* if (await isOnline()) {
|
|
60
|
-
* await fetchLatestVersion()
|
|
61
|
-
* }
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
|
-
async function isOnline() {
|
|
65
|
-
for (const domain of TEST_DOMAINS) try {
|
|
66
|
-
await node_dns.promises.resolve(domain);
|
|
67
|
-
return true;
|
|
68
|
-
} catch {}
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Executes `fn` only when the system is online. Returns `null` when offline or on error.
|
|
73
|
-
*
|
|
74
|
-
* @example
|
|
75
|
-
* ```ts
|
|
76
|
-
* const version = await executeIfOnline(() => fetchLatestVersion('kubb'))
|
|
77
|
-
* // null when offline
|
|
78
|
-
* ```
|
|
79
|
-
*/
|
|
80
|
-
async function executeIfOnline(fn) {
|
|
81
|
-
if (!await isOnline()) return null;
|
|
82
|
-
try {
|
|
83
|
-
return await fn();
|
|
84
|
-
} catch {
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
40
|
+
return process.stdout.isTTY && (process.stdout.columns ?? 0) > 0 && !isCIEnvironment();
|
|
87
41
|
}
|
|
88
42
|
//#endregion
|
|
89
43
|
//#region ../../internals/utils/src/runtime.ts
|
|
90
44
|
/**
|
|
91
|
-
*
|
|
45
|
+
* Detects the JavaScript runtime executing the current process and exposes its name and version.
|
|
92
46
|
*
|
|
93
|
-
*
|
|
94
|
-
* because Bun polyfills `process.versions.node` for Node compatibility and would
|
|
95
|
-
* otherwise look like Node.
|
|
96
|
-
*
|
|
97
|
-
* @example
|
|
98
|
-
* ```ts
|
|
99
|
-
* if (isBun()) {
|
|
100
|
-
* await Bun.write(path, data)
|
|
101
|
-
* }
|
|
102
|
-
* ```
|
|
47
|
+
* Prefer the shared {@link runtime} instance over constructing your own.
|
|
103
48
|
*/
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
*
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
* ```
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
49
|
+
var Runtime = class {
|
|
50
|
+
/**
|
|
51
|
+
* `true` when the current process is running under Bun.
|
|
52
|
+
*
|
|
53
|
+
* Detection keys off the global `Bun` object rather than `process.versions`,
|
|
54
|
+
* because Bun polyfills `process.versions.node` for Node compatibility and would
|
|
55
|
+
* otherwise look like Node.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* if (runtime.isBun) {
|
|
60
|
+
* await Bun.write(path, data)
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
get isBun() {
|
|
65
|
+
return typeof Bun !== "undefined";
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* `true` when the current process is running under Deno.
|
|
69
|
+
*/
|
|
70
|
+
get isDeno() {
|
|
71
|
+
return typeof globalThis.Deno !== "undefined";
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* `true` when the current process is running under Node.
|
|
75
|
+
*
|
|
76
|
+
* Bun and Deno are excluded first so a polyfilled `process` does not register as Node.
|
|
77
|
+
*/
|
|
78
|
+
get isNode() {
|
|
79
|
+
return !this.isBun && !this.isDeno && typeof process !== "undefined" && process.versions?.node != null;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Name of the runtime executing the current process.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* runtime.name // 'bun' when run with `bun kubb`, 'node' otherwise
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
get name() {
|
|
90
|
+
if (this.isBun) return "bun";
|
|
91
|
+
if (this.isDeno) return "deno";
|
|
92
|
+
return "node";
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Version of the active runtime, or an empty string when it cannot be read.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* runtime.version // '1.3.11' under Bun, '22.22.2' under Node
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
get version() {
|
|
103
|
+
if (this.isBun) return process.versions.bun ?? "";
|
|
104
|
+
if (this.isDeno) return globalThis.Deno?.version?.deno ?? "";
|
|
105
|
+
return process.versions?.node ?? "";
|
|
106
|
+
}
|
|
107
|
+
};
|
|
126
108
|
/**
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
* @example
|
|
130
|
-
* ```ts
|
|
131
|
-
* getRuntimeVersion() // '1.3.11' under Bun, '22.22.2' under Node
|
|
132
|
-
* ```
|
|
109
|
+
* Shared {@link Runtime} instance describing the JavaScript runtime executing the current process.
|
|
133
110
|
*/
|
|
134
|
-
|
|
135
|
-
if (isBun()) return process.versions.bun ?? "";
|
|
136
|
-
if (isDeno()) return globalThis.Deno?.version?.deno ?? "";
|
|
137
|
-
return process.versions?.node ?? "";
|
|
138
|
-
}
|
|
111
|
+
const runtime = new Runtime();
|
|
139
112
|
//#endregion
|
|
140
113
|
//#region src/constants.ts
|
|
141
114
|
/**
|
|
@@ -170,7 +143,7 @@ var Telemetry = class Telemetry {
|
|
|
170
143
|
/**
|
|
171
144
|
* Returns `true` when telemetry is disabled via `DO_NOT_TRACK` or `KUBB_DISABLE_TELEMETRY`.
|
|
172
145
|
*/
|
|
173
|
-
static isDisabled() {
|
|
146
|
+
static get isDisabled() {
|
|
174
147
|
return node_process.default.env["DO_NOT_TRACK"] === "1" || node_process.default.env["DO_NOT_TRACK"] === "true" || node_process.default.env["KUBB_DISABLE_TELEMETRY"] === "1" || node_process.default.env["KUBB_DISABLE_TELEMETRY"] === "true";
|
|
175
148
|
}
|
|
176
149
|
/**
|
|
@@ -183,8 +156,8 @@ var Telemetry = class Telemetry {
|
|
|
183
156
|
command: options.command,
|
|
184
157
|
kubbVersion: options.kubbVersion,
|
|
185
158
|
nodeVersion: node_process.default.versions.node.split(".")[0],
|
|
186
|
-
runtime:
|
|
187
|
-
runtimeVersion:
|
|
159
|
+
runtime: runtime.name,
|
|
160
|
+
runtimeVersion: runtime.version.split(".")[0],
|
|
188
161
|
platform: node_os.default.platform(),
|
|
189
162
|
ci: isCIEnvironment(),
|
|
190
163
|
plugins: options.plugins ?? [],
|
|
@@ -291,21 +264,19 @@ var Telemetry = class Telemetry {
|
|
|
291
264
|
* `KUBB_DISABLE_TELEMETRY`, and fails silently so telemetry never interrupts a run.
|
|
292
265
|
*/
|
|
293
266
|
static async send(event) {
|
|
294
|
-
if (Telemetry.isDisabled
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
} catch (_e) {}
|
|
308
|
-
});
|
|
267
|
+
if (Telemetry.isDisabled) return;
|
|
268
|
+
try {
|
|
269
|
+
await fetch(`${OTLP_ENDPOINT}/v1/traces`, {
|
|
270
|
+
method: "POST",
|
|
271
|
+
headers: {
|
|
272
|
+
"Content-Type": "application/json",
|
|
273
|
+
"Kubb-Telemetry-Version": "1",
|
|
274
|
+
"Kubb-Telemetry-Source": "kubb-core"
|
|
275
|
+
},
|
|
276
|
+
body: JSON.stringify(Telemetry.buildOtlpPayload(event)),
|
|
277
|
+
signal: AbortSignal.timeout(5e3)
|
|
278
|
+
});
|
|
279
|
+
} catch (_e) {}
|
|
309
280
|
}
|
|
310
281
|
};
|
|
311
282
|
//#endregion
|
|
@@ -339,11 +310,11 @@ Object.defineProperty(exports, "canUseTTY", {
|
|
|
339
310
|
return canUseTTY;
|
|
340
311
|
}
|
|
341
312
|
});
|
|
342
|
-
Object.defineProperty(exports, "
|
|
313
|
+
Object.defineProperty(exports, "runtime", {
|
|
343
314
|
enumerable: true,
|
|
344
315
|
get: function() {
|
|
345
|
-
return
|
|
316
|
+
return runtime;
|
|
346
317
|
}
|
|
347
318
|
});
|
|
348
319
|
|
|
349
|
-
//# sourceMappingURL=Telemetry-
|
|
320
|
+
//# sourceMappingURL=Telemetry-BuDSora3.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Telemetry-BuDSora3.cjs","names":["process","os"],"sources":["../../../internals/utils/src/env.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","/**\n * Name of the JavaScript runtime executing the current process.\n */\ntype RuntimeName = 'bun' | 'deno' | 'node'\n\n/**\n * Detects the JavaScript runtime executing the current process and exposes its name and version.\n *\n * Prefer the shared {@link runtime} instance over constructing your own.\n */\nclass Runtime {\n /**\n * `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 (runtime.isBun) {\n * await Bun.write(path, data)\n * }\n * ```\n */\n get isBun(): boolean {\n return typeof Bun !== 'undefined'\n }\n\n /**\n * `true` when the current process is running under Deno.\n */\n get isDeno(): boolean {\n return typeof (globalThis as { Deno?: unknown }).Deno !== 'undefined'\n }\n\n /**\n * `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 */\n get isNode(): boolean {\n return !this.isBun && !this.isDeno && typeof process !== 'undefined' && process.versions?.node != null\n }\n\n /**\n * Name of the runtime executing the current process.\n *\n * @example\n * ```ts\n * runtime.name // 'bun' when run with `bun kubb`, 'node' otherwise\n * ```\n */\n get name(): RuntimeName {\n if (this.isBun) return 'bun'\n if (this.isDeno) return 'deno'\n\n return 'node'\n }\n\n /**\n * Version of the active runtime, or an empty string when it cannot be read.\n *\n * @example\n * ```ts\n * runtime.version // '1.3.11' under Bun, '22.22.2' under Node\n * ```\n */\n get version(): string {\n if (this.isBun) return process.versions.bun ?? ''\n if (this.isDeno) return (globalThis as { Deno?: { version?: { deno?: string } } }).Deno?.version?.deno ?? ''\n\n return process.versions?.node ?? ''\n }\n}\n\n/**\n * Shared {@link Runtime} instance describing the JavaScript runtime executing the current process.\n */\nexport const runtime = new Runtime()\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 * 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<string>(['--help', '-h', '--version', '-v'])\n","import { randomBytes } from 'node:crypto'\nimport os from 'node:os'\nimport process from 'node:process'\nimport { isCIEnvironment, runtime } 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: string\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 get 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: runtime.name,\n runtimeVersion: runtime.version.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 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"],"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,QAAQ,OAAO,UAAU,QAAQ,OAAO,WAAW,KAAK,KAAK,CAAC,gBAAgB;AACvF;;;;;;;;ACnCA,IAAM,UAAN,MAAc;;;;;;;;;;;;;;;CAeZ,IAAI,QAAiB;EACnB,OAAO,OAAO,QAAQ;CACxB;;;;CAKA,IAAI,SAAkB;EACpB,OAAO,OAAQ,WAAkC,SAAS;CAC5D;;;;;;CAOA,IAAI,SAAkB;EACpB,OAAO,CAAC,KAAK,SAAS,CAAC,KAAK,UAAU,OAAO,YAAY,eAAe,QAAQ,UAAU,QAAQ;CACpG;;;;;;;;;CAUA,IAAI,OAAoB;EACtB,IAAI,KAAK,OAAO,OAAO;EACvB,IAAI,KAAK,QAAQ,OAAO;EAExB,OAAO;CACT;;;;;;;;;CAUA,IAAI,UAAkB;EACpB,IAAI,KAAK,OAAO,OAAO,QAAQ,SAAS,OAAO;EAC/C,IAAI,KAAK,QAAQ,OAAQ,WAA0D,MAAM,SAAS,QAAQ;EAE1G,OAAO,QAAQ,UAAU,QAAQ;CACnC;AACF;;;;AAKA,MAAa,UAAU,IAAI,QAAQ;;;;;;AC5EnC,MAAa,uBAAuB;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ACF;GACF,CACF;EACF,CACF,EACF;CACF;;;;;CAMA,aAAa,KAAK,OAAsC;EACtD,IAAI,UAAU,YACZ;EAGF,IAAI;GACF,MAAM,MAAM,GAAG,cAAc,aAAa;IACxC,QAAQ;IACR,SAAS;KACP,gBAAgB;KAChB,0BAA0B;KAC1B,yBAAyB;IAC3B;IACA,MAAM,KAAK,UAAU,UAAU,iBAAiB,KAAK,CAAC;IACtD,QAAQ,YAAY,QAAQ,GAAK;GACnC,CAAC;EACH,SAAS,IAAI,CAEb;CACF;AACF"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import "./chunk-C0LytTxp.js";
|
|
2
2
|
import { randomBytes } from "node:crypto";
|
|
3
|
-
import { promises } from "node:dns";
|
|
4
3
|
import os from "node:os";
|
|
5
4
|
import process$1 from "node:process";
|
|
6
5
|
//#region ../../internals/utils/src/env.ts
|
|
@@ -36,104 +35,78 @@ function isCIEnvironment() {
|
|
|
36
35
|
* ```
|
|
37
36
|
*/
|
|
38
37
|
function canUseTTY() {
|
|
39
|
-
return
|
|
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
|
-
}
|
|
38
|
+
return process.stdout.isTTY && (process.stdout.columns ?? 0) > 0 && !isCIEnvironment();
|
|
85
39
|
}
|
|
86
40
|
//#endregion
|
|
87
41
|
//#region ../../internals/utils/src/runtime.ts
|
|
88
42
|
/**
|
|
89
|
-
*
|
|
43
|
+
* Detects the JavaScript runtime executing the current process and exposes its name and version.
|
|
90
44
|
*
|
|
91
|
-
*
|
|
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
|
-
* ```
|
|
45
|
+
* Prefer the shared {@link runtime} instance over constructing your own.
|
|
101
46
|
*/
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
*
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* ```
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
47
|
+
var Runtime = class {
|
|
48
|
+
/**
|
|
49
|
+
* `true` when the current process is running under Bun.
|
|
50
|
+
*
|
|
51
|
+
* Detection keys off the global `Bun` object rather than `process.versions`,
|
|
52
|
+
* because Bun polyfills `process.versions.node` for Node compatibility and would
|
|
53
|
+
* otherwise look like Node.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* if (runtime.isBun) {
|
|
58
|
+
* await Bun.write(path, data)
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
get isBun() {
|
|
63
|
+
return typeof Bun !== "undefined";
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* `true` when the current process is running under Deno.
|
|
67
|
+
*/
|
|
68
|
+
get isDeno() {
|
|
69
|
+
return typeof globalThis.Deno !== "undefined";
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* `true` when the current process is running under Node.
|
|
73
|
+
*
|
|
74
|
+
* Bun and Deno are excluded first so a polyfilled `process` does not register as Node.
|
|
75
|
+
*/
|
|
76
|
+
get isNode() {
|
|
77
|
+
return !this.isBun && !this.isDeno && typeof process !== "undefined" && process.versions?.node != null;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Name of the runtime executing the current process.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* runtime.name // 'bun' when run with `bun kubb`, 'node' otherwise
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
get name() {
|
|
88
|
+
if (this.isBun) return "bun";
|
|
89
|
+
if (this.isDeno) return "deno";
|
|
90
|
+
return "node";
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Version of the active runtime, or an empty string when it cannot be read.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* runtime.version // '1.3.11' under Bun, '22.22.2' under Node
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
get version() {
|
|
101
|
+
if (this.isBun) return process.versions.bun ?? "";
|
|
102
|
+
if (this.isDeno) return globalThis.Deno?.version?.deno ?? "";
|
|
103
|
+
return process.versions?.node ?? "";
|
|
104
|
+
}
|
|
105
|
+
};
|
|
124
106
|
/**
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
* @example
|
|
128
|
-
* ```ts
|
|
129
|
-
* getRuntimeVersion() // '1.3.11' under Bun, '22.22.2' under Node
|
|
130
|
-
* ```
|
|
107
|
+
* Shared {@link Runtime} instance describing the JavaScript runtime executing the current process.
|
|
131
108
|
*/
|
|
132
|
-
|
|
133
|
-
if (isBun()) return process.versions.bun ?? "";
|
|
134
|
-
if (isDeno()) return globalThis.Deno?.version?.deno ?? "";
|
|
135
|
-
return process.versions?.node ?? "";
|
|
136
|
-
}
|
|
109
|
+
const runtime = new Runtime();
|
|
137
110
|
//#endregion
|
|
138
111
|
//#region src/constants.ts
|
|
139
112
|
/**
|
|
@@ -168,7 +141,7 @@ var Telemetry = class Telemetry {
|
|
|
168
141
|
/**
|
|
169
142
|
* Returns `true` when telemetry is disabled via `DO_NOT_TRACK` or `KUBB_DISABLE_TELEMETRY`.
|
|
170
143
|
*/
|
|
171
|
-
static isDisabled() {
|
|
144
|
+
static get isDisabled() {
|
|
172
145
|
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";
|
|
173
146
|
}
|
|
174
147
|
/**
|
|
@@ -181,8 +154,8 @@ var Telemetry = class Telemetry {
|
|
|
181
154
|
command: options.command,
|
|
182
155
|
kubbVersion: options.kubbVersion,
|
|
183
156
|
nodeVersion: process$1.versions.node.split(".")[0],
|
|
184
|
-
runtime:
|
|
185
|
-
runtimeVersion:
|
|
157
|
+
runtime: runtime.name,
|
|
158
|
+
runtimeVersion: runtime.version.split(".")[0],
|
|
186
159
|
platform: os.platform(),
|
|
187
160
|
ci: isCIEnvironment(),
|
|
188
161
|
plugins: options.plugins ?? [],
|
|
@@ -289,24 +262,22 @@ var Telemetry = class Telemetry {
|
|
|
289
262
|
* `KUBB_DISABLE_TELEMETRY`, and fails silently so telemetry never interrupts a run.
|
|
290
263
|
*/
|
|
291
264
|
static async send(event) {
|
|
292
|
-
if (Telemetry.isDisabled
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
} catch (_e) {}
|
|
306
|
-
});
|
|
265
|
+
if (Telemetry.isDisabled) return;
|
|
266
|
+
try {
|
|
267
|
+
await fetch(`${OTLP_ENDPOINT}/v1/traces`, {
|
|
268
|
+
method: "POST",
|
|
269
|
+
headers: {
|
|
270
|
+
"Content-Type": "application/json",
|
|
271
|
+
"Kubb-Telemetry-Version": "1",
|
|
272
|
+
"Kubb-Telemetry-Source": "kubb-core"
|
|
273
|
+
},
|
|
274
|
+
body: JSON.stringify(Telemetry.buildOtlpPayload(event)),
|
|
275
|
+
signal: AbortSignal.timeout(5e3)
|
|
276
|
+
});
|
|
277
|
+
} catch (_e) {}
|
|
307
278
|
}
|
|
308
279
|
};
|
|
309
280
|
//#endregion
|
|
310
|
-
export {
|
|
281
|
+
export { runtime as a, WATCHER_IGNORED_PATHS as i, KUBB_NPM_PACKAGE_URL as n, canUseTTY as o, QUIET_FLAGS as r, Telemetry as t };
|
|
311
282
|
|
|
312
|
-
//# sourceMappingURL=Telemetry-
|
|
283
|
+
//# sourceMappingURL=Telemetry-C66uYyC2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Telemetry-C66uYyC2.js","names":["process"],"sources":["../../../internals/utils/src/env.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","/**\n * Name of the JavaScript runtime executing the current process.\n */\ntype RuntimeName = 'bun' | 'deno' | 'node'\n\n/**\n * Detects the JavaScript runtime executing the current process and exposes its name and version.\n *\n * Prefer the shared {@link runtime} instance over constructing your own.\n */\nclass Runtime {\n /**\n * `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 (runtime.isBun) {\n * await Bun.write(path, data)\n * }\n * ```\n */\n get isBun(): boolean {\n return typeof Bun !== 'undefined'\n }\n\n /**\n * `true` when the current process is running under Deno.\n */\n get isDeno(): boolean {\n return typeof (globalThis as { Deno?: unknown }).Deno !== 'undefined'\n }\n\n /**\n * `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 */\n get isNode(): boolean {\n return !this.isBun && !this.isDeno && typeof process !== 'undefined' && process.versions?.node != null\n }\n\n /**\n * Name of the runtime executing the current process.\n *\n * @example\n * ```ts\n * runtime.name // 'bun' when run with `bun kubb`, 'node' otherwise\n * ```\n */\n get name(): RuntimeName {\n if (this.isBun) return 'bun'\n if (this.isDeno) return 'deno'\n\n return 'node'\n }\n\n /**\n * Version of the active runtime, or an empty string when it cannot be read.\n *\n * @example\n * ```ts\n * runtime.version // '1.3.11' under Bun, '22.22.2' under Node\n * ```\n */\n get version(): string {\n if (this.isBun) return process.versions.bun ?? ''\n if (this.isDeno) return (globalThis as { Deno?: { version?: { deno?: string } } }).Deno?.version?.deno ?? ''\n\n return process.versions?.node ?? ''\n }\n}\n\n/**\n * Shared {@link Runtime} instance describing the JavaScript runtime executing the current process.\n */\nexport const runtime = new Runtime()\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 * 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<string>(['--help', '-h', '--version', '-v'])\n","import { randomBytes } from 'node:crypto'\nimport os from 'node:os'\nimport process from 'node:process'\nimport { isCIEnvironment, runtime } 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: string\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 get 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: runtime.name,\n runtimeVersion: runtime.version.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 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"],"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,QAAQ,OAAO,UAAU,QAAQ,OAAO,WAAW,KAAK,KAAK,CAAC,gBAAgB;AACvF;;;;;;;;ACnCA,IAAM,UAAN,MAAc;;;;;;;;;;;;;;;CAeZ,IAAI,QAAiB;EACnB,OAAO,OAAO,QA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O,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,YACZ;EAGF,IAAI;GACF,MAAM,MAAM,GAAG,cAAc,aAAa;IACxC,QAAQ;IACR,SAAS;KACP,gBAAgB;KAChB,0BAA0B;KAC1B,yBAAyB;IAC3B;IACA,MAAM,KAAK,UAAU,UAAU,iBAAiB,KAAK,CAAC;IACtD,QAAQ,YAAY,QAAQ,GAAK;GACnC,CAAC;EACH,SAAS,IAAI,CAEb;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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?: Array<string>\n examples?: Array<string>\n options?: O\n subCommands?: Array<CommandDefinition>\n run?: (args: { values: InferValues<O>; positionals: Array<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 +1 @@
|
|
|
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
|
|
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?: Array<string>\n examples?: Array<string>\n options?: O\n subCommands?: Array<CommandDefinition>\n run?: (args: { values: InferValues<O>; positionals: Array<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"}
|
|
@@ -56,28 +56,22 @@ const command = defineCommand({
|
|
|
56
56
|
"json",
|
|
57
57
|
"file"
|
|
58
58
|
]
|
|
59
|
-
},
|
|
60
|
-
"no-cache": {
|
|
61
|
-
type: "boolean",
|
|
62
|
-
description: "Disable the incremental build cache and force a full regeneration",
|
|
63
|
-
default: false
|
|
64
59
|
}
|
|
65
60
|
},
|
|
66
61
|
async run({ values, positionals }) {
|
|
67
62
|
const logLevel = values.verbose ? "verbose" : values.silent ? "silent" : values.logLevel;
|
|
68
63
|
const reporters = values.reporter?.split(",").map((name) => name.trim()).filter(Boolean);
|
|
69
|
-
const { run } = await import("./run-
|
|
64
|
+
const { run } = await import("./run-CY0htF8O.js");
|
|
70
65
|
await run({
|
|
71
66
|
input: positionals[0],
|
|
72
67
|
configPath: values.config,
|
|
73
68
|
logLevel,
|
|
74
69
|
watch: values.watch,
|
|
75
|
-
reporters
|
|
76
|
-
noCache: values["no-cache"]
|
|
70
|
+
reporters
|
|
77
71
|
});
|
|
78
72
|
}
|
|
79
73
|
});
|
|
80
74
|
//#endregion
|
|
81
75
|
export { command };
|
|
82
76
|
|
|
83
|
-
//# sourceMappingURL=generate-
|
|
77
|
+
//# sourceMappingURL=generate-CByoI4cQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-CByoI4cQ.js","names":[],"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 },\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 })\n },\n})\n"],"mappings":";;;AAGA,MAAa,UAAU,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;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,MAAM,OAAO;EAE7B,MAAM,IAAI;GACR,OAAO,YAAY;GACnB,YAAY,OAAO;GACnB;GACA,OAAO,OAAO;GACd;EACF,CAAC;CACH;AACF,CAAC"}
|