@kubb/core 2.18.3 → 2.18.5
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/dist/chunk-7TB4GNKF.cjs +1268 -0
- package/dist/chunk-7TB4GNKF.cjs.map +1 -0
- package/dist/{chunk-JLT7YQF5.js → chunk-7UMWFPXG.js} +9 -10
- package/dist/chunk-7UMWFPXG.js.map +1 -0
- package/dist/{chunk-WNT5FJKX.cjs → chunk-BE4KSMB4.cjs} +5 -5
- package/dist/chunk-EPAC7V2R.js +597 -0
- package/dist/chunk-EPAC7V2R.js.map +1 -0
- package/dist/{chunk-LSRMKE3Q.cjs → chunk-FWUA552W.cjs} +29 -29
- package/dist/{chunk-I6K57NKM.cjs → chunk-JI763CHT.cjs} +18 -18
- package/dist/{chunk-CURDPCUG.cjs → chunk-M6VNU2SJ.cjs} +21 -22
- package/dist/chunk-M6VNU2SJ.cjs.map +1 -0
- package/dist/{chunk-SJLROYQM.cjs → chunk-TCFN5BZ6.cjs} +5 -13
- package/dist/chunk-TCFN5BZ6.cjs.map +1 -0
- package/dist/index.cjs +1297 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +54 -175
- package/dist/index.d.ts +54 -175
- package/dist/index.js +991 -22
- package/dist/index.js.map +1 -1
- package/dist/{logger-Cskfrvra.d.ts → logger-DChjnJMn.d.cts} +10 -2
- package/dist/{logger-Cskfrvra.d.cts → logger-DChjnJMn.d.ts} +10 -2
- package/dist/logger.cjs +5 -4
- package/dist/logger.d.cts +2 -1
- package/dist/logger.d.ts +2 -1
- package/dist/logger.js +3 -2
- package/dist/mocks.cjs +15 -14
- package/dist/mocks.cjs.map +1 -1
- package/dist/mocks.d.cts +6 -3
- package/dist/mocks.d.ts +6 -3
- package/dist/mocks.js +7 -6
- package/dist/mocks.js.map +1 -1
- package/dist/transformers.cjs +4 -4
- package/dist/utils.cjs +4 -4
- package/package.json +10 -19
- package/src/BarrelManager.ts +1 -1
- package/src/FileManager.ts +36 -167
- package/src/PackageManager.ts +1 -1
- package/src/PluginManager.ts +5 -5
- package/src/build.ts +6 -8
- package/src/config.ts +29 -2
- package/src/index.ts +2 -3
- package/src/logger.ts +11 -9
- package/src/types.ts +4 -30
- package/src/utils/TreeNode.ts +1 -1
- package/dist/chunk-2F7E62RD.js +0 -85
- package/dist/chunk-2F7E62RD.js.map +0 -1
- package/dist/chunk-CURDPCUG.cjs.map +0 -1
- package/dist/chunk-J7SXH3YG.js +0 -1597
- package/dist/chunk-J7SXH3YG.js.map +0 -1
- package/dist/chunk-JLT7YQF5.js.map +0 -1
- package/dist/chunk-KSXPJNIA.cjs +0 -2584
- package/dist/chunk-KSXPJNIA.cjs.map +0 -1
- package/dist/chunk-MDO6MCFJ.js +0 -65
- package/dist/chunk-MDO6MCFJ.js.map +0 -1
- package/dist/chunk-RPDYCQHF.cjs +0 -2332
- package/dist/chunk-RPDYCQHF.cjs.map +0 -1
- package/dist/chunk-SJLROYQM.cjs.map +0 -1
- package/dist/chunk-U2XQEWRF.cjs +0 -75
- package/dist/chunk-U2XQEWRF.cjs.map +0 -1
- package/dist/fs.cjs +0 -23
- package/dist/fs.cjs.map +0 -1
- package/dist/fs.d.cts +0 -5
- package/dist/fs.d.ts +0 -5
- package/dist/fs.js +0 -18
- package/dist/fs.js.map +0 -1
- package/dist/write-CN8f7bYv.d.cts +0 -10
- package/dist/write-CN8f7bYv.d.ts +0 -10
- package/src/fs/clean.ts +0 -5
- package/src/fs/index.ts +0 -3
- package/src/fs/read.ts +0 -68
- package/src/fs/write.ts +0 -83
- /package/dist/{chunk-WNT5FJKX.cjs.map → chunk-BE4KSMB4.cjs.map} +0 -0
- /package/dist/{chunk-LSRMKE3Q.cjs.map → chunk-FWUA552W.cjs.map} +0 -0
- /package/dist/{chunk-I6K57NKM.cjs.map → chunk-JI763CHT.cjs.map} +0 -0
package/src/FileManager.ts
CHANGED
|
@@ -5,12 +5,14 @@ import { orderBy } from 'natural-orderby'
|
|
|
5
5
|
import PQueue from 'p-queue'
|
|
6
6
|
import { isDeepEqual } from 'remeda'
|
|
7
7
|
|
|
8
|
+
import { getRelativePath, read, write } from '@kubb/fs'
|
|
8
9
|
import { BarrelManager } from './BarrelManager.ts'
|
|
9
|
-
import { getRelativePath, read } from './fs/read.ts'
|
|
10
|
-
import { write } from './fs/write.ts'
|
|
11
10
|
import { searchAndReplace } from './transformers/searchAndReplace.ts'
|
|
12
11
|
import { trimExtName } from './transformers/trim.ts'
|
|
13
12
|
|
|
13
|
+
import type * as KubbFile from '@kubb/fs/types'
|
|
14
|
+
|
|
15
|
+
import type { BaseName, File, UUID } from '@kubb/fs/src/types.ts'
|
|
14
16
|
import type { GreaterThan } from '@kubb/types'
|
|
15
17
|
import type { BarrelManagerOptions } from './BarrelManager.ts'
|
|
16
18
|
import type { Logger } from './logger.ts'
|
|
@@ -18,163 +20,30 @@ import transformers from './transformers/index.ts'
|
|
|
18
20
|
import type { Plugin } from './types.ts'
|
|
19
21
|
import { getParser } from './utils'
|
|
20
22
|
|
|
21
|
-
type
|
|
22
|
-
|
|
23
|
-
export namespace KubbFile {
|
|
24
|
-
export type Import = {
|
|
25
|
-
/**
|
|
26
|
-
* Import name to be used
|
|
27
|
-
* @example ["useState"]
|
|
28
|
-
* @example "React"
|
|
29
|
-
*/
|
|
30
|
-
name:
|
|
31
|
-
| string
|
|
32
|
-
| Array<
|
|
33
|
-
| string
|
|
34
|
-
| {
|
|
35
|
-
propertyName: string
|
|
36
|
-
name?: string
|
|
37
|
-
}
|
|
38
|
-
>
|
|
39
|
-
/**
|
|
40
|
-
* Path for the import
|
|
41
|
-
* @xample '@kubb/core'
|
|
42
|
-
*/
|
|
43
|
-
path: string
|
|
44
|
-
/**
|
|
45
|
-
* Add `type` prefix to the import, this will result in: `import type { Type } from './path'`.
|
|
46
|
-
*/
|
|
47
|
-
isTypeOnly?: boolean
|
|
48
|
-
/**
|
|
49
|
-
* Add `* as` prefix to the import, this will result in: `import * as path from './path'`.
|
|
50
|
-
*/
|
|
51
|
-
|
|
52
|
-
isNameSpace?: boolean
|
|
53
|
-
/**
|
|
54
|
-
* When root is set it will get the path with relative getRelativePath(root, path).
|
|
55
|
-
*/
|
|
56
|
-
root?: string
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export type Export = {
|
|
60
|
-
/**
|
|
61
|
-
* Export name to be used.
|
|
62
|
-
* @example ["useState"]
|
|
63
|
-
* @example "React"
|
|
64
|
-
*/
|
|
65
|
-
name?: string | Array<string>
|
|
66
|
-
/**
|
|
67
|
-
* Path for the import.
|
|
68
|
-
* @xample '@kubb/core'
|
|
69
|
-
*/
|
|
70
|
-
path: string
|
|
71
|
-
/**
|
|
72
|
-
* Add `type` prefix to the export, this will result in: `export type { Type } from './path'`.
|
|
73
|
-
*/
|
|
74
|
-
isTypeOnly?: boolean
|
|
75
|
-
/**
|
|
76
|
-
* Make it possible to override the name, this will result in: `export * as aliasName from './path'`.
|
|
77
|
-
*/
|
|
78
|
-
asAlias?: boolean
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export declare const dataTagSymbol: unique symbol
|
|
82
|
-
export type DataTag<Type, Value> = Type & {
|
|
83
|
-
[dataTagSymbol]: Value
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export type UUID = string
|
|
87
|
-
export type Source = string
|
|
88
|
-
|
|
89
|
-
export type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`
|
|
90
|
-
|
|
91
|
-
export type Mode = 'single' | 'split'
|
|
92
|
-
|
|
23
|
+
export type ResolvedFile<TMeta extends FileMetaBase = FileMetaBase, TBaseName extends BaseName = BaseName> = File<TMeta, TBaseName> & {
|
|
93
24
|
/**
|
|
94
|
-
*
|
|
95
|
-
* Based on UNIX basename
|
|
96
|
-
* @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
|
|
25
|
+
* @default crypto.randomUUID()
|
|
97
26
|
*/
|
|
98
|
-
|
|
99
|
-
|
|
27
|
+
id: UUID
|
|
100
28
|
/**
|
|
101
|
-
*
|
|
29
|
+
* Contains the first part of the baseName, generated based on baseName
|
|
30
|
+
* @link https://nodejs.org/api/path.html#pathformatpathobject
|
|
102
31
|
*/
|
|
103
|
-
export type Path = string
|
|
104
32
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
export type OptionalPath = Path | undefined | null
|
|
108
|
-
|
|
109
|
-
export type FileMetaBase = {
|
|
110
|
-
pluginKey?: Plugin['key']
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export type File<TMeta extends FileMetaBase = FileMetaBase, TBaseName extends BaseName = BaseName> = {
|
|
114
|
-
/**
|
|
115
|
-
* Unique identifier to reuse later
|
|
116
|
-
* @default crypto.randomUUID()
|
|
117
|
-
*/
|
|
118
|
-
id?: string
|
|
119
|
-
/**
|
|
120
|
-
* Name to be used to create the path
|
|
121
|
-
* Based on UNIX basename, `${name}.extName`
|
|
122
|
-
* @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
|
|
123
|
-
*/
|
|
124
|
-
baseName: TBaseName
|
|
125
|
-
/**
|
|
126
|
-
* Path will be full qualified path to a specified file
|
|
127
|
-
*/
|
|
128
|
-
path: AdvancedPath<TBaseName> | Path
|
|
129
|
-
source: Source
|
|
130
|
-
imports?: Import[]
|
|
131
|
-
exports?: Export[]
|
|
132
|
-
/**
|
|
133
|
-
* This will call fileManager.add instead of fileManager.addOrAppend, adding the source when the files already exists
|
|
134
|
-
* This will also ignore the combinefiles utils
|
|
135
|
-
* @default `false`
|
|
136
|
-
*/
|
|
137
|
-
override?: boolean
|
|
138
|
-
/**
|
|
139
|
-
* Use extra meta, this is getting used to generate the barrel/index files.
|
|
140
|
-
*/
|
|
141
|
-
meta?: TMeta
|
|
142
|
-
/**
|
|
143
|
-
* Override if a file can be exported by the BarrelManager
|
|
144
|
-
* @default true
|
|
145
|
-
*/
|
|
146
|
-
exportable?: boolean
|
|
147
|
-
/**
|
|
148
|
-
* This will override `process.env[key]` inside the `source`, see `getFileSource`.
|
|
149
|
-
*/
|
|
150
|
-
env?: NodeJS.ProcessEnv
|
|
151
|
-
/**
|
|
152
|
-
* The name of the language being used. This can be TypeScript, JavaScript and still have another ext.
|
|
153
|
-
*/
|
|
154
|
-
language?: string
|
|
155
|
-
}
|
|
33
|
+
name: string
|
|
34
|
+
}
|
|
156
35
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
* @default crypto.randomUUID()
|
|
160
|
-
*/
|
|
161
|
-
id: UUID
|
|
162
|
-
/**
|
|
163
|
-
* Contains the first part of the baseName, generated based on baseName
|
|
164
|
-
* @link https://nodejs.org/api/path.html#pathformatpathobject
|
|
165
|
-
*/
|
|
166
|
-
|
|
167
|
-
name: string
|
|
168
|
-
}
|
|
36
|
+
export type FileMetaBase = {
|
|
37
|
+
pluginKey?: Plugin['key']
|
|
169
38
|
}
|
|
170
39
|
|
|
171
|
-
type
|
|
40
|
+
type FileWithMeta<TMeta extends FileMetaBase = FileMetaBase> = KubbFile.File<TMeta>
|
|
41
|
+
|
|
42
|
+
type CacheItem = ResolvedFile & {
|
|
172
43
|
cancel?: () => void
|
|
173
44
|
}
|
|
174
45
|
|
|
175
|
-
type AddResult<T extends Array<
|
|
176
|
-
Awaited<GreaterThan<T['length'], 1> extends true ? Promise<KubbFile.ResolvedFile[]> : Promise<KubbFile.ResolvedFile>>
|
|
177
|
-
>
|
|
46
|
+
type AddResult<T extends Array<FileWithMeta>> = Promise<Awaited<GreaterThan<T['length'], 1> extends true ? Promise<ResolvedFile[]> : Promise<ResolvedFile>>>
|
|
178
47
|
|
|
179
48
|
type AddIndexesProps = {
|
|
180
49
|
/**
|
|
@@ -192,12 +61,12 @@ type AddIndexesProps = {
|
|
|
192
61
|
}
|
|
193
62
|
logger: Logger
|
|
194
63
|
options?: BarrelManagerOptions
|
|
195
|
-
meta?:
|
|
64
|
+
meta?: FileWithMeta['meta']
|
|
196
65
|
}
|
|
197
66
|
|
|
198
67
|
type Options = {
|
|
199
68
|
queue?: PQueue
|
|
200
|
-
task?: (file:
|
|
69
|
+
task?: (file: ResolvedFile) => Promise<ResolvedFile>
|
|
201
70
|
}
|
|
202
71
|
|
|
203
72
|
export class FileManager {
|
|
@@ -213,8 +82,8 @@ export class FileManager {
|
|
|
213
82
|
return this
|
|
214
83
|
}
|
|
215
84
|
|
|
216
|
-
get files(): Array<
|
|
217
|
-
const files: Array<
|
|
85
|
+
get files(): Array<FileWithMeta> {
|
|
86
|
+
const files: Array<FileWithMeta> = []
|
|
218
87
|
this.#cache.forEach((item) => {
|
|
219
88
|
files.push(...item.flat(1))
|
|
220
89
|
})
|
|
@@ -225,7 +94,7 @@ export class FileManager {
|
|
|
225
94
|
return this.#queue.size !== 0 && this.#queue.pending !== 0
|
|
226
95
|
}
|
|
227
96
|
|
|
228
|
-
async add<T extends Array<
|
|
97
|
+
async add<T extends Array<FileWithMeta> = Array<FileWithMeta>>(...files: T): AddResult<T> {
|
|
229
98
|
const promises = combineFiles(files).map((file) => {
|
|
230
99
|
if (file.override) {
|
|
231
100
|
return this.#add(file)
|
|
@@ -243,9 +112,9 @@ export class FileManager {
|
|
|
243
112
|
return resolvedFiles[0] as unknown as AddResult<T>
|
|
244
113
|
}
|
|
245
114
|
|
|
246
|
-
async #add(file:
|
|
115
|
+
async #add(file: FileWithMeta): Promise<ResolvedFile> {
|
|
247
116
|
const controller = new AbortController()
|
|
248
|
-
const resolvedFile:
|
|
117
|
+
const resolvedFile: ResolvedFile = {
|
|
249
118
|
id: crypto.randomUUID(),
|
|
250
119
|
name: trimExtName(file.baseName),
|
|
251
120
|
...file,
|
|
@@ -272,10 +141,10 @@ export class FileManager {
|
|
|
272
141
|
return this.#task?.(resolvedFile)
|
|
273
142
|
},
|
|
274
143
|
{ signal: controller.signal },
|
|
275
|
-
) as Promise<
|
|
144
|
+
) as Promise<ResolvedFile>
|
|
276
145
|
}
|
|
277
146
|
|
|
278
|
-
async #addOrAppend(file:
|
|
147
|
+
async #addOrAppend(file: FileWithMeta): Promise<ResolvedFile> {
|
|
279
148
|
const previousCaches = this.#cache.get(file.path)
|
|
280
149
|
const previousCache = previousCaches ? previousCaches.at(previousCaches.length - 1) : undefined
|
|
281
150
|
|
|
@@ -341,7 +210,7 @@ export class FileManager {
|
|
|
341
210
|
)
|
|
342
211
|
|
|
343
212
|
const rootPath = mode === 'split' ? `${exportPath}/index${output.extName || ''}` : `${exportPath}${output.extName || ''}`
|
|
344
|
-
const rootFile:
|
|
213
|
+
const rootFile: FileWithMeta = {
|
|
345
214
|
path: resolve(root, 'index.ts'),
|
|
346
215
|
baseName: 'index.ts',
|
|
347
216
|
source: '',
|
|
@@ -371,8 +240,8 @@ export class FileManager {
|
|
|
371
240
|
})
|
|
372
241
|
}
|
|
373
242
|
|
|
374
|
-
getCacheByUUID(UUID: KubbFile.UUID):
|
|
375
|
-
let cache:
|
|
243
|
+
getCacheByUUID(UUID: KubbFile.UUID): FileWithMeta | undefined {
|
|
244
|
+
let cache: FileWithMeta | undefined
|
|
376
245
|
|
|
377
246
|
this.#cache.forEach((files) => {
|
|
378
247
|
cache = files.find((item) => item.id === UUID)
|
|
@@ -380,7 +249,7 @@ export class FileManager {
|
|
|
380
249
|
return cache
|
|
381
250
|
}
|
|
382
251
|
|
|
383
|
-
get(path: KubbFile.Path): Array<
|
|
252
|
+
get(path: KubbFile.Path): Array<FileWithMeta> | undefined {
|
|
384
253
|
return this.#cache.get(path)
|
|
385
254
|
}
|
|
386
255
|
|
|
@@ -403,11 +272,11 @@ export class FileManager {
|
|
|
403
272
|
|
|
404
273
|
// statics
|
|
405
274
|
|
|
406
|
-
static async getSource<TMeta extends
|
|
275
|
+
static async getSource<TMeta extends FileMetaBase = FileMetaBase>(file: FileWithMeta<TMeta>): Promise<string> {
|
|
407
276
|
return getSource<TMeta>(file)
|
|
408
277
|
}
|
|
409
278
|
|
|
410
|
-
static combineFiles<TMeta extends
|
|
279
|
+
static combineFiles<TMeta extends FileMetaBase = FileMetaBase>(files: Array<FileWithMeta<TMeta> | null>): Array<FileWithMeta<TMeta>> {
|
|
411
280
|
return combineFiles<TMeta>(files)
|
|
412
281
|
}
|
|
413
282
|
static getMode(path: string | undefined | null): KubbFile.Mode {
|
|
@@ -426,9 +295,9 @@ export class FileManager {
|
|
|
426
295
|
}
|
|
427
296
|
}
|
|
428
297
|
|
|
429
|
-
function combineFiles<TMeta extends
|
|
298
|
+
function combineFiles<TMeta extends FileMetaBase = FileMetaBase>(files: Array<FileWithMeta<TMeta> | null>): Array<FileWithMeta<TMeta>> {
|
|
430
299
|
return files.filter(Boolean).reduce(
|
|
431
|
-
(acc, file:
|
|
300
|
+
(acc, file: FileWithMeta<TMeta>) => {
|
|
432
301
|
const prevIndex = acc.findIndex((item) => item.path === file.path)
|
|
433
302
|
|
|
434
303
|
if (prevIndex === -1) {
|
|
@@ -458,11 +327,11 @@ function combineFiles<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBas
|
|
|
458
327
|
|
|
459
328
|
return acc
|
|
460
329
|
},
|
|
461
|
-
[] as Array<
|
|
330
|
+
[] as Array<FileWithMeta<TMeta>>,
|
|
462
331
|
)
|
|
463
332
|
}
|
|
464
333
|
|
|
465
|
-
export async function getSource<TMeta extends
|
|
334
|
+
export async function getSource<TMeta extends FileMetaBase = FileMetaBase>(file: FileWithMeta<TMeta>): Promise<string> {
|
|
466
335
|
// only use .js, .ts or .tsx files for ESM imports
|
|
467
336
|
|
|
468
337
|
if (file.language ? !['typescript', 'javascript'].includes(file.language) : !FileManager.isJavascript(file.baseName)) {
|
package/src/PackageManager.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { pathToFileURL } from 'node:url'
|
|
|
5
5
|
import { findUp, findUpSync } from 'find-up'
|
|
6
6
|
import { coerce, satisfies } from 'semver'
|
|
7
7
|
|
|
8
|
-
import { read, readSync } from '
|
|
8
|
+
import { read, readSync } from '@kubb/fs'
|
|
9
9
|
|
|
10
10
|
type PackageJSON = {
|
|
11
11
|
dependencies?: Record<string, string>
|
package/src/PluginManager.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import PQueue from 'p-queue'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { readSync } from '@kubb/fs'
|
|
4
|
+
import { FileManager, type ResolvedFile } from './FileManager.ts'
|
|
4
5
|
import { isPromise, isPromiseRejectedResult } from './PromiseManager.ts'
|
|
5
6
|
import { PromiseManager } from './PromiseManager.ts'
|
|
6
7
|
import { ValidationPluginError } from './errors.ts'
|
|
7
|
-
import { readSync } from './fs/read.ts'
|
|
8
8
|
import { LogLevel } from './logger.ts'
|
|
9
9
|
import { pluginCore } from './plugin.ts'
|
|
10
10
|
import { transformReservedWord } from './transformers/transformReservedWord.ts'
|
|
11
11
|
import { EventEmitter } from './utils/EventEmitter.ts'
|
|
12
12
|
import { setUniqueName } from './utils/uniqueName.ts'
|
|
13
13
|
|
|
14
|
+
import type * as KubbFile from '@kubb/fs/types'
|
|
14
15
|
import type { PossiblePromise } from '@kubb/types'
|
|
15
|
-
import type { KubbFile } from './FileManager.ts'
|
|
16
16
|
import type { Logger } from './logger.ts'
|
|
17
17
|
import type { PluginCore } from './plugin.ts'
|
|
18
18
|
import type {
|
|
@@ -63,7 +63,7 @@ type Options = {
|
|
|
63
63
|
/**
|
|
64
64
|
* Task for the FileManager
|
|
65
65
|
*/
|
|
66
|
-
task: (file:
|
|
66
|
+
task: (file: ResolvedFile) => Promise<ResolvedFile>
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
type Events = {
|
|
@@ -634,7 +634,7 @@ export class PluginManager {
|
|
|
634
634
|
|
|
635
635
|
// default transform
|
|
636
636
|
if (!plugin.transform) {
|
|
637
|
-
plugin.transform = function transform(code) {
|
|
637
|
+
plugin.transform = function transform(_path, code) {
|
|
638
638
|
return code
|
|
639
639
|
}
|
|
640
640
|
}
|
package/src/build.ts
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import c from 'tinyrainbow'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { clean, read } from '@kubb/fs'
|
|
4
|
+
import { FileManager, type ResolvedFile } from './FileManager.ts'
|
|
4
5
|
import { PluginManager } from './PluginManager.ts'
|
|
5
6
|
import { isPromise } from './PromiseManager.ts'
|
|
6
7
|
import { isInputPath } from './config.ts'
|
|
7
|
-
import { clean } from './fs/clean.ts'
|
|
8
|
-
import { read } from './fs/read.ts'
|
|
9
8
|
import { LogLevel, createLogger, randomCliColour } from './logger.ts'
|
|
10
9
|
import { URLPath } from './utils/URLPath.ts'
|
|
11
10
|
|
|
12
|
-
import type { KubbFile } from './FileManager.ts'
|
|
13
11
|
import type { Logger } from './logger.ts'
|
|
14
12
|
import type { Plugin, PluginContext, PluginParameter, TransformResult } from './types.ts'
|
|
15
13
|
|
|
@@ -62,7 +60,7 @@ async function setup(options: BuildOptions): Promise<PluginManager> {
|
|
|
62
60
|
await clean(config.output.path)
|
|
63
61
|
}
|
|
64
62
|
|
|
65
|
-
const task = async (file:
|
|
63
|
+
const task = async (file: ResolvedFile): Promise<ResolvedFile> => {
|
|
66
64
|
const { path } = file
|
|
67
65
|
|
|
68
66
|
let source: string | null = await FileManager.getSource(file)
|
|
@@ -81,7 +79,7 @@ async function setup(options: BuildOptions): Promise<PluginManager> {
|
|
|
81
79
|
if (source) {
|
|
82
80
|
source = await pluginManager.hookReduceArg0({
|
|
83
81
|
hookName: 'transform',
|
|
84
|
-
parameters: [
|
|
82
|
+
parameters: [path, source],
|
|
85
83
|
reduce: transformReducer,
|
|
86
84
|
})
|
|
87
85
|
|
|
@@ -91,13 +89,13 @@ async function setup(options: BuildOptions): Promise<PluginManager> {
|
|
|
91
89
|
await pluginManager.hookForPlugin({
|
|
92
90
|
pluginKey: file.meta?.pluginKey,
|
|
93
91
|
hookName: 'writeFile',
|
|
94
|
-
parameters: [
|
|
92
|
+
parameters: [path, source],
|
|
95
93
|
})
|
|
96
94
|
}
|
|
97
95
|
|
|
98
96
|
await pluginManager.hookFirst({
|
|
99
97
|
hookName: 'writeFile',
|
|
100
|
-
parameters: [
|
|
98
|
+
parameters: [path, source],
|
|
101
99
|
})
|
|
102
100
|
}
|
|
103
101
|
}
|
package/src/config.ts
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
import type { PossiblePromise } from '@kubb/types'
|
|
2
|
-
import type {
|
|
2
|
+
import type { Config, InputPath, UserConfig } from './types.ts'
|
|
3
|
+
|
|
4
|
+
type Args = {
|
|
5
|
+
/**
|
|
6
|
+
* Path to `kubb.config.js`
|
|
7
|
+
*/
|
|
8
|
+
config?: string
|
|
9
|
+
/**
|
|
10
|
+
* Watch changes on input
|
|
11
|
+
*/
|
|
12
|
+
watch?: boolean
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Log level to report when using the CLI
|
|
16
|
+
*
|
|
17
|
+
* `silent` will hide all information that is not relevant
|
|
18
|
+
*
|
|
19
|
+
* `info` will show all information possible(not related to the PluginManager)
|
|
20
|
+
*
|
|
21
|
+
* `debug` will show all information possible(related to the PluginManager), handy for seeing logs
|
|
22
|
+
* @default `silent`
|
|
23
|
+
*/
|
|
24
|
+
logLevel?: string
|
|
25
|
+
/**
|
|
26
|
+
* Run Kubb with Bun
|
|
27
|
+
*/
|
|
28
|
+
bun?: boolean
|
|
29
|
+
}
|
|
3
30
|
|
|
4
31
|
/**
|
|
5
32
|
* Type helper to make it easier to use kubb.config.js
|
|
@@ -11,7 +38,7 @@ export function defineConfig(
|
|
|
11
38
|
| PossiblePromise<UserConfig | Array<UserConfig>>
|
|
12
39
|
| ((
|
|
13
40
|
/** The options derived from the CLI flags */
|
|
14
|
-
|
|
41
|
+
args: Args,
|
|
15
42
|
) => PossiblePromise<UserConfig | Array<UserConfig>>),
|
|
16
43
|
): typeof options {
|
|
17
44
|
return options
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export { build, build as default, safeBuild } from './build.ts'
|
|
2
2
|
export { defineConfig, isInputPath } from './config.ts'
|
|
3
3
|
export { Warning } from './errors.ts'
|
|
4
|
-
export { FileManager
|
|
4
|
+
export { FileManager } from './FileManager.ts'
|
|
5
|
+
export type { FileMetaBase } from './FileManager.ts'
|
|
5
6
|
export { Generator } from './Generator.ts'
|
|
6
7
|
export { PackageManager } from './PackageManager.ts'
|
|
7
8
|
export { createPlugin } from './plugin.ts'
|
|
@@ -11,5 +12,3 @@ export type * from './types.ts'
|
|
|
11
12
|
|
|
12
13
|
// biome-ignore lint/suspicious/noEmptyInterface: <explanation>
|
|
13
14
|
export interface _Register {}
|
|
14
|
-
|
|
15
|
-
export * as Kubb from './kubb.ts'
|
package/src/logger.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import seedrandom from 'seedrandom'
|
|
2
2
|
import c, { createColors } from 'tinyrainbow'
|
|
3
3
|
|
|
4
|
-
import { writeLog } from './fs/write.ts'
|
|
5
4
|
import { EventEmitter } from './utils/EventEmitter.ts'
|
|
6
5
|
|
|
6
|
+
import type { ConsolaInstance } from 'consola'
|
|
7
7
|
import type { Ora } from 'ora'
|
|
8
8
|
import type { Formatter } from 'tinyrainbow'
|
|
9
9
|
|
|
@@ -14,6 +14,12 @@ export const LogLevel = {
|
|
|
14
14
|
debug: 'debug',
|
|
15
15
|
} as const
|
|
16
16
|
|
|
17
|
+
export const LogMapper = {
|
|
18
|
+
silent: Number.NEGATIVE_INFINITY,
|
|
19
|
+
info: 3,
|
|
20
|
+
debug: 4,
|
|
21
|
+
} as const
|
|
22
|
+
|
|
17
23
|
export type LogLevel = keyof typeof LogLevel
|
|
18
24
|
|
|
19
25
|
type Events = {
|
|
@@ -29,8 +35,8 @@ export type Logger = {
|
|
|
29
35
|
*/
|
|
30
36
|
name?: string
|
|
31
37
|
logLevel: LogLevel
|
|
32
|
-
|
|
33
38
|
spinner?: Ora
|
|
39
|
+
consola?: ConsolaInstance
|
|
34
40
|
on: EventEmitter<Events>['on']
|
|
35
41
|
emit: EventEmitter<Events>['emit']
|
|
36
42
|
}
|
|
@@ -39,9 +45,10 @@ type Props = {
|
|
|
39
45
|
name?: string
|
|
40
46
|
logLevel: LogLevel
|
|
41
47
|
spinner?: Ora
|
|
48
|
+
consola?: ConsolaInstance
|
|
42
49
|
}
|
|
43
50
|
|
|
44
|
-
export function createLogger({ logLevel, name, spinner }: Props): Logger {
|
|
51
|
+
export function createLogger({ logLevel, name, spinner, consola }: Props): Logger {
|
|
45
52
|
const events = new EventEmitter<Events>()
|
|
46
53
|
|
|
47
54
|
events.on('start', (message) => {
|
|
@@ -70,16 +77,11 @@ export function createLogger({ logLevel, name, spinner }: Props): Logger {
|
|
|
70
77
|
throw error
|
|
71
78
|
})
|
|
72
79
|
|
|
73
|
-
events.on('debug', async (messages) => {
|
|
74
|
-
if (logLevel === LogLevel.debug) {
|
|
75
|
-
await writeLog(messages.join('\n'))
|
|
76
|
-
}
|
|
77
|
-
})
|
|
78
|
-
|
|
79
80
|
const logger: Logger = {
|
|
80
81
|
name,
|
|
81
82
|
logLevel,
|
|
82
83
|
spinner,
|
|
84
|
+
consola,
|
|
83
85
|
on: (...args) => {
|
|
84
86
|
return events.on(...args)
|
|
85
87
|
},
|
package/src/types.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import type * as KubbFile from '@kubb/fs/types'
|
|
1
2
|
import type { PossiblePromise } from '@kubb/types'
|
|
2
|
-
import type { FileManager
|
|
3
|
+
import type { FileManager } from './FileManager.ts'
|
|
3
4
|
import type { PluginManager } from './PluginManager.ts'
|
|
4
5
|
import type { OptionsPlugins, PluginUnion } from './kubb.ts'
|
|
5
|
-
import type {
|
|
6
|
+
import type { Logger } from './logger.ts'
|
|
6
7
|
import type { Cache } from './utils/cache.ts'
|
|
7
8
|
|
|
8
9
|
// config
|
|
@@ -96,33 +97,6 @@ export type Config<TInput = Input> = {
|
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
99
|
|
|
99
|
-
export type CLIOptions = {
|
|
100
|
-
/**
|
|
101
|
-
* Path to `kubb.config.js`
|
|
102
|
-
*/
|
|
103
|
-
config?: string
|
|
104
|
-
/**
|
|
105
|
-
* Watch changes on input
|
|
106
|
-
*/
|
|
107
|
-
watch?: string
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Log level to report when using the CLI
|
|
111
|
-
*
|
|
112
|
-
* `silent` will hide all information that is not relevant
|
|
113
|
-
*
|
|
114
|
-
* `info` will show all information possible(not related to the PluginManager)
|
|
115
|
-
*
|
|
116
|
-
* `debug` will show all information possible(related to the PluginManager), handy for seeing logs
|
|
117
|
-
* @default `silent`
|
|
118
|
-
*/
|
|
119
|
-
logLevel?: LogLevel
|
|
120
|
-
/**
|
|
121
|
-
* Run Kubb with Bun
|
|
122
|
-
*/
|
|
123
|
-
bun?: boolean
|
|
124
|
-
}
|
|
125
|
-
|
|
126
100
|
// plugin
|
|
127
101
|
|
|
128
102
|
export type UnionPlugins = PluginUnion
|
|
@@ -269,7 +243,7 @@ export type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactor
|
|
|
269
243
|
* Write the result to the file-system based on the id(defined by `resolvePath` or changed by `load`).
|
|
270
244
|
* @type hookParallel
|
|
271
245
|
*/
|
|
272
|
-
writeFile?: (this: Omit<PluginContext<TOptions>, 'addFile'>, source: string | undefined
|
|
246
|
+
writeFile?: (this: Omit<PluginContext<TOptions>, 'addFile'>, path: KubbFile.Path, source: string | undefined) => PossiblePromise<string | void>
|
|
273
247
|
/**
|
|
274
248
|
* End of the plugin lifecycle.
|
|
275
249
|
* @type hookParallel
|
package/src/utils/TreeNode.ts
CHANGED
|
@@ -2,8 +2,8 @@ import dirTree from 'directory-tree'
|
|
|
2
2
|
|
|
3
3
|
import { FileManager } from '../FileManager.ts'
|
|
4
4
|
|
|
5
|
+
import type * as KubbFile from '@kubb/fs/types'
|
|
5
6
|
import type { DirectoryTree, DirectoryTreeOptions } from 'directory-tree'
|
|
6
|
-
import type { KubbFile } from '../FileManager.ts'
|
|
7
7
|
|
|
8
8
|
export type TreeNodeOptions = DirectoryTreeOptions
|
|
9
9
|
|