@kubb/cli 5.9.2 → 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.
Files changed (108) hide show
  1. package/dist/Telemetry-ByFeVTz5.cjs +314 -0
  2. package/dist/Telemetry-ByFeVTz5.cjs.map +1 -0
  3. package/dist/Telemetry-E_BBHmnT.js +259 -0
  4. package/dist/Telemetry-E_BBHmnT.js.map +1 -0
  5. package/dist/background-CZ2nVKwB.js +1 -0
  6. package/dist/{background-Bh4FDWa3.cjs → background-DdUVvDwi.cjs} +7 -6
  7. package/dist/{background-Bh4FDWa3.cjs.map → background-DdUVvDwi.cjs.map} +1 -1
  8. package/dist/{background-B0YbkZ0s.js → background-H30JH70B.js} +3 -2
  9. package/dist/{background-B0YbkZ0s.js.map → background-H30JH70B.js.map} +1 -1
  10. package/dist/{reporters-B4rZOlo8.cjs → config-Ck2JHe5r.cjs} +36 -4
  11. package/dist/config-Ck2JHe5r.cjs.map +1 -0
  12. package/dist/{reporters-H21Jvrff.js → config-DxePdyxe.js} +29 -3
  13. package/dist/config-DxePdyxe.js.map +1 -0
  14. package/dist/credentials-C8tjAhTo.js +1 -0
  15. package/dist/credentials-CZK6zPLv.js +62 -0
  16. package/dist/credentials-CZK6zPLv.js.map +1 -0
  17. package/dist/credentials-DDaKqtJn.cjs +113 -0
  18. package/dist/credentials-DDaKqtJn.cjs.map +1 -0
  19. package/dist/index.cjs +702 -207
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.js +697 -206
  22. package/dist/index.js.map +1 -1
  23. package/dist/{output-BnK0scpX.cjs → output-Cd3Kmvo0.cjs} +141 -66
  24. package/dist/output-Cd3Kmvo0.cjs.map +1 -0
  25. package/dist/{output-qFt4vV7K.js → output-DS5hyqwL.js} +173 -129
  26. package/dist/output-DS5hyqwL.js.map +1 -0
  27. package/dist/{registry-B7BvdrGE.js → registry-CSXUuuCy.js} +2 -2
  28. package/dist/{registry-B7BvdrGE.js.map → registry-CSXUuuCy.js.map} +1 -1
  29. package/dist/{registry-DER9aRyg.cjs → registry-CrvQxnxy.cjs} +6 -6
  30. package/dist/{registry-DER9aRyg.cjs.map → registry-CrvQxnxy.cjs.map} +1 -1
  31. package/dist/rolldown-runtime-CPE0t6oh.cjs +53 -0
  32. package/dist/{run-BcMMYk7G.js → run-BPD5Vaon.js} +5 -7
  33. package/dist/{run-BcMMYk7G.js.map → run-BPD5Vaon.js.map} +1 -1
  34. package/dist/{run-e8gMz1M_.cjs → run-C0Tfrddq.cjs} +5 -6
  35. package/dist/{run-e8gMz1M_.cjs.map → run-C0Tfrddq.cjs.map} +1 -1
  36. package/dist/{run-fg0ycsS_.cjs → run-CbN00IHp.cjs} +16 -18
  37. package/dist/{run-fg0ycsS_.cjs.map → run-CbN00IHp.cjs.map} +1 -1
  38. package/dist/{run-KLPSFEv-.js → run-CecrPSop.js} +2 -3
  39. package/dist/{run-KLPSFEv-.js.map → run-CecrPSop.js.map} +1 -1
  40. package/dist/{run-BCswmM8Q.js → run-Ck04_W4q.js} +2 -3
  41. package/dist/{run-BCswmM8Q.js.map → run-Ck04_W4q.js.map} +1 -1
  42. package/dist/{run-BQQhNg8I.js → run-DcP1czVQ.js} +25 -84
  43. package/dist/run-DcP1czVQ.js.map +1 -0
  44. package/dist/{run-D8EJ2hKI.cjs → run-Dyc52IzX.cjs} +5 -6
  45. package/dist/{run-D8EJ2hKI.cjs.map → run-Dyc52IzX.cjs.map} +1 -1
  46. package/dist/{run-C8dyBAPb.cjs → run-QqLDhthl.cjs} +46 -158
  47. package/dist/run-QqLDhthl.cjs.map +1 -0
  48. package/dist/run-WkXSXG2V.js +1 -0
  49. package/dist/{snapshot-B45A4RfA.cjs → snapshot-NGLcfG6E.cjs} +17 -26
  50. package/dist/snapshot-NGLcfG6E.cjs.map +1 -0
  51. package/dist/{snapshot-C0WaZZiF.js → snapshot-iEjgROga.js} +15 -24
  52. package/dist/snapshot-iEjgROga.js.map +1 -0
  53. package/dist/studioWorker.js +2 -2
  54. package/package.json +7 -8
  55. package/dist/Telemetry-B_C4MVJd.cjs +0 -231
  56. package/dist/Telemetry-B_C4MVJd.cjs.map +0 -1
  57. package/dist/Telemetry-DER8LIO5.js +0 -207
  58. package/dist/Telemetry-DER8LIO5.js.map +0 -1
  59. package/dist/agent-BPIqnEl2.js +0 -59
  60. package/dist/agent-BPIqnEl2.js.map +0 -1
  61. package/dist/agent-DElUuYuy.cjs +0 -120
  62. package/dist/agent-DElUuYuy.cjs.map +0 -1
  63. package/dist/background-DSKoOwcG.js +0 -1
  64. package/dist/commands-BegVe5Mt.js +0 -81
  65. package/dist/commands-BegVe5Mt.js.map +0 -1
  66. package/dist/commands-hXDwA0zn.cjs +0 -87
  67. package/dist/commands-hXDwA0zn.cjs.map +0 -1
  68. package/dist/config-B6UIKcl1.js +0 -117
  69. package/dist/config-B6UIKcl1.js.map +0 -1
  70. package/dist/config-Bo9ro7vg.cjs +0 -129
  71. package/dist/config-Bo9ro7vg.cjs.map +0 -1
  72. package/dist/constants-Cii4HX64.js +0 -12
  73. package/dist/constants-Cii4HX64.js.map +0 -1
  74. package/dist/constants-Df449N47.cjs +0 -29
  75. package/dist/constants-Df449N47.cjs.map +0 -1
  76. package/dist/errors-BdA8M78q.cjs +0 -43
  77. package/dist/errors-BdA8M78q.cjs.map +0 -1
  78. package/dist/errors-DmC83ALX.js +0 -32
  79. package/dist/errors-DmC83ALX.js.map +0 -1
  80. package/dist/output-BnK0scpX.cjs.map +0 -1
  81. package/dist/output-qFt4vV7K.js.map +0 -1
  82. package/dist/reporters-B4rZOlo8.cjs.map +0 -1
  83. package/dist/reporters-H21Jvrff.js.map +0 -1
  84. package/dist/run-89YfZJuo.cjs +0 -67
  85. package/dist/run-89YfZJuo.cjs.map +0 -1
  86. package/dist/run-8HrdMihy.js +0 -1
  87. package/dist/run-BQQhNg8I.js.map +0 -1
  88. package/dist/run-BYff_byB.js +0 -71
  89. package/dist/run-BYff_byB.js.map +0 -1
  90. package/dist/run-C8dyBAPb.cjs.map +0 -1
  91. package/dist/run-CJHsZZB8.js +0 -178
  92. package/dist/run-CJHsZZB8.js.map +0 -1
  93. package/dist/run-Ca_OX3WZ.js +0 -105
  94. package/dist/run-Ca_OX3WZ.js.map +0 -1
  95. package/dist/run-Ct6kzKpg.cjs +0 -109
  96. package/dist/run-Ct6kzKpg.cjs.map +0 -1
  97. package/dist/run-DL2wLwBZ.cjs +0 -182
  98. package/dist/run-DL2wLwBZ.cjs.map +0 -1
  99. package/dist/run-Dej-hm91.js +0 -65
  100. package/dist/run-Dej-hm91.js.map +0 -1
  101. package/dist/run-DpAMfkm5.cjs +0 -72
  102. package/dist/run-DpAMfkm5.cjs.map +0 -1
  103. package/dist/snapshot-B45A4RfA.cjs.map +0 -1
  104. package/dist/snapshot-C0WaZZiF.js.map +0 -1
  105. package/dist/utils-BHW8kA8P.js +0 -83
  106. package/dist/utils-BHW8kA8P.js.map +0 -1
  107. package/dist/utils-BzQ46pgd.cjs +0 -109
  108. package/dist/utils-BzQ46pgd.cjs.map +0 -1
