@kubb/core 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.
- package/README.md +13 -40
- package/dist/PluginDriver-Cu1Kj9S-.cjs +1075 -0
- package/dist/PluginDriver-Cu1Kj9S-.cjs.map +1 -0
- package/dist/PluginDriver-D8Z0Htid.js +978 -0
- package/dist/PluginDriver-D8Z0Htid.js.map +1 -0
- package/dist/createKubb-ALdb8lmq.d.ts +2082 -0
- package/dist/index.cjs +747 -1667
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +175 -269
- package/dist/index.js +734 -1638
- 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/package.json +47 -60
- package/src/FileManager.ts +115 -0
- package/src/FileProcessor.ts +86 -0
- package/src/PluginDriver.ts +355 -561
- package/src/constants.ts +21 -48
- package/src/createAdapter.ts +88 -5
- package/src/createKubb.ts +1266 -0
- package/src/createRenderer.ts +57 -0
- package/src/createStorage.ts +13 -1
- package/src/defineGenerator.ts +160 -119
- package/src/defineLogger.ts +46 -5
- package/src/defineMiddleware.ts +62 -0
- package/src/defineParser.ts +44 -0
- package/src/definePlugin.ts +379 -0
- package/src/defineResolver.ts +548 -25
- package/src/devtools.ts +22 -15
- package/src/index.ts +13 -15
- package/src/mocks.ts +177 -0
- package/src/storages/fsStorage.ts +13 -8
- package/src/storages/memoryStorage.ts +4 -2
- package/src/types.ts +40 -547
- package/dist/PluginDriver-BkFepPdm.d.ts +0 -1054
- package/dist/chunk-ByKO4r7w.cjs +0 -38
- package/dist/hooks.cjs +0 -103
- package/dist/hooks.cjs.map +0 -1
- package/dist/hooks.d.ts +0 -77
- package/dist/hooks.js +0 -98
- package/dist/hooks.js.map +0 -1
- package/src/Kubb.ts +0 -224
- package/src/build.ts +0 -418
- package/src/config.ts +0 -56
- package/src/createPlugin.ts +0 -28
- package/src/hooks/index.ts +0 -4
- package/src/hooks/useKubb.ts +0 -143
- 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/diagnostics.ts +0 -15
- 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 -12
- package/src/utils/linters.ts +0 -25
- package/src/utils/packageJSON.ts +0 -61
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { CodeNode, FileNode } from '@kubb/ast'
|
|
2
|
+
import { extractStringsFromNodes } from '@kubb/ast'
|
|
3
|
+
import pLimit from 'p-limit'
|
|
4
|
+
import { PARALLEL_CONCURRENCY_LIMIT } from './constants.ts'
|
|
5
|
+
import type { Parser } from './defineParser.ts'
|
|
6
|
+
|
|
7
|
+
type ParseOptions = {
|
|
8
|
+
parsers?: Map<FileNode['extname'], Parser>
|
|
9
|
+
extension?: Record<FileNode['extname'], FileNode['extname'] | ''>
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type RunOptions = ParseOptions & {
|
|
13
|
+
/**
|
|
14
|
+
* @default 'sequential'
|
|
15
|
+
*/
|
|
16
|
+
mode?: 'sequential' | 'parallel'
|
|
17
|
+
onStart?: (files: Array<FileNode>) => Promise<void> | void
|
|
18
|
+
onEnd?: (files: Array<FileNode>) => Promise<void> | void
|
|
19
|
+
onUpdate?: (params: { file: FileNode; source?: string; processed: number; total: number; percentage: number }) => Promise<void> | void
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function joinSources(file: FileNode): string {
|
|
23
|
+
return file.sources
|
|
24
|
+
.map((item) => extractStringsFromNodes(item.nodes as Array<CodeNode>))
|
|
25
|
+
.filter(Boolean)
|
|
26
|
+
.join('\n\n')
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Converts a single file to a string using the registered parsers.
|
|
31
|
+
* Falls back to joining source values when no matching parser is found.
|
|
32
|
+
*
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
export class FileProcessor {
|
|
36
|
+
readonly #limit = pLimit(PARALLEL_CONCURRENCY_LIMIT)
|
|
37
|
+
|
|
38
|
+
async parse(file: FileNode, { parsers, extension }: ParseOptions = {}): Promise<string> {
|
|
39
|
+
const parseExtName = extension?.[file.extname] || undefined
|
|
40
|
+
|
|
41
|
+
if (!parsers || !file.extname) {
|
|
42
|
+
return joinSources(file)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const parser = parsers.get(file.extname)
|
|
46
|
+
|
|
47
|
+
if (!parser) {
|
|
48
|
+
return joinSources(file)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return parser.parse(file, { extname: parseExtName })
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async run(files: Array<FileNode>, { parsers, mode = 'sequential', extension, onStart, onEnd, onUpdate }: RunOptions = {}): Promise<Array<FileNode>> {
|
|
55
|
+
await onStart?.(files)
|
|
56
|
+
|
|
57
|
+
const total = files.length
|
|
58
|
+
let processed = 0
|
|
59
|
+
|
|
60
|
+
const processOne = async (file: FileNode) => {
|
|
61
|
+
const source = await this.parse(file, { extension, parsers })
|
|
62
|
+
const currentProcessed = ++processed
|
|
63
|
+
const percentage = (currentProcessed / total) * 100
|
|
64
|
+
|
|
65
|
+
await onUpdate?.({
|
|
66
|
+
file,
|
|
67
|
+
source,
|
|
68
|
+
processed: currentProcessed,
|
|
69
|
+
percentage,
|
|
70
|
+
total,
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (mode === 'sequential') {
|
|
75
|
+
for (const file of files) {
|
|
76
|
+
await processOne(file)
|
|
77
|
+
}
|
|
78
|
+
} else {
|
|
79
|
+
await Promise.all(files.map((file) => this.#limit(() => processOne(file))))
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
await onEnd?.(files)
|
|
83
|
+
|
|
84
|
+
return files
|
|
85
|
+
}
|
|
86
|
+
}
|