@kubb/cli 5.0.0-beta.63 → 5.0.0-beta.65
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/bin/kubb.js +9 -3
- package/dist/{Telemetry-C6rbhJMo.cjs → Telemetry-CfPP7MYq.cjs} +4 -4
- package/dist/{Telemetry-C6rbhJMo.cjs.map → Telemetry-CfPP7MYq.cjs.map} +1 -1
- package/dist/{Telemetry-DTKcvgbx.js → Telemetry-uAr3lK_-.js} +2 -2
- package/dist/{Telemetry-DTKcvgbx.js.map → Telemetry-uAr3lK_-.js.map} +1 -1
- package/dist/{define-C4AB3POr.cjs → defineCommand-Bo3yZTWI.cjs} +3 -21
- package/dist/defineCommand-Bo3yZTWI.cjs.map +1 -0
- package/dist/{define-C63T4jp6.js → defineCommand-DMEeqliP.js} +4 -16
- package/dist/defineCommand-DMEeqliP.js.map +1 -0
- package/dist/{errors-BsemQCMn.js → errors-Dc_d7BfX.js} +2 -2
- package/dist/{errors-BsemQCMn.js.map → errors-Dc_d7BfX.js.map} +1 -1
- package/dist/{errors-DykI11xo.cjs → errors-gxFK0vrp.cjs} +2 -2
- package/dist/{errors-DykI11xo.cjs.map → errors-gxFK0vrp.cjs.map} +1 -1
- package/dist/{generate-DC4--Iha.js → generate-Bv36TZRy.js} +4 -4
- package/dist/{generate-DC4--Iha.js.map → generate-Bv36TZRy.js.map} +1 -1
- package/dist/{generate-Dw7aWzeb.cjs → generate-WczcCx5K.cjs} +4 -4
- package/dist/{generate-Dw7aWzeb.cjs.map → generate-WczcCx5K.cjs.map} +1 -1
- package/dist/index.cjs +27 -62
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +27 -62
- package/dist/index.js.map +1 -1
- package/dist/{init-D2VvDsET.js → init-CK76OU9h.js} +5 -5
- package/dist/{init-D2VvDsET.js.map → init-CK76OU9h.js.map} +1 -1
- package/dist/{init-C7GC2NA8.cjs → init-DrbsCmnm.cjs} +6 -6
- package/dist/{init-C7GC2NA8.cjs.map → init-DrbsCmnm.cjs.map} +1 -1
- package/dist/mcp-CUNv25QY.cjs +21 -0
- package/dist/mcp-CUNv25QY.cjs.map +1 -0
- package/dist/mcp-DN1u2C54.js +21 -0
- package/dist/mcp-DN1u2C54.js.map +1 -0
- package/dist/package-DA31STdg.js +6 -0
- package/dist/package-DA31STdg.js.map +1 -0
- package/dist/{package-IO7JFU8g.cjs → package-IOP3izYE.cjs} +2 -2
- package/dist/package-IOP3izYE.cjs.map +1 -0
- package/dist/{run-DpKny2hT.cjs → run-AYlRjIX5.cjs} +8 -22
- package/dist/run-AYlRjIX5.cjs.map +1 -0
- package/dist/{run-FiqbWZEH.cjs → run-B9pmTHZT.cjs} +55 -62
- package/dist/run-B9pmTHZT.cjs.map +1 -0
- package/dist/{run-D_sbcTfX.cjs → run-BM1t8CSM.cjs} +8 -13
- package/dist/run-BM1t8CSM.cjs.map +1 -0
- package/dist/{run-Ctz9-vGE.js → run-BlFVmIJl.js} +7 -12
- package/dist/run-BlFVmIJl.js.map +1 -0
- package/dist/{run-BoXg14l_.cjs → run-CBc896in.cjs} +5 -5
- package/dist/{run-BoXg14l_.cjs.map → run-CBc896in.cjs.map} +1 -1
- package/dist/{run-BG7Giryi.js → run-D9mQoQHA.js} +4 -18
- package/dist/run-D9mQoQHA.js.map +1 -0
- package/dist/{run-DybX4Hpr.js → run-DTlsUFHr.js} +53 -60
- package/dist/run-DTlsUFHr.js.map +1 -0
- package/dist/{run-Bp8sI6h0.js → run-D_dWNFhX.js} +4 -4
- package/dist/{run-Bp8sI6h0.js.map → run-D_dWNFhX.js.map} +1 -1
- package/dist/{tools-_Xp8-_zy.cjs → tools-CZT9wSA6.cjs} +2 -2
- package/dist/{tools-_Xp8-_zy.cjs.map → tools-CZT9wSA6.cjs.map} +1 -1
- package/dist/{tools-BU99bhi8.js → tools-D0UogMU3.js} +2 -2
- package/dist/{tools-BU99bhi8.js.map → tools-D0UogMU3.js.map} +1 -1
- package/dist/{validate-DVYs1uzP.cjs → validate-BZRFhF5M.cjs} +6 -6
- package/dist/{validate-DVYs1uzP.cjs.map → validate-BZRFhF5M.cjs.map} +1 -1
- package/dist/{validate-C6tYZ5Bd.js → validate-SkDAzU_5.js} +5 -5
- package/dist/{validate-C6tYZ5Bd.js.map → validate-SkDAzU_5.js.map} +1 -1
- package/package.json +7 -8
- package/dist/define-C4AB3POr.cjs.map +0 -1
- package/dist/define-C63T4jp6.js.map +0 -1
- package/dist/mcp-DKPUyzpK.js +0 -39
- package/dist/mcp-DKPUyzpK.js.map +0 -1
- package/dist/mcp-uTUssJam.cjs +0 -39
- package/dist/mcp-uTUssJam.cjs.map +0 -1
- package/dist/package-DCrqV1yP.js +0 -6
- package/dist/package-DCrqV1yP.js.map +0 -1
- package/dist/package-IO7JFU8g.cjs.map +0 -1
- package/dist/run-BG7Giryi.js.map +0 -1
- package/dist/run-Ctz9-vGE.js.map +0 -1
- package/dist/run-D_sbcTfX.cjs.map +0 -1
- package/dist/run-DpKny2hT.cjs.map +0 -1
- package/dist/run-DybX4Hpr.js.map +0 -1
- package/dist/run-FiqbWZEH.cjs.map +0 -1
- package/src/Telemetry.ts +0 -304
- package/src/commands/generate.ts +0 -65
- package/src/commands/init.ts +0 -51
- package/src/commands/mcp.ts +0 -36
- package/src/commands/validate.ts +0 -22
- package/src/constants.ts +0 -19
- package/src/index.ts +0 -32
- package/src/loggers/clackLogger.ts +0 -392
- package/src/loggers/defineLogger.ts +0 -59
- package/src/loggers/plainLogger.ts +0 -199
- package/src/loggers/types.ts +0 -6
- package/src/loggers/utils.ts +0 -250
- package/src/runners/generate/run.ts +0 -399
- package/src/runners/generate/utils.ts +0 -235
- package/src/runners/init/run.ts +0 -210
- package/src/runners/init/utils.ts +0 -39
- package/src/runners/mcp/run.ts +0 -42
- package/src/runners/validate/run.ts +0 -63
- /package/dist/{chunk-Bx3C2hgW.cjs → rolldown-runtime-Bx3C2hgW.cjs} +0 -0
- /package/dist/{chunk-C0LytTxp.js → rolldown-runtime-C0LytTxp.js} +0 -0
package/src/runners/init/run.ts
DELETED
|
@@ -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 closing outro.
|
|
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
|
-
}
|
package/src/runners/mcp/run.ts
DELETED
|
@@ -1,42 +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
|
-
/**
|
|
25
|
-
* Starts the `@kubb/mcp` server and reports the outcome to telemetry.
|
|
26
|
-
*
|
|
27
|
-
* Runs over HTTP when `port` is set, otherwise over stdio.
|
|
28
|
-
*/
|
|
29
|
-
export async function run({ version, port, host }: McpOptions): Promise<void> {
|
|
30
|
-
const { run: startMcpServer } = (await import('@kubb/mcp')) as typeof McpModule
|
|
31
|
-
const hrStart = process.hrtime()
|
|
32
|
-
const report = (status: 'success' | 'failed') => Telemetry.send(Telemetry.build({ command: 'mcp', kubbVersion: version, hrStart, status }))
|
|
33
|
-
try {
|
|
34
|
-
console.log(styleText('cyan', '⏳ Starting MCP server...'))
|
|
35
|
-
console.warn(styleText('yellow', 'This feature is still under development, use with caution'))
|
|
36
|
-
await startMcpServer(undefined, { port: port !== undefined ? Number(port) : undefined, host })
|
|
37
|
-
await report('success')
|
|
38
|
-
} catch (error) {
|
|
39
|
-
await report('failed')
|
|
40
|
-
console.error(getErrorMessage(error))
|
|
41
|
-
}
|
|
42
|
-
}
|
|
@@ -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
|
-
}
|
|
File without changes
|
|
File without changes
|