@kubb/cli 5.0.0-alpha.9 → 5.0.0-beta.10

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 (173) hide show
  1. package/README.md +180 -27
  2. package/bin/kubb.js +6 -0
  3. package/dist/agent-Bx2yllmS.js +68 -0
  4. package/dist/agent-Bx2yllmS.js.map +1 -0
  5. package/dist/agent-CeLwj5im.cjs +70 -0
  6. package/dist/agent-CeLwj5im.cjs.map +1 -0
  7. package/dist/{chunk--u3MIqq1.js → chunk-BvFE5Tac.js} +1 -0
  8. package/dist/constants-B2JTeRBb.js +42 -0
  9. package/dist/constants-B2JTeRBb.js.map +1 -0
  10. package/dist/constants-BINTA5VZ.cjs +77 -0
  11. package/dist/constants-BINTA5VZ.cjs.map +1 -0
  12. package/dist/constants-BYGmiFs0.cjs +139 -0
  13. package/dist/constants-BYGmiFs0.cjs.map +1 -0
  14. package/dist/constants-DSJ-Xrbv.js +116 -0
  15. package/dist/constants-DSJ-Xrbv.js.map +1 -0
  16. package/dist/define-Bdn8j5VM.cjs +54 -0
  17. package/dist/define-Bdn8j5VM.cjs.map +1 -0
  18. package/dist/define-m_fp-Aqm.js +43 -0
  19. package/dist/define-m_fp-Aqm.js.map +1 -0
  20. package/dist/errors-CINO1EIv.js +43 -0
  21. package/dist/errors-CINO1EIv.js.map +1 -0
  22. package/dist/{errors-DBW0N9w4.cjs → errors-CLCjoSg0.cjs} +22 -6
  23. package/dist/errors-CLCjoSg0.cjs.map +1 -0
  24. package/dist/{generate-Rly1EXBN.js → generate-BLvcvoIj.js} +12 -6
  25. package/dist/generate-BLvcvoIj.js.map +1 -0
  26. package/dist/{generate-DU5zzc54.cjs → generate-drLxTAnz.cjs} +11 -5
  27. package/dist/generate-drLxTAnz.cjs.map +1 -0
  28. package/dist/index.cjs +52 -21
  29. package/dist/index.cjs.map +1 -1
  30. package/dist/index.d.ts +1 -1
  31. package/dist/index.js +53 -22
  32. package/dist/index.js.map +1 -1
  33. package/dist/init-CGu7JZEF.js +53 -0
  34. package/dist/init-CGu7JZEF.js.map +1 -0
  35. package/dist/init-CyCjvIEF.cjs +53 -0
  36. package/dist/init-CyCjvIEF.cjs.map +1 -0
  37. package/dist/mcp-Cq2sylQC.js +39 -0
  38. package/dist/mcp-Cq2sylQC.js.map +1 -0
  39. package/dist/mcp-DSF5gpI-.cjs +39 -0
  40. package/dist/mcp-DSF5gpI-.cjs.map +1 -0
  41. package/dist/{package-BJ6ionm6.cjs → package-DZ-6zAIO.cjs} +2 -2
  42. package/dist/package-DZ-6zAIO.cjs.map +1 -0
  43. package/dist/package-OLYIpjqw.js +6 -0
  44. package/dist/package-OLYIpjqw.js.map +1 -0
  45. package/dist/{generate-BHNyeQXl.js → run-Bfbr3RaM.js} +781 -502
  46. package/dist/run-Bfbr3RaM.js.map +1 -0
  47. package/dist/run-BzpYYOQs.js +121 -0
  48. package/dist/run-BzpYYOQs.js.map +1 -0
  49. package/dist/run-CCZ24VKk.js +51 -0
  50. package/dist/run-CCZ24VKk.js.map +1 -0
  51. package/dist/run-CF97BWVa.js +244 -0
  52. package/dist/run-CF97BWVa.js.map +1 -0
  53. package/dist/run-CQbj3ley.cjs +52 -0
  54. package/dist/run-CQbj3ley.cjs.map +1 -0
  55. package/dist/{generate-Cq5RDTBL.cjs → run-CVlrIZoW.cjs} +786 -507
  56. package/dist/run-CVlrIZoW.cjs.map +1 -0
  57. package/dist/run-D0hmRpHy.js +49 -0
  58. package/dist/run-D0hmRpHy.js.map +1 -0
  59. package/dist/run-DwdAwnLG.cjs +125 -0
  60. package/dist/run-DwdAwnLG.cjs.map +1 -0
  61. package/dist/run-Lr0Ctnu0.cjs +50 -0
  62. package/dist/run-Lr0Ctnu0.cjs.map +1 -0
  63. package/dist/run-YsoCk5we.cjs +248 -0
  64. package/dist/run-YsoCk5we.cjs.map +1 -0
  65. package/dist/{shell-7HPrTCJ5.cjs → shell-475fQKaX.cjs} +8 -3
  66. package/dist/shell-475fQKaX.cjs.map +1 -0
  67. package/dist/{shell-DqqWsHCD.js → shell-CN6DNqeC.js} +9 -4
  68. package/dist/shell-CN6DNqeC.js.map +1 -0
  69. package/dist/{telemetry-DZ7IrLAU.cjs → telemetry-B2iWkY5e.cjs} +53 -13
  70. package/dist/telemetry-B2iWkY5e.cjs.map +1 -0
  71. package/dist/{telemetry-BF3SMlH6.js → telemetry-BkektVz6.js} +52 -12
  72. package/dist/telemetry-BkektVz6.js.map +1 -0
  73. package/dist/validate-CAUqLaGt.js +26 -0
  74. package/dist/validate-CAUqLaGt.js.map +1 -0
  75. package/dist/validate-J6AEd5zK.cjs +26 -0
  76. package/dist/validate-J6AEd5zK.cjs.map +1 -0
  77. package/package.json +57 -48
  78. package/src/commands/agent/start.ts +27 -8
  79. package/src/commands/agent.ts +3 -1
  80. package/src/commands/generate.ts +39 -8
  81. package/src/commands/init.ts +40 -4
  82. package/src/commands/mcp.ts +28 -4
  83. package/src/commands/validate.ts +11 -4
  84. package/src/constants.ts +5 -80
  85. package/src/index.ts +12 -13
  86. package/src/loggers/clackLogger.ts +98 -88
  87. package/src/loggers/fileSystemLogger.ts +37 -25
  88. package/src/loggers/githubActionsLogger.ts +35 -48
  89. package/src/loggers/plainLogger.ts +33 -45
  90. package/src/loggers/types.ts +6 -0
  91. package/src/loggers/utils.ts +155 -9
  92. package/src/runners/agent/run.ts +113 -0
  93. package/src/runners/agent/utils.ts +98 -0
  94. package/src/runners/generate/run.ts +276 -0
  95. package/src/runners/generate/utils.ts +209 -0
  96. package/src/runners/init/run.ts +211 -0
  97. package/src/{utils/packageManager.ts → runners/init/utils.ts} +10 -0
  98. package/src/runners/mcp/run.ts +55 -0
  99. package/src/runners/validate/run.ts +63 -0
  100. package/src/{utils/telemetry.ts → telemetry.ts} +28 -8
  101. package/bin/kubb.cjs +0 -18
  102. package/dist/agent-5mmp7QzF.js +0 -56
  103. package/dist/agent-5mmp7QzF.js.map +0 -1
  104. package/dist/agent-BKphjOIF.cjs +0 -58
  105. package/dist/agent-BKphjOIF.cjs.map +0 -1
  106. package/dist/agent-BapvKB4r.cjs +0 -92
  107. package/dist/agent-BapvKB4r.cjs.map +0 -1
  108. package/dist/agent-CBrpIMMU.js +0 -88
  109. package/dist/agent-CBrpIMMU.js.map +0 -1
  110. package/dist/constants-D0XHAHeZ.cjs +0 -178
  111. package/dist/constants-D0XHAHeZ.cjs.map +0 -1
  112. package/dist/constants-DJM9zCXm.js +0 -131
  113. package/dist/constants-DJM9zCXm.js.map +0 -1
  114. package/dist/define--M_JMcDC.js +0 -25
  115. package/dist/define--M_JMcDC.js.map +0 -1
  116. package/dist/define-D6Kfm7-Z.cjs +0 -36
  117. package/dist/define-D6Kfm7-Z.cjs.map +0 -1
  118. package/dist/errors-6mF_WKxg.js +0 -27
  119. package/dist/errors-6mF_WKxg.js.map +0 -1
  120. package/dist/errors-DBW0N9w4.cjs.map +0 -1
  121. package/dist/generate-BHNyeQXl.js.map +0 -1
  122. package/dist/generate-Cq5RDTBL.cjs.map +0 -1
  123. package/dist/generate-DU5zzc54.cjs.map +0 -1
  124. package/dist/generate-Rly1EXBN.js.map +0 -1
  125. package/dist/init-BK6inBTR.cjs +0 -306
  126. package/dist/init-BK6inBTR.cjs.map +0 -1
  127. package/dist/init-BQ6zfsnw.js +0 -302
  128. package/dist/init-BQ6zfsnw.js.map +0 -1
  129. package/dist/init-CN1JFyGX.cjs +0 -25
  130. package/dist/init-CN1JFyGX.cjs.map +0 -1
  131. package/dist/init-iN7e1XwI.js +0 -25
  132. package/dist/init-iN7e1XwI.js.map +0 -1
  133. package/dist/jiti-Cd3S0xwr.cjs +0 -16
  134. package/dist/jiti-Cd3S0xwr.cjs.map +0 -1
  135. package/dist/jiti-e08mD2Ph.js +0 -11
  136. package/dist/jiti-e08mD2Ph.js.map +0 -1
  137. package/dist/mcp-BiGUvbWP.js +0 -41
  138. package/dist/mcp-BiGUvbWP.js.map +0 -1
  139. package/dist/mcp-CONmm_xT.cjs +0 -42
  140. package/dist/mcp-CONmm_xT.cjs.map +0 -1
  141. package/dist/mcp-T7Q4nWbT.cjs +0 -16
  142. package/dist/mcp-T7Q4nWbT.cjs.map +0 -1
  143. package/dist/mcp-eP1S40LZ.js +0 -16
  144. package/dist/mcp-eP1S40LZ.js.map +0 -1
  145. package/dist/package-BJ6ionm6.cjs.map +0 -1
  146. package/dist/package-BKZ0H3Zf.js +0 -6
  147. package/dist/package-BKZ0H3Zf.js.map +0 -1
  148. package/dist/shell-7HPrTCJ5.cjs.map +0 -1
  149. package/dist/shell-DqqWsHCD.js.map +0 -1
  150. package/dist/telemetry-BF3SMlH6.js.map +0 -1
  151. package/dist/telemetry-DZ7IrLAU.cjs.map +0 -1
  152. package/dist/validate-BImbbx1t.js +0 -41
  153. package/dist/validate-BImbbx1t.js.map +0 -1
  154. package/dist/validate-DAZdX_0i.js +0 -25
  155. package/dist/validate-DAZdX_0i.js.map +0 -1
  156. package/dist/validate-DucFMytl.cjs +0 -25
  157. package/dist/validate-DucFMytl.cjs.map +0 -1
  158. package/dist/validate-ujLCYSWU.cjs +0 -42
  159. package/dist/validate-ujLCYSWU.cjs.map +0 -1
  160. package/src/runners/agent.ts +0 -102
  161. package/src/runners/generate.ts +0 -343
  162. package/src/runners/init.ts +0 -323
  163. package/src/runners/mcp.ts +0 -32
  164. package/src/runners/validate.ts +0 -35
  165. package/src/types.ts +0 -11
  166. package/src/utils/Writables.ts +0 -17
  167. package/src/utils/executeHooks.ts +0 -45
  168. package/src/utils/flags.ts +0 -10
  169. package/src/utils/getCosmiConfig.ts +0 -71
  170. package/src/utils/getSummary.ts +0 -68
  171. package/src/utils/jiti.ts +0 -9
  172. package/src/utils/runHook.ts +0 -75
  173. package/src/utils/watcher.ts +0 -19
