@kubb/core 0.0.0-canary-20231213204140
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/LICENSE +21 -0
- package/README.md +44 -0
- package/dist/chunk-4A7WG6IA.js +128 -0
- package/dist/chunk-4A7WG6IA.js.map +1 -0
- package/dist/chunk-54P4AWHI.js +71 -0
- package/dist/chunk-54P4AWHI.js.map +1 -0
- package/dist/chunk-5TK7TMV6.cjs +131 -0
- package/dist/chunk-5TK7TMV6.cjs.map +1 -0
- package/dist/chunk-7S67BJXQ.js +85 -0
- package/dist/chunk-7S67BJXQ.js.map +1 -0
- package/dist/chunk-E3ANGQ5N.cjs +2290 -0
- package/dist/chunk-E3ANGQ5N.cjs.map +1 -0
- package/dist/chunk-H47IKRXJ.cjs +129 -0
- package/dist/chunk-H47IKRXJ.cjs.map +1 -0
- package/dist/chunk-HIE46T3F.js +129 -0
- package/dist/chunk-HIE46T3F.js.map +1 -0
- package/dist/chunk-K2H7BYQB.js +155 -0
- package/dist/chunk-K2H7BYQB.js.map +1 -0
- package/dist/chunk-NAWI7UXW.js +67 -0
- package/dist/chunk-NAWI7UXW.js.map +1 -0
- package/dist/chunk-PLVKILIY.cjs +162 -0
- package/dist/chunk-PLVKILIY.cjs.map +1 -0
- package/dist/chunk-W2FP7ZWW.cjs +71 -0
- package/dist/chunk-W2FP7ZWW.cjs.map +1 -0
- package/dist/chunk-WZQO3EPM.cjs +91 -0
- package/dist/chunk-WZQO3EPM.cjs.map +1 -0
- package/dist/chunk-XDHI63G7.cjs +104 -0
- package/dist/chunk-XDHI63G7.cjs.map +1 -0
- package/dist/chunk-XPOF4D5N.js +18 -0
- package/dist/chunk-XPOF4D5N.js.map +1 -0
- package/dist/fs.cjs +31 -0
- package/dist/fs.cjs.map +1 -0
- package/dist/fs.d.cts +5 -0
- package/dist/fs.d.ts +5 -0
- package/dist/fs.js +11 -0
- package/dist/fs.js.map +1 -0
- package/dist/index.cjs +3156 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +693 -0
- package/dist/index.d.ts +693 -0
- package/dist/index.js +2160 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.cjs +26 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +32 -0
- package/dist/logger.d.ts +32 -0
- package/dist/logger.js +8 -0
- package/dist/logger.js.map +1 -0
- package/dist/transformers.cjs +124 -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 +95 -0
- package/dist/transformers.js.map +1 -0
- package/dist/utils.cjs +118 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +94 -0
- package/dist/utils.d.ts +94 -0
- package/dist/utils.js +102 -0
- package/dist/utils.js.map +1 -0
- package/dist/write-A6VgHkYA.d.cts +10 -0
- package/dist/write-A6VgHkYA.d.ts +10 -0
- package/globals.d.ts +51 -0
- package/package.json +113 -0
- package/schema.json +86 -0
- package/src/BarrelManager.ts +113 -0
- package/src/FileManager.ts +581 -0
- package/src/Generator.ts +34 -0
- package/src/PackageManager.ts +178 -0
- package/src/PluginManager.ts +645 -0
- package/src/PromiseManager.ts +51 -0
- package/src/build.ts +221 -0
- package/src/config.ts +22 -0
- package/src/errors.ts +12 -0
- package/src/fs/clean.ts +5 -0
- package/src/fs/index.ts +3 -0
- package/src/fs/read.ts +68 -0
- package/src/fs/write.ts +79 -0
- package/src/index.ts +27 -0
- package/src/logger.ts +121 -0
- package/src/plugin.ts +80 -0
- package/src/transformers/casing.ts +9 -0
- package/src/transformers/combineCodes.ts +3 -0
- package/src/transformers/createJSDocBlockText.ts +9 -0
- package/src/transformers/escape.ts +31 -0
- package/src/transformers/indent.ts +3 -0
- package/src/transformers/index.ts +36 -0
- package/src/transformers/nameSorter.ts +9 -0
- package/src/transformers/searchAndReplace.ts +25 -0
- package/src/transformers/transformReservedWord.ts +97 -0
- package/src/transformers/trim.ts +7 -0
- package/src/types.ts +334 -0
- package/src/utils/EventEmitter.ts +24 -0
- package/src/utils/FunctionParams.ts +86 -0
- package/src/utils/TreeNode.ts +125 -0
- package/src/utils/URLPath.ts +133 -0
- package/src/utils/cache.ts +35 -0
- package/src/utils/executeStrategies.ts +83 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/promise.ts +13 -0
- package/src/utils/renderTemplate.ts +31 -0
- package/src/utils/timeout.ts +7 -0
- package/src/utils/uniqueName.ts +20 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,693 @@
|
|
|
1
|
+
import PQueue from 'p-queue';
|
|
2
|
+
import { w as write, r as read } from './write-A6VgHkYA.cjs';
|
|
3
|
+
import { PossiblePromise, GreaterThan, TupleToUnion, ObjValueTuple } from '@kubb/types';
|
|
4
|
+
import { DirectoryTreeOptions } from 'directory-tree';
|
|
5
|
+
import { Logger, LogLevel } from './logger.cjs';
|
|
6
|
+
import 'ora';
|
|
7
|
+
|
|
8
|
+
type BarrelManagerOptions = {
|
|
9
|
+
treeNode?: DirectoryTreeOptions;
|
|
10
|
+
isTypeOnly?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Add .ts or .js
|
|
13
|
+
*/
|
|
14
|
+
extName?: KubbFile.Extname;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
declare class EventEmitter<TEvents extends Record<string, any>> {
|
|
18
|
+
#private;
|
|
19
|
+
constructor();
|
|
20
|
+
emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArg: TEvents[TEventName]): void;
|
|
21
|
+
on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
|
|
22
|
+
off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
|
|
23
|
+
removeAll(): void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type RequiredPluginLifecycle = Required<PluginLifecycle>;
|
|
27
|
+
/**
|
|
28
|
+
* Get the type of the first argument in a function.
|
|
29
|
+
* @example Arg0<(a: string, b: number) => void> -> string
|
|
30
|
+
*/
|
|
31
|
+
type Argument0<H extends keyof PluginLifecycle> = Parameters<RequiredPluginLifecycle[H]>[0];
|
|
32
|
+
type Strategy$1 = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookReduceArg0' | 'hookSeq';
|
|
33
|
+
type Executer<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
34
|
+
strategy: Strategy$1;
|
|
35
|
+
hookName: H;
|
|
36
|
+
plugin: KubbPlugin;
|
|
37
|
+
parameters?: unknown[] | undefined;
|
|
38
|
+
output?: unknown;
|
|
39
|
+
};
|
|
40
|
+
type ParseResult<H extends PluginLifecycleHooks> = RequiredPluginLifecycle[H];
|
|
41
|
+
type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = {
|
|
42
|
+
result: Result;
|
|
43
|
+
plugin: KubbPlugin;
|
|
44
|
+
};
|
|
45
|
+
type Options$2 = {
|
|
46
|
+
logger: Logger;
|
|
47
|
+
/**
|
|
48
|
+
* Task for the FileManager
|
|
49
|
+
*/
|
|
50
|
+
task: (file: KubbFile.ResolvedFile) => Promise<KubbFile.ResolvedFile>;
|
|
51
|
+
};
|
|
52
|
+
type Events = {
|
|
53
|
+
execute: [executer: Executer];
|
|
54
|
+
executed: [executer: Executer];
|
|
55
|
+
error: [error: Error];
|
|
56
|
+
};
|
|
57
|
+
declare class PluginManager {
|
|
58
|
+
#private;
|
|
59
|
+
readonly plugins: KubbPluginWithLifeCycle[];
|
|
60
|
+
readonly fileManager: FileManager;
|
|
61
|
+
readonly events: EventEmitter<Events>;
|
|
62
|
+
readonly config: KubbConfig;
|
|
63
|
+
readonly executed: Array<Executer>;
|
|
64
|
+
readonly logger: Logger;
|
|
65
|
+
readonly queue: PQueue;
|
|
66
|
+
constructor(config: KubbConfig, options: Options$2);
|
|
67
|
+
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
|
|
68
|
+
resolveName: (params: ResolveNameParams) => string;
|
|
69
|
+
/**
|
|
70
|
+
* Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
|
|
71
|
+
*/
|
|
72
|
+
on<TEventName extends keyof Events & string>(eventName: TEventName, handler: (...eventArg: Events[TEventName]) => void): void;
|
|
73
|
+
/**
|
|
74
|
+
* Run a specific hookName for plugin x.
|
|
75
|
+
*/
|
|
76
|
+
hookForPlugin<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, }: {
|
|
77
|
+
pluginKey: KubbPlugin['key'];
|
|
78
|
+
hookName: H;
|
|
79
|
+
parameters: PluginParameter<H>;
|
|
80
|
+
}): Promise<Array<ReturnType<ParseResult<H>> | null>> | null;
|
|
81
|
+
/**
|
|
82
|
+
* Run a specific hookName for plugin x.
|
|
83
|
+
*/
|
|
84
|
+
hookForPluginSync<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, }: {
|
|
85
|
+
pluginKey: KubbPlugin['key'];
|
|
86
|
+
hookName: H;
|
|
87
|
+
parameters: PluginParameter<H>;
|
|
88
|
+
}): Array<ReturnType<ParseResult<H>>> | null;
|
|
89
|
+
/**
|
|
90
|
+
* First non-null result stops and will return it's value.
|
|
91
|
+
*/
|
|
92
|
+
hookFirst<H extends PluginLifecycleHooks>({ hookName, parameters, skipped, }: {
|
|
93
|
+
hookName: H;
|
|
94
|
+
parameters: PluginParameter<H>;
|
|
95
|
+
skipped?: ReadonlySet<KubbPlugin> | null;
|
|
96
|
+
}): Promise<SafeParseResult<H>>;
|
|
97
|
+
/**
|
|
98
|
+
* First non-null result stops and will return it's value.
|
|
99
|
+
*/
|
|
100
|
+
hookFirstSync<H extends PluginLifecycleHooks>({ hookName, parameters, skipped, }: {
|
|
101
|
+
hookName: H;
|
|
102
|
+
parameters: PluginParameter<H>;
|
|
103
|
+
skipped?: ReadonlySet<KubbPlugin> | null;
|
|
104
|
+
}): SafeParseResult<H>;
|
|
105
|
+
/**
|
|
106
|
+
* Run all plugins in parallel(order will be based on `this.plugin` and if `pre` or `post` is set).
|
|
107
|
+
*/
|
|
108
|
+
hookParallel<H extends PluginLifecycleHooks, TOuput = void>({ hookName, parameters, }: {
|
|
109
|
+
hookName: H;
|
|
110
|
+
parameters?: Parameters<RequiredPluginLifecycle[H]> | undefined;
|
|
111
|
+
}): Promise<Awaited<TOuput>[]>;
|
|
112
|
+
/**
|
|
113
|
+
* Chain all plugins, `reduce` can be passed through to handle every returned value. The return value of the first plugin will be used as the first parameter for the plugin after that.
|
|
114
|
+
*/
|
|
115
|
+
hookReduceArg0<H extends PluginLifecycleHooks>({ hookName, parameters, reduce, }: {
|
|
116
|
+
hookName: H;
|
|
117
|
+
parameters: PluginParameter<H>;
|
|
118
|
+
reduce: (reduction: Argument0<H>, result: ReturnType<ParseResult<H>>, plugin: KubbPlugin) => PossiblePromise<Argument0<H> | null>;
|
|
119
|
+
}): Promise<Argument0<H>>;
|
|
120
|
+
/**
|
|
121
|
+
* Chains plugins
|
|
122
|
+
*/
|
|
123
|
+
hookSeq<H extends PluginLifecycleHooks>({ hookName, parameters }: {
|
|
124
|
+
hookName: H;
|
|
125
|
+
parameters?: PluginParameter<H>;
|
|
126
|
+
}): Promise<void>;
|
|
127
|
+
getPluginsByKey(hookName: keyof PluginLifecycle, pluginKey: KubbPlugin['key']): KubbPlugin[];
|
|
128
|
+
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;
|
|
129
|
+
static get hooks(): readonly ["buildStart", "resolvePath", "resolveName", "load", "transform", "writeFile", "buildEnd"];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
interface Cache<TStore extends object = object> {
|
|
133
|
+
delete(id: keyof TStore): boolean;
|
|
134
|
+
get(id: keyof TStore): TStore[keyof TStore] | null;
|
|
135
|
+
has(id: keyof TStore): boolean;
|
|
136
|
+
set(id: keyof TStore, value: unknown): void;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Config used in `kubb.config.js`
|
|
141
|
+
*
|
|
142
|
+
* @example import { defineConfig } from '@kubb/core'
|
|
143
|
+
* export default defineConfig({
|
|
144
|
+
* ...
|
|
145
|
+
* })
|
|
146
|
+
*/
|
|
147
|
+
type KubbUserConfig = Omit<KubbConfig, 'root' | 'plugins'> & {
|
|
148
|
+
/**
|
|
149
|
+
* Project root directory. Can be an absolute path, or a path relative from
|
|
150
|
+
* the location of the config file itself.
|
|
151
|
+
* @default process.cwd()
|
|
152
|
+
*/
|
|
153
|
+
root?: string;
|
|
154
|
+
/**
|
|
155
|
+
* Plugin type can be KubbJSONPlugin or KubbPlugin
|
|
156
|
+
* Example: ['@kubb/swagger', { output: false }]
|
|
157
|
+
* Or: createSwagger({ output: false })
|
|
158
|
+
*/
|
|
159
|
+
plugins?: Array<Omit<UnknownKubbUserPlugin, 'api'> | KubbUnionPlugins | [name: string, options: object]>;
|
|
160
|
+
};
|
|
161
|
+
type InputPath = {
|
|
162
|
+
/**
|
|
163
|
+
* Path to be used as the input. This can be an absolute path or a path relative to the `root`.
|
|
164
|
+
*/
|
|
165
|
+
path: string;
|
|
166
|
+
};
|
|
167
|
+
type InputData = {
|
|
168
|
+
/**
|
|
169
|
+
* `string` or `object` containing the data.
|
|
170
|
+
*/
|
|
171
|
+
data: string | unknown;
|
|
172
|
+
};
|
|
173
|
+
type Input = InputPath | InputData;
|
|
174
|
+
/**
|
|
175
|
+
* @private
|
|
176
|
+
*/
|
|
177
|
+
type KubbConfig<TInput = Input> = {
|
|
178
|
+
/**
|
|
179
|
+
* Optional config name to show in CLI output
|
|
180
|
+
*/
|
|
181
|
+
name?: string;
|
|
182
|
+
/**
|
|
183
|
+
* Project root directory. Can be an absolute path, or a path relative from
|
|
184
|
+
* the location of the config file itself.
|
|
185
|
+
* @default process.cwd()
|
|
186
|
+
*/
|
|
187
|
+
root: string;
|
|
188
|
+
input: TInput;
|
|
189
|
+
output: {
|
|
190
|
+
/**
|
|
191
|
+
* Path to be used to export all generated files.
|
|
192
|
+
* This can be an absolute path, or a path relative based of the defined `root` option.
|
|
193
|
+
*/
|
|
194
|
+
path: string;
|
|
195
|
+
/**
|
|
196
|
+
* Clean output directory before each build.
|
|
197
|
+
*/
|
|
198
|
+
clean?: boolean;
|
|
199
|
+
/**
|
|
200
|
+
* Write files to the fileSystem
|
|
201
|
+
* This is being used for the playground.
|
|
202
|
+
* @default true
|
|
203
|
+
*/
|
|
204
|
+
write?: boolean;
|
|
205
|
+
};
|
|
206
|
+
/**
|
|
207
|
+
* Array of Kubb plugins to use.
|
|
208
|
+
* The plugin/package can forsee some options that you need to pass through.
|
|
209
|
+
* Sometimes a plugin is depended on another plugin, if that's the case you will get an error back from the plugin you installed.
|
|
210
|
+
*/
|
|
211
|
+
plugins?: Array<KubbPlugin>;
|
|
212
|
+
/**
|
|
213
|
+
* Hooks that will be called when a specific action is triggered in Kubb.
|
|
214
|
+
*/
|
|
215
|
+
hooks?: {
|
|
216
|
+
/**
|
|
217
|
+
* Hook that will be triggered at the end of all executions.
|
|
218
|
+
* Useful for running Prettier or ESLint to format/lint your code.
|
|
219
|
+
*/
|
|
220
|
+
done?: string | Array<string>;
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
type CLIOptions = {
|
|
224
|
+
/**
|
|
225
|
+
* Path to `kubb.config.js`
|
|
226
|
+
*/
|
|
227
|
+
config?: string;
|
|
228
|
+
/**
|
|
229
|
+
* Watch changes on input
|
|
230
|
+
*/
|
|
231
|
+
watch?: string;
|
|
232
|
+
/**
|
|
233
|
+
* Log level to report when using the CLI
|
|
234
|
+
*
|
|
235
|
+
* `silent` will hide all information that is not relevant
|
|
236
|
+
*
|
|
237
|
+
* `info` will show all information possible(not related to the PluginManager)
|
|
238
|
+
*
|
|
239
|
+
* `debug` will show all information possible(related to the PluginManager), handy for seeing logs
|
|
240
|
+
* @default `silent`
|
|
241
|
+
*/
|
|
242
|
+
logLevel?: LogLevel;
|
|
243
|
+
};
|
|
244
|
+
type KubbUnionPlugins = PluginUnion;
|
|
245
|
+
type KubbObjectPlugin = keyof OptionsPlugins;
|
|
246
|
+
type PluginFactoryOptions<
|
|
247
|
+
/**
|
|
248
|
+
* Name to be used for the plugin, this will also be used for they key.
|
|
249
|
+
*/
|
|
250
|
+
TName extends string = string,
|
|
251
|
+
/**
|
|
252
|
+
* Options of the plugin.
|
|
253
|
+
*/
|
|
254
|
+
TOptions extends object = object,
|
|
255
|
+
/**
|
|
256
|
+
* Options of the plugin that can be used later on, see `options` inside your plugin config.
|
|
257
|
+
*/
|
|
258
|
+
TResolvedOptions extends object = TOptions,
|
|
259
|
+
/**
|
|
260
|
+
* API that you want to expose to other plugins.
|
|
261
|
+
*/
|
|
262
|
+
TAPI = any,
|
|
263
|
+
/**
|
|
264
|
+
* When calling `resolvePath` you can specify better types.
|
|
265
|
+
*/
|
|
266
|
+
TResolvePathOptions extends object = object,
|
|
267
|
+
/**
|
|
268
|
+
* When using @kubb/react(based on React) you can specify here which types should be used when calling render.
|
|
269
|
+
* Always extend from `AppMeta` of the core.
|
|
270
|
+
*/
|
|
271
|
+
TAppMeta = unknown> = {
|
|
272
|
+
name: TName;
|
|
273
|
+
/**
|
|
274
|
+
* Same behaviour like what has been done with `QueryKey` in `@tanstack/react-query`
|
|
275
|
+
*/
|
|
276
|
+
key: [name: TName | string, identifier?: string | number];
|
|
277
|
+
options: TOptions;
|
|
278
|
+
resolvedOptions: TResolvedOptions;
|
|
279
|
+
api: TAPI;
|
|
280
|
+
resolvePathOptions: TResolvePathOptions;
|
|
281
|
+
appMeta: {
|
|
282
|
+
pluginManager: PluginManager;
|
|
283
|
+
plugin: KubbPlugin<PluginFactoryOptions<TName, TOptions, TResolvedOptions, TAPI, TResolvePathOptions, TAppMeta>>;
|
|
284
|
+
} & TAppMeta;
|
|
285
|
+
};
|
|
286
|
+
type GetPluginFactoryOptions<TPlugin extends KubbUserPlugin> = TPlugin extends KubbUserPlugin<infer X> ? X : never;
|
|
287
|
+
type KubbUserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
288
|
+
/**
|
|
289
|
+
* Unique name used for the plugin
|
|
290
|
+
* The name of the plugin follows the format scope:foo-bar or foo-bar, adding scope: can avoid naming conflicts with other plugins.
|
|
291
|
+
* @example @kubb/typescript
|
|
292
|
+
*/
|
|
293
|
+
name: TOptions['name'];
|
|
294
|
+
/**
|
|
295
|
+
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
296
|
+
*/
|
|
297
|
+
options: TOptions['resolvedOptions'];
|
|
298
|
+
/**
|
|
299
|
+
* 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.
|
|
300
|
+
* Can be used to validate depended plugins.
|
|
301
|
+
*/
|
|
302
|
+
pre?: Array<string>;
|
|
303
|
+
/**
|
|
304
|
+
* 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.
|
|
305
|
+
*/
|
|
306
|
+
post?: Array<string>;
|
|
307
|
+
} & (TOptions['api'] extends never ? {
|
|
308
|
+
api?: never;
|
|
309
|
+
} : {
|
|
310
|
+
api: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext<TOptions>, 'addFile'>) => TOptions['api'];
|
|
311
|
+
});
|
|
312
|
+
type KubbUserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = KubbUserPlugin<TOptions> & PluginLifecycle<TOptions>;
|
|
313
|
+
type UnknownKubbUserPlugin = KubbUserPlugin<PluginFactoryOptions<any, any, any, any, any, any>>;
|
|
314
|
+
type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
315
|
+
/**
|
|
316
|
+
* Unique name used for the plugin
|
|
317
|
+
* @example @kubb/typescript
|
|
318
|
+
*/
|
|
319
|
+
name: TOptions['name'];
|
|
320
|
+
/**
|
|
321
|
+
* Internal key used when a developer uses more than one of the same plugin
|
|
322
|
+
* @private
|
|
323
|
+
*/
|
|
324
|
+
key: TOptions['key'];
|
|
325
|
+
/**
|
|
326
|
+
* 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.
|
|
327
|
+
* Can be used to validate depended plugins.
|
|
328
|
+
*/
|
|
329
|
+
pre?: Array<string>;
|
|
330
|
+
/**
|
|
331
|
+
* 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.
|
|
332
|
+
*/
|
|
333
|
+
post?: Array<string>;
|
|
334
|
+
/**
|
|
335
|
+
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
336
|
+
*/
|
|
337
|
+
options: TOptions['resolvedOptions'];
|
|
338
|
+
} & (TOptions['api'] extends never ? {
|
|
339
|
+
api?: never;
|
|
340
|
+
} : {
|
|
341
|
+
api: TOptions['api'];
|
|
342
|
+
});
|
|
343
|
+
type KubbPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = KubbPlugin<TOptions> & PluginLifecycle<TOptions>;
|
|
344
|
+
type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
345
|
+
/**
|
|
346
|
+
* Start of the lifecycle of a plugin.
|
|
347
|
+
* @type hookParallel
|
|
348
|
+
*/
|
|
349
|
+
buildStart?: (this: PluginContext<TOptions>, kubbConfig: KubbConfig) => PossiblePromise<void>;
|
|
350
|
+
/**
|
|
351
|
+
* Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
|
|
352
|
+
* Options can als be included.
|
|
353
|
+
* @type hookFirst
|
|
354
|
+
* @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
|
|
355
|
+
*/
|
|
356
|
+
resolvePath?: (this: PluginContext<TOptions>, baseName: string, directory?: string, options?: TOptions['resolvePathOptions']) => KubbFile.OptionalPath;
|
|
357
|
+
/**
|
|
358
|
+
* Resolve to a name based on a string.
|
|
359
|
+
* Useful when converting to PascalCase or camelCase.
|
|
360
|
+
* @type hookFirst
|
|
361
|
+
* @example ('pet') => 'Pet'
|
|
362
|
+
*/
|
|
363
|
+
resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
364
|
+
/**
|
|
365
|
+
* Makes it possible to run async logic to override the path defined previously by `resolvePath`.
|
|
366
|
+
* @type hookFirst
|
|
367
|
+
*/
|
|
368
|
+
load?: (this: Omit<PluginContext<TOptions>, 'addFile'>, path: KubbFile.Path) => PossiblePromise<TransformResult | null>;
|
|
369
|
+
/**
|
|
370
|
+
* Transform the source-code.
|
|
371
|
+
* @type hookReduceArg0
|
|
372
|
+
*/
|
|
373
|
+
transform?: (this: Omit<PluginContext<TOptions>, 'addFile'>, source: string, path: KubbFile.Path) => PossiblePromise<TransformResult>;
|
|
374
|
+
/**
|
|
375
|
+
* Write the result to the file-system based on the id(defined by `resolvePath` or changed by `load`).
|
|
376
|
+
* @type hookParallel
|
|
377
|
+
*/
|
|
378
|
+
writeFile?: (this: Omit<PluginContext<TOptions>, 'addFile'>, source: string | undefined, path: KubbFile.Path) => PossiblePromise<string | void>;
|
|
379
|
+
/**
|
|
380
|
+
* End of the plugin lifecycle.
|
|
381
|
+
* @type hookParallel
|
|
382
|
+
*/
|
|
383
|
+
buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
384
|
+
};
|
|
385
|
+
type PluginLifecycleHooks = keyof PluginLifecycle;
|
|
386
|
+
type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
|
|
387
|
+
type PluginCache = Record<string, [number, unknown]>;
|
|
388
|
+
type ResolvePathParams<TOptions = object> = {
|
|
389
|
+
pluginKey?: KubbPlugin['key'];
|
|
390
|
+
baseName: string;
|
|
391
|
+
directory?: string | undefined;
|
|
392
|
+
/**
|
|
393
|
+
* Options to be passed to 'resolvePath' 3th parameter
|
|
394
|
+
*/
|
|
395
|
+
options?: TOptions;
|
|
396
|
+
};
|
|
397
|
+
type ResolveNameParams = {
|
|
398
|
+
name: string;
|
|
399
|
+
pluginKey?: KubbPlugin['key'];
|
|
400
|
+
/**
|
|
401
|
+
* `file` will be used to customize the name of the created file(use of camelCase)
|
|
402
|
+
* `function` can be used used to customize the exported functions(use of camelCase)
|
|
403
|
+
* `type` is a special type for TypeScript(use of PascalCase)
|
|
404
|
+
*/
|
|
405
|
+
type?: 'file' | 'function' | 'type';
|
|
406
|
+
};
|
|
407
|
+
type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
408
|
+
config: KubbConfig;
|
|
409
|
+
cache: Cache<PluginCache>;
|
|
410
|
+
fileManager: FileManager;
|
|
411
|
+
pluginManager: PluginManager;
|
|
412
|
+
addFile: (...file: Array<KubbFile.File>) => Promise<Array<KubbFile.File>>;
|
|
413
|
+
resolvePath: (params: ResolvePathParams<TOptions['resolvePathOptions']>) => KubbFile.OptionalPath;
|
|
414
|
+
resolveName: (params: ResolveNameParams) => string;
|
|
415
|
+
logger: Logger;
|
|
416
|
+
/**
|
|
417
|
+
* All plugins
|
|
418
|
+
*/
|
|
419
|
+
plugins: KubbPlugin[];
|
|
420
|
+
/**
|
|
421
|
+
* Current plugin
|
|
422
|
+
*/
|
|
423
|
+
plugin: KubbPlugin<TOptions>;
|
|
424
|
+
};
|
|
425
|
+
type TransformResult = string | null;
|
|
426
|
+
|
|
427
|
+
type BasePath<T extends string = string> = `${T}/`;
|
|
428
|
+
declare namespace KubbFile {
|
|
429
|
+
type Import = {
|
|
430
|
+
/**
|
|
431
|
+
* Import name to be used
|
|
432
|
+
* @example ["useState"]
|
|
433
|
+
* @example "React"
|
|
434
|
+
*/
|
|
435
|
+
name: string | Array<string | {
|
|
436
|
+
propertyName: string;
|
|
437
|
+
name?: string;
|
|
438
|
+
}>;
|
|
439
|
+
/**
|
|
440
|
+
* Path for the import
|
|
441
|
+
* @xample '@kubb/core'
|
|
442
|
+
*/
|
|
443
|
+
path: string;
|
|
444
|
+
/**
|
|
445
|
+
* Add `type` prefix to the import, this will result in: `import type { Type } from './path'`.
|
|
446
|
+
*/
|
|
447
|
+
isTypeOnly?: boolean;
|
|
448
|
+
/**
|
|
449
|
+
* Add `* as` prefix to the import, this will result in: `import * as path from './path'`.
|
|
450
|
+
*/
|
|
451
|
+
isNameSpace?: boolean;
|
|
452
|
+
/**
|
|
453
|
+
* When root is set it will get the path with relative getRelativePath(root, path).
|
|
454
|
+
*/
|
|
455
|
+
root?: string;
|
|
456
|
+
};
|
|
457
|
+
type Export = {
|
|
458
|
+
/**
|
|
459
|
+
* Export name to be used.
|
|
460
|
+
* @example ["useState"]
|
|
461
|
+
* @example "React"
|
|
462
|
+
*/
|
|
463
|
+
name?: string | Array<string>;
|
|
464
|
+
/**
|
|
465
|
+
* Path for the import.
|
|
466
|
+
* @xample '@kubb/core'
|
|
467
|
+
*/
|
|
468
|
+
path: string;
|
|
469
|
+
/**
|
|
470
|
+
* Add `type` prefix to the export, this will result in: `export type { Type } from './path'`.
|
|
471
|
+
*/
|
|
472
|
+
isTypeOnly?: boolean;
|
|
473
|
+
/**
|
|
474
|
+
* Make it possible to override the name, this will result in: `export * as aliasName from './path'`.
|
|
475
|
+
*/
|
|
476
|
+
asAlias?: boolean;
|
|
477
|
+
};
|
|
478
|
+
const dataTagSymbol: unique symbol;
|
|
479
|
+
type DataTag<Type, Value> = Type & {
|
|
480
|
+
[dataTagSymbol]: Value;
|
|
481
|
+
};
|
|
482
|
+
type UUID = string;
|
|
483
|
+
type Source = string;
|
|
484
|
+
type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`;
|
|
485
|
+
type Mode = 'file' | 'directory';
|
|
486
|
+
/**
|
|
487
|
+
* Name to be used to dynamicly create the baseName(based on input.path)
|
|
488
|
+
* Based on UNIX basename
|
|
489
|
+
* @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
|
|
490
|
+
*/
|
|
491
|
+
type BaseName = `${string}${Extname}`;
|
|
492
|
+
/**
|
|
493
|
+
* Path will be full qualified path to a specified file
|
|
494
|
+
*/
|
|
495
|
+
type Path = string;
|
|
496
|
+
type AdvancedPath<T extends BaseName = BaseName> = `${BasePath}${T}`;
|
|
497
|
+
type OptionalPath = Path | undefined | null;
|
|
498
|
+
type FileMetaBase = {
|
|
499
|
+
pluginKey?: KubbPlugin['key'];
|
|
500
|
+
};
|
|
501
|
+
type File<TMeta extends FileMetaBase = FileMetaBase, TBaseName extends BaseName = BaseName> = {
|
|
502
|
+
/**
|
|
503
|
+
* Unique identifier to reuse later
|
|
504
|
+
* @default crypto.randomUUID()
|
|
505
|
+
*/
|
|
506
|
+
id?: string;
|
|
507
|
+
/**
|
|
508
|
+
* Name to be used to create the path
|
|
509
|
+
* Based on UNIX basename, `${name}.extName`
|
|
510
|
+
* @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
|
|
511
|
+
*/
|
|
512
|
+
baseName: TBaseName;
|
|
513
|
+
/**
|
|
514
|
+
* Path will be full qualified path to a specified file
|
|
515
|
+
*/
|
|
516
|
+
path: AdvancedPath<TBaseName> | Path;
|
|
517
|
+
source: Source;
|
|
518
|
+
imports?: Import[];
|
|
519
|
+
exports?: Export[];
|
|
520
|
+
/**
|
|
521
|
+
* This will call fileManager.add instead of fileManager.addOrAppend, adding the source when the files already exists
|
|
522
|
+
* This will also ignore the combinefiles utils
|
|
523
|
+
* @default `false`
|
|
524
|
+
*/
|
|
525
|
+
override?: boolean;
|
|
526
|
+
/**
|
|
527
|
+
* Use extra meta, this is getting used to generate the barrel/index files.
|
|
528
|
+
*/
|
|
529
|
+
meta?: TMeta;
|
|
530
|
+
/**
|
|
531
|
+
* This will override `process.env[key]` inside the `source`, see `getFileSource`.
|
|
532
|
+
*/
|
|
533
|
+
env?: NodeJS.ProcessEnv;
|
|
534
|
+
};
|
|
535
|
+
type ResolvedFile<TMeta extends FileMetaBase = FileMetaBase, TBaseName extends BaseName = BaseName> = KubbFile.File<TMeta, TBaseName> & {
|
|
536
|
+
/**
|
|
537
|
+
* @default crypto.randomUUID()
|
|
538
|
+
*/
|
|
539
|
+
id: UUID;
|
|
540
|
+
/**
|
|
541
|
+
* Contains the first part of the baseName, generated based on baseName
|
|
542
|
+
* @link https://nodejs.org/api/path.html#pathformatpathobject
|
|
543
|
+
*/
|
|
544
|
+
name: string;
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
type AddResult<T extends Array<KubbFile.File>> = Promise<Awaited<GreaterThan<T['length'], 1> extends true ? Promise<KubbFile.ResolvedFile[]> : Promise<KubbFile.ResolvedFile>>>;
|
|
548
|
+
type AddIndexesProps = {
|
|
549
|
+
/**
|
|
550
|
+
* Root based on root and output.path specified in the config
|
|
551
|
+
*/
|
|
552
|
+
root: string;
|
|
553
|
+
/**
|
|
554
|
+
* Output for plugin
|
|
555
|
+
*/
|
|
556
|
+
output: {
|
|
557
|
+
path: string;
|
|
558
|
+
exportAs?: string;
|
|
559
|
+
extName?: KubbFile.Extname;
|
|
560
|
+
exportType?: 'barrel' | false;
|
|
561
|
+
};
|
|
562
|
+
options?: BarrelManagerOptions;
|
|
563
|
+
meta?: KubbFile.File['meta'];
|
|
564
|
+
};
|
|
565
|
+
type Options$1 = {
|
|
566
|
+
queue?: PQueue;
|
|
567
|
+
task?: (file: KubbFile.ResolvedFile) => Promise<KubbFile.ResolvedFile>;
|
|
568
|
+
};
|
|
569
|
+
declare class FileManager {
|
|
570
|
+
#private;
|
|
571
|
+
constructor({ task, queue }?: Options$1);
|
|
572
|
+
get files(): Array<KubbFile.File>;
|
|
573
|
+
get isExecuting(): boolean;
|
|
574
|
+
add<T extends Array<KubbFile.File> = Array<KubbFile.File>>(...files: T): AddResult<T>;
|
|
575
|
+
addIndexes({ root, output, meta, options }: AddIndexesProps): Promise<Array<KubbFile.File> | undefined>;
|
|
576
|
+
getCacheByUUID(UUID: KubbFile.UUID): KubbFile.File | undefined;
|
|
577
|
+
get(path: KubbFile.Path): Array<KubbFile.File> | undefined;
|
|
578
|
+
remove(path: KubbFile.Path): void;
|
|
579
|
+
write(...params: Parameters<typeof write>): Promise<string | undefined>;
|
|
580
|
+
read(...params: Parameters<typeof read>): Promise<string>;
|
|
581
|
+
static getSource<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase>(file: KubbFile.File<TMeta>): string;
|
|
582
|
+
static combineFiles<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase>(files: Array<KubbFile.File<TMeta> | null>): Array<KubbFile.File<TMeta>>;
|
|
583
|
+
static getMode(path: string | undefined | null): KubbFile.Mode;
|
|
584
|
+
static get extensions(): Array<KubbFile.Extname>;
|
|
585
|
+
static isExtensionAllowed(baseName: string): boolean;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
type BuildOptions = {
|
|
589
|
+
config: PluginContext['config'];
|
|
590
|
+
/**
|
|
591
|
+
* @default Logger without the spinner
|
|
592
|
+
*/
|
|
593
|
+
logger?: Logger;
|
|
594
|
+
};
|
|
595
|
+
type BuildOutput = {
|
|
596
|
+
files: FileManager['files'];
|
|
597
|
+
pluginManager: PluginManager;
|
|
598
|
+
/**
|
|
599
|
+
* Only for safeBuild
|
|
600
|
+
*/
|
|
601
|
+
error?: Error;
|
|
602
|
+
};
|
|
603
|
+
declare function build(options: BuildOptions): Promise<BuildOutput>;
|
|
604
|
+
declare function safeBuild(options: BuildOptions): Promise<BuildOutput>;
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* Type helper to make it easier to use kubb.config.js
|
|
608
|
+
* accepts a direct {@link KubbConfig} object, or a function that returns it.
|
|
609
|
+
* The function receives a {@link ConfigEnv} object that exposes two properties:
|
|
610
|
+
*/
|
|
611
|
+
declare function defineConfig(options: PossiblePromise<KubbUserConfig | Array<KubbUserConfig>> | ((
|
|
612
|
+
/** The options derived from the CLI flags */
|
|
613
|
+
cliOptions: CLIOptions) => PossiblePromise<KubbUserConfig | Array<KubbUserConfig>>)): typeof options;
|
|
614
|
+
declare function isInputPath(result: KubbConfig | undefined): result is KubbConfig<InputPath>;
|
|
615
|
+
|
|
616
|
+
/**
|
|
617
|
+
* Behaves as an Error to log a warning in the console(still stops the execution)
|
|
618
|
+
*/
|
|
619
|
+
declare class Warning extends Error {
|
|
620
|
+
constructor(message?: string, options?: {
|
|
621
|
+
cause: Error;
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
/**
|
|
626
|
+
* Abstract class that contains the building blocks for plugins to create their own Generator
|
|
627
|
+
* @link idea based on https://github.com/colinhacks/zod/blob/master/src/types.ts#L137
|
|
628
|
+
*/
|
|
629
|
+
declare abstract class Generator<TOptions = unknown, TContext = unknown> {
|
|
630
|
+
#private;
|
|
631
|
+
constructor(options?: TOptions, context?: TContext);
|
|
632
|
+
get options(): TOptions;
|
|
633
|
+
get context(): TContext;
|
|
634
|
+
set options(options: TOptions);
|
|
635
|
+
abstract build(...params: unknown[]): unknown;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
type PackageJSON = {
|
|
639
|
+
dependencies?: Record<string, string>;
|
|
640
|
+
devDependencies?: Record<string, string>;
|
|
641
|
+
};
|
|
642
|
+
type DependencyName = string;
|
|
643
|
+
type DependencyVersion = string;
|
|
644
|
+
declare class PackageManager {
|
|
645
|
+
#private;
|
|
646
|
+
constructor(workspace?: string);
|
|
647
|
+
set workspace(workspace: string);
|
|
648
|
+
get workspace(): string | undefined;
|
|
649
|
+
normalizeDirectory(directory: string): string;
|
|
650
|
+
getLocation(path: string): string;
|
|
651
|
+
import(path: string): Promise<any | undefined>;
|
|
652
|
+
getPackageJSON(): Promise<PackageJSON | undefined>;
|
|
653
|
+
getPackageJSONSync(): PackageJSON | undefined;
|
|
654
|
+
static setVersion(dependency: DependencyName, version: DependencyVersion): void;
|
|
655
|
+
getVersion(dependency: DependencyName | RegExp): Promise<DependencyVersion | undefined>;
|
|
656
|
+
getVersionSync(dependency: DependencyName | RegExp): DependencyVersion | undefined;
|
|
657
|
+
isValid(dependency: DependencyName | RegExp, version: DependencyVersion): Promise<boolean>;
|
|
658
|
+
isValidSync(dependency: DependencyName | RegExp, version: DependencyVersion): boolean;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
type KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> = (options: T['options']) => KubbUserPluginWithLifeCycle<T>;
|
|
662
|
+
declare function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(factory: KubbPluginFactory<T>): (options: T['options']) => ReturnType<KubbPluginFactory<T>>;
|
|
663
|
+
declare const pluginName = "core";
|
|
664
|
+
|
|
665
|
+
type PromiseFunc$1<T = unknown, T2 = never> = (state?: T) => T2 extends never ? Promise<T> : Promise<T> | T2;
|
|
666
|
+
type ValueOfPromiseFuncArray<TInput extends Array<unknown>> = TInput extends Array<PromiseFunc$1<infer X, infer Y>> ? X | Y : never;
|
|
667
|
+
type SeqOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue> = Array<Awaited<ValueOfPromiseFuncArray<TInput>>>;
|
|
668
|
+
type HookFirstOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue = unknown> = ValueOfPromiseFuncArray<TInput>;
|
|
669
|
+
type HookParallelOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue> = Promise<PromiseSettledResult<Awaited<ValueOfPromiseFuncArray<TInput>>>[]>;
|
|
670
|
+
type Strategy = 'seq' | 'first' | 'parallel';
|
|
671
|
+
type StrategySwitch<TStrategy extends Strategy, TInput extends Array<PromiseFunc$1<TValue, null>>, TValue> = TStrategy extends 'first' ? HookFirstOutput<TInput, TValue> : TStrategy extends 'seq' ? SeqOutput<TInput, TValue> : TStrategy extends 'parallel' ? HookParallelOutput<TInput, TValue> : never;
|
|
672
|
+
|
|
673
|
+
type PromiseFunc<T = unknown, T2 = never> = () => T2 extends never ? Promise<T> : Promise<T> | T2;
|
|
674
|
+
type Options<TState = any> = {
|
|
675
|
+
nullCheck?: (state: TState) => boolean;
|
|
676
|
+
};
|
|
677
|
+
declare class PromiseManager<TState = any> {
|
|
678
|
+
#private;
|
|
679
|
+
constructor(options?: Options<TState>);
|
|
680
|
+
run<TInput extends Array<PromiseFunc<TValue, null>>, TValue, TStrategy extends Strategy, TOutput = StrategySwitch<TStrategy, TInput, TValue>>(strategy: TStrategy, promises: TInput): TOutput;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
interface _Register {
|
|
684
|
+
}
|
|
685
|
+
type Plugins = _Register;
|
|
686
|
+
type OptionsPlugins = {
|
|
687
|
+
[K in keyof Plugins]: Plugins[K]['options'];
|
|
688
|
+
};
|
|
689
|
+
type OptionsOfPlugin<K extends keyof Plugins> = Plugins[K]['options'];
|
|
690
|
+
type PluginUnion = TupleToUnion<ObjValueTuple<OptionsPlugins>>;
|
|
691
|
+
type Plugin = keyof Plugins;
|
|
692
|
+
|
|
693
|
+
export { type CLIOptions, FileManager, Generator, type GetPluginFactoryOptions, type InputData, type InputPath, type KubbConfig, KubbFile, type KubbObjectPlugin, type KubbPlugin, type KubbPluginWithLifeCycle, type KubbUnionPlugins, type KubbUserConfig, type KubbUserPlugin, type KubbUserPluginWithLifeCycle, type OptionsOfPlugin, type OptionsPlugins, PackageManager, type Plugin, type PluginCache, type PluginContext, type PluginFactoryOptions, type PluginLifecycle, type PluginLifecycleHooks, PluginManager, type PluginParameter, type PluginUnion, type Plugins, PromiseManager, type ResolveNameParams, type ResolvePathParams, type TransformResult, Warning, type _Register, build, createPlugin, build as default, defineConfig, isInputPath, pluginName as name, pluginName, safeBuild };
|