@kubb/core 5.0.0-alpha.8 → 5.0.0-beta.1
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/README.md +23 -20
- package/dist/PluginDriver-BXibeQk-.cjs +1036 -0
- package/dist/PluginDriver-BXibeQk-.cjs.map +1 -0
- package/dist/PluginDriver-DV3p2Hky.js +945 -0
- package/dist/PluginDriver-DV3p2Hky.js.map +1 -0
- package/dist/index.cjs +756 -1693
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +297 -239
- package/dist/index.js +743 -1661
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +145 -0
- package/dist/mocks.cjs.map +1 -0
- package/dist/mocks.d.ts +80 -0
- package/dist/mocks.js +140 -0
- package/dist/mocks.js.map +1 -0
- package/dist/types-CuNocrbJ.d.ts +2148 -0
- package/package.json +51 -57
- package/src/FileManager.ts +115 -0
- package/src/FileProcessor.ts +86 -0
- package/src/Kubb.ts +208 -160
- package/src/PluginDriver.ts +326 -565
- package/src/constants.ts +20 -47
- package/src/createAdapter.ts +16 -6
- package/src/createKubb.ts +548 -0
- package/src/createRenderer.ts +57 -0
- package/src/createStorage.ts +40 -26
- package/src/defineGenerator.ts +87 -0
- package/src/defineLogger.ts +19 -0
- package/src/defineMiddleware.ts +62 -0
- package/src/defineParser.ts +44 -0
- package/src/definePlugin.ts +83 -0
- package/src/defineResolver.ts +521 -0
- package/src/devtools.ts +14 -14
- package/src/index.ts +14 -17
- package/src/mocks.ts +178 -0
- package/src/renderNode.ts +35 -0
- package/src/storages/fsStorage.ts +41 -11
- package/src/storages/memoryStorage.ts +4 -2
- package/src/types.ts +1054 -270
- package/src/utils/diagnostics.ts +4 -1
- package/src/utils/isInputPath.ts +10 -0
- package/src/utils/packageJSON.ts +99 -0
- package/dist/PluginDriver-DRfJIbG1.d.ts +0 -1056
- package/dist/chunk-ByKO4r7w.cjs +0 -38
- package/dist/hooks.cjs +0 -102
- package/dist/hooks.cjs.map +0 -1
- package/dist/hooks.d.ts +0 -75
- package/dist/hooks.js +0 -97
- package/dist/hooks.js.map +0 -1
- package/src/PackageManager.ts +0 -180
- package/src/build.ts +0 -419
- package/src/config.ts +0 -56
- package/src/createGenerator.ts +0 -106
- package/src/createLogger.ts +0 -7
- package/src/createPlugin.ts +0 -12
- package/src/errors.ts +0 -1
- package/src/hooks/index.ts +0 -4
- package/src/hooks/useKubb.ts +0 -138
- package/src/hooks/useMode.ts +0 -11
- package/src/hooks/usePlugin.ts +0 -11
- package/src/hooks/usePluginDriver.ts +0 -11
- package/src/utils/FunctionParams.ts +0 -155
- package/src/utils/TreeNode.ts +0 -215
- package/src/utils/executeStrategies.ts +0 -81
- package/src/utils/formatters.ts +0 -56
- package/src/utils/getBarrelFiles.ts +0 -141
- package/src/utils/getConfigs.ts +0 -30
- package/src/utils/getPlugins.ts +0 -23
- package/src/utils/linters.ts +0 -25
- package/src/utils/resolveOptions.ts +0 -93
package/src/build.ts
DELETED
|
@@ -1,419 +0,0 @@
|
|
|
1
|
-
import { dirname, relative, resolve } from 'node:path'
|
|
2
|
-
import { AsyncEventEmitter, exists, formatMs, getElapsedMs, getRelativePath, URLPath } from '@internals/utils'
|
|
3
|
-
import type { Fabric as FabricType, KubbFile } from '@kubb/fabric-core/types'
|
|
4
|
-
import { createFabric } from '@kubb/react-fabric'
|
|
5
|
-
import { typescriptParser } from '@kubb/react-fabric/parsers'
|
|
6
|
-
import { fsPlugin } from '@kubb/react-fabric/plugins'
|
|
7
|
-
import { isInputPath } from './config.ts'
|
|
8
|
-
import { BARREL_FILENAME, DEFAULT_BANNER, DEFAULT_CONCURRENCY, DEFAULT_EXTENSION, DEFAULT_STUDIO_URL } from './constants.ts'
|
|
9
|
-
import { BuildError } from './errors.ts'
|
|
10
|
-
import { PluginDriver } from './PluginDriver.ts'
|
|
11
|
-
import { fsStorage } from './storages/fsStorage.ts'
|
|
12
|
-
import type { AdapterSource, Config, DefineStorage, KubbEvents, Output, Plugin, UserConfig } from './types.ts'
|
|
13
|
-
import { getDiagnosticInfo } from './utils/diagnostics.ts'
|
|
14
|
-
import type { FileMetaBase } from './utils/getBarrelFiles.ts'
|
|
15
|
-
|
|
16
|
-
type BuildOptions = {
|
|
17
|
-
config: UserConfig
|
|
18
|
-
events?: AsyncEventEmitter<KubbEvents>
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
type BuildOutput = {
|
|
22
|
-
failedPlugins: Set<{ plugin: Plugin; error: Error }>
|
|
23
|
-
fabric: FabricType
|
|
24
|
-
files: Array<KubbFile.ResolvedFile>
|
|
25
|
-
driver: PluginDriver
|
|
26
|
-
pluginTimings: Map<string, number>
|
|
27
|
-
error?: Error
|
|
28
|
-
sources: Map<KubbFile.Path, string>
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
type SetupResult = {
|
|
32
|
-
events: AsyncEventEmitter<KubbEvents>
|
|
33
|
-
fabric: FabricType
|
|
34
|
-
driver: PluginDriver
|
|
35
|
-
sources: Map<KubbFile.Path, string>
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export async function setup(options: BuildOptions): Promise<SetupResult> {
|
|
39
|
-
const { config: userConfig, events = new AsyncEventEmitter<KubbEvents>() } = options
|
|
40
|
-
|
|
41
|
-
const sources: Map<KubbFile.Path, string> = new Map<KubbFile.Path, string>()
|
|
42
|
-
const diagnosticInfo = getDiagnosticInfo()
|
|
43
|
-
|
|
44
|
-
if (Array.isArray(userConfig.input)) {
|
|
45
|
-
await events.emit('warn', 'This feature is still under development — use with caution')
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
await events.emit('debug', {
|
|
49
|
-
date: new Date(),
|
|
50
|
-
logs: [
|
|
51
|
-
'Configuration:',
|
|
52
|
-
` • Name: ${userConfig.name || 'unnamed'}`,
|
|
53
|
-
` • Root: ${userConfig.root || process.cwd()}`,
|
|
54
|
-
` • Output: ${userConfig.output?.path || 'not specified'}`,
|
|
55
|
-
` • Plugins: ${userConfig.plugins?.length || 0}`,
|
|
56
|
-
'Output Settings:',
|
|
57
|
-
` • Storage: ${userConfig.output?.storage ? `custom(${userConfig.output.storage.name})` : userConfig.output?.write === false ? 'disabled' : 'filesystem (default)'}`,
|
|
58
|
-
` • Formatter: ${userConfig.output?.format || 'none'}`,
|
|
59
|
-
` • Linter: ${userConfig.output?.lint || 'none'}`,
|
|
60
|
-
'Environment:',
|
|
61
|
-
Object.entries(diagnosticInfo)
|
|
62
|
-
.map(([key, value]) => ` • ${key}: ${value}`)
|
|
63
|
-
.join('\n'),
|
|
64
|
-
],
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
try {
|
|
68
|
-
if (isInputPath(userConfig) && !new URLPath(userConfig.input.path).isURL) {
|
|
69
|
-
await exists(userConfig.input.path)
|
|
70
|
-
|
|
71
|
-
await events.emit('debug', {
|
|
72
|
-
date: new Date(),
|
|
73
|
-
logs: [`✓ Input file validated: ${userConfig.input.path}`],
|
|
74
|
-
})
|
|
75
|
-
}
|
|
76
|
-
} catch (caughtError) {
|
|
77
|
-
if (isInputPath(userConfig)) {
|
|
78
|
-
const error = caughtError as Error
|
|
79
|
-
|
|
80
|
-
throw new Error(
|
|
81
|
-
`Cannot read file/URL defined in \`input.path\` or set with \`kubb generate PATH\` in the CLI of your Kubb config ${userConfig.input.path}`,
|
|
82
|
-
{
|
|
83
|
-
cause: error,
|
|
84
|
-
},
|
|
85
|
-
)
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const definedConfig: Config = {
|
|
90
|
-
root: userConfig.root || process.cwd(),
|
|
91
|
-
...userConfig,
|
|
92
|
-
output: {
|
|
93
|
-
write: true,
|
|
94
|
-
barrelType: 'named',
|
|
95
|
-
extension: DEFAULT_EXTENSION,
|
|
96
|
-
defaultBanner: DEFAULT_BANNER,
|
|
97
|
-
...userConfig.output,
|
|
98
|
-
},
|
|
99
|
-
devtools: userConfig.devtools
|
|
100
|
-
? {
|
|
101
|
-
studioUrl: DEFAULT_STUDIO_URL,
|
|
102
|
-
...(typeof userConfig.devtools === 'boolean' ? {} : userConfig.devtools),
|
|
103
|
-
}
|
|
104
|
-
: undefined,
|
|
105
|
-
plugins: userConfig.plugins as Config['plugins'],
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// write: false is the explicit dry-run opt-out; otherwise use the provided
|
|
109
|
-
// storage or fall back to fsStorage (backwards-compatible default).
|
|
110
|
-
// Keys are root-relative (e.g. `src/gen/api/getPets.ts`) so fsStorage()
|
|
111
|
-
// needs no configuration — it resolves them against process.cwd().
|
|
112
|
-
const storage: DefineStorage | null = definedConfig.output.write === false ? null : (definedConfig.output.storage ?? fsStorage())
|
|
113
|
-
|
|
114
|
-
if (definedConfig.output.clean) {
|
|
115
|
-
await events.emit('debug', {
|
|
116
|
-
date: new Date(),
|
|
117
|
-
logs: ['Cleaning output directories', ` • Output: ${definedConfig.output.path}`],
|
|
118
|
-
})
|
|
119
|
-
await storage?.clear(resolve(definedConfig.root, definedConfig.output.path))
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const fabric = createFabric()
|
|
123
|
-
fabric.use(fsPlugin)
|
|
124
|
-
fabric.use(typescriptParser)
|
|
125
|
-
|
|
126
|
-
fabric.context.on('files:processing:start', (files) => {
|
|
127
|
-
events.emit('files:processing:start', files)
|
|
128
|
-
events.emit('debug', {
|
|
129
|
-
date: new Date(),
|
|
130
|
-
logs: [`Writing ${files.length} files...`],
|
|
131
|
-
})
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
fabric.context.on('file:processing:update', async (params) => {
|
|
135
|
-
const { file, source } = params
|
|
136
|
-
await events.emit('file:processing:update', {
|
|
137
|
-
...params,
|
|
138
|
-
config: definedConfig,
|
|
139
|
-
source,
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
if (source) {
|
|
143
|
-
// Key is root-relative so it's meaningful for any backend (fs, S3, Redis…)
|
|
144
|
-
const key = relative(resolve(definedConfig.root), file.path)
|
|
145
|
-
await storage?.setItem(key, source)
|
|
146
|
-
sources.set(file.path, source)
|
|
147
|
-
}
|
|
148
|
-
})
|
|
149
|
-
|
|
150
|
-
fabric.context.on('files:processing:end', async (files) => {
|
|
151
|
-
await events.emit('files:processing:end', files)
|
|
152
|
-
await events.emit('debug', {
|
|
153
|
-
date: new Date(),
|
|
154
|
-
logs: [`✓ File write process completed for ${files.length} files`],
|
|
155
|
-
})
|
|
156
|
-
})
|
|
157
|
-
|
|
158
|
-
await events.emit('debug', {
|
|
159
|
-
date: new Date(),
|
|
160
|
-
logs: [
|
|
161
|
-
'✓ Fabric initialized',
|
|
162
|
-
` • Storage: ${storage ? storage.name : 'disabled (dry-run)'}`,
|
|
163
|
-
` • Barrel type: ${definedConfig.output.barrelType || 'none'}`,
|
|
164
|
-
],
|
|
165
|
-
})
|
|
166
|
-
|
|
167
|
-
const pluginDriver = new PluginDriver(definedConfig, {
|
|
168
|
-
fabric,
|
|
169
|
-
events,
|
|
170
|
-
concurrency: DEFAULT_CONCURRENCY,
|
|
171
|
-
})
|
|
172
|
-
|
|
173
|
-
// Run the adapter (if provided) to produce the universal RootNode
|
|
174
|
-
if (definedConfig.adapter) {
|
|
175
|
-
const source = inputToAdapterSource(definedConfig)
|
|
176
|
-
|
|
177
|
-
await events.emit('debug', {
|
|
178
|
-
date: new Date(),
|
|
179
|
-
logs: [`Running adapter: ${definedConfig.adapter.name}`],
|
|
180
|
-
})
|
|
181
|
-
|
|
182
|
-
pluginDriver.adapter = definedConfig.adapter
|
|
183
|
-
pluginDriver.rootNode = await definedConfig.adapter.parse(source)
|
|
184
|
-
|
|
185
|
-
await events.emit('debug', {
|
|
186
|
-
date: new Date(),
|
|
187
|
-
logs: [
|
|
188
|
-
`✓ Adapter '${definedConfig.adapter.name}' resolved RootNode`,
|
|
189
|
-
` • Schemas: ${pluginDriver.rootNode.schemas.length}`,
|
|
190
|
-
` • Operations: ${pluginDriver.rootNode.operations.length}`,
|
|
191
|
-
],
|
|
192
|
-
})
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
return {
|
|
196
|
-
events,
|
|
197
|
-
fabric,
|
|
198
|
-
driver: pluginDriver,
|
|
199
|
-
sources,
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export async function build(options: BuildOptions, overrides?: SetupResult): Promise<BuildOutput> {
|
|
204
|
-
const { fabric, files, driver, failedPlugins, pluginTimings, error, sources } = await safeBuild(options, overrides)
|
|
205
|
-
|
|
206
|
-
if (error) {
|
|
207
|
-
throw error
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
if (failedPlugins.size > 0) {
|
|
211
|
-
const errors = [...failedPlugins].map(({ error }) => error)
|
|
212
|
-
|
|
213
|
-
throw new BuildError(`Build Error with ${failedPlugins.size} failed plugins`, { errors })
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
return {
|
|
217
|
-
failedPlugins,
|
|
218
|
-
fabric,
|
|
219
|
-
files,
|
|
220
|
-
driver,
|
|
221
|
-
pluginTimings,
|
|
222
|
-
error: undefined,
|
|
223
|
-
sources,
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
export async function safeBuild(options: BuildOptions, overrides?: SetupResult): Promise<BuildOutput> {
|
|
228
|
-
const { fabric, driver, events, sources } = overrides ? overrides : await setup(options)
|
|
229
|
-
|
|
230
|
-
const failedPlugins = new Set<{ plugin: Plugin; error: Error }>()
|
|
231
|
-
// in ms
|
|
232
|
-
const pluginTimings = new Map<string, number>()
|
|
233
|
-
const config = driver.config
|
|
234
|
-
|
|
235
|
-
try {
|
|
236
|
-
for (const plugin of driver.plugins) {
|
|
237
|
-
const context = driver.getContext(plugin)
|
|
238
|
-
const hrStart = process.hrtime()
|
|
239
|
-
|
|
240
|
-
const installer = plugin.install.bind(context)
|
|
241
|
-
|
|
242
|
-
try {
|
|
243
|
-
const timestamp = new Date()
|
|
244
|
-
|
|
245
|
-
await events.emit('plugin:start', plugin)
|
|
246
|
-
|
|
247
|
-
await events.emit('debug', {
|
|
248
|
-
date: timestamp,
|
|
249
|
-
logs: ['Installing plugin...', ` • Plugin Name: ${plugin.name}`],
|
|
250
|
-
})
|
|
251
|
-
|
|
252
|
-
await installer(context)
|
|
253
|
-
|
|
254
|
-
const duration = getElapsedMs(hrStart)
|
|
255
|
-
pluginTimings.set(plugin.name, duration)
|
|
256
|
-
|
|
257
|
-
await events.emit('plugin:end', plugin, { duration, success: true })
|
|
258
|
-
|
|
259
|
-
await events.emit('debug', {
|
|
260
|
-
date: new Date(),
|
|
261
|
-
logs: [`✓ Plugin installed successfully (${formatMs(duration)})`],
|
|
262
|
-
})
|
|
263
|
-
} catch (caughtError) {
|
|
264
|
-
const error = caughtError as Error
|
|
265
|
-
const errorTimestamp = new Date()
|
|
266
|
-
const duration = getElapsedMs(hrStart)
|
|
267
|
-
|
|
268
|
-
await events.emit('plugin:end', plugin, {
|
|
269
|
-
duration,
|
|
270
|
-
success: false,
|
|
271
|
-
error,
|
|
272
|
-
})
|
|
273
|
-
|
|
274
|
-
await events.emit('debug', {
|
|
275
|
-
date: errorTimestamp,
|
|
276
|
-
logs: [
|
|
277
|
-
'✗ Plugin installation failed',
|
|
278
|
-
` • Plugin Name: ${plugin.name}`,
|
|
279
|
-
` • Error: ${error.constructor.name} - ${error.message}`,
|
|
280
|
-
' • Stack Trace:',
|
|
281
|
-
error.stack || 'No stack trace available',
|
|
282
|
-
],
|
|
283
|
-
})
|
|
284
|
-
|
|
285
|
-
failedPlugins.add({ plugin, error })
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
if (config.output.barrelType) {
|
|
290
|
-
const root = resolve(config.root)
|
|
291
|
-
const rootPath = resolve(root, config.output.path, BARREL_FILENAME)
|
|
292
|
-
const rootDir = dirname(rootPath)
|
|
293
|
-
|
|
294
|
-
await events.emit('debug', {
|
|
295
|
-
date: new Date(),
|
|
296
|
-
logs: ['Generating barrel file', ` • Type: ${config.output.barrelType}`, ` • Path: ${rootPath}`],
|
|
297
|
-
})
|
|
298
|
-
|
|
299
|
-
const barrelFiles = fabric.files.filter((file) => {
|
|
300
|
-
return file.sources.some((source) => source.isIndexable)
|
|
301
|
-
})
|
|
302
|
-
|
|
303
|
-
await events.emit('debug', {
|
|
304
|
-
date: new Date(),
|
|
305
|
-
logs: [`Found ${barrelFiles.length} indexable files for barrel export`],
|
|
306
|
-
})
|
|
307
|
-
|
|
308
|
-
const existingBarrel = fabric.files.find((f) => f.path === rootPath)
|
|
309
|
-
const existingExports = new Set(
|
|
310
|
-
existingBarrel?.exports?.flatMap((e) => (Array.isArray(e.name) ? e.name : [e.name])).filter((n): n is string => Boolean(n)) ?? [],
|
|
311
|
-
)
|
|
312
|
-
|
|
313
|
-
const rootFile: KubbFile.File = {
|
|
314
|
-
path: rootPath,
|
|
315
|
-
baseName: BARREL_FILENAME,
|
|
316
|
-
exports: buildBarrelExports({ barrelFiles, rootDir, existingExports, config, driver }),
|
|
317
|
-
sources: [],
|
|
318
|
-
imports: [],
|
|
319
|
-
meta: {},
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
await fabric.upsertFile(rootFile)
|
|
323
|
-
|
|
324
|
-
await events.emit('debug', {
|
|
325
|
-
date: new Date(),
|
|
326
|
-
logs: [`✓ Generated barrel file (${rootFile.exports?.length || 0} exports)`],
|
|
327
|
-
})
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
const files = [...fabric.files]
|
|
331
|
-
|
|
332
|
-
await fabric.write({ extension: config.output.extension })
|
|
333
|
-
|
|
334
|
-
return {
|
|
335
|
-
failedPlugins,
|
|
336
|
-
fabric,
|
|
337
|
-
files,
|
|
338
|
-
driver,
|
|
339
|
-
pluginTimings,
|
|
340
|
-
sources,
|
|
341
|
-
}
|
|
342
|
-
} catch (error) {
|
|
343
|
-
return {
|
|
344
|
-
failedPlugins,
|
|
345
|
-
fabric,
|
|
346
|
-
files: [],
|
|
347
|
-
driver,
|
|
348
|
-
pluginTimings,
|
|
349
|
-
error: error as Error,
|
|
350
|
-
sources,
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
type BuildBarrelExportsParams = {
|
|
356
|
-
barrelFiles: KubbFile.ResolvedFile[]
|
|
357
|
-
rootDir: string
|
|
358
|
-
existingExports: Set<string>
|
|
359
|
-
config: Config
|
|
360
|
-
driver: PluginDriver
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
function buildBarrelExports({ barrelFiles, rootDir, existingExports, config, driver }: BuildBarrelExportsParams): KubbFile.Export[] {
|
|
364
|
-
const pluginNameMap = new Map<string, Plugin>()
|
|
365
|
-
for (const plugin of driver.plugins) {
|
|
366
|
-
pluginNameMap.set(plugin.name, plugin)
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
return barrelFiles.flatMap((file) => {
|
|
370
|
-
const containsOnlyTypes = file.sources?.every((source) => source.isTypeOnly)
|
|
371
|
-
|
|
372
|
-
return (file.sources ?? []).flatMap((source) => {
|
|
373
|
-
if (!file.path || !source.isIndexable) {
|
|
374
|
-
return []
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
const meta = file.meta as FileMetaBase | undefined
|
|
378
|
-
const plugin = meta?.pluginName ? pluginNameMap.get(meta.pluginName) : undefined
|
|
379
|
-
const pluginOptions = plugin?.options as { output?: Output<unknown> } | undefined
|
|
380
|
-
|
|
381
|
-
if (!pluginOptions || pluginOptions.output?.barrelType === false) {
|
|
382
|
-
return []
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
const exportName = config.output.barrelType === 'all' ? undefined : source.name ? [source.name] : undefined
|
|
386
|
-
if (exportName?.some((n) => existingExports.has(n))) {
|
|
387
|
-
return []
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
return [
|
|
391
|
-
{
|
|
392
|
-
name: exportName,
|
|
393
|
-
path: getRelativePath(rootDir, file.path),
|
|
394
|
-
isTypeOnly: config.output.barrelType === 'all' ? containsOnlyTypes : source.isTypeOnly,
|
|
395
|
-
} satisfies KubbFile.Export,
|
|
396
|
-
]
|
|
397
|
-
})
|
|
398
|
-
})
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
/**
|
|
402
|
-
* Maps the resolved `Config['input']` shape into an `AdapterSource` that
|
|
403
|
-
* the adapter's `parse()` can consume.
|
|
404
|
-
*/
|
|
405
|
-
function inputToAdapterSource(config: Config): AdapterSource {
|
|
406
|
-
if (Array.isArray(config.input)) {
|
|
407
|
-
return {
|
|
408
|
-
type: 'paths',
|
|
409
|
-
paths: config.input.map((i) => resolve(config.root, i.path)),
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
if ('data' in config.input) {
|
|
414
|
-
return { type: 'data', data: config.input.data }
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
const resolved = resolve(config.root, config.input.path)
|
|
418
|
-
return { type: 'path', path: resolved }
|
|
419
|
-
}
|
package/src/config.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import type { PossiblePromise } from '@internals/utils'
|
|
2
|
-
import type { InputPath, UserConfig } from './types.ts'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* CLI options derived from command-line flags.
|
|
6
|
-
*/
|
|
7
|
-
export type CLIOptions = {
|
|
8
|
-
/** Path to `kubb.config.js` */
|
|
9
|
-
config?: string
|
|
10
|
-
|
|
11
|
-
/** Enable watch mode for input files */
|
|
12
|
-
watch?: boolean
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Logging verbosity for CLI usage.
|
|
16
|
-
*
|
|
17
|
-
* - `silent`: hide non-essential logs
|
|
18
|
-
* - `info`: show general logs (non-plugin-related)
|
|
19
|
-
* - `debug`: include detailed plugin lifecycle logs
|
|
20
|
-
* @default 'silent'
|
|
21
|
-
*/
|
|
22
|
-
logLevel?: 'silent' | 'info' | 'debug'
|
|
23
|
-
|
|
24
|
-
/** Run Kubb with Bun */
|
|
25
|
-
bun?: boolean
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** All accepted forms of a Kubb configuration. */
|
|
29
|
-
export type ConfigInput = PossiblePromise<UserConfig | UserConfig[]> | ((cli: CLIOptions) => PossiblePromise<UserConfig | UserConfig[]>)
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Helper for defining a Kubb configuration.
|
|
33
|
-
*
|
|
34
|
-
* Accepts either:
|
|
35
|
-
* - A config object or array of configs
|
|
36
|
-
* - A function returning the config(s), optionally async,
|
|
37
|
-
* receiving the CLI options as argument
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* export default defineConfig(({ logLevel }) => ({
|
|
41
|
-
* root: 'src',
|
|
42
|
-
* plugins: [myPlugin()],
|
|
43
|
-
* }))
|
|
44
|
-
*/
|
|
45
|
-
export function defineConfig(config: (cli: CLIOptions) => PossiblePromise<UserConfig | UserConfig[]>): typeof config
|
|
46
|
-
export function defineConfig(config: PossiblePromise<UserConfig | UserConfig[]>): typeof config
|
|
47
|
-
export function defineConfig(config: ConfigInput): ConfigInput {
|
|
48
|
-
return config
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Type guard to check if a given config has an `input.path`.
|
|
53
|
-
*/
|
|
54
|
-
export function isInputPath(config: UserConfig | undefined): config is UserConfig<InputPath> {
|
|
55
|
-
return typeof config?.input === 'object' && config.input !== null && 'path' in config.input
|
|
56
|
-
}
|
package/src/createGenerator.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import type { OperationNode, SchemaNode } from '@kubb/ast/types'
|
|
2
|
-
import type { KubbFile } from '@kubb/fabric-core/types'
|
|
3
|
-
import type { FabricReactNode } from '@kubb/react-fabric/types'
|
|
4
|
-
import type { Adapter, Config, Plugin, PluginFactoryOptions } from './types.ts'
|
|
5
|
-
|
|
6
|
-
export type Version = '1' | '2'
|
|
7
|
-
|
|
8
|
-
// V2 props — fully typed with @kubb/ast (already a @kubb/core dependency)
|
|
9
|
-
export type OperationsV2Props<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
10
|
-
config: Config
|
|
11
|
-
adapter: Adapter
|
|
12
|
-
options: Plugin<TPlugin>['options']
|
|
13
|
-
nodes: Array<OperationNode>
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export type OperationV2Props<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
17
|
-
config: Config
|
|
18
|
-
adapter: Adapter
|
|
19
|
-
options: Plugin<TPlugin>['options']
|
|
20
|
-
node: OperationNode
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export type SchemaV2Props<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
24
|
-
config: Config
|
|
25
|
-
adapter: Adapter
|
|
26
|
-
options: Plugin<TPlugin>['options']
|
|
27
|
-
node: SchemaNode
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
type UserCoreGeneratorV2<TPlugin extends PluginFactoryOptions> = {
|
|
31
|
-
name: string
|
|
32
|
-
type: 'core'
|
|
33
|
-
version?: '2'
|
|
34
|
-
operations?(props: OperationsV2Props<TPlugin>): Promise<Array<KubbFile.File>>
|
|
35
|
-
operation?(props: OperationV2Props<TPlugin>): Promise<Array<KubbFile.File>>
|
|
36
|
-
schema?(props: SchemaV2Props<TPlugin>): Promise<Array<KubbFile.File>>
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
type UserReactGeneratorV2<TPlugin extends PluginFactoryOptions> = {
|
|
40
|
-
name: string
|
|
41
|
-
type: 'react'
|
|
42
|
-
version?: '2'
|
|
43
|
-
Operations?(props: OperationsV2Props<TPlugin>): FabricReactNode
|
|
44
|
-
Operation?(props: OperationV2Props<TPlugin>): FabricReactNode
|
|
45
|
-
Schema?(props: SchemaV2Props<TPlugin>): FabricReactNode
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export type CoreGeneratorV2<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
49
|
-
name: string
|
|
50
|
-
type: 'core'
|
|
51
|
-
version: '2'
|
|
52
|
-
operations(props: OperationsV2Props<TPlugin>): Promise<Array<KubbFile.File>>
|
|
53
|
-
operation(props: OperationV2Props<TPlugin>): Promise<Array<KubbFile.File>>
|
|
54
|
-
schema(props: SchemaV2Props<TPlugin>): Promise<Array<KubbFile.File>>
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export type ReactGeneratorV2<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
58
|
-
name: string
|
|
59
|
-
type: 'react'
|
|
60
|
-
version: '2'
|
|
61
|
-
Operations(props: OperationsV2Props<TPlugin>): FabricReactNode
|
|
62
|
-
Operation(props: OperationV2Props<TPlugin>): FabricReactNode
|
|
63
|
-
Schema(props: SchemaV2Props<TPlugin>): FabricReactNode
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export type Generator<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = UserCoreGeneratorV2<TPlugin> | UserReactGeneratorV2<TPlugin>
|
|
67
|
-
|
|
68
|
-
export function createGenerator<TPlugin extends PluginFactoryOptions = PluginFactoryOptions>(
|
|
69
|
-
generator: UserReactGeneratorV2<TPlugin>,
|
|
70
|
-
): ReactGeneratorV2<TPlugin>
|
|
71
|
-
|
|
72
|
-
export function createGenerator<TPlugin extends PluginFactoryOptions = PluginFactoryOptions>(generator: UserCoreGeneratorV2<TPlugin>): CoreGeneratorV2<TPlugin>
|
|
73
|
-
|
|
74
|
-
export function createGenerator<TPlugin extends PluginFactoryOptions = PluginFactoryOptions>(
|
|
75
|
-
generator: UserCoreGeneratorV2<TPlugin> | UserReactGeneratorV2<TPlugin>,
|
|
76
|
-
): unknown {
|
|
77
|
-
if (generator.type === 'react') {
|
|
78
|
-
return {
|
|
79
|
-
version: '2',
|
|
80
|
-
Operations() {
|
|
81
|
-
return null
|
|
82
|
-
},
|
|
83
|
-
Operation() {
|
|
84
|
-
return null
|
|
85
|
-
},
|
|
86
|
-
Schema() {
|
|
87
|
-
return null
|
|
88
|
-
},
|
|
89
|
-
...generator,
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return {
|
|
94
|
-
version: '2',
|
|
95
|
-
async operations() {
|
|
96
|
-
return []
|
|
97
|
-
},
|
|
98
|
-
async operation() {
|
|
99
|
-
return []
|
|
100
|
-
},
|
|
101
|
-
async schema() {
|
|
102
|
-
return []
|
|
103
|
-
},
|
|
104
|
-
...generator,
|
|
105
|
-
}
|
|
106
|
-
}
|
package/src/createLogger.ts
DELETED
package/src/createPlugin.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { PluginFactoryOptions, UserPluginWithLifeCycle } from './types.ts'
|
|
2
|
-
|
|
3
|
-
type PluginBuilder<T extends PluginFactoryOptions = PluginFactoryOptions> = (options: T['options']) => UserPluginWithLifeCycle<T>
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Wraps a plugin builder to make the options parameter optional.
|
|
7
|
-
*/
|
|
8
|
-
export function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(
|
|
9
|
-
build: PluginBuilder<T>,
|
|
10
|
-
): (options?: T['options']) => UserPluginWithLifeCycle<T> {
|
|
11
|
-
return (options) => build(options ?? ({} as T['options']))
|
|
12
|
-
}
|
package/src/errors.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { BuildError, ValidationPluginError } from '@internals/utils'
|
package/src/hooks/index.ts
DELETED