@kubb/cli 5.0.0-beta.62 → 5.0.0-beta.64

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 (93) hide show
  1. package/bin/kubb.js +9 -3
  2. package/dist/{Telemetry-DrppRqqW.cjs → Telemetry-CfPP7MYq.cjs} +6 -5
  3. package/dist/Telemetry-CfPP7MYq.cjs.map +1 -0
  4. package/dist/{Telemetry-CVdyJarO.js → Telemetry-uAr3lK_-.js} +4 -3
  5. package/dist/Telemetry-uAr3lK_-.js.map +1 -0
  6. package/dist/{define-C4AB3POr.cjs → define-Cq9hOxpK.cjs} +2 -2
  7. package/dist/{define-C4AB3POr.cjs.map → define-Cq9hOxpK.cjs.map} +1 -1
  8. package/dist/{define-C63T4jp6.js → define-GYXr00ky.js} +2 -2
  9. package/dist/{define-C63T4jp6.js.map → define-GYXr00ky.js.map} +1 -1
  10. package/dist/{errors-BsemQCMn.js → errors-Dc_d7BfX.js} +2 -2
  11. package/dist/{errors-BsemQCMn.js.map → errors-Dc_d7BfX.js.map} +1 -1
  12. package/dist/{errors-DykI11xo.cjs → errors-gxFK0vrp.cjs} +2 -2
  13. package/dist/{errors-DykI11xo.cjs.map → errors-gxFK0vrp.cjs.map} +1 -1
  14. package/dist/{generate-BI0qGM4M.js → generate-DHQnl_F1.js} +4 -4
  15. package/dist/{generate-BI0qGM4M.js.map → generate-DHQnl_F1.js.map} +1 -1
  16. package/dist/{generate-C4BcNMRq.cjs → generate-svfhwhEK.cjs} +4 -4
  17. package/dist/{generate-C4BcNMRq.cjs.map → generate-svfhwhEK.cjs.map} +1 -1
  18. package/dist/index.cjs +13 -8
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.ts +6 -1
  21. package/dist/index.js +13 -8
  22. package/dist/index.js.map +1 -1
  23. package/dist/{init-BzS2oVRl.js → init-B02NN_88.js} +5 -5
  24. package/dist/{init-BzS2oVRl.js.map → init-B02NN_88.js.map} +1 -1
  25. package/dist/{init-DbmOhX2-.cjs → init-Bg_68Ok6.cjs} +5 -5
  26. package/dist/{init-DbmOhX2-.cjs.map → init-Bg_68Ok6.cjs.map} +1 -1
  27. package/dist/{mcp-AyUriTgO.cjs → mcp-DUzIXdRV.cjs} +7 -25
  28. package/dist/mcp-DUzIXdRV.cjs.map +1 -0
  29. package/dist/mcp-ZJQksVUU.js +21 -0
  30. package/dist/mcp-ZJQksVUU.js.map +1 -0
  31. package/dist/package-BoXPsuNH.js +6 -0
  32. package/dist/package-BoXPsuNH.js.map +1 -0
  33. package/dist/{package-DXJ46ia8.cjs → package-Cdu8eJMb.cjs} +2 -2
  34. package/dist/package-Cdu8eJMb.cjs.map +1 -0
  35. package/dist/{run-DpKny2hT.cjs → run-B4rIAnch.cjs} +7 -7
  36. package/dist/run-B4rIAnch.cjs.map +1 -0
  37. package/dist/{run-9ZhHuNZQ.cjs → run-BM1t8CSM.cjs} +10 -10
  38. package/dist/run-BM1t8CSM.cjs.map +1 -0
  39. package/dist/{run-h8NTawHO.js → run-BlFVmIJl.js} +9 -9
  40. package/dist/run-BlFVmIJl.js.map +1 -0
  41. package/dist/{run-BQO_tPlc.cjs → run-CBc896in.cjs} +5 -5
  42. package/dist/{run-BQO_tPlc.cjs.map → run-CBc896in.cjs.map} +1 -1
  43. package/dist/{run-Drs-S6sa.cjs → run-CD3BE8yP.cjs} +70 -70
  44. package/dist/run-CD3BE8yP.cjs.map +1 -0
  45. package/dist/{run-CYnDu3ch.js → run-D_dWNFhX.js} +4 -4
  46. package/dist/{run-CYnDu3ch.js.map → run-D_dWNFhX.js.map} +1 -1
  47. package/dist/{run-C_7kOXnc.js → run-DkW2VQBq.js} +68 -68
  48. package/dist/run-DkW2VQBq.js.map +1 -0
  49. package/dist/{run-BG7Giryi.js → run-DzYeru-0.js} +3 -3
  50. package/dist/run-DzYeru-0.js.map +1 -0
  51. package/dist/{tools-_Xp8-_zy.cjs → tools-CZT9wSA6.cjs} +2 -2
  52. package/dist/{tools-_Xp8-_zy.cjs.map → tools-CZT9wSA6.cjs.map} +1 -1
  53. package/dist/{tools-BU99bhi8.js → tools-D0UogMU3.js} +2 -2
  54. package/dist/{tools-BU99bhi8.js.map → tools-D0UogMU3.js.map} +1 -1
  55. package/dist/{validate-CfdPbbz_.cjs → validate-B3EwltHu.cjs} +5 -5
  56. package/dist/{validate-CfdPbbz_.cjs.map → validate-B3EwltHu.cjs.map} +1 -1
  57. package/dist/{validate-jZWMwN4r.js → validate-DXYcZCm_.js} +5 -5
  58. package/dist/{validate-jZWMwN4r.js.map → validate-DXYcZCm_.js.map} +1 -1
  59. package/package.json +7 -8
  60. package/dist/Telemetry-CVdyJarO.js.map +0 -1
  61. package/dist/Telemetry-DrppRqqW.cjs.map +0 -1
  62. package/dist/mcp-AyUriTgO.cjs.map +0 -1
  63. package/dist/mcp-BY4D1lHt.js +0 -39
  64. package/dist/mcp-BY4D1lHt.js.map +0 -1
  65. package/dist/package-BSv0yWfQ.js +0 -6
  66. package/dist/package-BSv0yWfQ.js.map +0 -1
  67. package/dist/package-DXJ46ia8.cjs.map +0 -1
  68. package/dist/run-9ZhHuNZQ.cjs.map +0 -1
  69. package/dist/run-BG7Giryi.js.map +0 -1
  70. package/dist/run-C_7kOXnc.js.map +0 -1
  71. package/dist/run-DpKny2hT.cjs.map +0 -1
  72. package/dist/run-Drs-S6sa.cjs.map +0 -1
  73. package/dist/run-h8NTawHO.js.map +0 -1
  74. package/src/Telemetry.ts +0 -297
  75. package/src/commands/generate.ts +0 -65
  76. package/src/commands/init.ts +0 -51
  77. package/src/commands/mcp.ts +0 -36
  78. package/src/commands/validate.ts +0 -22
  79. package/src/constants.ts +0 -19
  80. package/src/index.ts +0 -27
  81. package/src/loggers/clackLogger.ts +0 -392
  82. package/src/loggers/defineLogger.ts +0 -59
  83. package/src/loggers/plainLogger.ts +0 -199
  84. package/src/loggers/types.ts +0 -6
  85. package/src/loggers/utils.ts +0 -249
  86. package/src/runners/generate/run.ts +0 -399
  87. package/src/runners/generate/utils.ts +0 -229
  88. package/src/runners/init/run.ts +0 -210
  89. package/src/runners/init/utils.ts +0 -39
  90. package/src/runners/mcp/run.ts +0 -37
  91. package/src/runners/validate/run.ts +0 -63
  92. /package/dist/{chunk-Bx3C2hgW.cjs → rolldown-runtime-Bx3C2hgW.cjs} +0 -0
  93. /package/dist/{chunk-C0LytTxp.js → rolldown-runtime-C0LytTxp.js} +0 -0