@@ -1,323 +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 type { PackageManagerInfo } from '@internals/utils'
7
- import { detectPackageManager } from '@internals/utils'
8
- import { initDefaults, pluginDefaultConfigs } from '../constants.ts'
9
- import { hasPackageJson, initPackageJson, installPackages } from '../utils/packageManager.ts'
10
-
11
- type PluginOption = {
12
- value: string
13
- label: string
14
- hint?: string
15
- packageName: string
16
- importName: string
17
- category: 'core' | 'typescript' | 'query' | 'validation' | 'testing' | 'mocking' | 'docs'
18
- }
19
-
20
- const availablePlugins: PluginOption[] = [
21
- {
22
- value: 'plugin-oas',
23
- label: 'OpenAPI Parser',
24
- hint: 'Required',
25
- packageName: '@kubb/plugin-oas',
26
- importName: 'pluginOas',
27
- category: 'core',
28
- },
29
- {
30
- value: 'plugin-ts',
31
- label: 'TypeScript',
32
- hint: 'Recommended',
33
- packageName: '@kubb/plugin-ts',
34
- importName: 'pluginTs',
35
- category: 'typescript',
36
- },
37
- {
38
- value: 'plugin-client',
39
- label: 'Client (Fetch/Axios)',
40
- packageName: '@kubb/plugin-client',
41
- importName: 'pluginClient',
42
- category: 'typescript',
43
- },
44
- {
45
- value: 'plugin-react-query',
46
- label: 'React Query / TanStack Query',
47
- packageName: '@kubb/plugin-react-query',
48
- importName: 'pluginReactQuery',
49
- category: 'query',
50
- },
51
- {
52
- value: 'plugin-solid-query',
53
- label: 'Solid Query',
54
- packageName: '@kubb/plugin-solid-query',
55
- importName: 'pluginSolidQuery',
56
- category: 'query',
57
- },
58
- {
59
- value: 'plugin-svelte-query',
60
- label: 'Svelte Query',
61
- packageName: '@kubb/plugin-svelte-query',
62
- importName: 'pluginSvelteQuery',
63
- category: 'query',
64
- },
65
- {
66
- value: 'plugin-vue-query',
67
- label: 'Vue Query',
68
- packageName: '@kubb/plugin-vue-query',
69
- importName: 'pluginVueQuery',
70
- category: 'query',
71
- },
72
- {
73
- value: 'plugin-swr',
74
- label: 'SWR',
75
- packageName: '@kubb/plugin-swr',
76
- importName: 'pluginSwr',
77
- category: 'query',
78
- },
79
- {
80
- value: 'plugin-zod',
81
- label: 'Zod Schemas',
82
- packageName: '@kubb/plugin-zod',
83
- importName: 'pluginZod',
84
- category: 'validation',
85
- },
86
- {
87
- value: 'plugin-faker',
88
- label: 'Faker.js Mocks',
89
- packageName: '@kubb/plugin-faker',
90
- importName: 'pluginFaker',
91
- category: 'mocking',
92
- },
93
- {
94
- value: 'plugin-msw',
95
- label: 'MSW Handlers',
96
- packageName: '@kubb/plugin-msw',
97
- importName: 'pluginMsw',
98
- category: 'mocking',
99
- },
100
- {
101
- value: 'plugin-cypress',
102
- label: 'Cypress Tests',
103
- packageName: '@kubb/plugin-cypress',
104
- importName: 'pluginCypress',
105
- category: 'testing',
106
- },
107
- {
108
- value: 'plugin-redoc',
109
- label: 'ReDoc Documentation',
110
- packageName: '@kubb/plugin-redoc',
111
- importName: 'pluginRedoc',
112
- category: 'docs',
113
- },
114
- ]
115
-
116
- function generateConfigFile(selectedPlugins: PluginOption[], inputPath: string, outputPath: string): string {
117
- const imports = selectedPlugins.map((plugin) => `import { ${plugin.importName} } from '${plugin.packageName}'`).join('\n')
118
-
119
- const pluginConfigs = selectedPlugins
120
- .map((plugin) => {
121
- const config = (pluginDefaultConfigs as Record<string, string>)[plugin.value] ?? `${plugin.importName}()`
122
- return ` ${config},`
123
- })
124
- .join('\n')
125
-
126
- return `import { defineConfig } from '@kubb/core'
127
- ${imports}
128
-
129
- export default defineConfig({
130
- root: '.',
131
- input: {
132
- path: '${inputPath}',
133
- },
134
- output: {
135
- path: '${outputPath}',
136
- clean: true,
137
- },
138
- plugins: [
139
- ${pluginConfigs}
140
- ],
141
- })
142
- `
143
- }
144
-
145
- function cancelAndExit(message = 'Operation cancelled.'): never {
146
- clack.cancel(message)
147
- process.exit(0)
148
- }
149
-
150
- type InitOptions = {
151
- yes: boolean
152
- version: string
153
- }
154
-
155
- export async function runInit({ yes, version }: InitOptions): Promise<void> {
156
- const cwd = process.cwd()
157
-
158
- clack.intro(styleText('bgCyan', styleText('black', ' Kubb Init ')))
159
-
160
- try {
161
- // Check/create package.json
162
- let packageManager: PackageManagerInfo
163
- if (!hasPackageJson(cwd)) {
164
- if (!yes) {
165
- const shouldInit = await clack.confirm({
166
- message: 'No package.json found. Would you like to create one?',
167
- initialValue: true,
168
- })
169
-
170
- if (clack.isCancel(shouldInit) || !shouldInit) {
171
- cancelAndExit()
172
- }
173
- }
174
-
175
- packageManager = detectPackageManager(cwd)
176
-
177
- const spinner = clack.spinner()
178
- spinner.start(`Initializing package.json with ${packageManager.name}`)
179
-
180
- await initPackageJson(cwd, packageManager)
181
-
182
- spinner.stop(`Created package.json with ${packageManager.name}`)
183
- } else {
184
- packageManager = detectPackageManager(cwd)
185
- clack.log.info(`Detected package manager: ${styleText('cyan', packageManager.name)}`)
186
- }
187
-
188
- // Prompt for OpenAPI spec path
189
- let inputPath: string
190
- if (yes) {
191
- inputPath = initDefaults.inputPath
192
- clack.log.info(`Using input path: ${styleText('cyan', inputPath)}`)
193
- } else {
194
- const inputPathResult = await clack.text({
195
- message: 'Where is your OpenAPI specification located?',
196
- placeholder: initDefaults.inputPath,
197
- defaultValue: initDefaults.inputPath,
198
- validate: (value) => {
199
- if (!value) return 'Input path is required'
200
- },
201
- })
202
-
203
- if (clack.isCancel(inputPathResult)) {
204
- cancelAndExit()
205
- }
206
- inputPath = inputPathResult as string
207
- }
208
-
209
- // Prompt for output directory
210
- let outputPath: string
211
- if (yes) {
212
- outputPath = initDefaults.outputPath
213
- clack.log.info(`Using output path: ${styleText('cyan', outputPath)}`)
214
- } else {
215
- const outputPathResult = await clack.text({
216
- message: 'Where should the generated files be output?',
217
- placeholder: initDefaults.outputPath,
218
- defaultValue: initDefaults.outputPath,
219
- validate: (value) => {
220
- if (!value) return 'Output path is required'
221
- },
222
- })
223
-
224
- if (clack.isCancel(outputPathResult)) {
225
- cancelAndExit()
226
- }
227
- outputPath = outputPathResult as string
228
- }
229
-
230
- // Plugin selection
231
- let selectedPlugins: PluginOption[]
232
- if (yes) {
233
- selectedPlugins = availablePlugins.filter((plugin) => (initDefaults.plugins as readonly string[]).includes(plugin.value))
234
- clack.log.info(`Using plugins: ${styleText('cyan', selectedPlugins.map((p) => p.label).join(', '))}`)
235
- } else {
236
- const selectedPluginValues = await clack.multiselect({
237
- message: 'Select plugins to use:',
238
- options: availablePlugins.map((plugin) => ({
239
- value: plugin.value,
240
- label: plugin.label,
241
- hint: plugin.hint,
242
- })),
243
- initialValues: [...initDefaults.plugins],
244
- required: true,
245
- })
246
-
247
- if (clack.isCancel(selectedPluginValues)) {
248
- cancelAndExit()
249
- }
250
-
251
- selectedPlugins = availablePlugins.filter((plugin) => (selectedPluginValues as string[]).includes(plugin.value))
252
- }
253
-
254
- // Ensure plugin-oas is always included
255
- if (!selectedPlugins.find((p) => p.value === 'plugin-oas')) {
256
- selectedPlugins.unshift(availablePlugins.find((p) => p.value === 'plugin-oas')!)
257
- }
258
-
259
- // Install packages
260
- const packagesToInstall = ['@kubb/core', '@kubb/cli', '@kubb/agent', ...selectedPlugins.map((p) => p.packageName)]
261
-
262
- const spinner = clack.spinner()
263
- spinner.start(`Installing ${packagesToInstall.length} packages with ${packageManager.name}`)
264
-
265
- try {
266
- await installPackages(packagesToInstall, packageManager, cwd)
267
- spinner.stop(`Installed ${packagesToInstall.length} packages`)
268
- } catch (error) {
269
- spinner.stop('Installation failed')
270
- throw error
271
- }
272
-
273
- // Generate config file
274
- const configSpinner = clack.spinner()
275
- configSpinner.start('Creating kubb.config.ts')
276
-
277
- const configContent = generateConfigFile(selectedPlugins, inputPath, outputPath)
278
- const configPath = path.join(cwd, 'kubb.config.ts')
279
-
280
- if (fs.existsSync(configPath)) {
281
- configSpinner.stop('kubb.config.ts already exists')
282
-
283
- if (!yes) {
284
- const shouldOverwrite = await clack.confirm({
285
- message: 'kubb.config.ts already exists. Overwrite?',
286
- initialValue: false,
287
- })
288
-
289
- if (clack.isCancel(shouldOverwrite) || !shouldOverwrite) {
290
- cancelAndExit('Keeping existing configuration. Packages have been installed.')
291
- }
292
- }
293
-
294
- configSpinner.start('Overwriting kubb.config.ts')
295
- }
296
-
297
- fs.writeFileSync(configPath, configContent, 'utf-8')
298
-
299
- configSpinner.stop('Created kubb.config.ts')
300
-
301
- clack.outro(
302
- styleText('green', '✓ All set!') +
303
- '\n\n' +
304
- styleText('dim', 'Next steps:') +
305
- '\n' +
306
- styleText('cyan', ` 1. Make sure your OpenAPI spec is at: ${inputPath}`) +
307
- '\n' +
308
- styleText('cyan', ' 2. Generate code with: npx kubb generate') +
309
- '\n' +
310
- styleText('cyan', ' Or start a stream server with: npx kubb start') +
311
- '\n' +
312
- styleText('cyan', ` 3. Find generated files in: ${outputPath}`) +
313
- '\n\n' +
314
- styleText('dim', `Using ${packageManager.name} • Kubb v${version}`),
315
- )
316
- } catch (error) {
317
- clack.log.error(styleText('red', 'An error occurred during initialization'))
318
- if (error instanceof Error) {
319
- clack.log.error(error.message)
320
- }
321
- process.exit(1)
322
- }
323
- }
@@ -1,32 +0,0 @@
1
- import process from 'node:process'
2
- import { styleText } from 'node:util'
3
- import { getErrorMessage } from '@internals/utils'
4
- import type * as McpModule from '@kubb/mcp'
5
- import { jiti } from '../utils/jiti.ts'
6
- import { buildTelemetryEvent, sendTelemetry } from '../utils/telemetry.ts'
7
-
8
- type McpOptions = {
9
- version: string
10
- }
11
-
12
- export async function runMcp({ version }: McpOptions): Promise<void> {
13
- let mod: typeof McpModule
14
- try {
15
- mod = (await jiti.import('@kubb/mcp', { default: true })) as typeof McpModule
16
- } catch (_e) {
17
- console.error(`Import of '@kubb/mcp' is required to start the MCP server`)
18
- process.exit(1)
19
- }
20
-
21
- const { run } = mod
22
- const hrStart = process.hrtime()
23
- try {
24
- console.log('⏳ Starting MCP server...')
25
- console.warn(styleText('yellow', 'This feature is still under development — use with caution'))
26
- run()
27
- await sendTelemetry(buildTelemetryEvent({ command: 'mcp', kubbVersion: version, hrStart, status: 'success' }))
28
- } catch (error) {
29
- await sendTelemetry(buildTelemetryEvent({ command: 'mcp', kubbVersion: version, hrStart, status: 'failed' }))
30
- console.error(getErrorMessage(error))
31
- }
32
- }
@@ -1,35 +0,0 @@
1
- import process from 'node:process'
2
- import { getErrorMessage } from '@internals/utils'
3
- import type * as OasModule from '@kubb/oas'
4
- import { jiti } from '../utils/jiti.ts'
5
- import { buildTelemetryEvent, sendTelemetry } from '../utils/telemetry.ts'
6
-
7
- type ValidateOptions = {
8
- input: string
9
- version: string
10
- }
11
-
12
- export async function runValidate({ input, version }: ValidateOptions): Promise<void> {
13
- let mod: typeof OasModule
14
- try {
15
- mod = (await jiti.import('@kubb/oas', { default: true })) as typeof OasModule
16
- } catch (_e) {
17
- console.error(`Import of '@kubb/oas' is required to do validation`)
18
- process.exit(1)
19
- }
20
-
21
- const { parse } = mod
22
- const hrStart = process.hrtime()
23
- try {
24
- const oas = await parse(input)
25
- await oas.validate()
26
-
27
- await sendTelemetry(buildTelemetryEvent({ command: 'validate', kubbVersion: version, hrStart, status: 'success' }))
28
- console.log('✅ Validation success')
29
- } catch (error) {
30
- await sendTelemetry(buildTelemetryEvent({ command: 'validate', kubbVersion: version, hrStart, status: 'failed' }))
31
- console.error('❌ Validation failed')
32
- console.error(getErrorMessage(error))
33
- process.exit(1)
34
- }
35
- }
package/src/types.ts DELETED
@@ -1,11 +0,0 @@
1
- export type QuiteFlag = '--help' | '-h' | '--version' | '-v'
2
-
3
- export type GenerateFlag = '--config' | '-c' | '--log-level' | '-l' | '--watch' | '-w' | '--debug' | '-d' | '--verbose' | '-v' | '--silent' | '-s'
4
-
5
- export type ValidateFlag = '--input' | '-i'
6
-
7
- export type InitFlag = '--yes' | '-y'
8
-
9
- export type AgentStartFlag = '--config' | '-c' | '--port' | '-p' | '--host' | '--allow-write' | '--allow-all'
10
-
11
- export type Arg = QuiteFlag | GenerateFlag | ValidateFlag | InitFlag | AgentStartFlag
@@ -1,17 +0,0 @@
1
- import type { WritableOptions } from 'node:stream'
2
- import { Writable } from 'node:stream'
3
- import { styleText } from 'node:util'
4
- import type * as clack from '@clack/prompts'
5
-
6
- export class ClackWritable extends Writable {
7
- taskLog: ReturnType<typeof clack.taskLog>
8
- constructor(taskLog: ReturnType<typeof clack.taskLog>, opts?: WritableOptions) {
9
- super(opts)
10
-
11
- this.taskLog = taskLog
12
- }
13
- _write(chunk: Buffer, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void {
14
- this.taskLog.message(`${styleText('dim', chunk.toString())}`)
15
- callback()
16
- }
17
- }
@@ -1,45 +0,0 @@
1
- import { createHash } from 'node:crypto'
2
- import { styleText } from 'node:util'
3
- import type { AsyncEventEmitter } from '@internals/utils'
4
- import { tokenize } from '@internals/utils'
5
- import type { Config, KubbEvents } from '@kubb/core'
6
-
7
- type ExecutingHooksProps = {
8
- hooks: NonNullable<Config['hooks']>
9
- events: AsyncEventEmitter<KubbEvents>
10
- }
11
-
12
- export async function executeHooks({ hooks, events }: ExecutingHooksProps): Promise<void> {
13
- const commands = Array.isArray(hooks.done) ? hooks.done : [hooks.done].filter(Boolean)
14
-
15
- for (const command of commands) {
16
- const [cmd, ...args] = tokenize(command)
17
-
18
- if (!cmd) {
19
- continue
20
- }
21
-
22
- const hookId = createHash('sha256').update(command).digest('hex')
23
-
24
- // Wire up the hook:end listener BEFORE emitting hook:start to avoid the race condition
25
- // where hook:end fires synchronously inside emit('hook:start') before the listener is registered.
26
- const hookEndPromise = new Promise<void>((resolve, reject) => {
27
- const handler = ({ id, success, error }: { id?: string; command: string; args?: readonly string[]; success: boolean; error: Error | null }) => {
28
- if (id !== hookId) return
29
- events.off('hook:end', handler)
30
- if (!success) {
31
- reject(error ?? new Error(`Hook failed: ${command}`))
32
- return
33
- }
34
- events
35
- .emit('success', `${styleText('dim', command)} successfully executed`)
36
- .then(resolve)
37
- .catch(reject)
38
- }
39
- events.on('hook:end', handler)
40
- })
41
-
42
- await events.emit('hook:start', { id: hookId, command: cmd, args })
43
- await hookEndPromise
44
- }
45
- }
@@ -1,10 +0,0 @@
1
- /**
2
- * Type guard that checks whether a raw string is a member of a typed flag set.
3
- * Avoids the need for type assertions when working with `Set<T extends string>`.
4
- */
5
- export function isFlag<T extends string>(set: ReadonlySet<T>, value: string): value is T {
6
- for (const flag of set) {
7
- if (flag === value) return true
8
- }
9
- return false
10
- }
@@ -1,71 +0,0 @@
1
- import type { defineConfig, UserConfig } from '@kubb/core'
2
- import { cosmiconfig } from 'cosmiconfig'
3
- import { createJiti } from 'jiti'
4
-
5
- type CosmiconfigResult = {
6
- filepath: string
7
- isEmpty?: boolean
8
- config: ReturnType<typeof defineConfig> | UserConfig
9
- }
10
-
11
- const jiti = createJiti(import.meta.url, {
12
- jsx: {
13
- runtime: 'automatic',
14
- importSource: '@kubb/react-fabric',
15
- },
16
- sourceMaps: true,
17
- interopDefault: true,
18
- })
19
-
20
- const tsLoader = async (configFile: string) => {
21
- const mod = await jiti.import(configFile, { default: true })
22
- return mod
23
- }
24
-
25
- export async function getCosmiConfig(moduleName: string, config?: string): Promise<CosmiconfigResult> {
26
- let result: CosmiconfigResult
27
- const searchPlaces = [
28
- 'package.json',
29
- `.${moduleName}rc`,
30
- `.${moduleName}rc.json`,
31
- `.${moduleName}rc.yaml`,
32
- `.${moduleName}rc.yml`,
33
-
34
- `.${moduleName}rc.ts`,
35
- `.${moduleName}rc.js`,
36
- `.${moduleName}rc.mjs`,
37
- `.${moduleName}rc.cjs`,
38
-
39
- `${moduleName}.config.ts`,
40
- `${moduleName}.config.js`,
41
- `${moduleName}.config.mjs`,
42
- `${moduleName}.config.cjs`,
43
- ]
44
- const explorer = cosmiconfig(moduleName, {
45
- cache: false,
46
- searchPlaces: [
47
- ...searchPlaces.map((searchPlace) => {
48
- return `.config/${searchPlace}`
49
- }),
50
- ...searchPlaces.map((searchPlace) => {
51
- return `configs/${searchPlace}`
52
- }),
53
- ...searchPlaces,
54
- ],
55
- loaders: {
56
- '.ts': tsLoader,
57
- },
58
- })
59
-
60
- try {
61
- result = config ? ((await explorer.load(config)) as CosmiconfigResult) : ((await explorer.search()) as CosmiconfigResult)
62
- } catch (error) {
63
- throw new Error('Config failed loading', { cause: error })
64
- }
65
-
66
- if (result?.isEmpty || !result || !result.config) {
67
- throw new Error('Config not defined, create a kubb.config.js or pass through your config with the option --config')
68
- }
69
-
70
- return result as CosmiconfigResult
71
- }
@@ -1,68 +0,0 @@
1
- import path from 'node:path'
2
- import { styleText } from 'node:util'
3
- import { formatHrtime, randomCliColor } from '@internals/utils'
4
- import type { Config, Plugin } from '@kubb/core'
5
- import { SUMMARY_MAX_BAR_LENGTH, SUMMARY_TIME_SCALE_DIVISOR } from '../constants.ts'
6
-
7
- type SummaryProps = {
8
- failedPlugins: Set<{ plugin: Plugin; error: Error }>
9
- status: 'success' | 'failed'
10
- hrStart: [number, number]
11
- filesCreated: number
12
- config: Config
13
- pluginTimings?: Map<string, number>
14
- }
15
-
16
- export function getSummary({ failedPlugins, filesCreated, status, hrStart, config, pluginTimings }: SummaryProps): string[] {
17
- const duration = formatHrtime(hrStart)
18
-
19
- const pluginsCount = config.plugins?.length ?? 0
20
- const successCount = pluginsCount - failedPlugins.size
21
-
22
- const meta = {
23
- plugins:
24
- status === 'success'
25
- ? `${styleText('green', `${successCount} successful`)}, ${pluginsCount} total`
26
- : `${styleText('green', `${successCount} successful`)}, ${styleText('red', `${failedPlugins.size} failed`)}, ${pluginsCount} total`,
27
- pluginsFailed: status === 'failed' ? [...failedPlugins].map(({ plugin }) => randomCliColor(plugin.name)).join(', ') : undefined,
28
- filesCreated,
29
- time: styleText('green', duration),
30
- output: path.isAbsolute(config.root) ? path.resolve(config.root, config.output.path) : config.root,
31
- } as const
32
-
33
- const labels = {
34
- plugins: 'Plugins:',
35
- failed: 'Failed:',
36
- generated: 'Generated:',
37
- pluginTimings: 'Plugin Timings:',
38
- output: 'Output:',
39
- }
40
- const maxLength = Math.max(0, ...[...Object.values(labels), ...(pluginTimings ? Array.from(pluginTimings.keys()) : [])].map((s) => s.length))
41
-
42
- const summaryLines: string[] = []
43
- summaryLines.push(`${labels.plugins.padEnd(maxLength + 2)} ${meta.plugins}`)
44
-
45
- if (meta.pluginsFailed) {
46
- summaryLines.push(`${labels.failed.padEnd(maxLength + 2)} ${meta.pluginsFailed}`)
47
- }
48
-
49
- summaryLines.push(`${labels.generated.padEnd(maxLength + 2)} ${meta.filesCreated} files in ${meta.time}`)
50
-
51
- if (pluginTimings && pluginTimings.size > 0) {
52
- const sortedTimings = Array.from(pluginTimings.entries()).sort((a, b) => b[1] - a[1])
53
-
54
- summaryLines.push(`${labels.pluginTimings}`)
55
-
56
- sortedTimings.forEach(([name, time]) => {
57
- const timeStr = time >= 1000 ? `${(time / 1000).toFixed(2)}s` : `${Math.round(time)}ms`
58
- const barLength = Math.min(Math.ceil(time / SUMMARY_TIME_SCALE_DIVISOR), SUMMARY_MAX_BAR_LENGTH)
59
- const bar = styleText('dim', '█'.repeat(barLength))
60
-
61
- summaryLines.push(`${styleText('dim', '•')} ${name.padEnd(maxLength + 1)}${bar} ${timeStr}`)
62
- })
63
- }
64
-
65
- summaryLines.push(`${labels.output.padEnd(maxLength + 2)} ${meta.output}`)
66
-
67
- return summaryLines
68
- }
package/src/utils/jiti.ts DELETED
@@ -1,9 +0,0 @@
1
- import { createJiti } from 'jiti'
2
-
3
- /**
4
- * Shared jiti instance for dynamic ESM/TS imports across CLI commands.
5
- * Created once at module scope to avoid the overhead of repeated instantiation.
6
- */
7
- export const jiti = createJiti(import.meta.url, {
8
- sourceMaps: true,
9
- })