@kubb/cli 5.9.3 → 5.9.4
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/dist/Telemetry-ByFeVTz5.cjs +314 -0
- package/dist/Telemetry-ByFeVTz5.cjs.map +1 -0
- package/dist/Telemetry-E_BBHmnT.js +259 -0
- package/dist/Telemetry-E_BBHmnT.js.map +1 -0
- package/dist/background-CZ2nVKwB.js +1 -0
- package/dist/{background-BcRoKru0.cjs → background-DdUVvDwi.cjs} +7 -6
- package/dist/{background-BcRoKru0.cjs.map → background-DdUVvDwi.cjs.map} +1 -1
- package/dist/{background-CCex47-d.js → background-H30JH70B.js} +3 -2
- package/dist/{background-CCex47-d.js.map → background-H30JH70B.js.map} +1 -1
- package/dist/{reporters-B4rZOlo8.cjs → config-Ck2JHe5r.cjs} +36 -4
- package/dist/config-Ck2JHe5r.cjs.map +1 -0
- package/dist/{reporters-H21Jvrff.js → config-DxePdyxe.js} +29 -3
- package/dist/config-DxePdyxe.js.map +1 -0
- package/dist/credentials-C8tjAhTo.js +1 -0
- package/dist/credentials-CZK6zPLv.js +62 -0
- package/dist/credentials-CZK6zPLv.js.map +1 -0
- package/dist/credentials-DDaKqtJn.cjs +113 -0
- package/dist/credentials-DDaKqtJn.cjs.map +1 -0
- package/dist/index.cjs +702 -208
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +697 -207
- package/dist/index.js.map +1 -1
- package/dist/{output-BnK0scpX.cjs → output-Cd3Kmvo0.cjs} +141 -66
- package/dist/output-Cd3Kmvo0.cjs.map +1 -0
- package/dist/{output-qFt4vV7K.js → output-DS5hyqwL.js} +173 -129
- package/dist/output-DS5hyqwL.js.map +1 -0
- package/dist/{registry-B7BvdrGE.js → registry-CSXUuuCy.js} +2 -2
- package/dist/{registry-B7BvdrGE.js.map → registry-CSXUuuCy.js.map} +1 -1
- package/dist/{registry-DER9aRyg.cjs → registry-CrvQxnxy.cjs} +6 -6
- package/dist/{registry-DER9aRyg.cjs.map → registry-CrvQxnxy.cjs.map} +1 -1
- package/dist/rolldown-runtime-CPE0t6oh.cjs +53 -0
- package/dist/{run-QPsBYkq_.js → run-BPD5Vaon.js} +5 -7
- package/dist/{run-QPsBYkq_.js.map → run-BPD5Vaon.js.map} +1 -1
- package/dist/{run-Co732JNO.cjs → run-C0Tfrddq.cjs} +5 -6
- package/dist/{run-Co732JNO.cjs.map → run-C0Tfrddq.cjs.map} +1 -1
- package/dist/{run-DFos0eOY.cjs → run-CbN00IHp.cjs} +16 -18
- package/dist/{run-DFos0eOY.cjs.map → run-CbN00IHp.cjs.map} +1 -1
- package/dist/{run-B1jaQu6Q.js → run-CecrPSop.js} +2 -3
- package/dist/{run-B1jaQu6Q.js.map → run-CecrPSop.js.map} +1 -1
- package/dist/{run-DunTcXOS.js → run-Ck04_W4q.js} +2 -3
- package/dist/{run-DunTcXOS.js.map → run-Ck04_W4q.js.map} +1 -1
- package/dist/{run-BRUwQ5Y7.js → run-DcP1czVQ.js} +25 -84
- package/dist/run-DcP1czVQ.js.map +1 -0
- package/dist/{run-CIvFRMLt.cjs → run-Dyc52IzX.cjs} +5 -6
- package/dist/{run-CIvFRMLt.cjs.map → run-Dyc52IzX.cjs.map} +1 -1
- package/dist/{run-DxGkjzRm.cjs → run-QqLDhthl.cjs} +46 -158
- package/dist/run-QqLDhthl.cjs.map +1 -0
- package/dist/run-WkXSXG2V.js +1 -0
- package/dist/{snapshot-DUJU70H_.cjs → snapshot-NGLcfG6E.cjs} +17 -26
- package/dist/snapshot-NGLcfG6E.cjs.map +1 -0
- package/dist/{snapshot-CkpJr-gr.js → snapshot-iEjgROga.js} +15 -24
- package/dist/snapshot-iEjgROga.js.map +1 -0
- package/dist/studioWorker.js +2 -2
- package/package.json +7 -8
- package/dist/Telemetry-C9gmBTr0.cjs +0 -231
- package/dist/Telemetry-C9gmBTr0.cjs.map +0 -1
- package/dist/Telemetry-CSc7OVsv.js +0 -207
- package/dist/Telemetry-CSc7OVsv.js.map +0 -1
- package/dist/agent-BPIqnEl2.js +0 -59
- package/dist/agent-BPIqnEl2.js.map +0 -1
- package/dist/agent-DElUuYuy.cjs +0 -120
- package/dist/agent-DElUuYuy.cjs.map +0 -1
- package/dist/background-1AFVK_yN.js +0 -1
- package/dist/commands-BuY0nrlU.cjs +0 -87
- package/dist/commands-BuY0nrlU.cjs.map +0 -1
- package/dist/commands-atq2z0Bo.js +0 -81
- package/dist/commands-atq2z0Bo.js.map +0 -1
- package/dist/config-B6UIKcl1.js +0 -117
- package/dist/config-B6UIKcl1.js.map +0 -1
- package/dist/config-Bo9ro7vg.cjs +0 -129
- package/dist/config-Bo9ro7vg.cjs.map +0 -1
- package/dist/constants-Cii4HX64.js +0 -12
- package/dist/constants-Cii4HX64.js.map +0 -1
- package/dist/constants-Df449N47.cjs +0 -29
- package/dist/constants-Df449N47.cjs.map +0 -1
- package/dist/errors-BdA8M78q.cjs +0 -43
- package/dist/errors-BdA8M78q.cjs.map +0 -1
- package/dist/errors-DmC83ALX.js +0 -32
- package/dist/errors-DmC83ALX.js.map +0 -1
- package/dist/output-BnK0scpX.cjs.map +0 -1
- package/dist/output-qFt4vV7K.js.map +0 -1
- package/dist/reporters-B4rZOlo8.cjs.map +0 -1
- package/dist/reporters-H21Jvrff.js.map +0 -1
- package/dist/run-BGTUbY2h.cjs +0 -130
- package/dist/run-BGTUbY2h.cjs.map +0 -1
- package/dist/run-BPQzGEIs.js +0 -178
- package/dist/run-BPQzGEIs.js.map +0 -1
- package/dist/run-BRUwQ5Y7.js.map +0 -1
- package/dist/run-BYff_byB.js +0 -71
- package/dist/run-BYff_byB.js.map +0 -1
- package/dist/run-Bhs7mJ1f.cjs +0 -79
- package/dist/run-Bhs7mJ1f.cjs.map +0 -1
- package/dist/run-CH48n-MJ.js +0 -1
- package/dist/run-DfEoWJuy.js +0 -126
- package/dist/run-DfEoWJuy.js.map +0 -1
- package/dist/run-Dm9OZUkQ.cjs +0 -182
- package/dist/run-Dm9OZUkQ.cjs.map +0 -1
- package/dist/run-DpAMfkm5.cjs +0 -72
- package/dist/run-DpAMfkm5.cjs.map +0 -1
- package/dist/run-DxGkjzRm.cjs.map +0 -1
- package/dist/run-DxxYCqEo.js +0 -77
- package/dist/run-DxxYCqEo.js.map +0 -1
- package/dist/snapshot-CkpJr-gr.js.map +0 -1
- package/dist/snapshot-DUJU70H_.cjs.map +0 -1
- package/dist/utils-BHW8kA8P.js +0 -83
- package/dist/utils-BHW8kA8P.js.map +0 -1
- package/dist/utils-BzQ46pgd.cjs +0 -109
- package/dist/utils-BzQ46pgd.cjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
const require_Telemetry = require("./Telemetry-
|
|
2
|
+
const require_rolldown_runtime = require("./rolldown-runtime-CPE0t6oh.cjs");
|
|
3
|
+
const require_Telemetry = require("./Telemetry-ByFeVTz5.cjs");
|
|
4
|
+
const require_output = require("./output-Cd3Kmvo0.cjs");
|
|
5
|
+
const require_registry = require("./registry-CrvQxnxy.cjs");
|
|
4
6
|
let node_util = require("node:util");
|
|
5
7
|
let _gunshi_plugin_dryrun = require("@gunshi/plugin-dryrun");
|
|
6
|
-
_gunshi_plugin_dryrun =
|
|
8
|
+
_gunshi_plugin_dryrun = require_rolldown_runtime.__toESM(_gunshi_plugin_dryrun, 1);
|
|
7
9
|
let gunshi = require("gunshi");
|
|
10
|
+
let node_process = require("node:process");
|
|
11
|
+
node_process = require_rolldown_runtime.__toESM(node_process, 1);
|
|
12
|
+
let tinyexec = require("tinyexec");
|
|
13
|
+
let node_path = require("node:path");
|
|
14
|
+
node_path = require_rolldown_runtime.__toESM(node_path, 1);
|
|
15
|
+
let _clack_prompts = require("@clack/prompts");
|
|
16
|
+
_clack_prompts = require_rolldown_runtime.__toESM(_clack_prompts, 1);
|
|
17
|
+
let node_fs = require("node:fs");
|
|
18
|
+
node_fs = require_rolldown_runtime.__toESM(node_fs, 1);
|
|
19
|
+
let _kubb_core = require("@kubb/core");
|
|
8
20
|
//#region src/commands/shared.ts
|
|
9
21
|
const configArg = { config: {
|
|
10
22
|
type: "string",
|
|
@@ -66,44 +78,6 @@ const studioPermissionArgs = {
|
|
|
66
78
|
}
|
|
67
79
|
};
|
|
68
80
|
//#endregion
|
|
69
|
-
//#region src/commands/add.ts
|
|
70
|
-
const command$13 = (0, gunshi.define)({
|
|
71
|
-
name: "add",
|
|
72
|
-
description: "Install a plugin, adapter, or parser from the Kubb registry at its reviewed version. Without an id, pick one from the registry. A plugin is added to kubb.config.ts, an adapter or parser prints the code to add. Reads KUBB_REGISTRY to use another registry.",
|
|
73
|
-
examples: [
|
|
74
|
-
"kubb add",
|
|
75
|
-
"kubb add plugin-zod",
|
|
76
|
-
"kubb add kubb-labs/plugin-react-query",
|
|
77
|
-
"kubb add acme/plugin-x --yes",
|
|
78
|
-
"kubb add plugin-zod --no-install"
|
|
79
|
-
].join("\n"),
|
|
80
|
-
toKebab: true,
|
|
81
|
-
args: {
|
|
82
|
-
id: {
|
|
83
|
-
type: "positional",
|
|
84
|
-
description: "Registry id: owner/slug, or a slug for an official extension. Asked for when omitted",
|
|
85
|
-
required: false
|
|
86
|
-
},
|
|
87
|
-
...configArg,
|
|
88
|
-
...yesArg,
|
|
89
|
-
install: {
|
|
90
|
-
type: "boolean",
|
|
91
|
-
description: "Install the package. Pass --no-install to only edit the config",
|
|
92
|
-
negatable: true,
|
|
93
|
-
default: true
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
async run({ values }) {
|
|
97
|
-
const { run } = await Promise.resolve().then(() => require("./run-BGTUbY2h.cjs"));
|
|
98
|
-
await run({
|
|
99
|
-
id: values.id,
|
|
100
|
-
configPath: values.config,
|
|
101
|
-
yes: values.yes,
|
|
102
|
-
install: values.install
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
//#endregion
|
|
107
81
|
//#region src/commands/generate.ts
|
|
108
82
|
const REPORTER_NAMES = [
|
|
109
83
|
"cli",
|
|
@@ -127,7 +101,7 @@ function resolveLogLevel({ verbose, silent, logLevel }) {
|
|
|
127
101
|
if (silent) return "silent";
|
|
128
102
|
return logLevel;
|
|
129
103
|
}
|
|
130
|
-
const command$
|
|
104
|
+
const command$13 = (0, gunshi.defineWithTypes)()({
|
|
131
105
|
name: "generate",
|
|
132
106
|
description: "Generate TypeScript types, API clients, React Query hooks, Zod schemas, and more from an OpenAPI specification. Reads kubb.config.ts by default. Pass an OpenAPI file path as the first argument to override the input without editing the config.",
|
|
133
107
|
examples: [
|
|
@@ -177,7 +151,7 @@ const command$12 = (0, gunshi.defineWithTypes)()({
|
|
|
177
151
|
async run(ctx) {
|
|
178
152
|
const { values } = ctx;
|
|
179
153
|
const logLevel = resolveLogLevel(values);
|
|
180
|
-
const { run } = await Promise.resolve().then(() => require("./run-
|
|
154
|
+
const { run } = await Promise.resolve().then(() => require("./run-CbN00IHp.cjs"));
|
|
181
155
|
await run({
|
|
182
156
|
input: values.input,
|
|
183
157
|
configPath: values.config,
|
|
@@ -189,71 +163,9 @@ const command$12 = (0, gunshi.defineWithTypes)()({
|
|
|
189
163
|
}
|
|
190
164
|
});
|
|
191
165
|
//#endregion
|
|
192
|
-
//#region src/commands/init.ts
|
|
193
|
-
const command$11 = (0, gunshi.defineWithTypes)()({
|
|
194
|
-
name: "init",
|
|
195
|
-
description: "Scaffold a kubb.config.ts and install plugins for code generation from an OpenAPI spec. Run without flags for interactive setup, or pass --input, --output, and --plugins to skip the prompts.",
|
|
196
|
-
examples: [
|
|
197
|
-
"kubb init",
|
|
198
|
-
"kubb init --yes",
|
|
199
|
-
"kubb init --input ./openapi.yaml --output ./src/gen --plugins plugin-ts,plugin-zod",
|
|
200
|
-
"kubb init --plugins plugin-ts,plugin-axios,plugin-react-query",
|
|
201
|
-
"kubb init --yes --dry-run"
|
|
202
|
-
].join("\n"),
|
|
203
|
-
toKebab: true,
|
|
204
|
-
args: {
|
|
205
|
-
yes: {
|
|
206
|
-
type: "boolean",
|
|
207
|
-
description: "Skip prompts and use default options",
|
|
208
|
-
short: "y",
|
|
209
|
-
default: false
|
|
210
|
-
},
|
|
211
|
-
input: {
|
|
212
|
-
type: "string",
|
|
213
|
-
description: "Path to the OpenAPI specification",
|
|
214
|
-
short: "i",
|
|
215
|
-
metavar: "path"
|
|
216
|
-
},
|
|
217
|
-
output: {
|
|
218
|
-
type: "string",
|
|
219
|
-
description: "Output directory for generated files",
|
|
220
|
-
short: "o",
|
|
221
|
-
metavar: "path"
|
|
222
|
-
},
|
|
223
|
-
plugins: {
|
|
224
|
-
type: "string",
|
|
225
|
-
description: "Comma-separated Kubb registry ids of the plugins to add, the same ids `kubb add` takes (plugin-ts, plugin-zod, acme/plugin-x)",
|
|
226
|
-
metavar: "plugin-ts,plugin-zod,..."
|
|
227
|
-
}
|
|
228
|
-
},
|
|
229
|
-
async run(ctx) {
|
|
230
|
-
const { values } = ctx;
|
|
231
|
-
const { run } = await Promise.resolve().then(() => require("./run-Dm9OZUkQ.cjs"));
|
|
232
|
-
await run({
|
|
233
|
-
yes: values.yes,
|
|
234
|
-
version: require_Telemetry.version,
|
|
235
|
-
input: values.input,
|
|
236
|
-
output: values.output,
|
|
237
|
-
plugins: values.plugins,
|
|
238
|
-
dryRun: ctx.extensions[_gunshi_plugin_dryrun.pluginId]
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
});
|
|
242
|
-
//#endregion
|
|
243
|
-
//#region src/commands/list.ts
|
|
244
|
-
const command$10 = (0, gunshi.define)({
|
|
245
|
-
name: "list",
|
|
246
|
-
description: "List the installed Kubb extensions: their registry id, package, installed version, the version the Kubb registry pins, and whether an update exists.",
|
|
247
|
-
examples: "kubb list",
|
|
248
|
-
async run() {
|
|
249
|
-
const { run } = await Promise.resolve().then(() => require("./run-DpAMfkm5.cjs"));
|
|
250
|
-
await run();
|
|
251
|
-
}
|
|
252
|
-
});
|
|
253
|
-
//#endregion
|
|
254
166
|
//#region src/commands/mcp.ts
|
|
255
167
|
/** The runner is imported when the command runs, so listing `kubb --help` never loads `@kubb/mcp`. */
|
|
256
|
-
const command$
|
|
168
|
+
const command$12 = (0, gunshi.define)({
|
|
257
169
|
name: "mcp",
|
|
258
170
|
description: "Start a Model Context Protocol (MCP) server that exposes Kubb code generation as tools for AI assistants. Once running, configure your AI client (Claude, Cursor, Windsurf, etc.) to connect to it — the assistant can then call kubb generate directly without leaving the chat.",
|
|
259
171
|
examples: [
|
|
@@ -263,13 +175,29 @@ const command$9 = (0, gunshi.define)({
|
|
|
263
175
|
].join("\n"),
|
|
264
176
|
rendering: { header: null },
|
|
265
177
|
async run() {
|
|
266
|
-
const { run } = await Promise.resolve().then(() => require("./run-
|
|
178
|
+
const { run } = await Promise.resolve().then(() => require("./run-Dyc52IzX.cjs"));
|
|
267
179
|
await run();
|
|
268
180
|
}
|
|
269
181
|
});
|
|
270
182
|
//#endregion
|
|
183
|
+
//#region src/commands/studio/studioCommand.ts
|
|
184
|
+
/**
|
|
185
|
+
* Defines a `kubb studio` subcommand. The runner, and with it `@kubb/studio`, loads only when the
|
|
186
|
+
* command runs, so `kubb --help` never does.
|
|
187
|
+
*/
|
|
188
|
+
function studioCommand({ action, block, ...definition }) {
|
|
189
|
+
return (0, gunshi.define)({
|
|
190
|
+
...definition,
|
|
191
|
+
toKebab: true,
|
|
192
|
+
async run({ values }) {
|
|
193
|
+
const { runStudio } = await Promise.resolve().then(() => require("./run-QqLDhthl.cjs"));
|
|
194
|
+
await runStudio(values, action, { block });
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
//#endregion
|
|
271
199
|
//#region src/commands/studio/connect.ts
|
|
272
|
-
const command$
|
|
200
|
+
const command$11 = studioCommand({
|
|
273
201
|
name: "connect",
|
|
274
202
|
description: "Connect this project to Kubb Studio and generate from the browser.",
|
|
275
203
|
examples: [
|
|
@@ -278,7 +206,6 @@ const command$8 = (0, gunshi.define)({
|
|
|
278
206
|
"kubb studio connect --allow-write --allow-exec",
|
|
279
207
|
"kubb studio connect --url http://localhost:3000"
|
|
280
208
|
].join("\n"),
|
|
281
|
-
toKebab: true,
|
|
282
209
|
args: {
|
|
283
210
|
...configArg,
|
|
284
211
|
...studioConnectionArgs,
|
|
@@ -291,45 +218,42 @@ const command$8 = (0, gunshi.define)({
|
|
|
291
218
|
},
|
|
292
219
|
...logLevelArg
|
|
293
220
|
},
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
await
|
|
221
|
+
block: true,
|
|
222
|
+
async action(options) {
|
|
223
|
+
const { connect } = await Promise.resolve().then(() => require("./run-QqLDhthl.cjs"));
|
|
224
|
+
await connect(options);
|
|
297
225
|
}
|
|
298
226
|
});
|
|
299
227
|
//#endregion
|
|
300
228
|
//#region src/commands/studio/login.ts
|
|
301
|
-
const command$
|
|
229
|
+
const command$10 = studioCommand({
|
|
302
230
|
name: "login",
|
|
303
231
|
description: "Pair this machine with Kubb Studio without connecting.",
|
|
304
232
|
examples: ["kubb studio login", "kubb studio login --url http://localhost:3000"].join("\n"),
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
await loginRunner(ctx);
|
|
233
|
+
args: command$11.args,
|
|
234
|
+
async action(options) {
|
|
235
|
+
const { login } = await Promise.resolve().then(() => require("./run-QqLDhthl.cjs"));
|
|
236
|
+
await login(options);
|
|
310
237
|
}
|
|
311
238
|
});
|
|
312
239
|
//#endregion
|
|
313
240
|
//#region src/commands/studio/logout.ts
|
|
314
|
-
const command$
|
|
241
|
+
const command$9 = studioCommand({
|
|
315
242
|
name: "logout",
|
|
316
243
|
description: "Forget the stored Kubb Studio token.",
|
|
317
|
-
examples:
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
async run(ctx) {
|
|
326
|
-
const { logoutRunner } = await Promise.resolve().then(() => require("./commands-BuY0nrlU.cjs"));
|
|
327
|
-
await logoutRunner(ctx);
|
|
244
|
+
examples: "kubb studio logout",
|
|
245
|
+
args: {},
|
|
246
|
+
async action() {
|
|
247
|
+
const { stopWorker } = await Promise.resolve().then(() => require("./background-DdUVvDwi.cjs"));
|
|
248
|
+
const { clearCredentials } = await Promise.resolve().then(() => require("./credentials-DDaKqtJn.cjs")).then((n) => n.credentials_exports);
|
|
249
|
+
await stopWorker();
|
|
250
|
+
await clearCredentials();
|
|
251
|
+
console.log("Signed out of Kubb Studio.");
|
|
328
252
|
}
|
|
329
253
|
});
|
|
330
254
|
//#endregion
|
|
331
255
|
//#region src/commands/studio/snapshot.ts
|
|
332
|
-
const command$
|
|
256
|
+
const command$8 = (0, gunshi.define)({
|
|
333
257
|
name: "snapshot",
|
|
334
258
|
description: "Generate and publish a Kubb Studio snapshot from CI.",
|
|
335
259
|
examples: ["kubb studio snapshot", "kubb studio snapshot --json"].join("\n"),
|
|
@@ -363,51 +287,69 @@ const command$5 = (0, gunshi.define)({
|
|
|
363
287
|
...logLevelArg
|
|
364
288
|
},
|
|
365
289
|
async run(ctx) {
|
|
366
|
-
const { runner } = await Promise.resolve().then(() => require("./snapshot-
|
|
290
|
+
const { runner } = await Promise.resolve().then(() => require("./snapshot-NGLcfG6E.cjs"));
|
|
367
291
|
await runner(ctx);
|
|
368
292
|
}
|
|
369
293
|
});
|
|
370
294
|
//#endregion
|
|
371
295
|
//#region src/commands/studio/background.ts
|
|
372
|
-
const command$
|
|
296
|
+
const command$7 = studioCommand({
|
|
373
297
|
name: "start",
|
|
374
298
|
description: "Keep this project connected to Kubb Studio in the background.",
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
await startRunner(ctx);
|
|
299
|
+
args: command$11.args,
|
|
300
|
+
async action(options) {
|
|
301
|
+
const { startWorker } = await Promise.resolve().then(() => require("./background-DdUVvDwi.cjs"));
|
|
302
|
+
await startWorker(options);
|
|
380
303
|
}
|
|
381
304
|
});
|
|
382
305
|
const stopCommand = (0, gunshi.define)({
|
|
383
306
|
name: "stop",
|
|
384
307
|
description: "Stop this project's background connection and keep its pairing.",
|
|
385
308
|
async run() {
|
|
386
|
-
const {
|
|
387
|
-
await
|
|
309
|
+
const { stopWorker } = await Promise.resolve().then(() => require("./background-DdUVvDwi.cjs"));
|
|
310
|
+
await stopWorker();
|
|
311
|
+
console.log("Background connection stopped.");
|
|
388
312
|
}
|
|
389
313
|
});
|
|
390
314
|
//#endregion
|
|
391
315
|
//#region src/commands/studio/status.ts
|
|
392
|
-
const command$
|
|
316
|
+
const command$6 = studioCommand({
|
|
393
317
|
name: "status",
|
|
394
318
|
description: "Show the project worker, Kubb Studio pairing, and saved permissions.",
|
|
395
|
-
examples:
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
const
|
|
405
|
-
|
|
319
|
+
examples: "kubb studio status",
|
|
320
|
+
args: { url: studioConnectionArgs.url },
|
|
321
|
+
async action(options) {
|
|
322
|
+
const { getWorkerLogPath, getWorkerStatus } = await Promise.resolve().then(() => require("./background-DdUVvDwi.cjs"));
|
|
323
|
+
const { readCredentials } = await Promise.resolve().then(() => require("./credentials-DDaKqtJn.cjs")).then((n) => n.credentials_exports);
|
|
324
|
+
const { formatPermissionRows } = await Promise.resolve().then(() => require("./run-QqLDhthl.cjs"));
|
|
325
|
+
const worker = await getWorkerStatus();
|
|
326
|
+
console.log(`Background connection: ${worker.state}${worker.running ? ` (PID ${worker.pid})` : ""}`);
|
|
327
|
+
console.log(`Logs: ${getWorkerLogPath()}`);
|
|
328
|
+
const credentials = await readCredentials();
|
|
329
|
+
if (!credentials) {
|
|
330
|
+
console.log("Not paired. Run `kubb studio login`.");
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
console.log(`Paired with ${credentials.studioUrl} as ${(0, node_util.styleText)("cyan", credentials.agentSlug || credentials.agentId)}`);
|
|
334
|
+
if (credentials.studioUrl !== options.studioUrl) console.log((0, node_util.styleText)("yellow", `Connecting to ${options.studioUrl} needs pairing again.`));
|
|
335
|
+
const remembered = credentials.projects?.[node_process.default.cwd()];
|
|
336
|
+
if (!remembered) {
|
|
337
|
+
console.log((0, node_util.styleText)("dim", "No saved permissions for this project. Run `kubb studio` to connect and choose."));
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
console.log((0, node_util.styleText)("dim", "Saved permissions"));
|
|
341
|
+
for (const row of formatPermissionRows({
|
|
342
|
+
allowRead: remembered.allowRead === true,
|
|
343
|
+
allowWrite: remembered.allowWrite === true,
|
|
344
|
+
allowConfigEdit: remembered.allowConfigEdit === true,
|
|
345
|
+
allowExec: remembered.allowExec === true
|
|
346
|
+
})) console.log(row);
|
|
406
347
|
}
|
|
407
348
|
});
|
|
408
349
|
//#endregion
|
|
409
350
|
//#region src/commands/studio/index.ts
|
|
410
|
-
const command$
|
|
351
|
+
const command$5 = (0, gunshi.define)({
|
|
352
|
+
...command$11,
|
|
411
353
|
name: "studio",
|
|
412
354
|
description: "Connect this project to Kubb Studio, or manage its pairing and snapshots.",
|
|
413
355
|
examples: [
|
|
@@ -418,20 +360,14 @@ const command$2 = (0, gunshi.define)({
|
|
|
418
360
|
"kubb studio logout",
|
|
419
361
|
"kubb studio snapshot"
|
|
420
362
|
].join("\n"),
|
|
421
|
-
toKebab: true,
|
|
422
|
-
args: command$8.args,
|
|
423
|
-
async run(ctx) {
|
|
424
|
-
const { connectRunner } = await Promise.resolve().then(() => require("./commands-BuY0nrlU.cjs"));
|
|
425
|
-
await connectRunner(ctx);
|
|
426
|
-
},
|
|
427
363
|
subCommands: {
|
|
428
|
-
start: command$
|
|
364
|
+
start: command$7,
|
|
429
365
|
stop: stopCommand,
|
|
430
|
-
connect: command$
|
|
431
|
-
login: command$
|
|
432
|
-
logout: command$
|
|
433
|
-
status: command$
|
|
434
|
-
snapshot: command$
|
|
366
|
+
connect: command$11,
|
|
367
|
+
login: command$10,
|
|
368
|
+
logout: command$9,
|
|
369
|
+
status: command$6,
|
|
370
|
+
snapshot: command$8
|
|
435
371
|
}
|
|
436
372
|
});
|
|
437
373
|
/**
|
|
@@ -448,41 +384,9 @@ function routeStudioFlags(args) {
|
|
|
448
384
|
];
|
|
449
385
|
}
|
|
450
386
|
//#endregion
|
|
451
|
-
//#region src/commands/update.ts
|
|
452
|
-
const command$1 = (0, gunshi.define)({
|
|
453
|
-
name: "update",
|
|
454
|
-
description: "Update installed extensions to the version the Kubb registry pins. Pass ids to update only those, or --check to list the updates without installing.",
|
|
455
|
-
examples: [
|
|
456
|
-
"kubb update",
|
|
457
|
-
"kubb update --check",
|
|
458
|
-
"kubb update plugin-zod plugin-ts --yes"
|
|
459
|
-
].join("\n"),
|
|
460
|
-
args: {
|
|
461
|
-
ids: {
|
|
462
|
-
type: "positional",
|
|
463
|
-
description: "Registry ids to update, all installed extensions when omitted",
|
|
464
|
-
multiple: true
|
|
465
|
-
},
|
|
466
|
-
check: {
|
|
467
|
-
type: "boolean",
|
|
468
|
-
description: "List the available updates without installing them",
|
|
469
|
-
default: false
|
|
470
|
-
},
|
|
471
|
-
...yesArg
|
|
472
|
-
},
|
|
473
|
-
async run({ values }) {
|
|
474
|
-
const { run } = await Promise.resolve().then(() => require("./run-Bhs7mJ1f.cjs"));
|
|
475
|
-
await run({
|
|
476
|
-
ids: values.ids ?? [],
|
|
477
|
-
check: values.check,
|
|
478
|
-
yes: values.yes
|
|
479
|
-
});
|
|
480
|
-
}
|
|
481
|
-
});
|
|
482
|
-
//#endregion
|
|
483
387
|
//#region src/commands/validate.ts
|
|
484
388
|
/** The runner is imported when the command runs, so listing `kubb --help` never loads `@kubb/adapter-oas`. */
|
|
485
|
-
const command = (0, gunshi.define)({
|
|
389
|
+
const command$4 = (0, gunshi.define)({
|
|
486
390
|
name: "validate",
|
|
487
391
|
description: "Parse and validate an OpenAPI/Swagger file for structural correctness. Reports schema errors, missing required fields, and malformed references. Use this before running generate to catch spec issues early.",
|
|
488
392
|
examples: ["kubb validate ./openapi.yaml", "kubb validate https://petstore3.swagger.io/api/v3/openapi.json"].join("\n"),
|
|
@@ -492,7 +396,7 @@ const command = (0, gunshi.define)({
|
|
|
492
396
|
required: true
|
|
493
397
|
} },
|
|
494
398
|
async run({ values }) {
|
|
495
|
-
const { run } = await Promise.resolve().then(() => require("./run-
|
|
399
|
+
const { run } = await Promise.resolve().then(() => require("./run-C0Tfrddq.cjs"));
|
|
496
400
|
await run({ input: values.input });
|
|
497
401
|
}
|
|
498
402
|
});
|
|
@@ -527,6 +431,596 @@ function resolveDeprecatedFlags(args) {
|
|
|
527
431
|
});
|
|
528
432
|
}
|
|
529
433
|
//#endregion
|
|
434
|
+
//#region ../../internals/shared/src/init.ts
|
|
435
|
+
/** The `kubb.config.ts` `kubb init` writes before `kubb add` puts each plugin in. */
|
|
436
|
+
function generateConfigFile({ inputPath, outputPath }) {
|
|
437
|
+
return `import { defineConfig } from 'kubb/config'
|
|
438
|
+
|
|
439
|
+
export default defineConfig({
|
|
440
|
+
input: '${inputPath}',
|
|
441
|
+
output: {
|
|
442
|
+
path: '${outputPath}',
|
|
443
|
+
clean: true,
|
|
444
|
+
},
|
|
445
|
+
plugins: [],
|
|
446
|
+
})
|
|
447
|
+
`;
|
|
448
|
+
}
|
|
449
|
+
//#endregion
|
|
450
|
+
//#region src/runners/init/utils.ts
|
|
451
|
+
/** Metadata for each supported package manager, keyed by its short name. */
|
|
452
|
+
const packageManagers = {
|
|
453
|
+
pnpm: {
|
|
454
|
+
name: "pnpm",
|
|
455
|
+
lockFiles: ["pnpm-lock.yaml"],
|
|
456
|
+
initCommand: ["init"],
|
|
457
|
+
installCommand: ["add", "-D"]
|
|
458
|
+
},
|
|
459
|
+
yarn: {
|
|
460
|
+
name: "yarn",
|
|
461
|
+
lockFiles: ["yarn.lock"],
|
|
462
|
+
initCommand: ["init", "-y"],
|
|
463
|
+
installCommand: ["add", "-D"]
|
|
464
|
+
},
|
|
465
|
+
bun: {
|
|
466
|
+
name: "bun",
|
|
467
|
+
lockFiles: ["bun.lock", "bun.lockb"],
|
|
468
|
+
initCommand: ["init", "-y"],
|
|
469
|
+
installCommand: ["add", "-d"]
|
|
470
|
+
},
|
|
471
|
+
npm: {
|
|
472
|
+
name: "npm",
|
|
473
|
+
lockFiles: ["package-lock.json"],
|
|
474
|
+
initCommand: ["init", "-y"],
|
|
475
|
+
installCommand: ["install", "--save-dev"]
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
/** Detects the package manager for `cwd`: the `packageManager` field in `package.json`, then a lock file, then `npm`. */
|
|
479
|
+
function detectPackageManager(cwd = node_process.default.cwd()) {
|
|
480
|
+
const packageJsonPath = node_path.default.join(cwd, "package.json");
|
|
481
|
+
if (node_fs.default.existsSync(packageJsonPath)) try {
|
|
482
|
+
const pmField = JSON.parse(node_fs.default.readFileSync(packageJsonPath, "utf-8")).packageManager;
|
|
483
|
+
if (typeof pmField === "string") {
|
|
484
|
+
const name = pmField.split("@")[0];
|
|
485
|
+
if (name && name in packageManagers) return packageManagers[name];
|
|
486
|
+
}
|
|
487
|
+
} catch {}
|
|
488
|
+
for (const pm of Object.values(packageManagers)) if (pm.lockFiles.some((lockFile) => node_fs.default.existsSync(node_path.default.join(cwd, lockFile)))) return pm;
|
|
489
|
+
return packageManagers.npm;
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Initializes a new `package.json` at `cwd` using the detected package manager.
|
|
493
|
+
*/
|
|
494
|
+
async function initPackageJson(cwd, packageManager) {
|
|
495
|
+
await (0, tinyexec.x)(packageManager.name, [...packageManager.initCommand], {
|
|
496
|
+
nodeOptions: {
|
|
497
|
+
cwd,
|
|
498
|
+
stdio: "inherit"
|
|
499
|
+
},
|
|
500
|
+
throwOnError: true
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Installs the given packages at `cwd` using the detected package manager.
|
|
505
|
+
*/
|
|
506
|
+
async function installPackages(packages, packageManager, cwd = node_process.default.cwd()) {
|
|
507
|
+
await (0, tinyexec.x)(packageManager.name, [...packageManager.installCommand, ...packages], {
|
|
508
|
+
nodeOptions: {
|
|
509
|
+
cwd,
|
|
510
|
+
stdio: "inherit"
|
|
511
|
+
},
|
|
512
|
+
throwOnError: true
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* What the installed manifests of the `selected` plugins say is missing from the selection: a
|
|
517
|
+
* `dependencies` entry, or a `client` plugin next to a `consumer`. Empty when nothing is missing.
|
|
518
|
+
* `optionalDependencies` are skipped, since `kubb init` writes the default options.
|
|
519
|
+
*/
|
|
520
|
+
function missingPluginDependencies({ selected, manifests }) {
|
|
521
|
+
const hasClient = manifests.some((manifest) => manifest.role === "client");
|
|
522
|
+
return manifests.flatMap((manifest) => [...(manifest.dependencies ?? []).filter((name) => !selected.includes(name)).map((name) => `${manifest.name} needs ${name}.`), ...manifest.role === "consumer" && !hasClient ? [`${manifest.name} needs a client plugin, such as plugin-axios or plugin-fetch.`] : []]);
|
|
523
|
+
}
|
|
524
|
+
//#endregion
|
|
525
|
+
//#region src/runners/add/run.ts
|
|
526
|
+
/** The import and the `defineConfig` property to merge into `kubb.config.ts` by hand. */
|
|
527
|
+
function toSnippet({ artifact, manifest }) {
|
|
528
|
+
const call = `${manifest.export}()`;
|
|
529
|
+
const property = {
|
|
530
|
+
plugin: `plugins: [..., ${call}],`,
|
|
531
|
+
adapter: `adapter: ${call},`,
|
|
532
|
+
parser: `parsers: [..., ${call}],`
|
|
533
|
+
};
|
|
534
|
+
return [
|
|
535
|
+
`import { ${manifest.export} } from '${artifact.package}'`,
|
|
536
|
+
"",
|
|
537
|
+
property[manifest.kind]
|
|
538
|
+
].join("\n");
|
|
539
|
+
}
|
|
540
|
+
/** Adds the plugin call and its import to the config file. Returns why it could not, or `undefined`. */
|
|
541
|
+
async function addToConfig({ detail, configFile }) {
|
|
542
|
+
const { artifact, manifest } = detail;
|
|
543
|
+
try {
|
|
544
|
+
const { writeConfigEdits } = await import("@kubb/studio");
|
|
545
|
+
const { outcomes } = await writeConfigEdits({
|
|
546
|
+
filePath: configFile,
|
|
547
|
+
edits: [{
|
|
548
|
+
operation: "add-plugin",
|
|
549
|
+
plugin: artifact.package
|
|
550
|
+
}],
|
|
551
|
+
extensions: /* @__PURE__ */ new Map([[artifact.package, {
|
|
552
|
+
package: artifact.package,
|
|
553
|
+
version: artifact.version,
|
|
554
|
+
manifest
|
|
555
|
+
}]])
|
|
556
|
+
});
|
|
557
|
+
return outcomes[0]?.applied ? void 0 : outcomes[0]?.reason ?? "the config file was not changed";
|
|
558
|
+
} catch (error) {
|
|
559
|
+
return require_Telemetry.getErrorMessage(error);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
async function selectExtension(registry) {
|
|
563
|
+
const options = (await require_registry.fetchRegistryIndex({ registry })).toSorted((a, b) => a.id.localeCompare(b.id)).map((entry) => ({
|
|
564
|
+
value: entry.id,
|
|
565
|
+
label: entry.manifest.displayName,
|
|
566
|
+
hint: `${entry.id} · ${entry.kind} ${entry.artifact.version} · ${entry.manifest.description}`
|
|
567
|
+
}));
|
|
568
|
+
if (!options.length) throw new Error(`The registry at ${registry} lists no extensions.`);
|
|
569
|
+
const id = await _clack_prompts.autocomplete({
|
|
570
|
+
message: "Select an extension to add:",
|
|
571
|
+
options,
|
|
572
|
+
filter: (search, option) => `${option.label} ${option.hint}`.toLowerCase().includes(search.toLowerCase())
|
|
573
|
+
});
|
|
574
|
+
return _clack_prompts.isCancel(id) ? void 0 : id;
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* Installs an extension from the Kubb registry at its reviewed version and, for a plugin, adds it to
|
|
578
|
+
* `kubb.config.ts`. Without an id, asks which one. Refuses when the running Kubb or Node.js version
|
|
579
|
+
* is outside its compatibility.
|
|
580
|
+
*/
|
|
581
|
+
async function run$4({ id: input, configPath, yes, install }) {
|
|
582
|
+
const cwd = node_process.default.cwd();
|
|
583
|
+
require_output.logIntro({ title: (0, node_util.styleText)("bgCyan", (0, node_util.styleText)("black", " Kubb Add ")) });
|
|
584
|
+
try {
|
|
585
|
+
const registry = require_registry.registryUrl();
|
|
586
|
+
if (!input && yes) throw new Error("Pass a registry id, such as plugin-zod, when using --yes.");
|
|
587
|
+
const id = input ? require_registry.toRegistryId(input) : await selectExtension(registry);
|
|
588
|
+
if (!id) {
|
|
589
|
+
_clack_prompts.cancel("Operation canceled.");
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
const detail = await require_registry.fetchRegistryDetail({
|
|
593
|
+
id,
|
|
594
|
+
registry
|
|
595
|
+
});
|
|
596
|
+
const { artifact, manifest } = detail;
|
|
597
|
+
const problem = require_registry.incompatibility(manifest);
|
|
598
|
+
if (problem) throw new Error(problem);
|
|
599
|
+
const spec = require_registry.installSpec(artifact);
|
|
600
|
+
const configFile = manifest.kind === "plugin" ? configPath ? node_path.default.resolve(configPath) : require_output.findConfigFile(cwd) : void 0;
|
|
601
|
+
if (manifest.kind === "plugin" && !configFile) throw new Error("No kubb.config.ts found. Run `kubb init` first, or pass --config.");
|
|
602
|
+
require_output.logInfo(`${(0, node_util.styleText)("cyan", manifest.displayName)} (${manifest.kind}): ${manifest.description}`);
|
|
603
|
+
require_output.logBlock([install ? `Install ${(0, node_util.styleText)("cyan", spec)} as a dev dependency` : `Skip installing ${spec}`, configFile ? `Add ${(0, node_util.styleText)("cyan", `${manifest.export}()`)} to ${node_path.default.relative(cwd, configFile) || configFile}` : `Print the ${manifest.kind} snippet to add`]);
|
|
604
|
+
const confirmed = yes || await _clack_prompts.confirm({
|
|
605
|
+
message: "Continue?",
|
|
606
|
+
initialValue: true
|
|
607
|
+
});
|
|
608
|
+
if (_clack_prompts.isCancel(confirmed) || !confirmed) {
|
|
609
|
+
_clack_prompts.cancel("Operation canceled.");
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
if (install) {
|
|
613
|
+
const packageManager = detectPackageManager(cwd);
|
|
614
|
+
require_output.logStep(`Installing ${spec} with ${packageManager.name}`);
|
|
615
|
+
await installPackages([spec], packageManager, cwd);
|
|
616
|
+
}
|
|
617
|
+
const reason = configFile ? await addToConfig({
|
|
618
|
+
detail,
|
|
619
|
+
configFile
|
|
620
|
+
}) : `add the ${manifest.kind} to your config`;
|
|
621
|
+
if (!reason) {
|
|
622
|
+
require_output.logOutro((0, node_util.styleText)("green", install ? `Added ${spec}` : `Added ${manifest.export}() to the config. Install ${spec} to use it.`));
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
if (configFile) require_output.logWarn(`Could not edit ${configFile}: ${reason}`);
|
|
626
|
+
require_output.logBlock([
|
|
627
|
+
"Add the import to your Kubb config and merge the property into its defineConfig call:",
|
|
628
|
+
"",
|
|
629
|
+
toSnippet(detail)
|
|
630
|
+
]);
|
|
631
|
+
require_output.logOutro((0, node_util.styleText)("green", install ? `Installed ${spec}. Add it with the snippet above.` : `Install ${spec} and add the snippet above.`));
|
|
632
|
+
} catch (error) {
|
|
633
|
+
require_output.logError(require_Telemetry.getErrorMessage(error));
|
|
634
|
+
node_process.default.exitCode = 1;
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
require_rolldown_runtime.__name(run$4, "run");
|
|
638
|
+
const command$3 = (0, gunshi.define)({
|
|
639
|
+
name: "add",
|
|
640
|
+
description: "Install a plugin, adapter, or parser from the Kubb registry at its reviewed version. Without an id, pick one from the registry. A plugin is added to kubb.config.ts, an adapter or parser prints the code to add. Reads KUBB_REGISTRY to use another registry.",
|
|
641
|
+
examples: [
|
|
642
|
+
"kubb add",
|
|
643
|
+
"kubb add plugin-zod",
|
|
644
|
+
"kubb add kubb-labs/plugin-react-query",
|
|
645
|
+
"kubb add acme/plugin-x --yes",
|
|
646
|
+
"kubb add plugin-zod --no-install"
|
|
647
|
+
].join("\n"),
|
|
648
|
+
toKebab: true,
|
|
649
|
+
args: {
|
|
650
|
+
id: {
|
|
651
|
+
type: "positional",
|
|
652
|
+
description: "Registry id: owner/slug, or a slug for an official extension. Asked for when omitted",
|
|
653
|
+
required: false
|
|
654
|
+
},
|
|
655
|
+
...configArg,
|
|
656
|
+
...yesArg,
|
|
657
|
+
install: {
|
|
658
|
+
type: "boolean",
|
|
659
|
+
description: "Install the package. Pass --no-install to only edit the config",
|
|
660
|
+
negatable: true,
|
|
661
|
+
default: true
|
|
662
|
+
}
|
|
663
|
+
},
|
|
664
|
+
run: ({ values }) => run$4({
|
|
665
|
+
id: values.id,
|
|
666
|
+
configPath: values.config,
|
|
667
|
+
yes: values.yes,
|
|
668
|
+
install: values.install
|
|
669
|
+
})
|
|
670
|
+
});
|
|
671
|
+
//#endregion
|
|
672
|
+
//#region src/runners/init/run.ts
|
|
673
|
+
function cancelAndExit(message = "Operation canceled.") {
|
|
674
|
+
_clack_prompts.cancel(message);
|
|
675
|
+
node_process.default.exit(0);
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* Runs the interactive Kubb scaffolding wizard.
|
|
679
|
+
* Detects the package manager, prompts for input/output paths and plugins, installs packages, and writes `kubb.config.ts`.
|
|
680
|
+
* Pass `yes: true` to skip all prompts and use defaults.
|
|
681
|
+
*/
|
|
682
|
+
async function run$3({ yes, input: inputFlag, output: outputFlag, plugins: pluginsFlag, dryRun }) {
|
|
683
|
+
const cwd = node_process.default.cwd();
|
|
684
|
+
require_output.logIntro({ title: (0, node_util.styleText)("bgCyan", (0, node_util.styleText)("black", " Kubb Init ")) });
|
|
685
|
+
/**
|
|
686
|
+
* Returns `flag` when provided, the `defaultValue` when `yes` is set,
|
|
687
|
+
* or calls `prompt()` for interactive input. Exits on cancellation.
|
|
688
|
+
*/
|
|
689
|
+
async function resolveOrPrompt(flag, defaultValue, logLabel, prompt) {
|
|
690
|
+
if (flag !== void 0) {
|
|
691
|
+
require_output.logInfo(`${logLabel}: ${(0, node_util.styleText)("cyan", String(flag))}`);
|
|
692
|
+
return flag;
|
|
693
|
+
}
|
|
694
|
+
if (yes) {
|
|
695
|
+
require_output.logInfo(`${logLabel}: ${(0, node_util.styleText)("cyan", String(defaultValue))}`);
|
|
696
|
+
return defaultValue;
|
|
697
|
+
}
|
|
698
|
+
const result = await prompt();
|
|
699
|
+
if (_clack_prompts.isCancel(result)) cancelAndExit();
|
|
700
|
+
return result;
|
|
701
|
+
}
|
|
702
|
+
try {
|
|
703
|
+
const plugins = (await require_registry.fetchRegistryIndex({ registry: require_registry.registryUrl() })).filter((entry) => entry.kind === "plugin" && !require_registry.incompatibility(entry.manifest));
|
|
704
|
+
const byId = new Map(plugins.map((entry) => [entry.id, entry]));
|
|
705
|
+
if (!node_fs.default.existsSync(node_path.default.join(cwd, "package.json"))) {
|
|
706
|
+
if (!yes) {
|
|
707
|
+
const shouldInit = await _clack_prompts.confirm({
|
|
708
|
+
message: "No package.json found. Would you like to create one?",
|
|
709
|
+
initialValue: true
|
|
710
|
+
});
|
|
711
|
+
if (_clack_prompts.isCancel(shouldInit) || !shouldInit) cancelAndExit();
|
|
712
|
+
}
|
|
713
|
+
const packageManager = detectPackageManager(cwd);
|
|
714
|
+
const spinner = require_output.createSpinner();
|
|
715
|
+
spinner.start(`Initializing package.json with ${packageManager.name}`);
|
|
716
|
+
await initPackageJson(cwd, packageManager);
|
|
717
|
+
spinner.stop(`Created package.json with ${packageManager.name}`);
|
|
718
|
+
}
|
|
719
|
+
const packageManager = detectPackageManager(cwd);
|
|
720
|
+
require_output.logInfo(`Detected package manager: ${(0, node_util.styleText)("cyan", packageManager.name)}`);
|
|
721
|
+
const inputPath = await resolveOrPrompt(inputFlag, require_output.initDefaults.inputPath, "Using input path", () => _clack_prompts.text({
|
|
722
|
+
message: "Where is your OpenAPI specification located?",
|
|
723
|
+
placeholder: require_output.initDefaults.inputPath,
|
|
724
|
+
defaultValue: require_output.initDefaults.inputPath,
|
|
725
|
+
validate: (value) => {
|
|
726
|
+
if (!value) return "Input path is required";
|
|
727
|
+
}
|
|
728
|
+
}));
|
|
729
|
+
const outputPath = await resolveOrPrompt(outputFlag, require_output.initDefaults.outputPath, "Using output path", () => _clack_prompts.text({
|
|
730
|
+
message: "Where should the generated files be output?",
|
|
731
|
+
placeholder: require_output.initDefaults.outputPath,
|
|
732
|
+
defaultValue: require_output.initDefaults.outputPath,
|
|
733
|
+
validate: (value) => {
|
|
734
|
+
if (!value) return "Output path is required";
|
|
735
|
+
}
|
|
736
|
+
}));
|
|
737
|
+
const defaultPlugins = require_output.initDefaults.plugins.flatMap((slug) => byId.get(require_registry.toRegistryId(slug)) ?? []);
|
|
738
|
+
const pluginLabel = (entries) => (0, node_util.styleText)("cyan", entries.map((entry) => entry.manifest.displayName).join(", "));
|
|
739
|
+
const selectedPlugins = await (async () => {
|
|
740
|
+
if (pluginsFlag) {
|
|
741
|
+
const ids = pluginsFlag.split(",").map((id) => id.trim()).filter(Boolean);
|
|
742
|
+
const unknown = ids.filter((id) => !byId.has(require_registry.toRegistryId(id)));
|
|
743
|
+
if (unknown.length) throw new Error(`Not in the Kubb registry: ${unknown.join(", ")}. Browse the plugins at https://kubb.dev/extensions.`);
|
|
744
|
+
const entries = ids.map((id) => byId.get(require_registry.toRegistryId(id)));
|
|
745
|
+
require_output.logInfo(`Using plugins: ${pluginLabel(entries)}`);
|
|
746
|
+
return entries;
|
|
747
|
+
}
|
|
748
|
+
if (yes) {
|
|
749
|
+
require_output.logInfo(`Using plugins: ${pluginLabel(defaultPlugins)}`);
|
|
750
|
+
return defaultPlugins;
|
|
751
|
+
}
|
|
752
|
+
const values = await _clack_prompts.multiselect({
|
|
753
|
+
message: "Select plugins to use:",
|
|
754
|
+
options: plugins.map(({ id, manifest }) => ({
|
|
755
|
+
value: id,
|
|
756
|
+
label: manifest.displayName,
|
|
757
|
+
hint: manifest.category
|
|
758
|
+
})),
|
|
759
|
+
initialValues: defaultPlugins.map((entry) => entry.id),
|
|
760
|
+
required: true
|
|
761
|
+
});
|
|
762
|
+
if (_clack_prompts.isCancel(values)) cancelAndExit();
|
|
763
|
+
return plugins.filter((entry) => values.includes(entry.id));
|
|
764
|
+
})();
|
|
765
|
+
const missing = missingPluginDependencies({
|
|
766
|
+
selected: selectedPlugins.map((entry) => entry.manifest.name),
|
|
767
|
+
manifests: selectedPlugins.map((entry) => entry.manifest)
|
|
768
|
+
});
|
|
769
|
+
if (missing.length) throw new Error(`${missing.join("\n")}\nAdd the missing plugins and run kubb init again.`);
|
|
770
|
+
const packagesToInstall = [`${require_output.KUBB_PACKAGE_NAME}@${require_Telemetry.version}`, ...selectedPlugins.map((entry) => require_registry.installSpec(entry.artifact))];
|
|
771
|
+
const spinner = require_output.createSpinner();
|
|
772
|
+
spinner.start(`Installing ${packagesToInstall.length} packages with ${packageManager.name}`);
|
|
773
|
+
try {
|
|
774
|
+
await dryRun.run(() => installPackages(packagesToInstall, packageManager, cwd), { message: `install ${packagesToInstall.length} packages with ${packageManager.name}` });
|
|
775
|
+
spinner.stop(`Installed ${packagesToInstall.length} packages`);
|
|
776
|
+
} catch (error) {
|
|
777
|
+
spinner.stop("Installation failed");
|
|
778
|
+
throw error;
|
|
779
|
+
}
|
|
780
|
+
const configSpinner = require_output.createSpinner();
|
|
781
|
+
configSpinner.start(`Creating ${require_output.KUBB_CONFIG_FILENAME}`);
|
|
782
|
+
const configContent = generateConfigFile({
|
|
783
|
+
inputPath,
|
|
784
|
+
outputPath
|
|
785
|
+
});
|
|
786
|
+
const configPath = node_path.default.join(cwd, require_output.KUBB_CONFIG_FILENAME);
|
|
787
|
+
if (node_fs.default.existsSync(configPath)) {
|
|
788
|
+
configSpinner.stop(`${require_output.KUBB_CONFIG_FILENAME} already exists`);
|
|
789
|
+
if (!yes) {
|
|
790
|
+
const shouldOverwrite = await _clack_prompts.confirm({
|
|
791
|
+
message: `${require_output.KUBB_CONFIG_FILENAME} already exists. Overwrite?`,
|
|
792
|
+
initialValue: false
|
|
793
|
+
});
|
|
794
|
+
if (_clack_prompts.isCancel(shouldOverwrite) || !shouldOverwrite) cancelAndExit("Keeping existing configuration. Packages have been installed.");
|
|
795
|
+
}
|
|
796
|
+
configSpinner.start(`Overwriting ${require_output.KUBB_CONFIG_FILENAME}`);
|
|
797
|
+
}
|
|
798
|
+
await dryRun.run(() => node_fs.default.promises.writeFile(configPath, configContent, "utf-8"), { message: `write ${require_output.KUBB_CONFIG_FILENAME}` });
|
|
799
|
+
for (const entry of selectedPlugins) {
|
|
800
|
+
const reason = await dryRun.run(() => addToConfig({
|
|
801
|
+
detail: entry,
|
|
802
|
+
configFile: configPath
|
|
803
|
+
}), {
|
|
804
|
+
message: `add ${entry.manifest.export}() to ${require_output.KUBB_CONFIG_FILENAME}`,
|
|
805
|
+
resolve: () => void 0
|
|
806
|
+
});
|
|
807
|
+
if (reason) throw new Error(`Could not add ${entry.manifest.export}() to ${require_output.KUBB_CONFIG_FILENAME}: ${reason}`);
|
|
808
|
+
}
|
|
809
|
+
configSpinner.stop(`Created ${require_output.KUBB_CONFIG_FILENAME}`);
|
|
810
|
+
require_output.logOutro((0, node_util.styleText)("green", "✓ All set!") + "\n\n" + (0, node_util.styleText)("dim", "Next steps:") + "\n" + (0, node_util.styleText)("cyan", ` 1. Make sure your OpenAPI spec is at: ${inputPath}`) + "\n" + (0, node_util.styleText)("cyan", " 2. Generate code with: npx kubb generate") + "\n" + (0, node_util.styleText)("cyan", ` 3. Find generated files in: ${outputPath}`) + "\n\n" + (0, node_util.styleText)("dim", `Using ${packageManager.name} • Kubb v${require_Telemetry.version}`));
|
|
811
|
+
} catch (error) {
|
|
812
|
+
require_output.logError((0, node_util.styleText)("red", "An error occurred during initialization"));
|
|
813
|
+
if (error instanceof Error) require_output.logError(error.message);
|
|
814
|
+
node_process.default.exit(1);
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
require_rolldown_runtime.__name(run$3, "run");
|
|
818
|
+
const command$2 = (0, gunshi.defineWithTypes)()({
|
|
819
|
+
name: "init",
|
|
820
|
+
description: "Scaffold a kubb.config.ts and install plugins for code generation from an OpenAPI spec. Run without flags for interactive setup, or pass --input, --output, and --plugins to skip the prompts.",
|
|
821
|
+
examples: [
|
|
822
|
+
"kubb init",
|
|
823
|
+
"kubb init --yes",
|
|
824
|
+
"kubb init --input ./openapi.yaml --output ./src/gen --plugins plugin-ts,plugin-zod",
|
|
825
|
+
"kubb init --plugins plugin-ts,plugin-axios,plugin-react-query",
|
|
826
|
+
"kubb init --yes --dry-run"
|
|
827
|
+
].join("\n"),
|
|
828
|
+
toKebab: true,
|
|
829
|
+
args: {
|
|
830
|
+
yes: {
|
|
831
|
+
type: "boolean",
|
|
832
|
+
description: "Skip prompts and use default options",
|
|
833
|
+
short: "y",
|
|
834
|
+
default: false
|
|
835
|
+
},
|
|
836
|
+
input: {
|
|
837
|
+
type: "string",
|
|
838
|
+
description: "Path to the OpenAPI specification",
|
|
839
|
+
short: "i",
|
|
840
|
+
metavar: "path"
|
|
841
|
+
},
|
|
842
|
+
output: {
|
|
843
|
+
type: "string",
|
|
844
|
+
description: "Output directory for generated files",
|
|
845
|
+
short: "o",
|
|
846
|
+
metavar: "path"
|
|
847
|
+
},
|
|
848
|
+
plugins: {
|
|
849
|
+
type: "string",
|
|
850
|
+
description: "Comma-separated Kubb registry ids of the plugins to add, the same ids `kubb add` takes (plugin-ts, plugin-zod, acme/plugin-x)",
|
|
851
|
+
metavar: "plugin-ts,plugin-zod,..."
|
|
852
|
+
}
|
|
853
|
+
},
|
|
854
|
+
run: ({ values, extensions }) => run$3({
|
|
855
|
+
yes: values.yes,
|
|
856
|
+
input: values.input,
|
|
857
|
+
output: values.output,
|
|
858
|
+
plugins: values.plugins,
|
|
859
|
+
dryRun: extensions[_gunshi_plugin_dryrun.pluginId]
|
|
860
|
+
})
|
|
861
|
+
});
|
|
862
|
+
//#endregion
|
|
863
|
+
//#region src/runners/list/run.ts
|
|
864
|
+
/**
|
|
865
|
+
* The installed packages that ship a `kubb-extension.json` or have a registry entry, with the
|
|
866
|
+
* version the registry pins.
|
|
867
|
+
*/
|
|
868
|
+
async function listExtensions({ cwd, registry }) {
|
|
869
|
+
const [installed, entries] = await Promise.all([(0, _kubb_core.readInstalledPackages)({ root: cwd }), require_registry.fetchRegistryIndex({ registry }).catch((error) => {
|
|
870
|
+
require_output.logWarn(`Showing installed extensions only: ${require_Telemetry.getErrorMessage(error)}`);
|
|
871
|
+
return [];
|
|
872
|
+
})]);
|
|
873
|
+
const byPackage = new Map(entries.map((entry) => [entry.artifact.package, entry]));
|
|
874
|
+
return installed.flatMap(({ package: name, version, manifest }) => {
|
|
875
|
+
const entry = byPackage.get(name);
|
|
876
|
+
if (!entry && !manifest) return [];
|
|
877
|
+
const latest = entry?.artifact.version;
|
|
878
|
+
return [{
|
|
879
|
+
id: entry?.id,
|
|
880
|
+
package: name,
|
|
881
|
+
installed: version,
|
|
882
|
+
registry: latest,
|
|
883
|
+
update: !!latest && require_registry.isOutdated({
|
|
884
|
+
installed: version,
|
|
885
|
+
latest
|
|
886
|
+
})
|
|
887
|
+
}];
|
|
888
|
+
});
|
|
889
|
+
}
|
|
890
|
+
/** Prints the installed extensions as a table. */
|
|
891
|
+
async function run$2() {
|
|
892
|
+
try {
|
|
893
|
+
const rows = await listExtensions({
|
|
894
|
+
cwd: node_process.default.cwd(),
|
|
895
|
+
registry: require_registry.registryUrl()
|
|
896
|
+
});
|
|
897
|
+
if (!rows.length) {
|
|
898
|
+
require_output.logOutro("No installed extensions found.");
|
|
899
|
+
return;
|
|
900
|
+
}
|
|
901
|
+
const header = [
|
|
902
|
+
"ID",
|
|
903
|
+
"PACKAGE",
|
|
904
|
+
"INSTALLED",
|
|
905
|
+
"REGISTRY",
|
|
906
|
+
"UPDATE"
|
|
907
|
+
];
|
|
908
|
+
const cells = rows.map((row) => [
|
|
909
|
+
row.id ?? "-",
|
|
910
|
+
row.package,
|
|
911
|
+
row.installed ?? "-",
|
|
912
|
+
row.registry ?? "-",
|
|
913
|
+
row.update ? "yes" : "no"
|
|
914
|
+
]);
|
|
915
|
+
const widths = header.map((title, index) => Math.max(title.length, ...cells.map((cell) => cell[index].length)));
|
|
916
|
+
const line = (cell) => cell.map((value, index) => value.padEnd(widths[index])).join(" ").trimEnd();
|
|
917
|
+
require_output.logBlock([(0, node_util.styleText)("dim", line(header)), ...cells.map(line)]);
|
|
918
|
+
} catch (error) {
|
|
919
|
+
require_output.logError(require_Telemetry.getErrorMessage(error));
|
|
920
|
+
node_process.default.exitCode = 1;
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
require_rolldown_runtime.__name(run$2, "run");
|
|
924
|
+
const command$1 = (0, gunshi.define)({
|
|
925
|
+
name: "list",
|
|
926
|
+
description: "List the installed Kubb extensions: their registry id, package, installed version, the version the Kubb registry pins, and whether an update exists.",
|
|
927
|
+
examples: "kubb list",
|
|
928
|
+
run: () => run$2()
|
|
929
|
+
});
|
|
930
|
+
//#endregion
|
|
931
|
+
//#region src/runners/update/run.ts
|
|
932
|
+
/**
|
|
933
|
+
* Moves installed extensions to the version the registry pins. Lists the proposals, asks, then
|
|
934
|
+
* installs them. With `check`, only lists them.
|
|
935
|
+
*/
|
|
936
|
+
async function run$1({ ids, check, yes }) {
|
|
937
|
+
const cwd = node_process.default.cwd();
|
|
938
|
+
require_output.logIntro({ title: (0, node_util.styleText)("bgCyan", (0, node_util.styleText)("black", " Kubb Update ")) });
|
|
939
|
+
try {
|
|
940
|
+
const wanted = new Set(ids.map(require_registry.toRegistryId));
|
|
941
|
+
const [entries, installed] = await Promise.all([require_registry.fetchRegistryIndex({ registry: require_registry.registryUrl() }), (0, _kubb_core.readInstalledPackages)({ root: cwd })]);
|
|
942
|
+
const versions = new Map(installed.map((item) => [item.package, item.version]));
|
|
943
|
+
const tracked = entries.filter((entry) => versions.has(entry.artifact.package) && (!wanted.size || wanted.has(entry.id)));
|
|
944
|
+
for (const id of wanted) if (!tracked.some((entry) => entry.id === id)) require_output.logWarn(`${id} is not installed, or not in the registry.`);
|
|
945
|
+
const proposals = tracked.filter((entry) => {
|
|
946
|
+
if (!require_registry.isOutdated({
|
|
947
|
+
installed: versions.get(entry.artifact.package),
|
|
948
|
+
latest: entry.artifact.version
|
|
949
|
+
})) return false;
|
|
950
|
+
const problem = require_registry.incompatibility(entry.manifest);
|
|
951
|
+
if (problem) require_output.logWarn(`Skipped ${entry.id}: ${problem}`);
|
|
952
|
+
return !problem;
|
|
953
|
+
});
|
|
954
|
+
if (!proposals.length) {
|
|
955
|
+
require_output.logOutro(ids.length ? `No updates for ${ids.join(", ")}.` : "Every installed extension is up to date.");
|
|
956
|
+
return;
|
|
957
|
+
}
|
|
958
|
+
const change = ({ kind, artifact }) => `${kind} ${versions.get(artifact.package) ?? "not installed"} -> ${(0, node_util.styleText)("green", artifact.version)}`;
|
|
959
|
+
require_output.logBlock(proposals.map((entry) => `${entry.artifact.package} ${change(entry)}`));
|
|
960
|
+
if (check) {
|
|
961
|
+
const plural = proposals.length === 1 ? "" : "s";
|
|
962
|
+
require_output.logOutro(`${proposals.length} update${plural} available. Run \`kubb update\` to install.`);
|
|
963
|
+
return;
|
|
964
|
+
}
|
|
965
|
+
let selected = proposals;
|
|
966
|
+
if (!yes) {
|
|
967
|
+
const chosen = await _clack_prompts.multiselect({
|
|
968
|
+
message: "Select the updates to install:",
|
|
969
|
+
options: proposals.map((entry) => ({
|
|
970
|
+
value: entry.id,
|
|
971
|
+
label: entry.artifact.package,
|
|
972
|
+
hint: change(entry)
|
|
973
|
+
})),
|
|
974
|
+
initialValues: proposals.map((entry) => entry.id),
|
|
975
|
+
required: true
|
|
976
|
+
});
|
|
977
|
+
if (_clack_prompts.isCancel(chosen)) {
|
|
978
|
+
_clack_prompts.cancel("Operation canceled.");
|
|
979
|
+
return;
|
|
980
|
+
}
|
|
981
|
+
selected = proposals.filter((entry) => chosen.includes(entry.id));
|
|
982
|
+
}
|
|
983
|
+
const plural = selected.length === 1 ? "" : "s";
|
|
984
|
+
const packageManager = detectPackageManager(cwd);
|
|
985
|
+
const specs = selected.map(({ artifact }) => require_registry.installSpec(artifact));
|
|
986
|
+
require_output.logStep(`Installing ${specs.join(", ")} with ${packageManager.name}`);
|
|
987
|
+
await installPackages(specs, packageManager, cwd);
|
|
988
|
+
require_output.logInfo(`Updated ${specs.length} extension${plural}`);
|
|
989
|
+
require_output.logOutro((0, node_util.styleText)("green", "Done"));
|
|
990
|
+
} catch (error) {
|
|
991
|
+
require_output.logError(require_Telemetry.getErrorMessage(error));
|
|
992
|
+
node_process.default.exitCode = 1;
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
require_rolldown_runtime.__name(run$1, "run");
|
|
996
|
+
const command = (0, gunshi.define)({
|
|
997
|
+
name: "update",
|
|
998
|
+
description: "Update installed extensions to the version the Kubb registry pins. Pass ids to update only those, or --check to list the updates without installing.",
|
|
999
|
+
examples: [
|
|
1000
|
+
"kubb update",
|
|
1001
|
+
"kubb update --check",
|
|
1002
|
+
"kubb update plugin-zod plugin-ts --yes"
|
|
1003
|
+
].join("\n"),
|
|
1004
|
+
args: {
|
|
1005
|
+
ids: {
|
|
1006
|
+
type: "positional",
|
|
1007
|
+
description: "Registry ids to update, all installed extensions when omitted",
|
|
1008
|
+
multiple: true
|
|
1009
|
+
},
|
|
1010
|
+
check: {
|
|
1011
|
+
type: "boolean",
|
|
1012
|
+
description: "List the available updates without installing them",
|
|
1013
|
+
default: false
|
|
1014
|
+
},
|
|
1015
|
+
...yesArg
|
|
1016
|
+
},
|
|
1017
|
+
run: ({ values }) => run$1({
|
|
1018
|
+
ids: values.ids ?? [],
|
|
1019
|
+
check: values.check,
|
|
1020
|
+
yes: values.yes
|
|
1021
|
+
})
|
|
1022
|
+
});
|
|
1023
|
+
//#endregion
|
|
530
1024
|
//#region src/index.ts
|
|
531
1025
|
/** Flags that short-circuit execution (help and version). The telemetry notice is suppressed for these. */
|
|
532
1026
|
const QUIET_FLAGS = /* @__PURE__ */ new Set([
|
|
@@ -544,19 +1038,19 @@ async function run(argv = process.argv.slice(2)) {
|
|
|
544
1038
|
const args = routeStudioFlags(resolveDeprecatedFlags(argv));
|
|
545
1039
|
const isQuietFlag = args.some((arg) => QUIET_FLAGS.has(arg));
|
|
546
1040
|
if (!require_Telemetry.isDisabled() && !isQuietFlag) console.error(`${(0, node_util.styleText)("yellow", "Notice:")} Kubb collects anonymous telemetry data to help improve the tool. No personal data or file contents are collected. \nTo disable, set ${(0, node_util.styleText)("cyan", "KUBB_DISABLE_TELEMETRY=1")}.\n`);
|
|
547
|
-
await (0, gunshi.cli)(args, command$
|
|
1041
|
+
await (0, gunshi.cli)(args, command$13, {
|
|
548
1042
|
name: "kubb",
|
|
549
1043
|
version: require_Telemetry.version,
|
|
550
1044
|
description: "Generate code from an OpenAPI specification, manage Kubb extensions, or connect the project to Kubb Studio.",
|
|
551
1045
|
subCommands: {
|
|
552
|
-
generate: command$
|
|
553
|
-
init: command$
|
|
554
|
-
validate: command,
|
|
555
|
-
mcp: command$
|
|
556
|
-
studio: command$
|
|
557
|
-
add: command$
|
|
558
|
-
update: command
|
|
559
|
-
list: command$
|
|
1046
|
+
generate: command$13,
|
|
1047
|
+
init: command$2,
|
|
1048
|
+
validate: command$4,
|
|
1049
|
+
mcp: command$12,
|
|
1050
|
+
studio: command$5,
|
|
1051
|
+
add: command$3,
|
|
1052
|
+
update: command,
|
|
1053
|
+
list: command$1
|
|
560
1054
|
},
|
|
561
1055
|
fallbackToEntry: true,
|
|
562
1056
|
strict: true,
|