@@ -1,178 +0,0 @@
1
- import "./rolldown-runtime-CRm0XQPb.js";
2
- import { n as KUBB_PACKAGE_NAME, r as initDefaults, t as KUBB_CONFIG_FILENAME } from "./constants-Cii4HX64.js";
3
- import { a as logInfo, i as logError, o as logIntro, s as logOutro, t as createSpinner } from "./output-qFt4vV7K.js";
4
- import { i as installSpec, n as fetchRegistryIndex, o as registryUrl, r as incompatibility, s as toRegistryId } from "./registry-B7BvdrGE.js";
5
- import { i as missingPluginDependencies, n as initPackageJson, r as installPackages, t as detectPackageManager } from "./utils-BHW8kA8P.js";
6
- import { t as addToConfig } from "./run-Ca_OX3WZ.js";
7
- import { styleText } from "node:util";
8
- import process from "node:process";
9
- import path from "node:path";
10
- import fs from "node:fs";
11
- import * as clack from "@clack/prompts";
12
- //#region ../../internals/shared/src/init.ts
13
- function generateConfigFile({ selectedPlugins, inputPath, outputPath }) {
14
- return `${[`import { defineConfig } from 'kubb/config'`, ...selectedPlugins.map((plugin) => `import { ${plugin.importName} } from '${plugin.packageName}'`)].join("\n")}
15
-
16
- export default defineConfig({
17
- input: '${inputPath}',
18
- output: {
19
- path: '${outputPath}',
20
- clean: true,
21
- },
22
- plugins: [
23
- ${selectedPlugins.map((plugin) => ` ${plugin.importName}(),`).join("\n")}
24
- ],
25
- })
26
- `;
27
- }
28
- //#endregion
29
- //#region src/runners/init/run.ts
30
- function cancelAndExit(message = "Operation canceled.") {
31
- clack.cancel(message);
32
- process.exit(0);
33
- }
34
- /**
35
- * Runs the interactive Kubb scaffolding wizard.
36
- * Detects the package manager, prompts for input/output paths and plugins, installs packages, and writes `kubb.config.ts`.
37
- * Pass `yes: true` to skip all prompts and use defaults.
38
- */
39
- async function run({ yes, version, input: inputFlag, output: outputFlag, plugins: pluginsFlag, dryRun }) {
40
- const cwd = process.cwd();
41
- logIntro({ title: styleText("bgCyan", styleText("black", " Kubb Init ")) });
42
- /**
43
- * Returns `flag` when provided, the `defaultValue` when `yes` is set,
44
- * or calls `prompt()` for interactive input. Exits on cancellation.
45
- */
46
- async function resolveOrPrompt(flag, defaultValue, logLabel, prompt) {
47
- if (flag !== void 0) {
48
- logInfo(`${logLabel}: ${styleText("cyan", String(flag))}`);
49
- return flag;
50
- }
51
- if (yes) {
52
- logInfo(`${logLabel}: ${styleText("cyan", String(defaultValue))}`);
53
- return defaultValue;
54
- }
55
- const result = await prompt();
56
- if (clack.isCancel(result)) cancelAndExit();
57
- return result;
58
- }
59
- try {
60
- const plugins = (await fetchRegistryIndex({ registry: registryUrl() })).filter((entry) => entry.kind === "plugin" && !incompatibility(entry.manifest));
61
- const byId = new Map(plugins.map((entry) => [entry.id, entry]));
62
- if (!fs.existsSync(path.join(cwd, "package.json"))) {
63
- if (!yes) {
64
- const shouldInit = await clack.confirm({
65
- message: "No package.json found. Would you like to create one?",
66
- initialValue: true
67
- });
68
- if (clack.isCancel(shouldInit) || !shouldInit) cancelAndExit();
69
- }
70
- const packageManager = detectPackageManager(cwd);
71
- const spinner = createSpinner();
72
- spinner.start(`Initializing package.json with ${packageManager.name}`);
73
- await initPackageJson(cwd, packageManager);
74
- spinner.stop(`Created package.json with ${packageManager.name}`);
75
- }
76
- const packageManager = detectPackageManager(cwd);
77
- logInfo(`Detected package manager: ${styleText("cyan", packageManager.name)}`);
78
- const inputPath = await resolveOrPrompt(inputFlag, initDefaults.inputPath, "Using input path", () => clack.text({
79
- message: "Where is your OpenAPI specification located?",
80
- placeholder: initDefaults.inputPath,
81
- defaultValue: initDefaults.inputPath,
82
- validate: (value) => {
83
- if (!value) return "Input path is required";
84
- }
85
- }));
86
- const outputPath = await resolveOrPrompt(outputFlag, initDefaults.outputPath, "Using output path", () => clack.text({
87
- message: "Where should the generated files be output?",
88
- placeholder: initDefaults.outputPath,
89
- defaultValue: initDefaults.outputPath,
90
- validate: (value) => {
91
- if (!value) return "Output path is required";
92
- }
93
- }));
94
- const defaultPlugins = initDefaults.plugins.flatMap((slug) => byId.get(toRegistryId(slug)) ?? []);
95
- const pluginLabel = (entries) => styleText("cyan", entries.map((entry) => entry.manifest.displayName).join(", "));
96
- const selectedPlugins = await (async () => {
97
- if (pluginsFlag) {
98
- const ids = pluginsFlag.split(",").map((id) => id.trim()).filter(Boolean);
99
- const unknown = ids.filter((id) => !byId.has(toRegistryId(id)));
100
- if (unknown.length) throw new Error(`Not in the Kubb registry: ${unknown.join(", ")}. Browse the plugins at https://kubb.dev/extensions.`);
101
- const entries = ids.map((id) => byId.get(toRegistryId(id)));
102
- logInfo(`Using plugins: ${pluginLabel(entries)}`);
103
- return entries;
104
- }
105
- if (yes) {
106
- logInfo(`Using plugins: ${pluginLabel(defaultPlugins)}`);
107
- return defaultPlugins;
108
- }
109
- const values = await clack.multiselect({
110
- message: "Select plugins to use:",
111
- options: plugins.map(({ id, manifest }) => ({
112
- value: id,
113
- label: manifest.displayName,
114
- hint: manifest.category
115
- })),
116
- initialValues: defaultPlugins.map((entry) => entry.id),
117
- required: true
118
- });
119
- if (clack.isCancel(values)) cancelAndExit();
120
- return plugins.filter((entry) => values.includes(entry.id));
121
- })();
122
- const missing = missingPluginDependencies({
123
- selected: selectedPlugins.map((entry) => entry.manifest.name),
124
- manifests: selectedPlugins.map((entry) => entry.manifest)
125
- });
126
- if (missing.length) throw new Error(`${missing.join("\n")}\nAdd the missing plugins and run kubb init again.`);
127
- const packagesToInstall = [`${KUBB_PACKAGE_NAME}@${version}`, ...selectedPlugins.map((entry) => installSpec(entry.artifact))];
128
- const spinner = createSpinner();
129
- spinner.start(`Installing ${packagesToInstall.length} packages with ${packageManager.name}`);
130
- try {
131
- await dryRun.run(() => installPackages(packagesToInstall, packageManager, cwd), { message: `install ${packagesToInstall.length} packages with ${packageManager.name}` });
132
- spinner.stop(`Installed ${packagesToInstall.length} packages`);
133
- } catch (error) {
134
- spinner.stop("Installation failed");
135
- throw error;
136
- }
137
- const configSpinner = createSpinner();
138
- configSpinner.start(`Creating ${KUBB_CONFIG_FILENAME}`);
139
- const configContent = generateConfigFile({
140
- selectedPlugins: [],
141
- inputPath,
142
- outputPath
143
- });
144
- const configPath = path.join(cwd, KUBB_CONFIG_FILENAME);
145
- if (fs.existsSync(configPath)) {
146
- configSpinner.stop(`${KUBB_CONFIG_FILENAME} already exists`);
147
- if (!yes) {
148
- const shouldOverwrite = await clack.confirm({
149
- message: `${KUBB_CONFIG_FILENAME} already exists. Overwrite?`,
150
- initialValue: false
151
- });
152
- if (clack.isCancel(shouldOverwrite) || !shouldOverwrite) cancelAndExit("Keeping existing configuration. Packages have been installed.");
153
- }
154
- configSpinner.start(`Overwriting ${KUBB_CONFIG_FILENAME}`);
155
- }
156
- await dryRun.run(() => fs.promises.writeFile(configPath, configContent, "utf-8"), { message: `write ${KUBB_CONFIG_FILENAME}` });
157
- for (const entry of selectedPlugins) {
158
- const reason = await dryRun.run(() => addToConfig({
159
- detail: entry,
160
- configFile: configPath
161
- }), {
162
- message: `add ${entry.manifest.export}() to ${KUBB_CONFIG_FILENAME}`,
163
- resolve: () => void 0
164
- });
165
- if (reason) throw new Error(`Could not add ${entry.manifest.export}() to ${KUBB_CONFIG_FILENAME}: ${reason}`);
166
- }
167
- configSpinner.stop(`Created ${KUBB_CONFIG_FILENAME}`);
168
- logOutro(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", ` 3. Find generated files in: ${outputPath}`) + "\n\n" + styleText("dim", `Using ${packageManager.name} • Kubb v${version}`));
169
- } catch (error) {
170
- logError(styleText("red", "An error occurred during initialization"));
171
- if (error instanceof Error) logError(error.message);
172
- process.exit(1);
173
- }
174
- }
175
- //#endregion
176
- export { run };
177
-
178
- //# sourceMappingURL=run-CJHsZZB8.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"run-CJHsZZB8.js","names":[],"sources":["../../../internals/shared/src/init.ts","../src/runners/init/run.ts"],"sourcesContent":["import { availablePlugins, type PluginOption } from './constants.ts'\n\n/**\n * Resolves a comma-separated plugin flag (e.g. `--plugins plugin-ts,plugin-zod`) into the\n * matching known plugin options. Unrecognized names are dropped, and a missing flag yields\n * an empty list.\n */\nexport function resolvePlugins(pluginsFlag: string | undefined): Array<PluginOption> {\n if (!pluginsFlag) {\n return []\n }\n const requested = pluginsFlag\n .split(',')\n .map((value) => value.trim())\n .filter(Boolean)\n return availablePlugins.filter((plugin) => requested.includes(plugin.value))\n}\n\nexport function generateConfigFile({\n selectedPlugins,\n inputPath,\n outputPath,\n}: {\n selectedPlugins: Array<PluginOption>\n inputPath: string\n outputPath: string\n}): string {\n const imports = [\n `import { defineConfig } from 'kubb/config'`,\n ...selectedPlugins.map((plugin) => `import { ${plugin.importName} } from '${plugin.packageName}'`),\n ].join('\\n')\n\n const pluginConfigs = selectedPlugins.map((plugin) => ` ${plugin.importName}(),`).join('\\n')\n\n return `${imports}\n\nexport default defineConfig({\n input: '${inputPath}',\n output: {\n path: '${outputPath}',\n clean: true,\n },\n plugins: [\n${pluginConfigs}\n ],\n})\n`\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 { DryRunExtension } from '@gunshi/plugin-dryrun'\nimport { generateConfigFile, initDefaults, KUBB_CONFIG_FILENAME, KUBB_PACKAGE_NAME } from '@internals/shared'\nimport type { RegistryEntry } from '@kubb/core'\nimport { createSpinner, logError, logInfo, logIntro, logOutro } from '../../loggers/output.ts'\nimport { addToConfig } from '../add/run.ts'\nimport { fetchRegistryIndex, incompatibility, installSpec, registryUrl, toRegistryId } from '../../utils/registry.ts'\nimport { detectPackageManager, initPackageJson, installPackages, missingPluginDependencies } from './utils.ts'\n\nfunction cancelAndExit(message = 'Operation canceled.'): never {\n clack.cancel(message)\n process.exit(0)\n}\n\ntype InitOptions = {\n /**\n * When `true`, skips all interactive prompts and uses default values.\n */\n yes: boolean\n /**\n * Current `@kubb/cli` version string, shown in the closing outro.\n */\n version: string\n /**\n * Input path flag value from `--input`. When provided, skips the input prompt.\n */\n input?: string\n /**\n * Output directory flag value from `--output`. When provided, skips the output prompt.\n */\n output?: string\n /**\n * Comma-separated plugin list from `--plugins`, e.g. `'plugin-ts,plugin-zod'`. When provided, skips the plugin selection prompt.\n */\n plugins?: string\n /**\n * Dry-run extension from `@gunshi/plugin-dryrun`. When enabled, package installation and the\n * config file write are skipped.\n */\n dryRun: DryRunExtension\n}\n\n/**\n * Runs the interactive Kubb scaffolding wizard.\n * Detects the package manager, prompts for input/output paths and plugins, installs packages, and writes `kubb.config.ts`.\n * Pass `yes: true` to skip all prompts and use defaults.\n */\nexport async function run({ yes, version, input: inputFlag, output: outputFlag, plugins: pluginsFlag, dryRun }: InitOptions): Promise<void> {\n const cwd = process.cwd()\n\n logIntro({ title: styleText('bgCyan', styleText('black', ' Kubb Init ')) })\n\n /**\n * Returns `flag` when provided, the `defaultValue` when `yes` is set,\n * or calls `prompt()` for interactive input. Exits on cancellation.\n */\n async function resolveOrPrompt<T>(flag: T | undefined, defaultValue: T, logLabel: string, prompt: () => Promise<NoInfer<T> | symbol>): Promise<T> {\n if (flag !== undefined) {\n logInfo(`${logLabel}: ${styleText('cyan', String(flag))}`)\n return flag\n }\n if (yes) {\n logInfo(`${logLabel}: ${styleText('cyan', String(defaultValue))}`)\n return defaultValue\n }\n const result = await prompt()\n if (clack.isCancel(result)) cancelAndExit()\n return result as T\n }\n\n try {\n // The plugins come from the Kubb registry, like `kubb add`, so read it before changing anything\n const plugins = (await fetchRegistryIndex({ registry: registryUrl() })).filter((entry) => entry.kind === 'plugin' && !incompatibility(entry.manifest))\n const byId = new Map(plugins.map((entry) => [entry.id, entry]))\n\n // Check/create package.json, detect package manager once after the block\n if (!fs.existsSync(path.join(cwd, 'package.json'))) {\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 const packageManager = detectPackageManager(cwd)\n const spinner = createSpinner()\n spinner.start(`Initializing package.json with ${packageManager.name}`)\n await initPackageJson(cwd, packageManager)\n spinner.stop(`Created package.json with ${packageManager.name}`)\n }\n\n const packageManager = detectPackageManager(cwd)\n logInfo(`Detected package manager: ${styleText('cyan', packageManager.name)}`)\n\n // Prompt for OpenAPI spec path\n const inputPath = await resolveOrPrompt(inputFlag, initDefaults.inputPath, 'Using input path', () =>\n 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\n // Prompt for output directory\n const outputPath = await resolveOrPrompt(outputFlag, initDefaults.outputPath, 'Using output path', () =>\n 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\n // Plugin selection\n const defaultPlugins = initDefaults.plugins.flatMap((slug) => byId.get(toRegistryId(slug)) ?? [])\n const pluginLabel = (entries: Array<RegistryEntry>) => styleText('cyan', entries.map((entry) => entry.manifest.displayName).join(', '))\n\n const selectedPlugins: Array<RegistryEntry> = await (async () => {\n if (pluginsFlag) {\n const ids = pluginsFlag\n .split(',')\n .map((id) => id.trim())\n .filter(Boolean)\n const unknown = ids.filter((id) => !byId.has(toRegistryId(id)))\n if (unknown.length) throw new Error(`Not in the Kubb registry: ${unknown.join(', ')}. Browse the plugins at https://kubb.dev/extensions.`)\n const entries = ids.map((id) => byId.get(toRegistryId(id))!)\n logInfo(`Using plugins: ${pluginLabel(entries)}`)\n return entries\n }\n if (yes) {\n logInfo(`Using plugins: ${pluginLabel(defaultPlugins)}`)\n return defaultPlugins\n }\n const values = await clack.multiselect({\n message: 'Select plugins to use:',\n options: plugins.map(({ id, manifest }) => ({ value: id, label: manifest.displayName, hint: manifest.category })),\n initialValues: defaultPlugins.map((entry) => entry.id),\n required: true,\n })\n if (clack.isCancel(values)) cancelAndExit()\n return plugins.filter((entry) => (values as Array<string>).includes(entry.id))\n })()\n\n // Check the selection against the plugins' manifests before installing anything\n const missing = missingPluginDependencies({\n selected: selectedPlugins.map((entry) => entry.manifest.name),\n manifests: selectedPlugins.map((entry) => entry.manifest),\n })\n if (missing.length) {\n throw new Error(`${missing.join('\\n')}\\nAdd the missing plugins and run kubb init again.`)\n }\n\n // Install `kubb` at the running CLI's version and each plugin at the version the registry pins\n const packagesToInstall = [`${KUBB_PACKAGE_NAME}@${version}`, ...selectedPlugins.map((entry) => installSpec(entry.artifact))]\n\n const spinner = createSpinner()\n spinner.start(`Installing ${packagesToInstall.length} packages with ${packageManager.name}`)\n\n try {\n await dryRun.run(() => installPackages(packagesToInstall, packageManager, cwd), {\n message: `install ${packagesToInstall.length} packages with ${packageManager.name}`,\n })\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 = createSpinner()\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 await dryRun.run(() => fs.promises.writeFile(configPath, configContent, 'utf-8'), { message: `write ${KUBB_CONFIG_FILENAME}` })\n\n // Add each plugin the way `kubb add` does\n for (const entry of selectedPlugins) {\n const reason = await dryRun.run(() => addToConfig({ detail: entry, configFile: configPath }), {\n message: `add ${entry.manifest.export}() to ${KUBB_CONFIG_FILENAME}`,\n resolve: () => undefined,\n })\n if (reason) throw new Error(`Could not add ${entry.manifest.export}() to ${KUBB_CONFIG_FILENAME}: ${reason}`)\n }\n\n configSpinner.stop(`Created ${KUBB_CONFIG_FILENAME}`)\n\n logOutro(\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', ` 3. Find generated files in: ${outputPath}`) +\n '\\n\\n' +\n styleText('dim', `Using ${packageManager.name} • Kubb v${version}`),\n )\n } catch (error) {\n logError(styleText('red', 'An error occurred during initialization'))\n if (error instanceof Error) {\n logError(error.message)\n }\n process.exit(1)\n }\n}\n"],"mappings":";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E;CACF,SAAS,OAAO;EACd,SAAS,UAAU,OAAO,yCAAyC,CAAC;EACpE,IAAI,iBAAiB,OACnB,SAAS,MAAM,OAAO;EAExB,QAAQ,KAAK,CAAC;CAChB;AACF"}
@@ -1,105 +0,0 @@
1
- import "./rolldown-runtime-CRm0XQPb.js";
2
- import { t as getErrorMessage } from "./errors-DmC83ALX.js";
3
- import { t as findConfigFile } from "./config-B6UIKcl1.js";
4
- import { a as logInfo, d as logWarn, i as logError, l as logStep, o as logIntro, r as logBlock, s as logOutro } from "./output-qFt4vV7K.js";
5
- import { i as installSpec, o as registryUrl, r as incompatibility, s as toRegistryId, t as fetchRegistryDetail } from "./registry-B7BvdrGE.js";
6
- import { r as installPackages, t as detectPackageManager } from "./utils-BHW8kA8P.js";
7
- import { styleText } from "node:util";
8
- import process from "node:process";
9
- import path from "node:path";
10
- import * as clack from "@clack/prompts";
11
- //#region src/runners/add/run.ts
12
- /** The import and the `defineConfig` property to merge into `kubb.config.ts` by hand. */
13
- function toSnippet({ artifact, manifest }) {
14
- const call = `${manifest.export}()`;
15
- const property = {
16
- plugin: `plugins: [..., ${call}],`,
17
- adapter: `adapter: ${call},`,
18
- parser: `parsers: [..., ${call}],`
19
- };
20
- return [
21
- `import { ${manifest.export} } from '${artifact.package}'`,
22
- "",
23
- property[manifest.kind]
24
- ].join("\n");
25
- }
26
- /** Adds the plugin call and its import to the config file. Returns why it could not, or `undefined`. */
27
- async function addToConfig({ detail, configFile }) {
28
- const { artifact, manifest } = detail;
29
- try {
30
- const { writeConfigEdits } = await import("@kubb/studio");
31
- const { outcomes } = await writeConfigEdits({
32
- filePath: configFile,
33
- edits: [{
34
- operation: "add-plugin",
35
- plugin: artifact.package
36
- }],
37
- extensions: /* @__PURE__ */ new Map([[artifact.package, {
38
- package: artifact.package,
39
- version: artifact.version,
40
- manifest
41
- }]])
42
- });
43
- return outcomes[0]?.applied ? void 0 : outcomes[0]?.reason ?? "the config file was not changed";
44
- } catch (error) {
45
- return getErrorMessage(error);
46
- }
47
- }
48
- /**
49
- * Installs an extension from the Kubb registry at its reviewed version and, for a plugin, adds it to
50
- * `kubb.config.ts`. Refuses when the running Kubb or Node.js version is outside its compatibility.
51
- */
52
- async function run({ id: input, configPath, yes, install }) {
53
- const cwd = process.cwd();
54
- logIntro({ title: styleText("bgCyan", styleText("black", " Kubb Add ")) });
55
- try {
56
- const registry = registryUrl();
57
- const detail = await fetchRegistryDetail({
58
- id: toRegistryId(input),
59
- registry
60
- });
61
- const { artifact, manifest } = detail;
62
- const problem = incompatibility(manifest);
63
- if (problem) throw new Error(problem);
64
- const spec = installSpec(artifact);
65
- const configFile = manifest.kind === "plugin" ? configPath ? path.resolve(configPath) : findConfigFile(cwd) : void 0;
66
- if (manifest.kind === "plugin" && !configFile) throw new Error("No kubb.config.ts found. Run `kubb init` first, or pass --config.");
67
- logInfo(`${styleText("cyan", manifest.displayName)} (${manifest.kind}): ${manifest.description}`);
68
- logBlock([install ? `Install ${styleText("cyan", spec)} as a dev dependency` : `Skip installing ${spec}`, configFile ? `Add ${styleText("cyan", `${manifest.export}()`)} to ${path.relative(cwd, configFile) || configFile}` : `Print the ${manifest.kind} snippet to add`]);
69
- const confirmed = yes || await clack.confirm({
70
- message: "Continue?",
71
- initialValue: true
72
- });
73
- if (clack.isCancel(confirmed) || !confirmed) {
74
- clack.cancel("Operation canceled.");
75
- return;
76
- }
77
- if (install) {
78
- const packageManager = detectPackageManager(cwd);
79
- logStep(`Installing ${spec} with ${packageManager.name}`);
80
- await installPackages([spec], packageManager, cwd);
81
- }
82
- const reason = configFile ? await addToConfig({
83
- detail,
84
- configFile
85
- }) : `add the ${manifest.kind} to your config`;
86
- if (!reason) {
87
- logOutro(styleText("green", install ? `Added ${spec}` : `Added ${manifest.export}() to the config. Install ${spec} to use it.`));
88
- return;
89
- }
90
- if (configFile) logWarn(`Could not edit ${configFile}: ${reason}`);
91
- logBlock([
92
- "Add the import to your Kubb config and merge the property into its defineConfig call:",
93
- "",
94
- toSnippet(detail)
95
- ]);
96
- logOutro(styleText("green", install ? `Installed ${spec}. Add it with the snippet above.` : `Install ${spec} and add the snippet above.`));
97
- } catch (error) {
98
- logError(getErrorMessage(error));
99
- process.exitCode = 1;
100
- }
101
- }
102
- //#endregion
103
- export { run as n, toSnippet as r, addToConfig as t };
104
-
105
- //# sourceMappingURL=run-Ca_OX3WZ.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"run-Ca_OX3WZ.js","names":[],"sources":["../src/runners/add/run.ts"],"sourcesContent":["import path from 'node:path'\nimport process from 'node:process'\nimport { styleText } from 'node:util'\nimport * as clack from '@clack/prompts'\nimport { getErrorMessage } from '@internals/utils'\nimport type { ExtensionManifest, RegistryDetail } from '@kubb/core'\nimport { findConfigFile } from '../../config.ts'\nimport { logBlock, logError, logInfo, logIntro, logOutro, logStep, logWarn } from '../../loggers/output.ts'\nimport { fetchRegistryDetail, incompatibility, installSpec, registryUrl, toRegistryId } from '../../utils/registry.ts'\nimport { detectPackageManager, installPackages } from '../init/utils.ts'\n\nexport type AddOptions = {\n /**\n * `owner/slug`, or a bare `slug` for an official extension.\n */\n id: string\n configPath?: string\n yes: boolean\n install: boolean\n}\n\n/** The import and the `defineConfig` property to merge into `kubb.config.ts` by hand. */\nexport function toSnippet({ artifact, manifest }: Pick<RegistryDetail, 'artifact' | 'manifest'>): string {\n const call = `${manifest.export}()`\n const property: Record<ExtensionManifest['kind'], string> = {\n plugin: `plugins: [..., ${call}],`,\n adapter: `adapter: ${call},`,\n parser: `parsers: [..., ${call}],`,\n }\n return [`import { ${manifest.export} } from '${artifact.package}'`, '', property[manifest.kind]].join('\\n')\n}\n\n/** Adds the plugin call and its import to the config file. Returns why it could not, or `undefined`. */\nexport async function addToConfig({\n detail,\n configFile,\n}: {\n detail: Pick<RegistryDetail, 'artifact' | 'manifest'>\n configFile: string\n}): Promise<string | undefined> {\n const { artifact, manifest } = detail\n try {\n const { writeConfigEdits } = await import('@kubb/studio')\n const { outcomes } = await writeConfigEdits({\n filePath: configFile,\n edits: [{ operation: 'add-plugin', plugin: artifact.package }],\n extensions: new Map([[artifact.package, { package: artifact.package, version: artifact.version, manifest }]]),\n })\n return outcomes[0]?.applied ? undefined : (outcomes[0]?.reason ?? 'the config file was not changed')\n } catch (error) {\n return getErrorMessage(error)\n }\n}\n\n/**\n * Installs an extension from the Kubb registry at its reviewed version and, for a plugin, adds it to\n * `kubb.config.ts`. Refuses when the running Kubb or Node.js version is outside its compatibility.\n */\nexport async function run({ id: input, configPath, yes, install }: AddOptions): Promise<void> {\n const cwd = process.cwd()\n logIntro({ title: styleText('bgCyan', styleText('black', ' Kubb Add ')) })\n\n try {\n const registry = registryUrl()\n const detail = await fetchRegistryDetail({ id: toRegistryId(input), registry })\n const { artifact, manifest } = detail\n\n const problem = incompatibility(manifest)\n if (problem) throw new Error(problem)\n\n const spec = installSpec(artifact)\n const configFile = manifest.kind === 'plugin' ? (configPath ? path.resolve(configPath) : findConfigFile(cwd)) : undefined\n if (manifest.kind === 'plugin' && !configFile) throw new Error('No kubb.config.ts found. Run `kubb init` first, or pass --config.')\n\n logInfo(`${styleText('cyan', manifest.displayName)} (${manifest.kind}): ${manifest.description}`)\n logBlock([\n install ? `Install ${styleText('cyan', spec)} as a dev dependency` : `Skip installing ${spec}`,\n configFile\n ? `Add ${styleText('cyan', `${manifest.export}()`)} to ${path.relative(cwd, configFile) || configFile}`\n : `Print the ${manifest.kind} snippet to add`,\n ])\n\n const confirmed = yes || (await clack.confirm({ message: 'Continue?', initialValue: true }))\n if (clack.isCancel(confirmed) || !confirmed) {\n clack.cancel('Operation canceled.')\n return\n }\n\n if (install) {\n const packageManager = detectPackageManager(cwd)\n logStep(`Installing ${spec} with ${packageManager.name}`)\n await installPackages([spec], packageManager, cwd)\n }\n\n const reason = configFile ? await addToConfig({ detail, configFile }) : `add the ${manifest.kind} to your config`\n if (!reason) {\n logOutro(styleText('green', install ? `Added ${spec}` : `Added ${manifest.export}() to the config. Install ${spec} to use it.`))\n return\n }\n\n if (configFile) logWarn(`Could not edit ${configFile}: ${reason}`)\n logBlock(['Add the import to your Kubb config and merge the property into its defineConfig call:', '', toSnippet(detail)])\n logOutro(styleText('green', install ? `Installed ${spec}. Add it with the snippet above.` : `Install ${spec} and add the snippet above.`))\n } catch (error) {\n logError(getErrorMessage(error))\n process.exitCode = 1\n }\n}\n"],"mappings":";;;;;;;;;;;;AAsBA,SAAgB,UAAU,EAAE,UAAU,YAAmE;CACvG,MAAM,OAAO,GAAG,SAAS,OAAO;CAChC,MAAM,WAAsD;EAC1D,QAAQ,kBAAkB,KAAK;EAC/B,SAAS,YAAY,KAAK;EAC1B,QAAQ,kBAAkB,KAAK;CACjC;CACA,OAAO;EAAC,YAAY,SAAS,OAAO,WAAW,SAAS,QAAQ;EAAI;EAAI,SAAS,SAAS;CAAK,CAAC,CAAC,KAAK,IAAI;AAC5G;;AAGA,eAAsB,YAAY,EAChC,QACA,cAI8B;CAC9B,MAAM,EAAE,UAAU,aAAa;CAC/B,IAAI;EACF,MAAM,EAAE,qBAAqB,MAAM,OAAO;EAC1C,MAAM,EAAE,aAAa,MAAM,iBAAiB;GAC1C,UAAU;GACV,OAAO,CAAC;IAAE,WAAW;IAAc,QAAQ,SAAS;GAAQ,CAAC;GAC7D,4BAAY,IAAI,IAAI,CAAC,CAAC,SAAS,SAAS;IAAE,SAAS,SAAS;IAAS,SAAS,SAAS;IAAS;GAAS,CAAC,CAAC,CAAC;EAC9G,CAAC;EACD,OAAO,SAAS,EAAE,EAAE,UAAU,KAAA,IAAa,SAAS,EAAE,EAAE,UAAU;CACpE,SAAS,OAAO;EACd,OAAO,gBAAgB,KAAK;CAC9B;AACF;;;;;AAMA,eAAsB,IAAI,EAAE,IAAI,OAAO,YAAY,KAAK,WAAsC;CAC5F,MAAM,MAAM,QAAQ,IAAI;CACxB,SAAS,EAAE,OAAO,UAAU,UAAU,UAAU,SAAS,YAAY,CAAC,EAAE,CAAC;CAEzE,IAAI;EACF,MAAM,WAAW,YAA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kB,WAAW,IAAI,QAAQ;EACjE,SAAS;GAAC;GAAyF;GAAI,UAAU,MAAM;EAAC,CAAC;EACzH,SAAS,UAAU,SAAS,UAAU,aAAa,KAAK,oCAAoC,WAAW,KAAK,4BAA4B,CAAC;CAC3I,SAAS,OAAO;EACd,SAAS,gBAAgB,KAAK,CAAC;EAC/B,QAAQ,WAAW;CACrB;AACF"}
@@ -1,109 +0,0 @@
1
- const require_agent = require("./agent-DElUuYuy.cjs");
2
- const require_errors = require("./errors-BdA8M78q.cjs");
3
- const require_config = require("./config-Bo9ro7vg.cjs");
4
- const require_output = require("./output-BnK0scpX.cjs");
5
- const require_registry = require("./registry-DER9aRyg.cjs");
6
- const require_utils = require("./utils-BzQ46pgd.cjs");
7
- let node_util = require("node:util");
8
- let node_process = require("node:process");
9
- node_process = require_agent.__toESM(node_process, 1);
10
- let node_path = require("node:path");
11
- node_path = require_agent.__toESM(node_path, 1);
12
- let _clack_prompts = require("@clack/prompts");
13
- _clack_prompts = require_agent.__toESM(_clack_prompts, 1);
14
- //#region src/runners/add/run.ts
15
- /** The import and the `defineConfig` property to merge into `kubb.config.ts` by hand. */
16
- function toSnippet({ artifact, manifest }) {
17
- const call = `${manifest.export}()`;
18
- const property = {
19
- plugin: `plugins: [..., ${call}],`,
20
- adapter: `adapter: ${call},`,
21
- parser: `parsers: [..., ${call}],`
22
- };
23
- return [
24
- `import { ${manifest.export} } from '${artifact.package}'`,
25
- "",
26
- property[manifest.kind]
27
- ].join("\n");
28
- }
29
- /** Adds the plugin call and its import to the config file. Returns why it could not, or `undefined`. */
30
- async function addToConfig({ detail, configFile }) {
31
- const { artifact, manifest } = detail;
32
- try {
33
- const { writeConfigEdits } = await import("@kubb/studio");
34
- const { outcomes } = await writeConfigEdits({
35
- filePath: configFile,
36
- edits: [{
37
- operation: "add-plugin",
38
- plugin: artifact.package
39
- }],
40
- extensions: /* @__PURE__ */ new Map([[artifact.package, {
41
- package: artifact.package,
42
- version: artifact.version,
43
- manifest
44
- }]])
45
- });
46
- return outcomes[0]?.applied ? void 0 : outcomes[0]?.reason ?? "the config file was not changed";
47
- } catch (error) {
48
- return require_errors.getErrorMessage(error);
49
- }
50
- }
51
- /**
52
- * Installs an extension from the Kubb registry at its reviewed version and, for a plugin, adds it to
53
- * `kubb.config.ts`. Refuses when the running Kubb or Node.js version is outside its compatibility.
54
- */
55
- async function run({ id: input, configPath, yes, install }) {
56
- const cwd = node_process.default.cwd();
57
- require_output.logIntro({ title: (0, node_util.styleText)("bgCyan", (0, node_util.styleText)("black", " Kubb Add ")) });
58
- try {
59
- const registry = require_registry.registryUrl();
60
- const detail = await require_registry.fetchRegistryDetail({
61
- id: require_registry.toRegistryId(input),
62
- registry
63
- });
64
- const { artifact, manifest } = detail;
65
- const problem = require_registry.incompatibility(manifest);
66
- if (problem) throw new Error(problem);
67
- const spec = require_registry.installSpec(artifact);
68
- const configFile = manifest.kind === "plugin" ? configPath ? node_path.default.resolve(configPath) : require_config.findConfigFile(cwd) : void 0;
69
- if (manifest.kind === "plugin" && !configFile) throw new Error("No kubb.config.ts found. Run `kubb init` first, or pass --config.");
70
- require_output.logInfo(`${(0, node_util.styleText)("cyan", manifest.displayName)} (${manifest.kind}): ${manifest.description}`);
71
- 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`]);
72
- const confirmed = yes || await _clack_prompts.confirm({
73
- message: "Continue?",
74
- initialValue: true
75
- });
76
- if (_clack_prompts.isCancel(confirmed) || !confirmed) {
77
- _clack_prompts.cancel("Operation canceled.");
78
- return;
79
- }
80
- if (install) {
81
- const packageManager = require_utils.detectPackageManager(cwd);
82
- require_output.logStep(`Installing ${spec} with ${packageManager.name}`);
83
- await require_utils.installPackages([spec], packageManager, cwd);
84
- }
85
- const reason = configFile ? await addToConfig({
86
- detail,
87
- configFile
88
- }) : `add the ${manifest.kind} to your config`;
89
- if (!reason) {
90
- require_output.logOutro((0, node_util.styleText)("green", install ? `Added ${spec}` : `Added ${manifest.export}() to the config. Install ${spec} to use it.`));
91
- return;
92
- }
93
- if (configFile) require_output.logWarn(`Could not edit ${configFile}: ${reason}`);
94
- require_output.logBlock([
95
- "Add the import to your Kubb config and merge the property into its defineConfig call:",
96
- "",
97
- toSnippet(detail)
98
- ]);
99
- require_output.logOutro((0, node_util.styleText)("green", install ? `Installed ${spec}. Add it with the snippet above.` : `Install ${spec} and add the snippet above.`));
100
- } catch (error) {
101
- require_output.logError(require_errors.getErrorMessage(error));
102
- node_process.default.exitCode = 1;
103
- }
104
- }
105
- //#endregion
106
- exports.addToConfig = addToConfig;
107
- exports.run = run;
108
-
109
- //# sourceMappingURL=run-Ct6kzKpg.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"run-Ct6kzKpg.cjs","names":["getErrorMessage","process","styleText","registryUrl","fetchRegistryDetail","toRegistryId","incompatibility","installSpec","path","findConfigFile","clack","detectPackageManager","installPackages"],"sources":["../src/runners/add/run.ts"],"sourcesContent":["import path from 'node:path'\nimport process from 'node:process'\nimport { styleText } from 'node:util'\nimport * as clack from '@clack/prompts'\nimport { getErrorMessage } from '@internals/utils'\nimport type { ExtensionManifest, RegistryDetail } from '@kubb/core'\nimport { findConfigFile } from '../../config.ts'\nimport { logBlock, logError, logInfo, logIntro, logOutro, logStep, logWarn } from '../../loggers/output.ts'\nimport { fetchRegistryDetail, incompatibility, installSpec, registryUrl, toRegistryId } from '../../utils/registry.ts'\nimport { detectPackageManager, installPackages } from '../init/utils.ts'\n\nexport type AddOptions = {\n /**\n * `owner/slug`, or a bare `slug` for an official extension.\n */\n id: string\n configPath?: string\n yes: boolean\n install: boolean\n}\n\n/** The import and the `defineConfig` property to merge into `kubb.config.ts` by hand. */\nexport function toSnippet({ artifact, manifest }: Pick<RegistryDetail, 'artifact' | 'manifest'>): string {\n const call = `${manifest.export}()`\n const property: Record<ExtensionManifest['kind'], string> = {\n plugin: `plugins: [..., ${call}],`,\n adapter: `adapter: ${call},`,\n parser: `parsers: [..., ${call}],`,\n }\n return [`import { ${manifest.export} } from '${artifact.package}'`, '', property[manifest.kind]].join('\\n')\n}\n\n/** Adds the plugin call and its import to the config file. Returns why it could not, or `undefined`. */\nexport async function addToConfig({\n detail,\n configFile,\n}: {\n detail: Pick<RegistryDetail, 'artifact' | 'manifest'>\n configFile: string\n}): Promise<string | undefined> {\n const { artifact, manifest } = detail\n try {\n const { writeConfigEdits } = await import('@kubb/studio')\n const { outcomes } = await writeConfigEdits({\n filePath: configFile,\n edits: [{ operation: 'add-plugin', plugin: artifact.package }],\n extensions: new Map([[artifact.package, { package: artifact.package, version: artifact.version, manifest }]]),\n })\n return outcomes[0]?.applied ? undefined : (outcomes[0]?.reason ?? 'the config file was not changed')\n } catch (error) {\n return getErrorMessage(error)\n }\n}\n\n/**\n * Installs an extension from the Kubb registry at its reviewed version and, for a plugin, adds it to\n * `kubb.config.ts`. Refuses when the running Kubb or Node.js version is outside its compatibility.\n */\nexport async function run({ id: input, configPath, yes, install }: AddOptions): Promise<void> {\n const cwd = process.cwd()\n logIntro({ title: styleText('bgCyan', styleText('black', ' Kubb Add ')) })\n\n try {\n const registry = registryUrl()\n const detail = await fetchRegistryDetail({ id: toRegistryId(input), registry })\n const { artifact, manifest } = detail\n\n const problem = incompatibility(manifest)\n if (problem) throw new Error(problem)\n\n const spec = installSpec(artifact)\n const configFile = manifest.kind === 'plugin' ? (configPath ? path.resolve(configPath) : findConfigFile(cwd)) : undefined\n if (manifest.kind === 'plugin' && !configFile) throw new Error('No kubb.config.ts found. Run `kubb init` first, or pass --config.')\n\n logInfo(`${styleText('cyan', manifest.displayName)} (${manifest.kind}): ${manifest.description}`)\n logBlock([\n install ? `Install ${styleText('cyan', spec)} as a dev dependency` : `Skip installing ${spec}`,\n configFile\n ? `Add ${styleText('cyan', `${manifest.export}()`)} to ${path.relative(cwd, configFile) || configFile}`\n : `Print the ${manifest.kind} snippet to add`,\n ])\n\n const confirmed = yes || (await clack.confirm({ message: 'Continue?', initialValue: true }))\n if (clack.isCancel(confirmed) || !confirmed) {\n clack.cancel('Operation canceled.')\n return\n }\n\n if (install) {\n const packageManager = detectPackageManager(cwd)\n logStep(`Installing ${spec} with ${packageManager.name}`)\n await installPackages([spec], packageManager, cwd)\n }\n\n const reason = configFile ? await addToConfig({ detail, configFile }) : `add the ${manifest.kind} to your config`\n if (!reason) {\n logOutro(styleText('green', install ? `Added ${spec}` : `Added ${manifest.export}() to the config. Install ${spec} to use it.`))\n return\n }\n\n if (configFile) logWarn(`Could not edit ${configFile}: ${reason}`)\n logBlock(['Add the import to your Kubb config and merge the property into its defineConfig call:', '', toSnippet(detail)])\n logOutro(styleText('green', install ? `Installed ${spec}. Add it with the snippet above.` : `Install ${spec} and add the snippet above.`))\n } catch (error) {\n logError(getErrorMessage(error))\n process.exitCode = 1\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAsBA,SAAgB,UAAU,EAAE,UAAU,YAAmE;CACvG,MAAM,OAAO,GAAG,SAAS,OAAO;CAChC,MAAM,WAAsD;EAC1D,QAAQ,kBAAkB,KAAK;EAC/B,SAAS,YAAY,KAAK;EAC1B,QAAQ,kBAAkB,KAAK;CACjC;CACA,OAAO;EAAC,YAAY,SAAS,OAAO,WAAW,SAAS,QAAQ;EAAI;EAAI,SAAS,SAAS;CAAK,CAAC,CAAC,KAAK,IAAI;AAC5G;;AAGA,eAAsB,YAAY,EAChC,QACA,cAI8B;CAC9B,MAAM,EAAE,UAAU,aAAa;CAC/B,IAAI;EACF,MAAM,EAAE,qBAAqB,MAAM,OAAO;EAC1C,MAAM,EAAE,aAAa,MAAM,iBAAiB;GAC1C,UAAU;GACV,OAAO,CAAC;IAAE,WAAW;IAAc,QAAQ,SAAS;GAAQ,CAAC;GAC7D,4BAAY,IAAI,IAAI,CAAC,CAAC,SAAS,SAAS;IAAE,SAA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,UAAU,KAAK,eACzF,aAAa,SAAS,KAAK,gBACjC,CAAC;EAED,MAAM,YAAY,OAAQ,MAAME,eAAM,QAAQ;GAAE,SAAS;GAAa,cAAc;EAAK,CAAC;EAC1F,IAAIA,eAAM,SAAS,SAAS,KAAK,CAAC,WAAW;GAC3C,eAAM,OAAO,qBAAqB;GAClC;EACF;EAEA,IAAI,SAAS;GACX,MAAM,iBAAiBC,cAAAA,qBAAqB,GAAG;GAC/C,eAAA,QAAQ,cAAc,KAAK,QAAQ,eAAe,MAAM;GACxD,MAAMC,cAAAA,gBAAgB,CAAC,IAAI,GAAG,gBAAgB,GAAG;EACnD;EAEA,MAAM,SAAS,aAAa,MAAM,YAAY;GAAE;GAAQ;EAAW,CAAC,IAAI,WAAW,SAAS,KAAK;EACjG,IAAI,CAAC,QAAQ;GACX,eAAA,UAAA,GAASV,UAAAA,UAAAA,CAAU,SAAS,UAAU,SAAS,SAAS,SAAS,SAAS,OAAO,4BAA4B,KAAK,YAAY,CAAC;GAC/H;EACF;EAEA,IAAI,YAAY,eAAA,QAAQ,kBAAkB,WAAW,IAAI,QAAQ;EACjE,eAAA,SAAS;GAAC;GAAyF;GAAI,UAAU,MAAM;EAAC,CAAC;EACzH,eAAA,UAAA,GAASA,UAAAA,UAAAA,CAAU,SAAS,UAAU,aAAa,KAAK,oCAAoC,WAAW,KAAK,4BAA4B,CAAC;CAC3I,SAAS,OAAO;EACd,eAAA,SAASF,eAAAA,gBAAgB,KAAK,CAAC;EAC/B,aAAA,QAAA,WAAmB;CACrB;AACF"}
@@ -1,182 +0,0 @@
1
- const require_agent = require("./agent-DElUuYuy.cjs");
2
- const require_constants = require("./constants-Df449N47.cjs");
3
- const require_output = require("./output-BnK0scpX.cjs");
4
- const require_registry = require("./registry-DER9aRyg.cjs");
5
- const require_utils = require("./utils-BzQ46pgd.cjs");
6
- const require_run = require("./run-Ct6kzKpg.cjs");
7
- let node_util = require("node:util");
8
- let node_process = require("node:process");
9
- node_process = require_agent.__toESM(node_process, 1);
10
- let node_path = require("node:path");
11
- node_path = require_agent.__toESM(node_path, 1);
12
- let _clack_prompts = require("@clack/prompts");
13
- _clack_prompts = require_agent.__toESM(_clack_prompts, 1);
14
- let node_fs = require("node:fs");
15
- node_fs = require_agent.__toESM(node_fs, 1);
16
- //#region ../../internals/shared/src/init.ts
17
- function generateConfigFile({ selectedPlugins, inputPath, outputPath }) {
18
- return `${[`import { defineConfig } from 'kubb/config'`, ...selectedPlugins.map((plugin) => `import { ${plugin.importName} } from '${plugin.packageName}'`)].join("\n")}
19
-
20
- export default defineConfig({
21
- input: '${inputPath}',
22
- output: {
23
- path: '${outputPath}',
24
- clean: true,
25
- },
26
- plugins: [
27
- ${selectedPlugins.map((plugin) => ` ${plugin.importName}(),`).join("\n")}
28
- ],
29
- })
30
- `;
31
- }
32
- //#endregion
33
- //#region src/runners/init/run.ts
34
- function cancelAndExit(message = "Operation canceled.") {
35
- _clack_prompts.cancel(message);
36
- node_process.default.exit(0);
37
- }
38
- /**
39
- * Runs the interactive Kubb scaffolding wizard.
40
- * Detects the package manager, prompts for input/output paths and plugins, installs packages, and writes `kubb.config.ts`.
41
- * Pass `yes: true` to skip all prompts and use defaults.
42
- */
43
- async function run({ yes, version, input: inputFlag, output: outputFlag, plugins: pluginsFlag, dryRun }) {
44
- const cwd = node_process.default.cwd();
45
- require_output.logIntro({ title: (0, node_util.styleText)("bgCyan", (0, node_util.styleText)("black", " Kubb Init ")) });
46
- /**
47
- * Returns `flag` when provided, the `defaultValue` when `yes` is set,
48
- * or calls `prompt()` for interactive input. Exits on cancellation.
49
- */
50
- async function resolveOrPrompt(flag, defaultValue, logLabel, prompt) {
51
- if (flag !== void 0) {
52
- require_output.logInfo(`${logLabel}: ${(0, node_util.styleText)("cyan", String(flag))}`);
53
- return flag;
54
- }
55
- if (yes) {
56
- require_output.logInfo(`${logLabel}: ${(0, node_util.styleText)("cyan", String(defaultValue))}`);
57
- return defaultValue;
58
- }
59
- const result = await prompt();
60
- if (_clack_prompts.isCancel(result)) cancelAndExit();
61
- return result;
62
- }
63
- try {
64
- const plugins = (await require_registry.fetchRegistryIndex({ registry: require_registry.registryUrl() })).filter((entry) => entry.kind === "plugin" && !require_registry.incompatibility(entry.manifest));
65
- const byId = new Map(plugins.map((entry) => [entry.id, entry]));
66
- if (!node_fs.default.existsSync(node_path.default.join(cwd, "package.json"))) {
67
- if (!yes) {
68
- const shouldInit = await _clack_prompts.confirm({
69
- message: "No package.json found. Would you like to create one?",
70
- initialValue: true
71
- });
72
- if (_clack_prompts.isCancel(shouldInit) || !shouldInit) cancelAndExit();
73
- }
74
- const packageManager = require_utils.detectPackageManager(cwd);
75
- const spinner = require_output.createSpinner();
76
- spinner.start(`Initializing package.json with ${packageManager.name}`);
77
- await require_utils.initPackageJson(cwd, packageManager);
78
- spinner.stop(`Created package.json with ${packageManager.name}`);
79
- }
80
- const packageManager = require_utils.detectPackageManager(cwd);
81
- require_output.logInfo(`Detected package manager: ${(0, node_util.styleText)("cyan", packageManager.name)}`);
82
- const inputPath = await resolveOrPrompt(inputFlag, require_constants.initDefaults.inputPath, "Using input path", () => _clack_prompts.text({
83
- message: "Where is your OpenAPI specification located?",
84
- placeholder: require_constants.initDefaults.inputPath,
85
- defaultValue: require_constants.initDefaults.inputPath,
86
- validate: (value) => {
87
- if (!value) return "Input path is required";
88
- }
89
- }));
90
- const outputPath = await resolveOrPrompt(outputFlag, require_constants.initDefaults.outputPath, "Using output path", () => _clack_prompts.text({
91
- message: "Where should the generated files be output?",
92
- placeholder: require_constants.initDefaults.outputPath,
93
- defaultValue: require_constants.initDefaults.outputPath,
94
- validate: (value) => {
95
- if (!value) return "Output path is required";
96
- }
97
- }));
98
- const defaultPlugins = require_constants.initDefaults.plugins.flatMap((slug) => byId.get(require_registry.toRegistryId(slug)) ?? []);
99
- const pluginLabel = (entries) => (0, node_util.styleText)("cyan", entries.map((entry) => entry.manifest.displayName).join(", "));
100
- const selectedPlugins = await (async () => {
101
- if (pluginsFlag) {
102
- const ids = pluginsFlag.split(",").map((id) => id.trim()).filter(Boolean);
103
- const unknown = ids.filter((id) => !byId.has(require_registry.toRegistryId(id)));
104
- if (unknown.length) throw new Error(`Not in the Kubb registry: ${unknown.join(", ")}. Browse the plugins at https://kubb.dev/extensions.`);
105
- const entries = ids.map((id) => byId.get(require_registry.toRegistryId(id)));
106
- require_output.logInfo(`Using plugins: ${pluginLabel(entries)}`);
107
- return entries;
108
- }
109
- if (yes) {
110
- require_output.logInfo(`Using plugins: ${pluginLabel(defaultPlugins)}`);
111
- return defaultPlugins;
112
- }
113
- const values = await _clack_prompts.multiselect({
114
- message: "Select plugins to use:",
115
- options: plugins.map(({ id, manifest }) => ({
116
- value: id,
117
- label: manifest.displayName,
118
- hint: manifest.category
119
- })),
120
- initialValues: defaultPlugins.map((entry) => entry.id),
121
- required: true
122
- });
123
- if (_clack_prompts.isCancel(values)) cancelAndExit();
124
- return plugins.filter((entry) => values.includes(entry.id));
125
- })();
126
- const missing = require_utils.missingPluginDependencies({
127
- selected: selectedPlugins.map((entry) => entry.manifest.name),
128
- manifests: selectedPlugins.map((entry) => entry.manifest)
129
- });
130
- if (missing.length) throw new Error(`${missing.join("\n")}\nAdd the missing plugins and run kubb init again.`);
131
- const packagesToInstall = [`${require_constants.KUBB_PACKAGE_NAME}@${version}`, ...selectedPlugins.map((entry) => require_registry.installSpec(entry.artifact))];
132
- const spinner = require_output.createSpinner();
133
- spinner.start(`Installing ${packagesToInstall.length} packages with ${packageManager.name}`);
134
- try {
135
- await dryRun.run(() => require_utils.installPackages(packagesToInstall, packageManager, cwd), { message: `install ${packagesToInstall.length} packages with ${packageManager.name}` });
136
- spinner.stop(`Installed ${packagesToInstall.length} packages`);
137
- } catch (error) {
138
- spinner.stop("Installation failed");
139
- throw error;
140
- }
141
- const configSpinner = require_output.createSpinner();
142
- configSpinner.start(`Creating ${require_constants.KUBB_CONFIG_FILENAME}`);
143
- const configContent = generateConfigFile({
144
- selectedPlugins: [],
145
- inputPath,
146
- outputPath
147
- });
148
- const configPath = node_path.default.join(cwd, require_constants.KUBB_CONFIG_FILENAME);
149
- if (node_fs.default.existsSync(configPath)) {
150
- configSpinner.stop(`${require_constants.KUBB_CONFIG_FILENAME} already exists`);
151
- if (!yes) {
152
- const shouldOverwrite = await _clack_prompts.confirm({
153
- message: `${require_constants.KUBB_CONFIG_FILENAME} already exists. Overwrite?`,
154
- initialValue: false
155
- });
156
- if (_clack_prompts.isCancel(shouldOverwrite) || !shouldOverwrite) cancelAndExit("Keeping existing configuration. Packages have been installed.");
157
- }
158
- configSpinner.start(`Overwriting ${require_constants.KUBB_CONFIG_FILENAME}`);
159
- }
160
- await dryRun.run(() => node_fs.default.promises.writeFile(configPath, configContent, "utf-8"), { message: `write ${require_constants.KUBB_CONFIG_FILENAME}` });
161
- for (const entry of selectedPlugins) {
162
- const reason = await dryRun.run(() => require_run.addToConfig({
163
- detail: entry,
164
- configFile: configPath
165
- }), {
166
- message: `add ${entry.manifest.export}() to ${require_constants.KUBB_CONFIG_FILENAME}`,
167
- resolve: () => void 0
168
- });
169
- if (reason) throw new Error(`Could not add ${entry.manifest.export}() to ${require_constants.KUBB_CONFIG_FILENAME}: ${reason}`);
170
- }
171
- configSpinner.stop(`Created ${require_constants.KUBB_CONFIG_FILENAME}`);
172
- 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${version}`));
173
- } catch (error) {
174
- require_output.logError((0, node_util.styleText)("red", "An error occurred during initialization"));
175
- if (error instanceof Error) require_output.logError(error.message);
176
- node_process.default.exit(1);
177
- }
178
- }
179
- //#endregion
180
- exports.run = run;
181
-
182
- //# sourceMappingURL=run-DL2wLwBZ.cjs.map