@kubb/core 2.0.0-beta.1 → 2.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/dist/index.cjs +292 -240
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +61 -61
- package/dist/index.d.ts +61 -61
- package/dist/index.js +289 -236
- package/dist/index.js.map +1 -1
- package/dist/transformers.cjs +222 -0
- package/dist/transformers.cjs.map +1 -0
- package/dist/transformers.d.cts +55 -0
- package/dist/transformers.d.ts +55 -0
- package/dist/transformers.js +207 -0
- package/dist/transformers.js.map +1 -0
- package/dist/utils.cjs +302 -274
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +515 -67
- package/dist/utils.d.ts +515 -67
- package/dist/utils.js +303 -274
- package/dist/utils.js.map +1 -1
- package/package.json +14 -9
- package/src/BarrelManager.ts +55 -65
- package/src/FileManager.ts +93 -24
- package/src/PluginManager.ts +35 -17
- package/src/build.ts +1 -11
- package/src/index.ts +0 -1
- package/src/plugin.ts +4 -4
- package/src/transformers/casing.ts +9 -0
- package/src/transformers/createJSDocBlockText.ts +9 -0
- package/src/transformers/index.ts +36 -0
- package/src/transformers/trim.ts +7 -0
- package/src/types.ts +22 -41
- package/src/utils/FunctionParams.ts +3 -2
- package/src/utils/TreeNode.ts +6 -3
- package/src/utils/URLPath.ts +5 -5
- package/src/utils/index.ts +0 -1
- package/src/SchemaGenerator.ts +0 -8
- package/src/utils/transformers/createJSDocBlockText.ts +0 -15
- package/src/utils/transformers/index.ts +0 -22
- package/src/utils/transformers/trim.ts +0 -3
- /package/src/{utils/transformers → transformers}/combineCodes.ts +0 -0
- /package/src/{utils/transformers → transformers}/escape.ts +0 -0
- /package/src/{utils/transformers → transformers}/indent.ts +0 -0
- /package/src/{utils/transformers → transformers}/nameSorter.ts +0 -0
- /package/src/{utils/transformers → transformers}/searchAndReplace.ts +0 -0
- /package/src/{utils/transformers → transformers}/transformReservedWord.ts +0 -0
package/dist/utils.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { PossiblePromise } from '@kubb/types';
|
|
1
|
+
import { PossiblePromise, GreaterThan } from '@kubb/types';
|
|
3
2
|
import { DirectoryTreeOptions } from 'directory-tree';
|
|
3
|
+
import { Ora } from 'ora';
|
|
4
4
|
export { default as pc } from 'picocolors';
|
|
5
5
|
|
|
6
6
|
declare function getRelativePath(rootDir?: string | null, filePath?: string | null, platform?: 'windows' | 'mac' | 'linux'): string;
|
|
@@ -9,6 +9,25 @@ declare function readSync(path: string): string;
|
|
|
9
9
|
|
|
10
10
|
declare function write(data: string, path: string): Promise<string | undefined>;
|
|
11
11
|
|
|
12
|
+
type TreeNodeOptions = DirectoryTreeOptions;
|
|
13
|
+
type BarrelData = {
|
|
14
|
+
type: KubbFile.Mode;
|
|
15
|
+
path: KubbFile.Path;
|
|
16
|
+
name: string;
|
|
17
|
+
};
|
|
18
|
+
declare class TreeNode<T = BarrelData> {
|
|
19
|
+
data: T;
|
|
20
|
+
parent?: TreeNode<T>;
|
|
21
|
+
children: Array<TreeNode<T>>;
|
|
22
|
+
constructor(data: T, parent?: TreeNode<T>);
|
|
23
|
+
addChild(data: T): TreeNode<T>;
|
|
24
|
+
find(data?: T): TreeNode<T> | null;
|
|
25
|
+
get leaves(): TreeNode<T>[];
|
|
26
|
+
get root(): TreeNode<T>;
|
|
27
|
+
forEach(callback: (treeNode: TreeNode<T>) => void): this;
|
|
28
|
+
static build(path: string, options?: TreeNodeOptions): TreeNode | null;
|
|
29
|
+
}
|
|
30
|
+
|
|
12
31
|
declare class EventEmitter<TEvents extends Record<string, any>> {
|
|
13
32
|
#private;
|
|
14
33
|
constructor();
|
|
@@ -26,13 +45,13 @@ type RunOptions = {
|
|
|
26
45
|
name?: string;
|
|
27
46
|
description?: string;
|
|
28
47
|
};
|
|
29
|
-
type Events = {
|
|
48
|
+
type Events$1 = {
|
|
30
49
|
jobDone: [result: unknown];
|
|
31
50
|
jobFailed: [error: Error];
|
|
32
51
|
};
|
|
33
52
|
declare class Queue {
|
|
34
53
|
#private;
|
|
35
|
-
readonly eventEmitter: EventEmitter<Events>;
|
|
54
|
+
readonly eventEmitter: EventEmitter<Events$1>;
|
|
36
55
|
constructor(maxParallel: number, debug?: boolean);
|
|
37
56
|
run<T>(job: QueueJob<T>, options?: RunOptions): Promise<T>;
|
|
38
57
|
runSync<T>(job: QueueJob<T>, options?: RunOptions): void;
|
|
@@ -66,7 +85,498 @@ type Props = {
|
|
|
66
85
|
};
|
|
67
86
|
declare function createLogger({ logLevel, name, spinner }: Props): Logger;
|
|
68
87
|
|
|
88
|
+
type RequiredPluginLifecycle = Required<PluginLifecycle>;
|
|
89
|
+
/**
|
|
90
|
+
* Get the type of the first argument in a function.
|
|
91
|
+
* @example Arg0<(a: string, b: number) => void> -> string
|
|
92
|
+
*/
|
|
93
|
+
type Argument0<H extends keyof PluginLifecycle> = Parameters<RequiredPluginLifecycle[H]>[0];
|
|
94
|
+
type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookReduceArg0' | 'hookSeq';
|
|
95
|
+
type Executer<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
96
|
+
strategy: Strategy;
|
|
97
|
+
hookName: H;
|
|
98
|
+
plugin: KubbPlugin;
|
|
99
|
+
parameters?: unknown[] | undefined;
|
|
100
|
+
output?: unknown;
|
|
101
|
+
};
|
|
102
|
+
type ParseResult<H extends PluginLifecycleHooks> = RequiredPluginLifecycle[H];
|
|
103
|
+
type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = {
|
|
104
|
+
result: Result;
|
|
105
|
+
plugin: KubbPlugin;
|
|
106
|
+
};
|
|
107
|
+
type Options$1 = {
|
|
108
|
+
logger: Logger;
|
|
109
|
+
/**
|
|
110
|
+
* Task for the FileManager
|
|
111
|
+
*/
|
|
112
|
+
task: QueueJob<KubbFile.ResolvedFile>;
|
|
113
|
+
/**
|
|
114
|
+
* Timeout between writes in the FileManager
|
|
115
|
+
*/
|
|
116
|
+
writeTimeout?: number;
|
|
117
|
+
};
|
|
118
|
+
type Events = {
|
|
119
|
+
execute: [executer: Executer];
|
|
120
|
+
executed: [executer: Executer];
|
|
121
|
+
error: [error: Error];
|
|
122
|
+
};
|
|
123
|
+
declare class PluginManager {
|
|
124
|
+
#private;
|
|
125
|
+
readonly plugins: KubbPluginWithLifeCycle[];
|
|
126
|
+
readonly fileManager: FileManager;
|
|
127
|
+
readonly eventEmitter: EventEmitter<Events>;
|
|
128
|
+
readonly queue: Queue;
|
|
129
|
+
readonly config: KubbConfig;
|
|
130
|
+
readonly executed: Executer[];
|
|
131
|
+
readonly logger: Logger;
|
|
132
|
+
constructor(config: KubbConfig, options: Options$1);
|
|
133
|
+
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
|
|
134
|
+
resolveName: (params: ResolveNameParams) => string;
|
|
135
|
+
on<TEventName extends keyof Events & string>(eventName: TEventName, handler: (...eventArg: Events[TEventName]) => void): void;
|
|
136
|
+
/**
|
|
137
|
+
* Run only hook for a specific plugin name
|
|
138
|
+
*/
|
|
139
|
+
hookForPlugin<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, }: {
|
|
140
|
+
pluginKey: KubbPlugin['key'];
|
|
141
|
+
hookName: H;
|
|
142
|
+
parameters: PluginParameter<H>;
|
|
143
|
+
}): Promise<Array<ReturnType<ParseResult<H>> | null>> | null;
|
|
144
|
+
hookForPluginSync<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, }: {
|
|
145
|
+
pluginKey: KubbPlugin['key'];
|
|
146
|
+
hookName: H;
|
|
147
|
+
parameters: PluginParameter<H>;
|
|
148
|
+
}): Array<ReturnType<ParseResult<H>>> | null;
|
|
149
|
+
/**
|
|
150
|
+
* Chains, first non-null result stops and returns
|
|
151
|
+
*/
|
|
152
|
+
hookFirst<H extends PluginLifecycleHooks>({ hookName, parameters, skipped, }: {
|
|
153
|
+
hookName: H;
|
|
154
|
+
parameters: PluginParameter<H>;
|
|
155
|
+
skipped?: ReadonlySet<KubbPlugin> | null;
|
|
156
|
+
}): Promise<SafeParseResult<H>>;
|
|
157
|
+
/**
|
|
158
|
+
* Chains, first non-null result stops and returns
|
|
159
|
+
*/
|
|
160
|
+
hookFirstSync<H extends PluginLifecycleHooks>({ hookName, parameters, skipped, }: {
|
|
161
|
+
hookName: H;
|
|
162
|
+
parameters: PluginParameter<H>;
|
|
163
|
+
skipped?: ReadonlySet<KubbPlugin> | null;
|
|
164
|
+
}): SafeParseResult<H>;
|
|
165
|
+
/**
|
|
166
|
+
* Parallel, runs all plugins
|
|
167
|
+
*/
|
|
168
|
+
hookParallel<H extends PluginLifecycleHooks, TOuput = void>({ hookName, parameters, }: {
|
|
169
|
+
hookName: H;
|
|
170
|
+
parameters?: Parameters<RequiredPluginLifecycle[H]> | undefined;
|
|
171
|
+
}): Promise<Awaited<TOuput>[]>;
|
|
172
|
+
/**
|
|
173
|
+
* Chains, reduces returned value, handling the reduced value as the first hook argument
|
|
174
|
+
*/
|
|
175
|
+
hookReduceArg0<H extends PluginLifecycleHooks>({ hookName, parameters, reduce, }: {
|
|
176
|
+
hookName: H;
|
|
177
|
+
parameters: PluginParameter<H>;
|
|
178
|
+
reduce: (reduction: Argument0<H>, result: ReturnType<ParseResult<H>>, plugin: KubbPlugin) => PossiblePromise<Argument0<H> | null>;
|
|
179
|
+
}): Promise<Argument0<H>>;
|
|
180
|
+
/**
|
|
181
|
+
* Chains plugins
|
|
182
|
+
*/
|
|
183
|
+
hookSeq<H extends PluginLifecycleHooks>({ hookName, parameters }: {
|
|
184
|
+
hookName: H;
|
|
185
|
+
parameters?: PluginParameter<H>;
|
|
186
|
+
}): Promise<void>;
|
|
187
|
+
getPluginsByKey(hookName: keyof PluginLifecycle, pluginKey: KubbPlugin['key']): KubbPlugin[];
|
|
188
|
+
static getDependedPlugins<T1 extends PluginFactoryOptions, T2 extends PluginFactoryOptions = never, T3 extends PluginFactoryOptions = never, TOutput = T3 extends never ? T2 extends never ? [T1: KubbPlugin<T1>] : [T1: KubbPlugin<T1>, T2: KubbPlugin<T2>] : [T1: KubbPlugin<T1>, T2: KubbPlugin<T2>, T3: KubbPlugin<T3>]>(plugins: Array<KubbPlugin>, dependedPluginNames: string | string[]): TOutput;
|
|
189
|
+
static get hooks(): readonly ["buildStart", "resolvePath", "resolveName", "load", "transform", "writeFile", "buildEnd"];
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
type BarrelManagerOptions = {
|
|
193
|
+
treeNode?: DirectoryTreeOptions;
|
|
194
|
+
isTypeOnly?: boolean;
|
|
195
|
+
/**
|
|
196
|
+
* Add .ts or .js
|
|
197
|
+
*/
|
|
198
|
+
extName?: KubbFile.Extname;
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
type BasePath<T extends string = string> = `${T}/`;
|
|
202
|
+
declare namespace KubbFile {
|
|
203
|
+
type Import = {
|
|
204
|
+
/**
|
|
205
|
+
* Import name to be used
|
|
206
|
+
* @example ["useState"]
|
|
207
|
+
* @example "React"
|
|
208
|
+
*/
|
|
209
|
+
name: string | Array<string | {
|
|
210
|
+
propertyName: string;
|
|
211
|
+
name?: string;
|
|
212
|
+
}>;
|
|
213
|
+
/**
|
|
214
|
+
* Path for the import
|
|
215
|
+
* @xample '@kubb/core'
|
|
216
|
+
*/
|
|
217
|
+
path: string;
|
|
218
|
+
/**
|
|
219
|
+
* Add `type` prefix to the import, this will result in: `import type { Type } from './path'`.
|
|
220
|
+
*/
|
|
221
|
+
isTypeOnly?: boolean;
|
|
222
|
+
/**
|
|
223
|
+
* Add `* as` prefix to the import, this will result in: `import * as path from './path'`.
|
|
224
|
+
*/
|
|
225
|
+
isNameSpace?: boolean;
|
|
226
|
+
/**
|
|
227
|
+
* When root is set it will get the path with relative getRelativePath(root, path).
|
|
228
|
+
*/
|
|
229
|
+
root?: string;
|
|
230
|
+
};
|
|
231
|
+
type Export = {
|
|
232
|
+
/**
|
|
233
|
+
* Export name to be used.
|
|
234
|
+
* @example ["useState"]
|
|
235
|
+
* @example "React"
|
|
236
|
+
*/
|
|
237
|
+
name?: string | Array<string>;
|
|
238
|
+
/**
|
|
239
|
+
* Path for the import.
|
|
240
|
+
* @xample '@kubb/core'
|
|
241
|
+
*/
|
|
242
|
+
path: string;
|
|
243
|
+
/**
|
|
244
|
+
* Add `type` prefix to the export, this will result in: `export type { Type } from './path'`.
|
|
245
|
+
*/
|
|
246
|
+
isTypeOnly?: boolean;
|
|
247
|
+
/**
|
|
248
|
+
* Make it possible to override the name, this will result in: `export * as aliasName from './path'`.
|
|
249
|
+
*/
|
|
250
|
+
asAlias?: boolean;
|
|
251
|
+
};
|
|
252
|
+
const dataTagSymbol: unique symbol;
|
|
253
|
+
type DataTag<Type, Value> = Type & {
|
|
254
|
+
[dataTagSymbol]: Value;
|
|
255
|
+
};
|
|
256
|
+
type UUID = string;
|
|
257
|
+
type Source = string;
|
|
258
|
+
type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`;
|
|
259
|
+
type Mode = 'file' | 'directory';
|
|
260
|
+
/**
|
|
261
|
+
* Name to be used to dynamicly create the baseName(based on input.path)
|
|
262
|
+
* Based on UNIX basename
|
|
263
|
+
* @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
|
|
264
|
+
*/
|
|
265
|
+
type BaseName = `${string}${Extname}`;
|
|
266
|
+
/**
|
|
267
|
+
* Path will be full qualified path to a specified file
|
|
268
|
+
*/
|
|
269
|
+
type Path = string;
|
|
270
|
+
type AdvancedPath<T extends BaseName = BaseName> = `${BasePath}${T}`;
|
|
271
|
+
type OptionalPath = Path | undefined | null;
|
|
272
|
+
type FileMetaBase = {
|
|
273
|
+
pluginKey?: KubbPlugin['key'];
|
|
274
|
+
};
|
|
275
|
+
type File<TMeta extends FileMetaBase = FileMetaBase, TBaseName extends BaseName = BaseName> = {
|
|
276
|
+
/**
|
|
277
|
+
* Unique identifier to reuse later
|
|
278
|
+
* @default crypto.randomUUID()
|
|
279
|
+
*/
|
|
280
|
+
id?: string;
|
|
281
|
+
/**
|
|
282
|
+
* Name to be used to create the path
|
|
283
|
+
* Based on UNIX basename, `${name}.extName`
|
|
284
|
+
* @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
|
|
285
|
+
*/
|
|
286
|
+
baseName: TBaseName;
|
|
287
|
+
/**
|
|
288
|
+
* Path will be full qualified path to a specified file
|
|
289
|
+
*/
|
|
290
|
+
path: AdvancedPath<TBaseName> | Path;
|
|
291
|
+
source: Source;
|
|
292
|
+
imports?: Import[];
|
|
293
|
+
exports?: Export[];
|
|
294
|
+
/**
|
|
295
|
+
* This will call fileManager.add instead of fileManager.addOrAppend, adding the source when the files already exists
|
|
296
|
+
* This will also ignore the combinefiles utils
|
|
297
|
+
* @default `false`
|
|
298
|
+
*/
|
|
299
|
+
override?: boolean;
|
|
300
|
+
/**
|
|
301
|
+
* Use extra meta, this is getting used to generate the barrel/index files.
|
|
302
|
+
*/
|
|
303
|
+
meta?: TMeta;
|
|
304
|
+
/**
|
|
305
|
+
* This will override `process.env[key]` inside the `source`, see `getFileSource`.
|
|
306
|
+
*/
|
|
307
|
+
env?: NodeJS.ProcessEnv;
|
|
308
|
+
};
|
|
309
|
+
type ResolvedFile<TMeta extends FileMetaBase = FileMetaBase, TBaseName extends BaseName = BaseName> = KubbFile.File<TMeta, TBaseName> & {
|
|
310
|
+
/**
|
|
311
|
+
* @default crypto.randomUUID()
|
|
312
|
+
*/
|
|
313
|
+
id: UUID;
|
|
314
|
+
/**
|
|
315
|
+
* Contains the first part of the baseName, generated based on baseName
|
|
316
|
+
* @link https://nodejs.org/api/path.html#pathformatpathobject
|
|
317
|
+
*/
|
|
318
|
+
name: string;
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
type AddResult<T extends Array<KubbFile.File>> = Promise<Awaited<GreaterThan<T['length'], 1> extends true ? Promise<KubbFile.ResolvedFile[]> : Promise<KubbFile.ResolvedFile>>>;
|
|
322
|
+
type AddIndexesProps = {
|
|
323
|
+
/**
|
|
324
|
+
* Root based on root and output.path specified in the config
|
|
325
|
+
*/
|
|
326
|
+
root: string;
|
|
327
|
+
/**
|
|
328
|
+
* Output for plugin
|
|
329
|
+
*/
|
|
330
|
+
output: {
|
|
331
|
+
path: string;
|
|
332
|
+
exportAs?: string;
|
|
333
|
+
extName?: KubbFile.Extname;
|
|
334
|
+
exportType?: 'barrel' | false;
|
|
335
|
+
};
|
|
336
|
+
options?: BarrelManagerOptions;
|
|
337
|
+
meta?: KubbFile.File['meta'];
|
|
338
|
+
};
|
|
339
|
+
type Options = {
|
|
340
|
+
queue?: Queue;
|
|
341
|
+
task?: QueueJob<KubbFile.ResolvedFile>;
|
|
342
|
+
/**
|
|
343
|
+
* Timeout between writes
|
|
344
|
+
*/
|
|
345
|
+
timeout?: number;
|
|
346
|
+
};
|
|
347
|
+
declare class FileManager {
|
|
348
|
+
#private;
|
|
349
|
+
constructor(options?: Options);
|
|
350
|
+
get files(): Array<KubbFile.File>;
|
|
351
|
+
get isExecuting(): boolean;
|
|
352
|
+
add<T extends Array<KubbFile.File> = Array<KubbFile.File>>(...files: T): AddResult<T>;
|
|
353
|
+
addIndexes({ root, output, meta, options }: AddIndexesProps): Promise<Array<KubbFile.File> | undefined>;
|
|
354
|
+
getCacheByUUID(UUID: KubbFile.UUID): KubbFile.File | undefined;
|
|
355
|
+
get(path: KubbFile.Path): Array<KubbFile.File> | undefined;
|
|
356
|
+
remove(path: KubbFile.Path): void;
|
|
357
|
+
write(...params: Parameters<typeof write>): Promise<string | undefined>;
|
|
358
|
+
read(...params: Parameters<typeof read>): Promise<string>;
|
|
359
|
+
static getSource<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase>(file: KubbFile.File<TMeta>): string;
|
|
360
|
+
static combineFiles<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase>(files: Array<KubbFile.File<TMeta> | null>): Array<KubbFile.File<TMeta>>;
|
|
361
|
+
static getMode(path: string | undefined | null): KubbFile.Mode;
|
|
362
|
+
static get extensions(): Array<KubbFile.Extname>;
|
|
363
|
+
static isExtensionAllowed(baseName: string): boolean;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
type InputPath = {
|
|
367
|
+
/**
|
|
368
|
+
* Path to be used as the input. This can be an absolute path or a path relative to the `root`.
|
|
369
|
+
*/
|
|
370
|
+
path: string;
|
|
371
|
+
};
|
|
372
|
+
type InputData = {
|
|
373
|
+
/**
|
|
374
|
+
* `string` or `object` containing the data.
|
|
375
|
+
*/
|
|
376
|
+
data: string | unknown;
|
|
377
|
+
};
|
|
378
|
+
type Input = InputPath | InputData;
|
|
379
|
+
/**
|
|
380
|
+
* @private
|
|
381
|
+
*/
|
|
382
|
+
type KubbConfig<TInput = Input> = {
|
|
383
|
+
/**
|
|
384
|
+
* Optional config name to show in CLI output
|
|
385
|
+
*/
|
|
386
|
+
name?: string;
|
|
387
|
+
/**
|
|
388
|
+
* Project root directory. Can be an absolute path, or a path relative from
|
|
389
|
+
* the location of the config file itself.
|
|
390
|
+
* @default process.cwd()
|
|
391
|
+
*/
|
|
392
|
+
root: string;
|
|
393
|
+
input: TInput;
|
|
394
|
+
output: {
|
|
395
|
+
/**
|
|
396
|
+
* Path to be used to export all generated files.
|
|
397
|
+
* This can be an absolute path, or a path relative based of the defined `root` option.
|
|
398
|
+
*/
|
|
399
|
+
path: string;
|
|
400
|
+
/**
|
|
401
|
+
* Clean output directory before each build.
|
|
402
|
+
*/
|
|
403
|
+
clean?: boolean;
|
|
404
|
+
/**
|
|
405
|
+
* Write files to the fileSystem
|
|
406
|
+
* This is being used for the playground.
|
|
407
|
+
* @default true
|
|
408
|
+
*/
|
|
409
|
+
write?: boolean;
|
|
410
|
+
};
|
|
411
|
+
/**
|
|
412
|
+
* Array of Kubb plugins to use.
|
|
413
|
+
* The plugin/package can forsee some options that you need to pass through.
|
|
414
|
+
* Sometimes a plugin is depended on another plugin, if that's the case you will get an error back from the plugin you installed.
|
|
415
|
+
*/
|
|
416
|
+
plugins?: Array<KubbPlugin>;
|
|
417
|
+
/**
|
|
418
|
+
* Hooks that will be called when a specific action is triggered in Kubb.
|
|
419
|
+
*/
|
|
420
|
+
hooks?: {
|
|
421
|
+
/**
|
|
422
|
+
* Hook that will be triggered at the end of all executions.
|
|
423
|
+
* Useful for running Prettier or ESLint to format/lint your code.
|
|
424
|
+
*/
|
|
425
|
+
done?: string | Array<string>;
|
|
426
|
+
};
|
|
427
|
+
};
|
|
428
|
+
type PluginFactoryOptions<
|
|
429
|
+
/**
|
|
430
|
+
* Name to be used for the plugin, this will also be used for they key.
|
|
431
|
+
*/
|
|
432
|
+
TName extends string = string,
|
|
433
|
+
/**
|
|
434
|
+
* Options of the plugin.
|
|
435
|
+
*/
|
|
436
|
+
TOptions extends object = object,
|
|
437
|
+
/**
|
|
438
|
+
* Options of the plugin that can be used later on, see `options` inside your plugin config.
|
|
439
|
+
*/
|
|
440
|
+
TResolvedOptions extends object = TOptions,
|
|
441
|
+
/**
|
|
442
|
+
* API that you want to expose to other plugins.
|
|
443
|
+
*/
|
|
444
|
+
TAPI = any,
|
|
445
|
+
/**
|
|
446
|
+
* When calling `resolvePath` you can specify better types.
|
|
447
|
+
*/
|
|
448
|
+
TResolvePathOptions extends object = object,
|
|
449
|
+
/**
|
|
450
|
+
* When using @kubb/react(based on React) you can specify here which types should be used when calling render.
|
|
451
|
+
* Always extend from `AppMeta` of the core.
|
|
452
|
+
*/
|
|
453
|
+
TAppMeta = unknown> = {
|
|
454
|
+
name: TName;
|
|
455
|
+
/**
|
|
456
|
+
* Same behaviour like what has been done with `QueryKey` in `@tanstack/react-query`
|
|
457
|
+
*/
|
|
458
|
+
key: [name: TName | string, identifier?: string | number];
|
|
459
|
+
options: TOptions;
|
|
460
|
+
resolvedOptions: TResolvedOptions;
|
|
461
|
+
api: TAPI;
|
|
462
|
+
resolvePathOptions: TResolvePathOptions;
|
|
463
|
+
appMeta: {
|
|
464
|
+
pluginManager: PluginManager;
|
|
465
|
+
plugin: KubbPlugin<PluginFactoryOptions<TName, TOptions, TResolvedOptions, TAPI, TResolvePathOptions, TAppMeta>>;
|
|
466
|
+
} & TAppMeta;
|
|
467
|
+
};
|
|
468
|
+
type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
469
|
+
/**
|
|
470
|
+
* Unique name used for the plugin
|
|
471
|
+
* @example @kubb/typescript
|
|
472
|
+
*/
|
|
473
|
+
name: TOptions['name'];
|
|
474
|
+
/**
|
|
475
|
+
* Internal key used when a developer uses more than one of the same plugin
|
|
476
|
+
* @private
|
|
477
|
+
*/
|
|
478
|
+
key: TOptions['key'];
|
|
479
|
+
/**
|
|
480
|
+
* Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin will be executed after these plugins.
|
|
481
|
+
* Can be used to validate depended plugins.
|
|
482
|
+
*/
|
|
483
|
+
pre?: Array<string>;
|
|
484
|
+
/**
|
|
485
|
+
* Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin will be executed before these plugins.
|
|
486
|
+
*/
|
|
487
|
+
post?: Array<string>;
|
|
488
|
+
/**
|
|
489
|
+
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
490
|
+
*/
|
|
491
|
+
options: TOptions['resolvedOptions'];
|
|
492
|
+
} & (TOptions['api'] extends never ? {
|
|
493
|
+
api?: never;
|
|
494
|
+
} : {
|
|
495
|
+
api: TOptions['api'];
|
|
496
|
+
});
|
|
497
|
+
type KubbPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = KubbPlugin<TOptions> & PluginLifecycle<TOptions>;
|
|
498
|
+
type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
499
|
+
/**
|
|
500
|
+
* Start of the lifecycle of a plugin.
|
|
501
|
+
* @type hookParallel
|
|
502
|
+
*/
|
|
503
|
+
buildStart?: (this: PluginContext<TOptions>, kubbConfig: KubbConfig) => PossiblePromise<void>;
|
|
504
|
+
/**
|
|
505
|
+
* Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
|
|
506
|
+
* Options can als be included.
|
|
507
|
+
* @type hookFirst
|
|
508
|
+
* @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
|
|
509
|
+
*/
|
|
510
|
+
resolvePath?: (this: PluginContext<TOptions>, baseName: string, directory?: string, options?: TOptions['resolvePathOptions']) => KubbFile.OptionalPath;
|
|
511
|
+
/**
|
|
512
|
+
* Resolve to a name based on a string.
|
|
513
|
+
* Useful when converting to PascalCase or camelCase.
|
|
514
|
+
* @type hookFirst
|
|
515
|
+
* @example ('pet') => 'Pet'
|
|
516
|
+
*/
|
|
517
|
+
resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
518
|
+
/**
|
|
519
|
+
* Makes it possible to run async logic to override the path defined previously by `resolvePath`.
|
|
520
|
+
* @type hookFirst
|
|
521
|
+
*/
|
|
522
|
+
load?: (this: Omit<PluginContext<TOptions>, 'addFile'>, path: KubbFile.Path) => PossiblePromise<TransformResult | null>;
|
|
523
|
+
/**
|
|
524
|
+
* Transform the source-code.
|
|
525
|
+
* @type hookReduceArg0
|
|
526
|
+
*/
|
|
527
|
+
transform?: (this: Omit<PluginContext<TOptions>, 'addFile'>, source: string, path: KubbFile.Path) => PossiblePromise<TransformResult>;
|
|
528
|
+
/**
|
|
529
|
+
* Write the result to the file-system based on the id(defined by `resolvePath` or changed by `load`).
|
|
530
|
+
* @type hookParallel
|
|
531
|
+
*/
|
|
532
|
+
writeFile?: (this: Omit<PluginContext<TOptions>, 'addFile'>, source: string | undefined, path: KubbFile.Path) => PossiblePromise<string | void>;
|
|
533
|
+
/**
|
|
534
|
+
* End of the plugin lifecycle.
|
|
535
|
+
* @type hookParallel
|
|
536
|
+
*/
|
|
537
|
+
buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
538
|
+
};
|
|
539
|
+
type PluginLifecycleHooks = keyof PluginLifecycle;
|
|
540
|
+
type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
|
|
69
541
|
type PluginCache = Record<string, [number, unknown]>;
|
|
542
|
+
type ResolvePathParams<TOptions = object> = {
|
|
543
|
+
pluginKey?: KubbPlugin['key'];
|
|
544
|
+
baseName: string;
|
|
545
|
+
directory?: string | undefined;
|
|
546
|
+
/**
|
|
547
|
+
* Options to be passed to 'resolvePath' 3th parameter
|
|
548
|
+
*/
|
|
549
|
+
options?: TOptions;
|
|
550
|
+
};
|
|
551
|
+
type ResolveNameParams = {
|
|
552
|
+
name: string;
|
|
553
|
+
pluginKey?: KubbPlugin['key'];
|
|
554
|
+
/**
|
|
555
|
+
* `file` will be used to customize the name of the created file(use of camelCase)
|
|
556
|
+
* `function` can be used used to customize the exported functions(use of camelCase)
|
|
557
|
+
* `type` is a special type for TypeScript(use of PascalCase)
|
|
558
|
+
*/
|
|
559
|
+
type?: 'file' | 'function' | 'type';
|
|
560
|
+
};
|
|
561
|
+
type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
562
|
+
config: KubbConfig;
|
|
563
|
+
cache: Cache<PluginCache>;
|
|
564
|
+
fileManager: FileManager;
|
|
565
|
+
pluginManager: PluginManager;
|
|
566
|
+
addFile: (...file: Array<KubbFile.File>) => Promise<Array<KubbFile.File>>;
|
|
567
|
+
resolvePath: (params: ResolvePathParams<TOptions['resolvePathOptions']>) => KubbFile.OptionalPath;
|
|
568
|
+
resolveName: (params: ResolveNameParams) => string;
|
|
569
|
+
logger: Logger;
|
|
570
|
+
/**
|
|
571
|
+
* All plugins
|
|
572
|
+
*/
|
|
573
|
+
plugins: KubbPlugin[];
|
|
574
|
+
/**
|
|
575
|
+
* Current plugin
|
|
576
|
+
*/
|
|
577
|
+
plugin: KubbPlugin<TOptions>;
|
|
578
|
+
};
|
|
579
|
+
type TransformResult = string | null;
|
|
70
580
|
|
|
71
581
|
interface Cache<TStore extends object = object> {
|
|
72
582
|
delete(id: keyof TStore): boolean;
|
|
@@ -128,68 +638,6 @@ declare const throttle: <R, A extends any[]>(fn: (...args: A) => R, delay: numbe
|
|
|
128
638
|
|
|
129
639
|
declare function timeout(ms: number): Promise<unknown>;
|
|
130
640
|
|
|
131
|
-
declare function combineCodes(codes: string[]): string;
|
|
132
|
-
|
|
133
|
-
declare function createJSDocBlockText({ comments, newLine }: {
|
|
134
|
-
comments: Array<string>;
|
|
135
|
-
newLine?: boolean;
|
|
136
|
-
}): string;
|
|
137
|
-
|
|
138
|
-
declare function escape(text?: string): string;
|
|
139
|
-
/**
|
|
140
|
-
* Escape all characters not included in SingleStringCharacters and DoubleStringCharacters on
|
|
141
|
-
* @link http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4
|
|
142
|
-
* @link https://github.com/joliss/js-string-escape/blob/master/index.js
|
|
143
|
-
*/
|
|
144
|
-
declare function jsStringEscape(input: any): string;
|
|
145
|
-
|
|
146
|
-
declare function createIndent(size: number): string;
|
|
147
|
-
|
|
148
|
-
declare function nameSorter<T extends {
|
|
149
|
-
name: string;
|
|
150
|
-
}>(a: T, b: T): 0 | 1 | -1;
|
|
151
|
-
|
|
152
|
-
type Options = {
|
|
153
|
-
text: string;
|
|
154
|
-
replaceBy: string;
|
|
155
|
-
prefix?: string;
|
|
156
|
-
key: string;
|
|
157
|
-
searchValues?: (prefix: string, key: string) => Array<RegExp | string>;
|
|
158
|
-
};
|
|
159
|
-
declare function searchAndReplace(options: Options): string;
|
|
160
|
-
|
|
161
|
-
declare function transformReservedWord(word: string): string;
|
|
162
|
-
|
|
163
|
-
declare function trim(text: string): string;
|
|
164
|
-
|
|
165
|
-
declare const transformers: {
|
|
166
|
-
readonly combineCodes: typeof combineCodes;
|
|
167
|
-
readonly escape: typeof escape;
|
|
168
|
-
readonly jsStringEscape: typeof jsStringEscape;
|
|
169
|
-
readonly createIndent: typeof createIndent;
|
|
170
|
-
readonly transformReservedWord: typeof transformReservedWord;
|
|
171
|
-
readonly nameSorter: typeof nameSorter;
|
|
172
|
-
readonly searchAndReplace: typeof searchAndReplace;
|
|
173
|
-
readonly trim: typeof trim;
|
|
174
|
-
readonly JSDoc: {
|
|
175
|
-
readonly createJSDocBlockText: typeof createJSDocBlockText;
|
|
176
|
-
};
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
type TreeNodeOptions = DirectoryTreeOptions;
|
|
180
|
-
declare class TreeNode<T = unknown> {
|
|
181
|
-
data: T;
|
|
182
|
-
parent?: TreeNode<T>;
|
|
183
|
-
children: Array<TreeNode<T>>;
|
|
184
|
-
constructor(data: T, parent?: TreeNode<T>);
|
|
185
|
-
addChild(data: T): TreeNode<T>;
|
|
186
|
-
find(data?: T): TreeNode<T> | null;
|
|
187
|
-
get leaves(): TreeNode<T>[];
|
|
188
|
-
get root(): TreeNode<T>;
|
|
189
|
-
forEach(callback: (treeNode: TreeNode<T>) => void): this;
|
|
190
|
-
static build<T = unknown>(path: string, options?: TreeNodeOptions): TreeNode<T> | null;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
641
|
declare function getUniqueName(originalName: string, data: Record<string, number>): string;
|
|
194
642
|
declare function setUniqueName(originalName: string, data: Record<string, number>): string;
|
|
195
643
|
|
|
@@ -236,4 +684,4 @@ declare class URLPath {
|
|
|
236
684
|
toURLPath(): string;
|
|
237
685
|
}
|
|
238
686
|
|
|
239
|
-
export { type Cache, FunctionParams, type FunctionParamsAST, LogLevel, type Logger, Queue, type QueueJob, TreeNode, type TreeNodeOptions, type URLObject, URLPath, clean, createLogger, createPluginCache, getRelativePath, getUniqueName, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, randomColour, randomPicoColour, read, readSync, renderTemplate, setUniqueName, throttle, timeout,
|
|
687
|
+
export { type Cache, FunctionParams, type FunctionParamsAST, LogLevel, type Logger, Queue, type QueueJob, TreeNode, type TreeNodeOptions, type URLObject, URLPath, clean, createLogger, createPluginCache, getRelativePath, getUniqueName, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, randomColour, randomPicoColour, read, readSync, renderTemplate, setUniqueName, throttle, timeout, write };
|