@@ -1,210 +0,0 @@
1
- import fs from 'node:fs'
2
- import path from 'node:path'
3
- import process from 'node:process'
4
- import { styleText } from 'node:util'
5
- import * as clack from '@clack/prompts'
6
- import { detectPackageManager } from '@internals/utils'
7
- import { availablePlugins, generateConfigFile, initDefaults, KUBB_CONFIG_FILENAME, type PluginOption } from '@internals/shared'
8
- import { hasPackageJson, initPackageJson, installPackages } from './utils.ts'
9
-
10
- function cancelAndExit(message = 'Operation canceled.'): never {
11
- clack.cancel(message)
12
- process.exit(0)
13
- }
14
-
15
- type InitOptions = {
16
- /**
17
- * When `true`, skips all interactive prompts and uses default values.
18
- */
19
- yes: boolean
20
- /**
21
- * Current `@kubb/cli` version string, shown in the outro and used for package installation.
22
- */
23
- version: string
24
- /**
25
- * Input path flag value from `--input`. When provided, skips the input prompt.
26
- */
27
- input?: string
28
- /**
29
- * Output directory flag value from `--output`. When provided, skips the output prompt.
30
- */
31
- output?: string
32
- /**
33
- * Comma-separated plugin list from `--plugins`, e.g. `'plugin-ts,plugin-zod'`. When provided, skips the plugin selection prompt.
34
- */
35
- plugins?: string
36
- }
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
- export async function run({ yes, version, input: inputFlag, output: outputFlag, plugins: pluginsFlag }: InitOptions): Promise<void> {
44
- const cwd = process.cwd()
45
-
46
- clack.intro(styleText('bgCyan', styleText('black', ' Kubb Init ')))
47
-
48
- /**
49
- * Returns `flag` when provided, the `defaultValue` when `yes` is set,
50
- * or calls `prompt()` for interactive input. Exits on cancellation.
51
- */
52
- async function resolveOrPrompt<T>(flag: T | undefined, defaultValue: T, logLabel: string, prompt: () => Promise<T | symbol>): Promise<T> {
53
- if (flag !== undefined) {
54
- clack.log.info(`${logLabel}: ${styleText('cyan', String(flag))}`)
55
- return flag
56
- }
57
- if (yes) {
58
- clack.log.info(`${logLabel}: ${styleText('cyan', String(defaultValue))}`)
59
- return defaultValue
60
- }
61
- const result = await prompt()
62
- if (clack.isCancel(result)) cancelAndExit()
63
- return result as T
64
- }
65
-
66
- try {
67
- // Check/create package.json, detect package manager once after the block
68
- if (!hasPackageJson(cwd)) {
69
- if (!yes) {
70
- const shouldInit = await clack.confirm({
71
- message: 'No package.json found. Would you like to create one?',
72
- initialValue: true,
73
- })
74
-
75
- if (clack.isCancel(shouldInit) || !shouldInit) {
76
- cancelAndExit()
77
- }
78
- }
79
-
80
- const packageManager = detectPackageManager(cwd)
81
- const spinner = clack.spinner()
82
- spinner.start(`Initializing package.json with ${packageManager.name}`)
83
- await initPackageJson(cwd, packageManager)
84
- spinner.stop(`Created package.json with ${packageManager.name}`)
85
- }
86
-
87
- const packageManager = detectPackageManager(cwd)
88
- if (hasPackageJson(cwd)) {
89
- clack.log.info(`Detected package manager: ${styleText('cyan', packageManager.name)}`)
90
- }
91
-
92
- // Prompt for OpenAPI spec path
93
- const inputPath = await resolveOrPrompt(inputFlag, initDefaults.inputPath, 'Using input path', () =>
94
- clack.text({
95
- message: 'Where is your OpenAPI specification located?',
96
- placeholder: initDefaults.inputPath,
97
- defaultValue: initDefaults.inputPath,
98
- validate: (value) => {
99
- if (!value) return 'Input path is required'
100
- },
101
- }),
102
- )
103
-
104
- // Prompt for output directory
105
- const outputPath = await resolveOrPrompt(outputFlag, initDefaults.outputPath, 'Using output path', () =>
106
- clack.text({
107
- message: 'Where should the generated files be output?',
108
- placeholder: initDefaults.outputPath,
109
- defaultValue: initDefaults.outputPath,
110
- validate: (value) => {
111
- if (!value) return 'Output path is required'
112
- },
113
- }),
114
- )
115
-
116
- // Plugin selection
117
- const defaultPlugins = availablePlugins.filter((p) => (initDefaults.plugins as ReadonlyArray<string>).includes(p.value))
118
- const pluginLabel = (plugins: Array<PluginOption>) => styleText('cyan', plugins.map((p) => p.label).join(', '))
119
-
120
- const selectedPlugins: Array<PluginOption> = await (async () => {
121
- if (pluginsFlag) {
122
- const requested = pluginsFlag
123
- .split(',')
124
- .map((v) => v.trim())
125
- .filter(Boolean)
126
- const plugins = availablePlugins.filter((p) => requested.includes(p.value))
127
- if (plugins.length === 0) {
128
- clack.log.warn(`No valid plugins found in --plugins value; falling back to default: ${pluginLabel(defaultPlugins)}`)
129
- return defaultPlugins
130
- }
131
- clack.log.info(`Using plugins: ${pluginLabel(plugins)}`)
132
- return plugins
133
- }
134
- if (yes) {
135
- clack.log.info(`Using plugins: ${pluginLabel(defaultPlugins)}`)
136
- return defaultPlugins
137
- }
138
- const values = await clack.multiselect({
139
- message: 'Select plugins to use:',
140
- options: availablePlugins.map(({ value, label, hint }) => ({ value, label, hint })),
141
- initialValues: [...initDefaults.plugins],
142
- required: true,
143
- })
144
- if (clack.isCancel(values)) cancelAndExit()
145
- return availablePlugins.filter((p) => (values as Array<string>).includes(p.value))
146
- })()
147
-
148
- // Install packages
149
- const packagesToInstall = ['kubb', ...selectedPlugins.map((p) => p.packageName)]
150
-
151
- const spinner = clack.spinner()
152
- spinner.start(`Installing ${packagesToInstall.length} packages with ${packageManager.name}`)
153
-
154
- try {
155
- await installPackages(packagesToInstall, packageManager, cwd)
156
- spinner.stop(`Installed ${packagesToInstall.length} packages`)
157
- } catch (error) {
158
- spinner.stop('Installation failed')
159
- throw error
160
- }
161
-
162
- // Generate config file
163
- const configSpinner = clack.spinner()
164
- configSpinner.start(`Creating ${KUBB_CONFIG_FILENAME}`)
165
-
166
- const configContent = generateConfigFile({ selectedPlugins, inputPath, outputPath })
167
- const configPath = path.join(cwd, KUBB_CONFIG_FILENAME)
168
-
169
- if (fs.existsSync(configPath)) {
170
- configSpinner.stop(`${KUBB_CONFIG_FILENAME} already exists`)
171
-
172
- if (!yes) {
173
- const shouldOverwrite = await clack.confirm({
174
- message: `${KUBB_CONFIG_FILENAME} already exists. Overwrite?`,
175
- initialValue: false,
176
- })
177
-
178
- if (clack.isCancel(shouldOverwrite) || !shouldOverwrite) {
179
- cancelAndExit('Keeping existing configuration. Packages have been installed.')
180
- }
181
- }
182
-
183
- configSpinner.start(`Overwriting ${KUBB_CONFIG_FILENAME}`)
184
- }
185
-
186
- await fs.promises.writeFile(configPath, configContent, 'utf-8')
187
-
188
- configSpinner.stop(`Created ${KUBB_CONFIG_FILENAME}`)
189
-
190
- clack.outro(
191
- styleText('green', '✓ All set!') +
192
- '\n\n' +
193
- styleText('dim', 'Next steps:') +
194
- '\n' +
195
- styleText('cyan', ` 1. Make sure your OpenAPI spec is at: ${inputPath}`) +
196
- '\n' +
197
- styleText('cyan', ' 2. Generate code with: npx kubb generate') +
198
- '\n' +
199
- styleText('cyan', ` 3. Find generated files in: ${outputPath}`) +
200
- '\n\n' +
201
- styleText('dim', `Using ${packageManager.name} • Kubb v${version}`),
202
- )
203
- } catch (error) {
204
- clack.log.error(styleText('red', 'An error occurred during initialization'))
205
- if (error instanceof Error) {
206
- clack.log.error(error.message)
207
- }
208
- process.exit(1)
209
- }
210
- }
@@ -1,39 +0,0 @@
1
- import fs from 'node:fs'
2
- import path from 'node:path'
3
- import process from 'node:process'
4
- import type { PackageManagerInfo, PackageManagerName } from '@internals/utils'
5
- import { x } from 'tinyexec'
6
-
7
- /**
8
- * Returns `true` when a `package.json` exists at `cwd`.
9
- */
10
- export function hasPackageJson(cwd: string = process.cwd()): boolean {
11
- return fs.existsSync(path.join(cwd, 'package.json'))
12
- }
13
-
14
- /**
15
- * Initializes a new `package.json` at `cwd` using the detected package manager.
16
- */
17
- export async function initPackageJson(cwd: string, packageManager: PackageManagerInfo): Promise<void> {
18
- const commands: Record<PackageManagerName, Array<string>> = {
19
- npm: ['init', '-y'],
20
- pnpm: ['init'],
21
- yarn: ['init', '-y'],
22
- bun: ['init', '-y'],
23
- }
24
-
25
- await x(packageManager.name, commands[packageManager.name], {
26
- nodeOptions: { cwd, stdio: 'inherit' },
27
- throwOnError: true,
28
- })
29
- }
30
-
31
- /**
32
- * Installs the given packages at `cwd` using the detected package manager.
33
- */
34
- export async function installPackages(packages: Array<string>, packageManager: PackageManagerInfo, cwd: string = process.cwd()): Promise<void> {
35
- await x(packageManager.name, [...packageManager.installCommand, ...packages], {
36
- nodeOptions: { cwd, stdio: 'inherit' },
37
- throwOnError: true,
38
- })
39
- }
@@ -1,37 +0,0 @@
1
- import process from 'node:process'
2
- import { styleText } from 'node:util'
3
- import { getErrorMessage } from '@internals/utils'
4
- import { Telemetry } from '../../Telemetry.ts'
5
- import type * as McpModule from '@kubb/mcp'
6
-
7
- type McpOptions = {
8
- /**
9
- * Current `@kubb/cli` version string, used for the telemetry payload.
10
- */
11
- version: string
12
- /**
13
- * TCP port for the HTTP MCP server. When `undefined`, the server uses stdio transport.
14
- */
15
- port?: string
16
- /**
17
- * Hostname to bind to when running in HTTP mode.
18
- *
19
- * @default 'localhost'
20
- */
21
- host?: string
22
- }
23
-
24
- export async function run({ version, port, host }: McpOptions): Promise<void> {
25
- const { run: startMcpServer } = (await import('@kubb/mcp')) as typeof McpModule
26
- const hrStart = process.hrtime()
27
- const report = (status: 'success' | 'failed') => Telemetry.send(Telemetry.build({ command: 'mcp', kubbVersion: version, hrStart, status }))
28
- try {
29
- console.log(styleText('cyan', '⏳ Starting MCP server...'))
30
- console.warn(styleText('yellow', 'This feature is still under development, use with caution'))
31
- await startMcpServer(undefined, { port: port !== undefined ? Number(port) : undefined, host })
32
- await report('success')
33
- } catch (error) {
34
- await report('failed')
35
- console.error(getErrorMessage(error))
36
- }
37
- }
@@ -1,63 +0,0 @@
1
- import process from 'node:process'
2
- import { styleText } from 'node:util'
3
- import { getErrorMessage } from '@internals/utils'
4
- import { Telemetry } from '../../Telemetry.ts'
5
-
6
- type ValidateOptions = {
7
- /**
8
- * Path or URL to the OpenAPI/Swagger file to validate.
9
- */
10
- input: string
11
- /**
12
- * Current `@kubb/cli` version string, used for the telemetry payload.
13
- */
14
- version: string
15
- }
16
-
17
- type ValidateModule = typeof import('@kubb/adapter-oas')
18
- type ValidateDependencies = {
19
- /**
20
- * Loads `@kubb/adapter-oas`. Injected so tests can substitute a mock.
21
- */
22
- loadValidateModule: () => Promise<ValidateModule>
23
- }
24
-
25
- /**
26
- * Dynamically loads `@kubb/adapter-oas` for OpenAPI validation.
27
- */
28
- export function loadValidateModule(): Promise<ValidateModule> {
29
- return import('@kubb/adapter-oas') as Promise<ValidateModule>
30
- }
31
-
32
- /**
33
- * Validates an OpenAPI/Swagger file at `input` using `@kubb/adapter-oas`.
34
- * Exits the process with code 1 on validation failure or missing dependency.
35
- */
36
- export async function run({ input, version }: ValidateOptions, dependencies: ValidateDependencies = { loadValidateModule }): Promise<void> {
37
- const hrStart = process.hrtime()
38
- const report = (status: 'success' | 'failed') => Telemetry.send(Telemetry.build({ command: 'validate', kubbVersion: version, hrStart, status }))
39
- try {
40
- const { adapterOas } = await dependencies.loadValidateModule()
41
- const adapter = adapterOas()
42
- if (!adapter.validate) {
43
- throw new Error('The loaded adapter does not support validation.')
44
- }
45
- await adapter.validate(input, { throwOnError: true })
46
- await report('success')
47
- console.log('✅ Validation success')
48
- } catch (error) {
49
- await report('failed')
50
- if (error instanceof Error && /@kubb\/adapter-oas/.test(error.message)) {
51
- console.error(styleText('red', 'The @kubb/adapter-oas package is not installed.'))
52
- console.error('')
53
- console.error('Install it with:')
54
- console.error(styleText('cyan', ' npm install @kubb/adapter-oas'))
55
- console.error(styleText('cyan', ' # or'))
56
- console.error(styleText('cyan', ' pnpm install @kubb/adapter-oas'))
57
- console.error('')
58
- }
59
- console.error('❌ Validation failed')
60
- console.error(getErrorMessage(error))
61
- process.exit(1)
62
- }
63
- }