@kubb/cli 5.0.0-alpha.8 → 5.0.0-beta.75
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 +4 -2
- package/bin/kubb.js +6 -0
- package/dist/{agent-B116NMCE.cjs → agent-BEgI2HXH.cjs} +5 -5
- package/dist/agent-BEgI2HXH.cjs.map +1 -0
- package/dist/agent-B_pirbeB.cjs +116 -0
- package/dist/agent-B_pirbeB.cjs.map +1 -0
- package/dist/{agent-CFRroclh.js → agent-CTdJEHEs.js} +5 -5
- package/dist/agent-CTdJEHEs.js.map +1 -0
- package/dist/agent-Ev5hU5hH.js +112 -0
- package/dist/agent-Ev5hU5hH.js.map +1 -0
- package/dist/{constants-BTUap0zs.cjs → constants-CnDXa1R6.cjs} +60 -20
- package/dist/constants-CnDXa1R6.cjs.map +1 -0
- package/dist/constants-aL3CP_Wq.js +95 -0
- package/dist/constants-aL3CP_Wq.js.map +1 -0
- package/dist/define-Bdn8j5VM.cjs +54 -0
- package/dist/define-Bdn8j5VM.cjs.map +1 -0
- package/dist/define-Ctii4bel.js +43 -0
- package/dist/define-Ctii4bel.js.map +1 -0
- package/dist/{errors-DBW0N9w4.cjs → errors-CLCjoSg0.cjs} +22 -6
- package/dist/errors-CLCjoSg0.cjs.map +1 -0
- package/dist/errors-CjPmyZHy.js +43 -0
- package/dist/errors-CjPmyZHy.js.map +1 -0
- package/dist/{generate-BblrHXQC.js → generate-Cg8yufrw.js} +556 -262
- package/dist/generate-Cg8yufrw.js.map +1 -0
- package/dist/{generate-D58EaZny.cjs → generate-DDCwNQNo.cjs} +3 -3
- package/dist/generate-DDCwNQNo.cjs.map +1 -0
- package/dist/{generate-D_pi7lhe.cjs → generate-K8MJ9aQF.cjs} +563 -269
- package/dist/generate-K8MJ9aQF.cjs.map +1 -0
- package/dist/{generate-B8tpu0Dc.js → generate-YPtfjsg4.js} +3 -3
- package/dist/generate-YPtfjsg4.js.map +1 -0
- package/dist/index.cjs +48 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +48 -21
- package/dist/index.js.map +1 -1
- package/dist/{init-B56F3Qon.cjs → init-Bu95ML_u.cjs} +4 -4
- package/dist/init-Bu95ML_u.cjs.map +1 -0
- package/dist/{init-hmolV6B4.cjs → init-CZ5Xq2Hd.cjs} +45 -58
- package/dist/init-CZ5Xq2Hd.cjs.map +1 -0
- package/dist/{init-C-InrmSY.js → init-eNRlotJK.js} +41 -54
- package/dist/init-eNRlotJK.js.map +1 -0
- package/dist/{init-v0GeyJkz.js → init-ooJeOBGt.js} +4 -4
- package/dist/init-ooJeOBGt.js.map +1 -0
- package/dist/{mcp-0AmU5JUD.js → mcp-C-d5N1wZ.js} +4 -4
- package/dist/{mcp-0AmU5JUD.js.map → mcp-C-d5N1wZ.js.map} +1 -1
- package/dist/{mcp-ChHFPRzD.cjs → mcp-CLcDV4Jm.cjs} +5 -6
- package/dist/mcp-CLcDV4Jm.cjs.map +1 -0
- package/dist/{mcp-D2SHEg_d.js → mcp-D7EIR9fR.js} +4 -5
- package/dist/mcp-D7EIR9fR.js.map +1 -0
- package/dist/{mcp-B0Jz5z2r.cjs → mcp-Dpu8vzzj.cjs} +4 -4
- package/dist/{mcp-B0Jz5z2r.cjs.map → mcp-Dpu8vzzj.cjs.map} +1 -1
- package/dist/{package-CbrJTkI2.cjs → package-D5arPDnh.cjs} +2 -2
- package/dist/package-D5arPDnh.cjs.map +1 -0
- package/dist/package-DqZsMLZ9.js +6 -0
- package/dist/package-DqZsMLZ9.js.map +1 -0
- package/dist/{shell-7HPrTCJ5.cjs → shell-475fQKaX.cjs} +8 -3
- package/dist/shell-475fQKaX.cjs.map +1 -0
- package/dist/{shell-DqqWsHCD.js → shell-DLzN4fRo.js} +8 -3
- package/dist/shell-DLzN4fRo.js.map +1 -0
- package/dist/{telemetry-Cn9X1I5B.cjs → telemetry-DN95_2pF.cjs} +50 -8
- package/dist/telemetry-DN95_2pF.cjs.map +1 -0
- package/dist/{telemetry-DxiR7clS.js → telemetry-LgT_sdPe.js} +48 -6
- package/dist/telemetry-LgT_sdPe.js.map +1 -0
- package/dist/{validate-D5CuvkLl.js → validate-CIR3_lZI.js} +4 -4
- package/dist/validate-CIR3_lZI.js.map +1 -0
- package/dist/{validate-D8Zb-dns.cjs → validate-DcqUb4DM.cjs} +4 -4
- package/dist/validate-DcqUb4DM.cjs.map +1 -0
- package/dist/{validate-l8vLmwKA.js → validate-kLJoT_hi.js} +5 -13
- package/dist/validate-kLJoT_hi.js.map +1 -0
- package/dist/{validate-Bbrn3Q-A.cjs → validate-yKKzqEZ5.cjs} +6 -14
- package/dist/validate-yKKzqEZ5.cjs.map +1 -0
- package/package.json +47 -46
- package/src/commands/agent/start.ts +20 -4
- package/src/commands/generate.ts +35 -6
- package/src/commands/init.ts +6 -1
- package/src/commands/validate.ts +6 -1
- package/src/constants.ts +50 -22
- package/src/index.ts +10 -12
- package/src/loggers/clackLogger.ts +57 -50
- package/src/loggers/fileSystemLogger.ts +17 -18
- package/src/loggers/githubActionsLogger.ts +25 -26
- package/src/loggers/plainLogger.ts +24 -25
- package/src/runners/agent.ts +81 -34
- package/src/runners/generate.ts +90 -100
- package/src/runners/init.ts +24 -51
- package/src/runners/mcp.ts +17 -4
- package/src/runners/validate.ts +19 -15
- package/src/types.ts +11 -0
- package/src/utils/executeHooks.ts +15 -15
- package/src/utils/flags.ts +9 -0
- package/src/utils/getConfig.ts +10 -0
- package/src/utils/getCosmiConfig.ts +21 -12
- package/src/utils/getSummary.ts +1 -1
- package/src/utils/runHook.ts +29 -13
- package/src/utils/telemetry.ts +16 -3
- package/bin/kubb.cjs +0 -18
- package/dist/agent-B116NMCE.cjs.map +0 -1
- package/dist/agent-C6o_6GSJ.cjs +0 -92
- package/dist/agent-C6o_6GSJ.cjs.map +0 -1
- package/dist/agent-CFRroclh.js.map +0 -1
- package/dist/agent-L50VNhXv.js +0 -88
- package/dist/agent-L50VNhXv.js.map +0 -1
- package/dist/constants-BTUap0zs.cjs.map +0 -1
- package/dist/constants-CM3dJzjK.js +0 -67
- package/dist/constants-CM3dJzjK.js.map +0 -1
- package/dist/define--M_JMcDC.js +0 -25
- package/dist/define--M_JMcDC.js.map +0 -1
- package/dist/define-D6Kfm7-Z.cjs +0 -36
- package/dist/define-D6Kfm7-Z.cjs.map +0 -1
- package/dist/errors-6mF_WKxg.js +0 -27
- package/dist/errors-6mF_WKxg.js.map +0 -1
- package/dist/errors-DBW0N9w4.cjs.map +0 -1
- package/dist/generate-B8tpu0Dc.js.map +0 -1
- package/dist/generate-BblrHXQC.js.map +0 -1
- package/dist/generate-D58EaZny.cjs.map +0 -1
- package/dist/generate-D_pi7lhe.cjs.map +0 -1
- package/dist/init-B56F3Qon.cjs.map +0 -1
- package/dist/init-C-InrmSY.js.map +0 -1
- package/dist/init-hmolV6B4.cjs.map +0 -1
- package/dist/init-v0GeyJkz.js.map +0 -1
- package/dist/jiti-Cd3S0xwr.cjs +0 -16
- package/dist/jiti-Cd3S0xwr.cjs.map +0 -1
- package/dist/jiti-e08mD2Ph.js +0 -11
- package/dist/jiti-e08mD2Ph.js.map +0 -1
- package/dist/mcp-ChHFPRzD.cjs.map +0 -1
- package/dist/mcp-D2SHEg_d.js.map +0 -1
- package/dist/package-BAVK5o-U.js +0 -6
- package/dist/package-BAVK5o-U.js.map +0 -1
- package/dist/package-CbrJTkI2.cjs.map +0 -1
- package/dist/shell-7HPrTCJ5.cjs.map +0 -1
- package/dist/shell-DqqWsHCD.js.map +0 -1
- package/dist/telemetry-Cn9X1I5B.cjs.map +0 -1
- package/dist/telemetry-DxiR7clS.js.map +0 -1
- package/dist/validate-Bbrn3Q-A.cjs.map +0 -1
- package/dist/validate-D5CuvkLl.js.map +0 -1
- package/dist/validate-D8Zb-dns.cjs.map +0 -1
- package/dist/validate-l8vLmwKA.js.map +0 -1
- package/src/utils/getIntro.ts +0 -1
- package/src/utils/jiti.ts +0 -9
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
import "./chunk--u3MIqq1.js";
|
|
2
|
-
import { t as spawnAsync } from "./shell-
|
|
3
|
-
import {
|
|
2
|
+
import { t as spawnAsync } from "./shell-DLzN4fRo.js";
|
|
3
|
+
import { c as initDefaults, l as pluginDefaultConfigs, t as KUBB_CONFIG_FILENAME } from "./constants-aL3CP_Wq.js";
|
|
4
4
|
import { styleText } from "node:util";
|
|
5
5
|
import fs, { existsSync, readFileSync } from "node:fs";
|
|
6
6
|
import path, { join } from "node:path";
|
|
7
7
|
import process$1 from "node:process";
|
|
8
8
|
import * as clack from "@clack/prompts";
|
|
9
9
|
//#region ../../internals/utils/src/packageManager.ts
|
|
10
|
+
/**
|
|
11
|
+
* Metadata for each supported package manager, keyed by its short name.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* packageManagers.pnpm.installCommand // ['add', '-D']
|
|
16
|
+
* packageManagers.npm.lockFile // 'package-lock.json'
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
10
19
|
const packageManagers = {
|
|
11
20
|
pnpm: {
|
|
12
21
|
name: "pnpm",
|
|
@@ -32,7 +41,13 @@ const packageManagers = {
|
|
|
32
41
|
/**
|
|
33
42
|
* Detects the active package manager for the given directory.
|
|
34
43
|
* Resolution order: `packageManager` field in `package.json`, then presence of a lock file.
|
|
35
|
-
* Falls back to npm when no signal is found.
|
|
44
|
+
* Falls back to `npm` when no signal is found.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* detectPackageManager('/my/project') // { name: 'pnpm', lockFile: 'pnpm-lock.yaml', ... }
|
|
49
|
+
* detectPackageManager() // falls back to npm when no lock file is found
|
|
50
|
+
* ```
|
|
36
51
|
*/
|
|
37
52
|
function detectPackageManager(cwd = process.cwd()) {
|
|
38
53
|
const packageJsonPath = join(cwd, "package.json");
|
|
@@ -65,63 +80,34 @@ async function installPackages(packages, packageManager, cwd = process.cwd()) {
|
|
|
65
80
|
//#endregion
|
|
66
81
|
//#region src/runners/init.ts
|
|
67
82
|
const availablePlugins = [
|
|
68
|
-
{
|
|
69
|
-
value: "plugin-oas",
|
|
70
|
-
label: "OpenAPI Parser",
|
|
71
|
-
hint: "Required",
|
|
72
|
-
packageName: "@kubb/plugin-oas",
|
|
73
|
-
importName: "pluginOas",
|
|
74
|
-
category: "core"
|
|
75
|
-
},
|
|
76
83
|
{
|
|
77
84
|
value: "plugin-ts",
|
|
78
85
|
label: "TypeScript",
|
|
79
86
|
hint: "Recommended",
|
|
80
87
|
packageName: "@kubb/plugin-ts",
|
|
81
88
|
importName: "pluginTs",
|
|
82
|
-
category: "
|
|
89
|
+
category: "types"
|
|
83
90
|
},
|
|
84
91
|
{
|
|
85
92
|
value: "plugin-client",
|
|
86
93
|
label: "Client (Fetch/Axios)",
|
|
87
94
|
packageName: "@kubb/plugin-client",
|
|
88
95
|
importName: "pluginClient",
|
|
89
|
-
category: "
|
|
96
|
+
category: "client"
|
|
90
97
|
},
|
|
91
98
|
{
|
|
92
99
|
value: "plugin-react-query",
|
|
93
100
|
label: "React Query / TanStack Query",
|
|
94
101
|
packageName: "@kubb/plugin-react-query",
|
|
95
102
|
importName: "pluginReactQuery",
|
|
96
|
-
category: "
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
value: "plugin-solid-query",
|
|
100
|
-
label: "Solid Query",
|
|
101
|
-
packageName: "@kubb/plugin-solid-query",
|
|
102
|
-
importName: "pluginSolidQuery",
|
|
103
|
-
category: "query"
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
value: "plugin-svelte-query",
|
|
107
|
-
label: "Svelte Query",
|
|
108
|
-
packageName: "@kubb/plugin-svelte-query",
|
|
109
|
-
importName: "pluginSvelteQuery",
|
|
110
|
-
category: "query"
|
|
103
|
+
category: "framework"
|
|
111
104
|
},
|
|
112
105
|
{
|
|
113
106
|
value: "plugin-vue-query",
|
|
114
107
|
label: "Vue Query",
|
|
115
108
|
packageName: "@kubb/plugin-vue-query",
|
|
116
109
|
importName: "pluginVueQuery",
|
|
117
|
-
category: "
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
value: "plugin-swr",
|
|
121
|
-
label: "SWR",
|
|
122
|
-
packageName: "@kubb/plugin-swr",
|
|
123
|
-
importName: "pluginSwr",
|
|
124
|
-
category: "query"
|
|
110
|
+
category: "framework"
|
|
125
111
|
},
|
|
126
112
|
{
|
|
127
113
|
value: "plugin-zod",
|
|
@@ -135,14 +121,14 @@ const availablePlugins = [
|
|
|
135
121
|
label: "Faker.js Mocks",
|
|
136
122
|
packageName: "@kubb/plugin-faker",
|
|
137
123
|
importName: "pluginFaker",
|
|
138
|
-
category: "
|
|
124
|
+
category: "mocks"
|
|
139
125
|
},
|
|
140
126
|
{
|
|
141
127
|
value: "plugin-msw",
|
|
142
128
|
label: "MSW Handlers",
|
|
143
129
|
packageName: "@kubb/plugin-msw",
|
|
144
130
|
importName: "pluginMsw",
|
|
145
|
-
category: "
|
|
131
|
+
category: "mocks"
|
|
146
132
|
},
|
|
147
133
|
{
|
|
148
134
|
value: "plugin-cypress",
|
|
@@ -151,16 +137,23 @@ const availablePlugins = [
|
|
|
151
137
|
importName: "pluginCypress",
|
|
152
138
|
category: "testing"
|
|
153
139
|
},
|
|
140
|
+
{
|
|
141
|
+
value: "plugin-mcp",
|
|
142
|
+
label: "MCP Server (AI / Model Context Protocol)",
|
|
143
|
+
packageName: "@kubb/plugin-mcp",
|
|
144
|
+
importName: "pluginMcp",
|
|
145
|
+
category: "ai"
|
|
146
|
+
},
|
|
154
147
|
{
|
|
155
148
|
value: "plugin-redoc",
|
|
156
149
|
label: "ReDoc Documentation",
|
|
157
150
|
packageName: "@kubb/plugin-redoc",
|
|
158
151
|
importName: "pluginRedoc",
|
|
159
|
-
category: "
|
|
152
|
+
category: "documentation"
|
|
160
153
|
}
|
|
161
154
|
];
|
|
162
155
|
function generateConfigFile(selectedPlugins, inputPath, outputPath) {
|
|
163
|
-
return `import { defineConfig } from '
|
|
156
|
+
return `import { defineConfig } from 'kubb'
|
|
164
157
|
${selectedPlugins.map((plugin) => `import { ${plugin.importName} } from '${plugin.packageName}'`).join("\n")}
|
|
165
158
|
|
|
166
159
|
export default defineConfig({
|
|
@@ -256,13 +249,7 @@ async function runInit({ yes, version }) {
|
|
|
256
249
|
if (clack.isCancel(selectedPluginValues)) cancelAndExit();
|
|
257
250
|
selectedPlugins = availablePlugins.filter((plugin) => selectedPluginValues.includes(plugin.value));
|
|
258
251
|
}
|
|
259
|
-
|
|
260
|
-
const packagesToInstall = [
|
|
261
|
-
"@kubb/core",
|
|
262
|
-
"@kubb/cli",
|
|
263
|
-
"@kubb/agent",
|
|
264
|
-
...selectedPlugins.map((p) => p.packageName)
|
|
265
|
-
];
|
|
252
|
+
const packagesToInstall = ["kubb", ...selectedPlugins.map((p) => p.packageName)];
|
|
266
253
|
const spinner = clack.spinner();
|
|
267
254
|
spinner.start(`Installing ${packagesToInstall.length} packages with ${packageManager.name}`);
|
|
268
255
|
try {
|
|
@@ -273,22 +260,22 @@ async function runInit({ yes, version }) {
|
|
|
273
260
|
throw error;
|
|
274
261
|
}
|
|
275
262
|
const configSpinner = clack.spinner();
|
|
276
|
-
configSpinner.start(
|
|
263
|
+
configSpinner.start(`Creating ${KUBB_CONFIG_FILENAME}`);
|
|
277
264
|
const configContent = generateConfigFile(selectedPlugins, inputPath, outputPath);
|
|
278
|
-
const configPath = path.join(cwd,
|
|
265
|
+
const configPath = path.join(cwd, KUBB_CONFIG_FILENAME);
|
|
279
266
|
if (fs.existsSync(configPath)) {
|
|
280
|
-
configSpinner.stop(
|
|
267
|
+
configSpinner.stop(`${KUBB_CONFIG_FILENAME} already exists`);
|
|
281
268
|
if (!yes) {
|
|
282
269
|
const shouldOverwrite = await clack.confirm({
|
|
283
|
-
message:
|
|
270
|
+
message: `${KUBB_CONFIG_FILENAME} already exists. Overwrite?`,
|
|
284
271
|
initialValue: false
|
|
285
272
|
});
|
|
286
273
|
if (clack.isCancel(shouldOverwrite) || !shouldOverwrite) cancelAndExit("Keeping existing configuration. Packages have been installed.");
|
|
287
274
|
}
|
|
288
|
-
configSpinner.start(
|
|
275
|
+
configSpinner.start(`Overwriting ${KUBB_CONFIG_FILENAME}`);
|
|
289
276
|
}
|
|
290
277
|
fs.writeFileSync(configPath, configContent, "utf-8");
|
|
291
|
-
configSpinner.stop(
|
|
278
|
+
configSpinner.stop(`Created ${KUBB_CONFIG_FILENAME}`);
|
|
292
279
|
clack.outro(styleText("green", "✓ All set!") + "\n\n" + styleText("dim", "Next steps:") + "\n" + styleText("cyan", ` 1. Make sure your OpenAPI spec is at: ${inputPath}`) + "\n" + styleText("cyan", " 2. Generate code with: npx kubb generate") + "\n" + styleText("cyan", " Or start a stream server with: npx kubb start") + "\n" + styleText("cyan", ` 3. Find generated files in: ${outputPath}`) + "\n\n" + styleText("dim", `Using ${packageManager.name} • Kubb v${version}`));
|
|
293
280
|
} catch (error) {
|
|
294
281
|
clack.log.error(styleText("red", "An error occurred during initialization"));
|
|
@@ -299,4 +286,4 @@ async function runInit({ yes, version }) {
|
|
|
299
286
|
//#endregion
|
|
300
287
|
export { runInit };
|
|
301
288
|
|
|
302
|
-
//# sourceMappingURL=init-
|
|
289
|
+
//# sourceMappingURL=init-eNRlotJK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init-eNRlotJK.js","names":["process"],"sources":["../../../internals/utils/src/packageManager.ts","../src/utils/packageManager.ts","../src/runners/init.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs'\nimport { join } from 'node:path'\n\n/**\n * Supported package manager identifiers.\n *\n * @example\n * ```ts\n * const pm: PackageManagerName = 'pnpm'\n * ```\n */\nexport type PackageManagerName = 'npm' | 'pnpm' | 'yarn' | 'bun'\n\n/**\n * Metadata describing a package manager's lock file and install command.\n */\nexport interface PackageManagerInfo {\n /**\n * Identifier used in CLI commands, e.g. `pnpm`, `yarn`.\n */\n name: PackageManagerName\n /**\n * Lock file name that uniquely identifies this package manager in a project root.\n */\n lockFile: string\n /**\n * Subcommands passed to the package manager binary to install a dev dependency.\n */\n installCommand: ReadonlyArray<string>\n}\n/**\n * Metadata for each supported package manager, keyed by its short name.\n *\n * @example\n * ```ts\n * packageManagers.pnpm.installCommand // ['add', '-D']\n * packageManagers.npm.lockFile // 'package-lock.json'\n * ```\n */\nconst packageManagers: Record<PackageManagerName, PackageManagerInfo> = {\n pnpm: {\n name: 'pnpm',\n lockFile: 'pnpm-lock.yaml',\n installCommand: ['add', '-D'],\n },\n yarn: {\n name: 'yarn',\n lockFile: 'yarn.lock',\n installCommand: ['add', '-D'],\n },\n bun: {\n name: 'bun',\n lockFile: 'bun.lockb',\n installCommand: ['add', '-d'],\n },\n npm: {\n name: 'npm',\n lockFile: 'package-lock.json',\n installCommand: ['install', '--save-dev'],\n },\n}\n\n/**\n * Minimal shape of `package.json` fields read during detection.\n */\ntype PackageJson = {\n /**\n * The `packageManager` field from `package.json` (e.g. `\"pnpm@9.0.0\"`).\n */\n packageManager?: string\n}\n\n/**\n * Detects the active package manager for the given directory.\n * Resolution order: `packageManager` field in `package.json`, then presence of a lock file.\n * Falls back to `npm` when no signal is found.\n *\n * @example\n * ```ts\n * detectPackageManager('/my/project') // { name: 'pnpm', lockFile: 'pnpm-lock.yaml', ... }\n * detectPackageManager() // falls back to npm when no lock file is found\n * ```\n */\nexport function detectPackageManager(cwd: string = process.cwd()): PackageManagerInfo {\n const packageJsonPath = join(cwd, 'package.json')\n if (existsSync(packageJsonPath)) {\n try {\n const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8')) as PackageJson\n const pmField = packageJson.packageManager\n if (typeof pmField === 'string') {\n const name = pmField.split('@')[0]\n if (name && name in packageManagers) {\n return packageManagers[name as PackageManagerName]\n }\n }\n } catch {\n // Continue to lock file detection\n }\n }\n\n for (const pm of Object.values(packageManagers)) {\n if (existsSync(join(cwd, pm.lockFile))) {\n return pm\n }\n }\n\n return packageManagers.npm\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\nimport type { PackageManagerInfo, PackageManagerName } from '@internals/utils'\nimport { spawnAsync } from '@internals/utils'\n\nexport function hasPackageJson(cwd: string = process.cwd()): boolean {\n return fs.existsSync(path.join(cwd, 'package.json'))\n}\n\nexport async function initPackageJson(cwd: string, packageManager: PackageManagerInfo): Promise<void> {\n const commands: Record<PackageManagerName, string[]> = {\n npm: ['init', '-y'],\n pnpm: ['init'],\n yarn: ['init', '-y'],\n bun: ['init', '-y'],\n }\n\n await spawnAsync(packageManager.name, commands[packageManager.name], { cwd })\n}\n\nexport async function installPackages(packages: string[], packageManager: PackageManagerInfo, cwd: string = process.cwd()): Promise<void> {\n await spawnAsync(packageManager.name, [...packageManager.installCommand, ...packages], { cwd })\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { styleText } from 'node:util'\nimport * as clack from '@clack/prompts'\nimport type { PackageManagerInfo } from '@internals/utils'\nimport { detectPackageManager } from '@internals/utils'\nimport { initDefaults, KUBB_CONFIG_FILENAME, pluginDefaultConfigs } from '../constants.ts'\nimport { hasPackageJson, initPackageJson, installPackages } from '../utils/packageManager.ts'\n\ntype PluginOption = {\n value: string\n label: string\n hint?: string\n packageName: string\n importName: string\n category: 'types' | 'client' | 'framework' | 'validation' | 'testing' | 'mocks' | 'documentation' | 'ai'\n}\n\nconst availablePlugins: PluginOption[] = [\n {\n value: 'plugin-ts',\n label: 'TypeScript',\n hint: 'Recommended',\n packageName: '@kubb/plugin-ts',\n importName: 'pluginTs',\n category: 'types',\n },\n {\n value: 'plugin-client',\n label: 'Client (Fetch/Axios)',\n packageName: '@kubb/plugin-client',\n importName: 'pluginClient',\n category: 'client',\n },\n {\n value: 'plugin-react-query',\n label: 'React Query / TanStack Query',\n packageName: '@kubb/plugin-react-query',\n importName: 'pluginReactQuery',\n category: 'framework',\n },\n {\n value: 'plugin-vue-query',\n label: 'Vue Query',\n packageName: '@kubb/plugin-vue-query',\n importName: 'pluginVueQuery',\n category: 'framework',\n },\n {\n value: 'plugin-zod',\n label: 'Zod Schemas',\n packageName: '@kubb/plugin-zod',\n importName: 'pluginZod',\n category: 'validation',\n },\n {\n value: 'plugin-faker',\n label: 'Faker.js Mocks',\n packageName: '@kubb/plugin-faker',\n importName: 'pluginFaker',\n category: 'mocks',\n },\n {\n value: 'plugin-msw',\n label: 'MSW Handlers',\n packageName: '@kubb/plugin-msw',\n importName: 'pluginMsw',\n category: 'mocks',\n },\n {\n value: 'plugin-cypress',\n label: 'Cypress Tests',\n packageName: '@kubb/plugin-cypress',\n importName: 'pluginCypress',\n category: 'testing',\n },\n {\n value: 'plugin-mcp',\n label: 'MCP Server (AI / Model Context Protocol)',\n packageName: '@kubb/plugin-mcp',\n importName: 'pluginMcp',\n category: 'ai',\n },\n {\n value: 'plugin-redoc',\n label: 'ReDoc Documentation',\n packageName: '@kubb/plugin-redoc',\n importName: 'pluginRedoc',\n category: 'documentation',\n },\n]\n\nfunction generateConfigFile(selectedPlugins: PluginOption[], inputPath: string, outputPath: string): string {\n const imports = selectedPlugins.map((plugin) => `import { ${plugin.importName} } from '${plugin.packageName}'`).join('\\n')\n\n const pluginConfigs = selectedPlugins\n .map((plugin) => {\n const config = (pluginDefaultConfigs as Record<string, string>)[plugin.value] ?? `${plugin.importName}()`\n return ` ${config},`\n })\n .join('\\n')\n\n return `import { defineConfig } from 'kubb'\n${imports}\n\nexport default defineConfig({\n root: '.',\n input: {\n path: '${inputPath}',\n },\n output: {\n path: '${outputPath}',\n clean: true,\n },\n plugins: [\n${pluginConfigs}\n ],\n})\n`\n}\n\nfunction cancelAndExit(message = 'Operation cancelled.'): never {\n clack.cancel(message)\n process.exit(0)\n}\n\ntype InitOptions = {\n yes: boolean\n version: string\n}\n\nexport async function runInit({ yes, version }: InitOptions): Promise<void> {\n const cwd = process.cwd()\n\n clack.intro(styleText('bgCyan', styleText('black', ' Kubb Init ')))\n\n try {\n // Check/create package.json\n let packageManager: PackageManagerInfo\n if (!hasPackageJson(cwd)) {\n if (!yes) {\n const shouldInit = await clack.confirm({\n message: 'No package.json found. Would you like to create one?',\n initialValue: true,\n })\n\n if (clack.isCancel(shouldInit) || !shouldInit) {\n cancelAndExit()\n }\n }\n\n packageManager = detectPackageManager(cwd)\n\n const spinner = clack.spinner()\n spinner.start(`Initializing package.json with ${packageManager.name}`)\n\n await initPackageJson(cwd, packageManager)\n\n spinner.stop(`Created package.json with ${packageManager.name}`)\n } else {\n packageManager = detectPackageManager(cwd)\n clack.log.info(`Detected package manager: ${styleText('cyan', packageManager.name)}`)\n }\n\n // Prompt for OpenAPI spec path\n let inputPath: string\n if (yes) {\n inputPath = initDefaults.inputPath\n clack.log.info(`Using input path: ${styleText('cyan', inputPath)}`)\n } else {\n const inputPathResult = await clack.text({\n message: 'Where is your OpenAPI specification located?',\n placeholder: initDefaults.inputPath,\n defaultValue: initDefaults.inputPath,\n validate: (value) => {\n if (!value) return 'Input path is required'\n },\n })\n\n if (clack.isCancel(inputPathResult)) {\n cancelAndExit()\n }\n inputPath = inputPathResult as string\n }\n\n // Prompt for output directory\n let outputPath: string\n if (yes) {\n outputPath = initDefaults.outputPath\n clack.log.info(`Using output path: ${styleText('cyan', outputPath)}`)\n } else {\n const outputPathResult = await clack.text({\n message: 'Where should the generated files be output?',\n placeholder: initDefaults.outputPath,\n defaultValue: initDefaults.outputPath,\n validate: (value) => {\n if (!value) return 'Output path is required'\n },\n })\n\n if (clack.isCancel(outputPathResult)) {\n cancelAndExit()\n }\n outputPath = outputPathResult as string\n }\n\n // Plugin selection\n let selectedPlugins: PluginOption[]\n if (yes) {\n selectedPlugins = availablePlugins.filter((plugin) => (initDefaults.plugins as readonly string[]).includes(plugin.value))\n clack.log.info(`Using plugins: ${styleText('cyan', selectedPlugins.map((p) => p.label).join(', '))}`)\n } else {\n const selectedPluginValues = await clack.multiselect({\n message: 'Select plugins to use:',\n options: availablePlugins.map((plugin) => ({\n value: plugin.value,\n label: plugin.label,\n hint: plugin.hint,\n })),\n initialValues: [...initDefaults.plugins],\n required: true,\n })\n\n if (clack.isCancel(selectedPluginValues)) {\n cancelAndExit()\n }\n\n selectedPlugins = availablePlugins.filter((plugin) => (selectedPluginValues as string[]).includes(plugin.value))\n }\n\n // Install packages\n const packagesToInstall = ['kubb', ...selectedPlugins.map((p) => p.packageName)]\n\n const spinner = clack.spinner()\n spinner.start(`Installing ${packagesToInstall.length} packages with ${packageManager.name}`)\n\n try {\n await installPackages(packagesToInstall, packageManager, cwd)\n spinner.stop(`Installed ${packagesToInstall.length} packages`)\n } catch (error) {\n spinner.stop('Installation failed')\n throw error\n }\n\n // Generate config file\n const configSpinner = clack.spinner()\n configSpinner.start(`Creating ${KUBB_CONFIG_FILENAME}`)\n\n const configContent = generateConfigFile(selectedPlugins, inputPath, outputPath)\n const configPath = path.join(cwd, KUBB_CONFIG_FILENAME)\n\n if (fs.existsSync(configPath)) {\n configSpinner.stop(`${KUBB_CONFIG_FILENAME} already exists`)\n\n if (!yes) {\n const shouldOverwrite = await clack.confirm({\n message: `${KUBB_CONFIG_FILENAME} already exists. Overwrite?`,\n initialValue: false,\n })\n\n if (clack.isCancel(shouldOverwrite) || !shouldOverwrite) {\n cancelAndExit('Keeping existing configuration. Packages have been installed.')\n }\n }\n\n configSpinner.start(`Overwriting ${KUBB_CONFIG_FILENAME}`)\n }\n\n fs.writeFileSync(configPath, configContent, 'utf-8')\n\n configSpinner.stop(`Created ${KUBB_CONFIG_FILENAME}`)\n\n clack.outro(\n styleText('green', '✓ All set!') +\n '\\n\\n' +\n styleText('dim', 'Next steps:') +\n '\\n' +\n styleText('cyan', ` 1. Make sure your OpenAPI spec is at: ${inputPath}`) +\n '\\n' +\n styleText('cyan', ' 2. Generate code with: npx kubb generate') +\n '\\n' +\n styleText('cyan', ' Or start a stream server with: npx kubb start') +\n '\\n' +\n styleText('cyan', ` 3. Find generated files in: ${outputPath}`) +\n '\\n\\n' +\n styleText('dim', `Using ${packageManager.name} • Kubb v${version}`),\n )\n } catch (error) {\n clack.log.error(styleText('red', 'An error occurred during initialization'))\n if (error instanceof Error) {\n clack.log.error(error.message)\n }\n process.exit(1)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAuCA,MAAM,kBAAkE;CACtE,MAAM;EACJ,MAAM;EACN,UAAU;EACV,gBAAgB,CAAC,OAAO,KAAK;EAC9B;CACD,MAAM;EACJ,MAAM;EACN,UAAU;EACV,gBAAgB,CAAC,OAAO,KAAK;EAC9B;CACD,KAAK;EACH,MAAM;EACN,UAAU;EACV,gBAAgB,CAAC,OAAO,KAAK;EAC9B;CACD,KAAK;EACH,MAAM;EACN,UAAU;EACV,gBAAgB,CAAC,WAAW,aAAa;EAC1C;CACF;;;;;;;;;;;;AAuBD,SAAgB,qBAAqB,MAAc,QAAQ,KAAK,EAAsB;CACpF,MAAM,kBAAkB,KAAK,KAAK,eAAe;AACjD,KAAI,WAAW,gBAAgB,CAC7B,KAAI;EAEF,MAAM,UADc,KAAK,MAAM,aAAa,iBAAiB,QAAQ,CAC1C,CAAC;AAC5B,MAAI,OAAO,YAAY,UAAU;GAC/B,MAAM,OAAO,QAAQ,MAAM,IAAI,CAAC;AAChC,OAAI,QAAQ,QAAQ,gBAClB,QAAO,gBAAgB;;SAGrB;AAKV,MAAK,MAAM,MAAM,OAAO,OAAO,gBAAgB,CAC7C,KAAI,WAAW,KAAK,KAAK,GAAG,SAAS,CAAC,CACpC,QAAO;AAIX,QAAO,gBAAgB;;;;ACrGzB,SAAgB,eAAe,MAAc,QAAQ,KAAK,EAAW;AACnE,QAAO,GAAG,WAAW,KAAK,KAAK,KAAK,eAAe,CAAC;;AAGtD,eAAsB,gBAAgB,KAAa,gBAAmD;AAQpG,OAAM,WAAW,eAAe,MAAM;EANpC,KAAK,CAAC,QAAQ,KAAK;EACnB,MAAM,CAAC,OAAO;EACd,MAAM,CAAC,QAAQ,KAAK;EACpB,KAAK,CAAC,QAAQ,KAAK;EAGyB,CAAC,eAAe,OAA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;KAC1C,SAAS,GAAG,qBAAqB;KACjC,cAAc;KACf,CAAC;AAEF,QAAI,MAAM,SAAS,gBAAgB,IAAI,CAAC,gBACtC,eAAc,gEAAgE;;AAIlF,iBAAc,MAAM,eAAe,uBAAuB;;AAG5D,KAAG,cAAc,YAAY,eAAe,QAAQ;AAEpD,gBAAc,KAAK,WAAW,uBAAuB;AAErD,QAAM,MACJ,UAAU,SAAS,aAAa,GAC9B,SACA,UAAU,OAAO,cAAc,GAC/B,OACA,UAAU,QAAQ,2CAA2C,YAAY,GACzE,OACA,UAAU,QAAQ,6CAA6C,GAC/D,OACA,UAAU,QAAQ,qDAAqD,GACvE,OACA,UAAU,QAAQ,iCAAiC,aAAa,GAChE,SACA,UAAU,OAAO,SAAS,eAAe,KAAK,WAAW,UAAU,CACtE;UACM,OAAO;AACd,QAAM,IAAI,MAAM,UAAU,OAAO,0CAA0C,CAAC;AAC5E,MAAI,iBAAiB,MACnB,OAAM,IAAI,MAAM,MAAM,QAAQ;AAEhC,YAAQ,KAAK,EAAE"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./chunk--u3MIqq1.js";
|
|
2
|
-
import { n as defineCommand } from "./define
|
|
3
|
-
import { t as version } from "./package-
|
|
2
|
+
import { n as defineCommand } from "./define-Ctii4bel.js";
|
|
3
|
+
import { t as version } from "./package-DqZsMLZ9.js";
|
|
4
4
|
//#region src/commands/init.ts
|
|
5
5
|
const command = defineCommand({
|
|
6
6
|
name: "init",
|
|
@@ -12,7 +12,7 @@ const command = defineCommand({
|
|
|
12
12
|
default: false
|
|
13
13
|
} },
|
|
14
14
|
async run({ values }) {
|
|
15
|
-
const { runInit } = await import("./init-
|
|
15
|
+
const { runInit } = await import("./init-eNRlotJK.js");
|
|
16
16
|
await runInit({
|
|
17
17
|
yes: values.yes,
|
|
18
18
|
version
|
|
@@ -22,4 +22,4 @@ const command = defineCommand({
|
|
|
22
22
|
//#endregion
|
|
23
23
|
export { command };
|
|
24
24
|
|
|
25
|
-
//# sourceMappingURL=init-
|
|
25
|
+
//# sourceMappingURL=init-ooJeOBGt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init-ooJeOBGt.js","names":[],"sources":["../src/commands/init.ts"],"sourcesContent":["import { defineCommand } from '@internals/utils'\nimport { version } from '../../package.json'\n\nexport const command = defineCommand({\n name: 'init',\n description: 'Initialize a new Kubb project with interactive setup',\n options: {\n yes: {\n type: 'boolean',\n description: 'Skip prompts and use default options',\n short: 'y',\n default: false,\n },\n },\n async run({ values }) {\n const { runInit } = await import('../runners/init.ts')\n\n await runInit({ yes: values.yes, version })\n },\n})\n"],"mappings":";;;;AAGA,MAAa,UAAU,cAAc;CACnC,MAAM;CACN,aAAa;CACb,SAAS,EACP,KAAK;EACH,MAAM;EACN,aAAa;EACb,OAAO;EACP,SAAS;EACV,EACF;CACD,MAAM,IAAI,EAAE,UAAU;EACpB,MAAM,EAAE,YAAY,MAAM,OAAO;AAEjC,QAAM,QAAQ;GAAE,KAAK,OAAO;GAAK;GAAS,CAAC;;CAE9C,CAAC"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import "./chunk--u3MIqq1.js";
|
|
2
|
-
import { n as defineCommand } from "./define
|
|
3
|
-
import { t as version } from "./package-
|
|
2
|
+
import { n as defineCommand } from "./define-Ctii4bel.js";
|
|
3
|
+
import { t as version } from "./package-DqZsMLZ9.js";
|
|
4
4
|
//#region src/commands/mcp.ts
|
|
5
5
|
const command = defineCommand({
|
|
6
6
|
name: "mcp",
|
|
7
7
|
description: "Start the server to enable the MCP client to interact with the LLM.",
|
|
8
8
|
async run() {
|
|
9
|
-
const { runMcp } = await import("./mcp-
|
|
9
|
+
const { runMcp } = await import("./mcp-D7EIR9fR.js");
|
|
10
10
|
await runMcp({ version });
|
|
11
11
|
}
|
|
12
12
|
});
|
|
13
13
|
//#endregion
|
|
14
14
|
export { command };
|
|
15
15
|
|
|
16
|
-
//# sourceMappingURL=mcp-
|
|
16
|
+
//# sourceMappingURL=mcp-C-d5N1wZ.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-
|
|
1
|
+
{"version":3,"file":"mcp-C-d5N1wZ.js","names":[],"sources":["../src/commands/mcp.ts"],"sourcesContent":["import { defineCommand } from '@internals/utils'\nimport { version } from '../../package.json'\n\nexport const command = defineCommand({\n name: 'mcp',\n description: 'Start the server to enable the MCP client to interact with the LLM.',\n async run() {\n const { runMcp } = await import('../runners/mcp.ts')\n\n await runMcp({ version })\n },\n})\n"],"mappings":";;;;AAGA,MAAa,UAAU,cAAc;CACnC,MAAM;CACN,aAAa;CACb,MAAM,MAAM;EACV,MAAM,EAAE,WAAW,MAAM,OAAO;AAEhC,QAAM,OAAO,EAAE,SAAS,CAAC;;CAE5B,CAAC"}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
const require_chunk = require("./chunk-ByKO4r7w.cjs");
|
|
2
|
-
const require_errors = require("./errors-
|
|
3
|
-
const require_telemetry = require("./telemetry-
|
|
4
|
-
const require_jiti = require("./jiti-Cd3S0xwr.cjs");
|
|
2
|
+
const require_errors = require("./errors-CLCjoSg0.cjs");
|
|
3
|
+
const require_telemetry = require("./telemetry-DN95_2pF.cjs");
|
|
5
4
|
let node_util = require("node:util");
|
|
6
5
|
let node_process = require("node:process");
|
|
7
|
-
node_process = require_chunk.__toESM(node_process);
|
|
6
|
+
node_process = require_chunk.__toESM(node_process, 1);
|
|
8
7
|
//#region src/runners/mcp.ts
|
|
9
8
|
async function runMcp({ version }) {
|
|
10
9
|
let mod;
|
|
11
10
|
try {
|
|
12
|
-
mod = await
|
|
11
|
+
mod = await import("@kubb/mcp");
|
|
13
12
|
} catch (_e) {
|
|
14
13
|
console.error(`Import of '@kubb/mcp' is required to start the MCP server`);
|
|
15
14
|
node_process.default.exit(1);
|
|
@@ -39,4 +38,4 @@ async function runMcp({ version }) {
|
|
|
39
38
|
//#endregion
|
|
40
39
|
exports.runMcp = runMcp;
|
|
41
40
|
|
|
42
|
-
//# sourceMappingURL=mcp-
|
|
41
|
+
//# sourceMappingURL=mcp-CLcDV4Jm.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-CLcDV4Jm.cjs","names":["process","sendTelemetry","buildTelemetryEvent","getErrorMessage"],"sources":["../src/runners/mcp.ts"],"sourcesContent":["import process from 'node:process'\nimport { styleText } from 'node:util'\nimport { getErrorMessage } from '@internals/utils'\nimport type * as McpModule from '@kubb/mcp'\nimport { buildTelemetryEvent, sendTelemetry } from '../utils/telemetry.ts'\n\ntype McpOptions = {\n version: string\n}\n\nexport async function runMcp({ version }: McpOptions): Promise<void> {\n let mod: typeof McpModule\n try {\n mod = (await import('@kubb/mcp')) as typeof McpModule\n } catch (_e) {\n console.error(`Import of '@kubb/mcp' is required to start the MCP server`)\n process.exit(1)\n }\n\n const { run } = mod\n const hrStart = process.hrtime()\n try {\n console.log('⏳ Starting MCP server...')\n console.warn(styleText('yellow', 'This feature is still under development — use with caution'))\n run()\n await sendTelemetry(\n buildTelemetryEvent({\n command: 'mcp',\n kubbVersion: version,\n hrStart,\n status: 'success',\n }),\n )\n } catch (error) {\n await sendTelemetry(\n buildTelemetryEvent({\n command: 'mcp',\n kubbVersion: version,\n hrStart,\n status: 'failed',\n }),\n )\n console.error(getErrorMessage(error))\n }\n}\n"],"mappings":";;;;;;;AAUA,eAAsB,OAAO,EAAE,WAAsC;CACnE,IAAI;AACJ,KAAI;AACF,QAAO,MAAM,OAAO;UACb,IAAI;AACX,UAAQ,MAAM,4DAA4D;AAC1E,eAAA,QAAQ,KAAK,EAAE;;CAGjB,MAAM,EAAE,QAAQ;CAChB,MAAM,UAAUA,aAAAA,QAAQ,QAAQ;AAChC,KAAI;AACF,UAAQ,IAAI,2BAA2B;AACvC,UAAQ,MAAA,GAAA,UAAA,WAAe,UAAU,6DAA6D,CAAC;AAC/F,OAAK;AACL,QAAMC,kBAAAA,cACJC,kBAAAA,oBAAoB;GAClB,SAAS;GACT,aAAa;GACb;GACA,QAAQ;GACT,CAAC,CACH;UACM,OAAO;AACd,QAAMD,kBAAAA,cACJC,kBAAAA,oBAAoB;GAClB,SAAS;GACT,aAAa;GACb;GACA,QAAQ;GACT,CAAC,CACH;AACD,UAAQ,MAAMC,eAAAA,gBAAgB,MAAM,CAAC"}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import "./chunk--u3MIqq1.js";
|
|
2
|
-
import { t as getErrorMessage } from "./errors-
|
|
3
|
-
import { r as sendTelemetry, t as buildTelemetryEvent } from "./telemetry-
|
|
4
|
-
import { t as jiti } from "./jiti-e08mD2Ph.js";
|
|
2
|
+
import { t as getErrorMessage } from "./errors-CjPmyZHy.js";
|
|
3
|
+
import { r as sendTelemetry, t as buildTelemetryEvent } from "./telemetry-LgT_sdPe.js";
|
|
5
4
|
import { styleText } from "node:util";
|
|
6
5
|
import process from "node:process";
|
|
7
6
|
//#region src/runners/mcp.ts
|
|
8
7
|
async function runMcp({ version }) {
|
|
9
8
|
let mod;
|
|
10
9
|
try {
|
|
11
|
-
mod = await
|
|
10
|
+
mod = await import("@kubb/mcp");
|
|
12
11
|
} catch (_e) {
|
|
13
12
|
console.error(`Import of '@kubb/mcp' is required to start the MCP server`);
|
|
14
13
|
process.exit(1);
|
|
@@ -38,4 +37,4 @@ async function runMcp({ version }) {
|
|
|
38
37
|
//#endregion
|
|
39
38
|
export { runMcp };
|
|
40
39
|
|
|
41
|
-
//# sourceMappingURL=mcp-
|
|
40
|
+
//# sourceMappingURL=mcp-D7EIR9fR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-D7EIR9fR.js","names":[],"sources":["../src/runners/mcp.ts"],"sourcesContent":["import process from 'node:process'\nimport { styleText } from 'node:util'\nimport { getErrorMessage } from '@internals/utils'\nimport type * as McpModule from '@kubb/mcp'\nimport { buildTelemetryEvent, sendTelemetry } from '../utils/telemetry.ts'\n\ntype McpOptions = {\n version: string\n}\n\nexport async function runMcp({ version }: McpOptions): Promise<void> {\n let mod: typeof McpModule\n try {\n mod = (await import('@kubb/mcp')) as typeof McpModule\n } catch (_e) {\n console.error(`Import of '@kubb/mcp' is required to start the MCP server`)\n process.exit(1)\n }\n\n const { run } = mod\n const hrStart = process.hrtime()\n try {\n console.log('⏳ Starting MCP server...')\n console.warn(styleText('yellow', 'This feature is still under development — use with caution'))\n run()\n await sendTelemetry(\n buildTelemetryEvent({\n command: 'mcp',\n kubbVersion: version,\n hrStart,\n status: 'success',\n }),\n )\n } catch (error) {\n await sendTelemetry(\n buildTelemetryEvent({\n command: 'mcp',\n kubbVersion: version,\n hrStart,\n status: 'failed',\n }),\n )\n console.error(getErrorMessage(error))\n }\n}\n"],"mappings":";;;;;;AAUA,eAAsB,OAAO,EAAE,WAAsC;CACnE,IAAI;AACJ,KAAI;AACF,QAAO,MAAM,OAAO;UACb,IAAI;AACX,UAAQ,MAAM,4DAA4D;AAC1E,UAAQ,KAAK,EAAE;;CAGjB,MAAM,EAAE,QAAQ;CAChB,MAAM,UAAU,QAAQ,QAAQ;AAChC,KAAI;AACF,UAAQ,IAAI,2BAA2B;AACvC,UAAQ,KAAK,UAAU,UAAU,6DAA6D,CAAC;AAC/F,OAAK;AACL,QAAM,cACJ,oBAAoB;GAClB,SAAS;GACT,aAAa;GACb;GACA,QAAQ;GACT,CAAC,CACH;UACM,OAAO;AACd,QAAM,cACJ,oBAAoB;GAClB,SAAS;GACT,aAAa;GACb;GACA,QAAQ;GACT,CAAC,CACH;AACD,UAAQ,MAAM,gBAAgB,MAAM,CAAC"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
require("./chunk-ByKO4r7w.cjs");
|
|
2
|
-
const require_define = require("./define-
|
|
3
|
-
const require_package = require("./package-
|
|
2
|
+
const require_define = require("./define-Bdn8j5VM.cjs");
|
|
3
|
+
const require_package = require("./package-D5arPDnh.cjs");
|
|
4
4
|
//#region src/commands/mcp.ts
|
|
5
5
|
const command = require_define.defineCommand({
|
|
6
6
|
name: "mcp",
|
|
7
7
|
description: "Start the server to enable the MCP client to interact with the LLM.",
|
|
8
8
|
async run() {
|
|
9
|
-
const { runMcp } = await Promise.resolve().then(() => require("./mcp-
|
|
9
|
+
const { runMcp } = await Promise.resolve().then(() => require("./mcp-CLcDV4Jm.cjs"));
|
|
10
10
|
await runMcp({ version: require_package.version });
|
|
11
11
|
}
|
|
12
12
|
});
|
|
13
13
|
//#endregion
|
|
14
14
|
exports.command = command;
|
|
15
15
|
|
|
16
|
-
//# sourceMappingURL=mcp-
|
|
16
|
+
//# sourceMappingURL=mcp-Dpu8vzzj.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-
|
|
1
|
+
{"version":3,"file":"mcp-Dpu8vzzj.cjs","names":["defineCommand"],"sources":["../src/commands/mcp.ts"],"sourcesContent":["import { defineCommand } from '@internals/utils'\nimport { version } from '../../package.json'\n\nexport const command = defineCommand({\n name: 'mcp',\n description: 'Start the server to enable the MCP client to interact with the LLM.',\n async run() {\n const { runMcp } = await import('../runners/mcp.ts')\n\n await runMcp({ version })\n },\n})\n"],"mappings":";;;;AAGA,MAAa,UAAUA,eAAAA,cAAc;CACnC,MAAM;CACN,aAAa;CACb,MAAM,MAAM;EACV,MAAM,EAAE,WAAW,MAAA,QAAA,SAAA,CAAA,WAAA,QAAM,qBAAA,CAAA;AAEzB,QAAM,OAAO,EAAE,SAAA,gBAAA,SAAS,CAAC;;CAE5B,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//#region package.json
|
|
2
|
-
var version = "5.0.0-
|
|
2
|
+
var version = "5.0.0-beta.75";
|
|
3
3
|
//#endregion
|
|
4
4
|
Object.defineProperty(exports, "version", {
|
|
5
5
|
enumerable: true,
|
|
@@ -8,4 +8,4 @@ Object.defineProperty(exports, "version", {
|
|
|
8
8
|
}
|
|
9
9
|
});
|
|
10
10
|
|
|
11
|
-
//# sourceMappingURL=package-
|
|
11
|
+
//# sourceMappingURL=package-D5arPDnh.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-D5arPDnh.cjs","names":[],"sources":["../package.json"],"sourcesContent":[""],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-DqZsMLZ9.js","names":[],"sources":["../package.json"],"sourcesContent":[""],"mappings":""}
|
|
@@ -15,8 +15,13 @@ function tokenize(command) {
|
|
|
15
15
|
* Spawns `cmd` with `args` and returns a promise that settles when the child process finishes.
|
|
16
16
|
*
|
|
17
17
|
* Foreground mode (default) inherits the parent's stdio and rejects on non-zero exit or signal.
|
|
18
|
-
* Detached mode spawns the child in its own process group, unref's it, and resolves immediately
|
|
19
|
-
*
|
|
18
|
+
* Detached mode spawns the child in its own process group, unref's it, and resolves immediately.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* await spawnAsync('pnpm', ['install'])
|
|
23
|
+
* await spawnAsync('node', ['server.js'], { detached: true }) // fire-and-forget
|
|
24
|
+
* ```
|
|
20
25
|
*/
|
|
21
26
|
function spawnAsync(cmd, args, options = {}) {
|
|
22
27
|
const { cwd = process.cwd(), env, detached = false } = options;
|
|
@@ -54,4 +59,4 @@ Object.defineProperty(exports, "tokenize", {
|
|
|
54
59
|
}
|
|
55
60
|
});
|
|
56
61
|
|
|
57
|
-
//# sourceMappingURL=shell-
|
|
62
|
+
//# sourceMappingURL=shell-475fQKaX.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell-475fQKaX.cjs","names":[],"sources":["../../../internals/utils/src/shell.ts"],"sourcesContent":["import { spawn } from 'node:child_process'\n\n/**\n * Tokenizes a shell command string, respecting single and double quotes.\n *\n * @example\n * tokenize('git commit -m \"initial commit\"')\n * // → ['git', 'commit', '-m', 'initial commit']\n */\nexport function tokenize(command: string): string[] {\n return (command.match(/[^\\s\"']+|\"([^\"]*)\"|'([^']*)'/g) ?? []).map((token) => token.replace(/^[\"']|[\"']$/g, ''))\n}\n\ntype SpawnOptions = {\n /**\n * Working directory for the child process.\n * @default process.cwd()\n */\n cwd?: string\n /**\n * Environment variables passed to the child process.\n * @default process.env\n */\n env?: NodeJS.ProcessEnv\n /**\n * When `true`, spawns a detached background process and resolves immediately.\n * The child is unref'd so the parent process can exit independently.\n * @default false\n */\n detached?: boolean\n}\n\n/**\n * Spawns `cmd` with `args` and returns a promise that settles when the child process finishes.\n *\n * Foreground mode (default) inherits the parent's stdio and rejects on non-zero exit or signal.\n * Detached mode spawns the child in its own process group, unref's it, and resolves immediately.\n *\n * @example\n * ```ts\n * await spawnAsync('pnpm', ['install'])\n * await spawnAsync('node', ['server.js'], { detached: true }) // fire-and-forget\n * ```\n */\nexport function spawnAsync(cmd: string, args: string[], options: SpawnOptions = {}): Promise<void> {\n const { cwd = process.cwd(), env, detached = false } = options\n\n return new Promise((resolve, reject) => {\n const child = spawn(cmd, args, {\n stdio: detached ? 'ignore' : 'inherit',\n cwd,\n env,\n detached,\n })\n\n if (detached) {\n child.unref()\n resolve()\n return\n }\n\n child.on('close', (code, signal) => {\n if (code === 0) {\n resolve()\n } else if (signal !== null) {\n reject(new Error(`\"${cmd} ${args.join(' ')}\" was terminated by signal ${signal}`))\n } else {\n reject(new Error(`\"${cmd} ${args.join(' ')}\" exited with code ${code}`))\n }\n })\n child.on('error', reject)\n })\n}\n"],"mappings":";;;;;;;;;;AASA,SAAgB,SAAS,SAA2B;AAClD,SAAQ,QAAQ,MAAM,gCAAgC,IAAI,EAAE,EAAE,KAAK,UAAU,MAAM,QAAQ,gBAAgB,GAAG,CAAC;;;;;;;;;;;;;;AAkCjH,SAAgB,WAAW,KAAa,MAAgB,UAAwB,EAAE,EAAiB;CACjG,MAAM,EAAE,MAAM,QAAQ,KAAK,EAAE,KAAK,WAAW,UAAU;AAEvD,QAAO,IAAI,SAAS,SAAS,WAAW;EACtC,MAAM,SAAA,GAAA,mBAAA,OAAc,KAAK,MAAM;GAC7B,OAAO,WAAW,WAAW;GAC7B;GACA;GACA;GACD,CAAC;AAEF,MAAI,UAAU;AACZ,SAAM,OAAO;AACb,YAAS;AACT;;AAGF,QAAM,GAAG,UAAU,MAAM,WAAW;AAClC,OAAI,SAAS,EACX,UAAS;YACA,WAAW,KACpB,wBAAO,IAAI,MAAM,IAAI,IAAI,GAAG,KAAK,KAAK,IAAI,CAAC,6BAA6B,SAAS,CAAC;OAElF,wBAAO,IAAI,MAAM,IAAI,IAAI,GAAG,KAAK,KAAK,IAAI,CAAC,qBAAqB,OAAO,CAAC;IAE1E;AACF,QAAM,GAAG,SAAS,OAAO;GACzB"}
|
|
@@ -15,8 +15,13 @@ function tokenize(command) {
|
|
|
15
15
|
* Spawns `cmd` with `args` and returns a promise that settles when the child process finishes.
|
|
16
16
|
*
|
|
17
17
|
* Foreground mode (default) inherits the parent's stdio and rejects on non-zero exit or signal.
|
|
18
|
-
* Detached mode spawns the child in its own process group, unref's it, and resolves immediately
|
|
19
|
-
*
|
|
18
|
+
* Detached mode spawns the child in its own process group, unref's it, and resolves immediately.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* await spawnAsync('pnpm', ['install'])
|
|
23
|
+
* await spawnAsync('node', ['server.js'], { detached: true }) // fire-and-forget
|
|
24
|
+
* ```
|
|
20
25
|
*/
|
|
21
26
|
function spawnAsync(cmd, args, options = {}) {
|
|
22
27
|
const { cwd = process.cwd(), env, detached = false } = options;
|
|
@@ -43,4 +48,4 @@ function spawnAsync(cmd, args, options = {}) {
|
|
|
43
48
|
//#endregion
|
|
44
49
|
export { tokenize as n, spawnAsync as t };
|
|
45
50
|
|
|
46
|
-
//# sourceMappingURL=shell-
|
|
51
|
+
//# sourceMappingURL=shell-DLzN4fRo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell-DLzN4fRo.js","names":[],"sources":["../../../internals/utils/src/shell.ts"],"sourcesContent":["import { spawn } from 'node:child_process'\n\n/**\n * Tokenizes a shell command string, respecting single and double quotes.\n *\n * @example\n * tokenize('git commit -m \"initial commit\"')\n * // → ['git', 'commit', '-m', 'initial commit']\n */\nexport function tokenize(command: string): string[] {\n return (command.match(/[^\\s\"']+|\"([^\"]*)\"|'([^']*)'/g) ?? []).map((token) => token.replace(/^[\"']|[\"']$/g, ''))\n}\n\ntype SpawnOptions = {\n /**\n * Working directory for the child process.\n * @default process.cwd()\n */\n cwd?: string\n /**\n * Environment variables passed to the child process.\n * @default process.env\n */\n env?: NodeJS.ProcessEnv\n /**\n * When `true`, spawns a detached background process and resolves immediately.\n * The child is unref'd so the parent process can exit independently.\n * @default false\n */\n detached?: boolean\n}\n\n/**\n * Spawns `cmd` with `args` and returns a promise that settles when the child process finishes.\n *\n * Foreground mode (default) inherits the parent's stdio and rejects on non-zero exit or signal.\n * Detached mode spawns the child in its own process group, unref's it, and resolves immediately.\n *\n * @example\n * ```ts\n * await spawnAsync('pnpm', ['install'])\n * await spawnAsync('node', ['server.js'], { detached: true }) // fire-and-forget\n * ```\n */\nexport function spawnAsync(cmd: string, args: string[], options: SpawnOptions = {}): Promise<void> {\n const { cwd = process.cwd(), env, detached = false } = options\n\n return new Promise((resolve, reject) => {\n const child = spawn(cmd, args, {\n stdio: detached ? 'ignore' : 'inherit',\n cwd,\n env,\n detached,\n })\n\n if (detached) {\n child.unref()\n resolve()\n return\n }\n\n child.on('close', (code, signal) => {\n if (code === 0) {\n resolve()\n } else if (signal !== null) {\n reject(new Error(`\"${cmd} ${args.join(' ')}\" was terminated by signal ${signal}`))\n } else {\n reject(new Error(`\"${cmd} ${args.join(' ')}\" exited with code ${code}`))\n }\n })\n child.on('error', reject)\n })\n}\n"],"mappings":";;;;;;;;;;AASA,SAAgB,SAAS,SAA2B;AAClD,SAAQ,QAAQ,MAAM,gCAAgC,IAAI,EAAE,EAAE,KAAK,UAAU,MAAM,QAAQ,gBAAgB,GAAG,CAAC;;;;;;;;;;;;;;AAkCjH,SAAgB,WAAW,KAAa,MAAgB,UAAwB,EAAE,EAAiB;CACjG,MAAM,EAAE,MAAM,QAAQ,KAAK,EAAE,KAAK,WAAW,UAAU;AAEvD,QAAO,IAAI,SAAS,SAAS,WAAW;EACtC,MAAM,QAAQ,MAAM,KAAK,MAAM;GAC7B,OAAO,WAAW,WAAW;GAC7B;GACA;GACA;GACD,CAAC;AAEF,MAAI,UAAU;AACZ,SAAM,OAAO;AACb,YAAS;AACT;;AAGF,QAAM,GAAG,UAAU,MAAM,WAAW;AAClC,OAAI,SAAS,EACX,UAAS;YACA,WAAW,KACpB,wBAAO,IAAI,MAAM,IAAI,IAAI,GAAG,KAAK,KAAK,IAAI,CAAC,6BAA6B,SAAS,CAAC;OAElF,wBAAO,IAAI,MAAM,IAAI,IAAI,GAAG,KAAK,KAAK,IAAI,CAAC,qBAAqB,OAAO,CAAC;IAE1E;AACF,QAAM,GAAG,SAAS,OAAO;GACzB"}
|
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
const require_chunk = require("./chunk-ByKO4r7w.cjs");
|
|
2
|
-
const require_constants = require("./constants-
|
|
2
|
+
const require_constants = require("./constants-CnDXa1R6.cjs");
|
|
3
3
|
let node_crypto = require("node:crypto");
|
|
4
4
|
let node_dns = require("node:dns");
|
|
5
5
|
let node_os = require("node:os");
|
|
6
|
-
node_os = require_chunk.__toESM(node_os);
|
|
6
|
+
node_os = require_chunk.__toESM(node_os, 1);
|
|
7
7
|
let node_process = require("node:process");
|
|
8
|
-
node_process = require_chunk.__toESM(node_process);
|
|
8
|
+
node_process = require_chunk.__toESM(node_process, 1);
|
|
9
9
|
//#region ../../internals/utils/src/env.ts
|
|
10
10
|
/**
|
|
11
11
|
* Returns `true` when running inside a GitHub Actions workflow.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* if (isGitHubActions()) {
|
|
16
|
+
* core.setOutput('result', 'ok')
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
12
19
|
*/
|
|
13
20
|
function isGitHubActions() {
|
|
14
21
|
return !!process.env.GITHUB_ACTIONS;
|
|
@@ -17,19 +24,41 @@ function isGitHubActions() {
|
|
|
17
24
|
* Returns `true` when the process is running in a CI environment.
|
|
18
25
|
* Covers GitHub Actions, GitLab CI, CircleCI, Travis CI, Jenkins, Bitbucket,
|
|
19
26
|
* TeamCity, Buildkite, and Azure Pipelines.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* if (isCIEnvironment()) {
|
|
31
|
+
* logger.level = 'error'
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
20
34
|
*/
|
|
21
35
|
function isCIEnvironment() {
|
|
22
36
|
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);
|
|
23
37
|
}
|
|
24
38
|
/**
|
|
25
|
-
* Returns `true` when the process has an interactive TTY
|
|
39
|
+
* Returns `true` when the process has an interactive TTY with a valid terminal
|
|
40
|
+
* width and is not running in CI.
|
|
41
|
+
*
|
|
42
|
+
* Some IDE-embedded terminals report `isTTY = true` but set `columns` to `0`,
|
|
43
|
+
* which breaks clack's box-drawing helpers (they call `String.prototype.repeat`
|
|
44
|
+
* with a negative count and throw a `RangeError`). We therefore require a
|
|
45
|
+
* positive column count before declaring the TTY usable.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* if (canUseTTY()) {
|
|
50
|
+
* renderProgressBar()
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
26
53
|
*/
|
|
27
54
|
function canUseTTY() {
|
|
28
|
-
return !!process.stdout.isTTY && !isCIEnvironment();
|
|
55
|
+
return !!process.stdout.isTTY && (process.stdout.columns ?? 0) > 0 && !isCIEnvironment();
|
|
29
56
|
}
|
|
30
57
|
//#endregion
|
|
31
58
|
//#region ../../internals/utils/src/network.ts
|
|
32
|
-
/**
|
|
59
|
+
/**
|
|
60
|
+
* Well-known stable domains used as DNS probes to check internet connectivity.
|
|
61
|
+
*/
|
|
33
62
|
const TEST_DOMAINS = [
|
|
34
63
|
"dns.google.com",
|
|
35
64
|
"cloudflare.com",
|
|
@@ -37,7 +66,14 @@ const TEST_DOMAINS = [
|
|
|
37
66
|
];
|
|
38
67
|
/**
|
|
39
68
|
* Returns `true` when the system has internet connectivity.
|
|
40
|
-
*
|
|
69
|
+
* Probes DNS resolution against well-known stable domains.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* if (await isOnline()) {
|
|
74
|
+
* await fetchLatestVersion()
|
|
75
|
+
* }
|
|
76
|
+
* ```
|
|
41
77
|
*/
|
|
42
78
|
async function isOnline() {
|
|
43
79
|
for (const domain of TEST_DOMAINS) try {
|
|
@@ -48,6 +84,12 @@ async function isOnline() {
|
|
|
48
84
|
}
|
|
49
85
|
/**
|
|
50
86
|
* Executes `fn` only when the system is online. Returns `null` when offline or on error.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* const version = await executeIfOnline(() => fetchLatestVersion('kubb'))
|
|
91
|
+
* // null when offline
|
|
92
|
+
* ```
|
|
51
93
|
*/
|
|
52
94
|
async function executeIfOnline(fn) {
|
|
53
95
|
if (!await isOnline()) return null;
|
|
@@ -237,4 +279,4 @@ Object.defineProperty(exports, "sendTelemetry", {
|
|
|
237
279
|
}
|
|
238
280
|
});
|
|
239
281
|
|
|
240
|
-
//# sourceMappingURL=telemetry-
|
|
282
|
+
//# sourceMappingURL=telemetry-DN95_2pF.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetry-DN95_2pF.cjs","names":["dnsPromises","process","OTLP_ENDPOINT","os"],"sources":["../../../internals/utils/src/env.ts","../../../internals/utils/src/network.ts","../src/utils/telemetry.ts"],"sourcesContent":["/**\n * Returns `true` when running inside a GitHub Actions workflow.\n *\n * @example\n * ```ts\n * if (isGitHubActions()) {\n * core.setOutput('result', 'ok')\n * }\n * ```\n */\nexport function isGitHubActions(): boolean {\n return !!process.env.GITHUB_ACTIONS\n}\n\n/**\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","import { randomBytes } from 'node:crypto'\nimport os from 'node:os'\nimport process from 'node:process'\nimport { executeIfOnline, isCIEnvironment } 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: OtlpAnyValue[] } }\ntype OtlpKvListValue = { kvlistValue: { values: 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: OtlpKeyValue[]\n droppedAttributesCount?: number\n}\n\ntype OtlpInstrumentationScope = {\n name: string\n version?: string\n attributes?: 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?: OtlpKeyValue[]\n droppedAttributesCount?: number\n events?: OtlpSpanEvent[]\n droppedEventsCount?: number\n links?: OtlpSpanLink[]\n droppedLinksCount?: number\n status?: OtlpStatus\n}\n\ntype OtlpSpanEvent = {\n timeUnixNano: string\n name: string\n attributes?: OtlpKeyValue[]\n droppedAttributesCount?: number\n}\n\ntype OtlpSpanLink = {\n traceId: string\n spanId: string\n traceState?: string\n attributes?: OtlpKeyValue[]\n droppedAttributesCount?: number\n}\n\ntype OtlpScopeSpans = {\n scope: OtlpInstrumentationScope\n spans: OtlpSpan[]\n schemaUrl?: string\n}\n\ntype OtlpResourceSpans = {\n resource: OtlpResource\n scopeSpans: OtlpScopeSpans[]\n schemaUrl?: string\n}\n\n/** Root payload sent to POST /v1/traces */\ntype OtlpExportTraceServiceRequest = {\n resourceSpans: OtlpResourceSpans[]\n}\n\nexport type TelemetryPlugin = {\n name: string\n options: Record<string, unknown>\n}\n\ntype TelemetryEvent = {\n command: string\n kubbVersion: string\n nodeVersion: string\n platform: string\n ci: boolean\n plugins: TelemetryPlugin[]\n duration: number\n filesCreated: number\n status: 'success' | 'failed'\n}\n\n/**\n * Detect whether the current process is running inside a CI environment.\n * Delegates to the canonical isCIEnvironment() from envDetection.\n */\nexport function isCi(): boolean {\n return isCIEnvironment()\n}\n\n/**\n * Check if telemetry is disabled via DO_NOT_TRACK or KUBB_DISABLE_TELEMETRY.\n * Respects the standard DO_NOT_TRACK convention used across development tools.\n */\nexport function isTelemetryDisabled(): 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 * Convert a TelemetryEvent into an OTLP-compatible JSON trace payload.\n * See https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/\n */\nexport function 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: 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.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-cli' } },\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-cli', 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.\n * Respects DO_NOT_TRACK and KUBB_DISABLE_TELEMETRY environment variables.\n * Fails silently to never interrupt the generation process.\n */\nexport async function sendTelemetry(event: TelemetryEvent): Promise<void> {\n if (isTelemetryDisabled()) {\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-cli',\n },\n body: JSON.stringify(buildOtlpPayload(event)),\n signal: AbortSignal.timeout(5_000),\n })\n } catch (_e) {\n // Fail silently – telemetry must never break the CLI\n }\n })\n}\n\n/**\n * Build an anonymous telemetry payload from a completed generation run.\n * No file paths, OpenAPI specs, or secrets are included.\n */\nexport function buildTelemetryEvent(options: {\n command: 'generate' | 'mcp' | 'validate' | 'agent'\n kubbVersion: string\n plugins?: 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 platform: os.platform(),\n ci: isCi(),\n plugins: options.plugins ?? [],\n duration,\n filesCreated: options.filesCreated ?? 0,\n status: options.status,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAUA,SAAgB,kBAA2B;AACzC,QAAO,CAAC,CAAC,QAAQ,IAAI;;;;;;;;;;;;;;AAevB,SAAgB,kBAA2B;AACzC,QAAO,CAAC,EACN,QAAQ,IAAI,MACZ,QAAQ,IAAI,kBACZ,QAAQ,IAAI,aACZ,QAAQ,IAAI,0BACZ,QAAQ,IAAI,eACZ,QAAQ,IAAI,YACZ,QAAQ,I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