@kubb/core 3.0.0-alpha.9 → 3.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -5
- package/dist/{FileManager-B0GJlthB.d.cts → FileManager-C9aZTwst.d.ts} +94 -77
- package/dist/{FileManager-BFycBDqG.d.ts → FileManager-ibNoWwHN.d.cts} +94 -77
- package/dist/chunk-2EU7DMPM.js +2 -3
- package/dist/chunk-2EU7DMPM.js.map +1 -1
- package/dist/{chunk-5E2I6KH4.cjs → chunk-7FIOLZNC.cjs} +54 -37
- package/dist/chunk-7FIOLZNC.cjs.map +1 -0
- package/dist/{chunk-4X5FFJPJ.js → chunk-BQXM32UO.js} +11 -16
- package/dist/chunk-BQXM32UO.js.map +1 -0
- package/dist/{chunk-27CPVXAT.js → chunk-DXGMSPTW.js} +174 -231
- package/dist/chunk-DXGMSPTW.js.map +1 -0
- package/dist/{chunk-SCR3LUXT.js → chunk-E6CN2CZC.js} +38 -27
- package/dist/chunk-E6CN2CZC.js.map +1 -0
- package/dist/{chunk-A6PCLWEY.cjs → chunk-GT5BP3R3.cjs} +30 -31
- package/dist/chunk-GT5BP3R3.cjs.map +1 -0
- package/dist/{chunk-5IGANEGE.cjs → chunk-GYVPCXVO.cjs} +268 -301
- package/dist/chunk-GYVPCXVO.cjs.map +1 -0
- package/dist/chunk-HBQM723K.js +12 -26
- package/dist/chunk-HBQM723K.js.map +1 -1
- package/dist/{chunk-DID47EQD.cjs → chunk-NXUSJIVM.cjs} +6 -7
- package/dist/chunk-NXUSJIVM.cjs.map +1 -0
- package/dist/{chunk-SEH6NUCX.cjs → chunk-VD74XCQ4.cjs} +10 -10
- package/dist/chunk-VD74XCQ4.cjs.map +1 -0
- package/dist/{chunk-IPZQXBA2.cjs → chunk-ZFYMG5ID.cjs} +57 -34
- package/dist/chunk-ZFYMG5ID.cjs.map +1 -0
- package/dist/index.cjs +223 -241
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -6
- package/dist/index.d.ts +4 -6
- package/dist/index.js +106 -148
- package/dist/index.js.map +1 -1
- package/dist/{logger-BWFeedRk.d.cts → logger-DvbHXjIO.d.cts} +10 -8
- package/dist/{logger-BWFeedRk.d.ts → logger-DvbHXjIO.d.ts} +10 -8
- package/dist/logger.cjs +25 -14
- package/dist/logger.cjs.map +1 -1
- package/dist/logger.d.cts +1 -1
- package/dist/logger.d.ts +1 -1
- package/dist/logger.js +3 -13
- package/dist/logger.js.map +1 -1
- package/dist/mocks.cjs +29 -24
- package/dist/mocks.cjs.map +1 -1
- package/dist/mocks.d.cts +4 -3
- package/dist/mocks.d.ts +4 -3
- package/dist/mocks.js +22 -25
- package/dist/mocks.js.map +1 -1
- package/dist/{prompt-DVQN7JTN.cjs → prompt-GVDKBQQY.cjs} +89 -89
- package/dist/prompt-GVDKBQQY.cjs.map +1 -0
- package/dist/prompt-WQQUN22Z.js +8 -13
- package/dist/prompt-WQQUN22Z.js.map +1 -1
- package/dist/transformers.cjs +63 -52
- package/dist/transformers.cjs.map +1 -1
- package/dist/transformers.d.cts +1 -1
- package/dist/transformers.d.ts +1 -1
- package/dist/transformers.js +10 -37
- package/dist/transformers.js.map +1 -1
- package/dist/utils.cjs +65 -34
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +6 -8
- package/dist/utils.d.ts +6 -8
- package/dist/utils.js +3 -33
- package/dist/utils.js.map +1 -1
- package/package.json +10 -13
- package/src/BarrelManager.ts +76 -74
- package/src/FileManager.ts +55 -60
- package/src/PluginManager.ts +61 -61
- package/src/PromiseManager.ts +1 -1
- package/src/__snapshots__/barrel.json +11 -29
- package/src/__snapshots__/grouped.json +18 -12
- package/src/__snapshots__/ordered.json +18 -12
- package/src/build.ts +24 -11
- package/src/config.ts +2 -4
- package/src/index.ts +1 -1
- package/src/logger.ts +41 -7
- package/src/plugin.ts +0 -3
- package/src/transformers/escape.ts +0 -10
- package/src/transformers/stringify.ts +1 -1
- package/src/types.ts +70 -38
- package/src/utils/TreeNode.ts +31 -56
- package/src/utils/executeStrategies.ts +2 -2
- package/src/utils/parser.ts +38 -39
- package/dist/chunk-27CPVXAT.js.map +0 -1
- package/dist/chunk-4X5FFJPJ.js.map +0 -1
- package/dist/chunk-5E2I6KH4.cjs.map +0 -1
- package/dist/chunk-5IGANEGE.cjs.map +0 -1
- package/dist/chunk-A6PCLWEY.cjs.map +0 -1
- package/dist/chunk-DID47EQD.cjs.map +0 -1
- package/dist/chunk-IPZQXBA2.cjs.map +0 -1
- package/dist/chunk-SCR3LUXT.js.map +0 -1
- package/dist/chunk-SEH6NUCX.cjs.map +0 -1
- package/dist/prompt-DVQN7JTN.cjs.map +0 -1
- package/src/utils/cache.ts +0 -35
package/README.md
CHANGED
|
@@ -13,12 +13,8 @@
|
|
|
13
13
|
[![Coverage][coverage-src]][coverage-href]
|
|
14
14
|
[![License][license-src]][license-href]
|
|
15
15
|
|
|
16
|
-
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
17
|
-
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
18
|
-
</p>
|
|
19
|
-
|
|
20
16
|
<h4>
|
|
21
|
-
<a href="https://codesandbox.io/s/github/kubb-labs/kubb/tree/
|
|
17
|
+
<a href="https://codesandbox.io/s/github/kubb-labs/kubb/tree/main//examples/typescript" target="_blank">View Demo</a>
|
|
22
18
|
<span> · </span>
|
|
23
19
|
<a href="https://kubb.dev/" target="_blank">Documentation</a>
|
|
24
20
|
<span> · </span>
|
|
@@ -28,6 +24,19 @@
|
|
|
28
24
|
</h4>
|
|
29
25
|
</div>
|
|
30
26
|
|
|
27
|
+
## Supporting Kubb
|
|
28
|
+
|
|
29
|
+
Kubb uses an MIT-licensed open source project with its ongoing development made possible entirely by the support of Sponsors. If you would like to become a sponsor, please consider:
|
|
30
|
+
|
|
31
|
+
- [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
|
|
32
|
+
|
|
33
|
+
<p align="center">
|
|
34
|
+
<a href="https://github.com/sponsors/stijnvanhulle">
|
|
35
|
+
<img src="https://raw.githubusercontent.com/stijnvanhulle/sponsors/main/sponsors.svg" alt="My sponsors" />
|
|
36
|
+
</a>
|
|
37
|
+
</p>
|
|
38
|
+
|
|
39
|
+
|
|
31
40
|
<!-- Badges -->
|
|
32
41
|
|
|
33
42
|
[npm-version-src]: https://img.shields.io/npm/v/@kubb/core?flat&colorA=18181B&colorB=f58517
|
|
@@ -2,16 +2,12 @@ import { write, read } from '@kubb/fs';
|
|
|
2
2
|
import * as KubbFile from '@kubb/fs/types';
|
|
3
3
|
import { ResolvedFile } from '@kubb/fs/types';
|
|
4
4
|
import { PossiblePromise, GreaterThan } from '@kubb/types';
|
|
5
|
-
import { E as EventEmitter, L as Logger } from './logger-
|
|
5
|
+
import { E as EventEmitter, L as Logger } from './logger-DvbHXjIO.js';
|
|
6
6
|
|
|
7
7
|
type RequiredPluginLifecycle = Required<PluginLifecycle>;
|
|
8
|
-
|
|
9
|
-
* Get the type of the first argument in a function.
|
|
10
|
-
* @example Arg0<(a: string, b: number) => void> -> string
|
|
11
|
-
*/
|
|
12
|
-
type Argument0<H extends keyof PluginLifecycle> = Parameters<RequiredPluginLifecycle[H]>[0];
|
|
13
|
-
type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookReduceArg0' | 'hookSeq';
|
|
8
|
+
type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookSeq';
|
|
14
9
|
type Executer<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
10
|
+
message: string;
|
|
15
11
|
strategy: Strategy;
|
|
16
12
|
hookName: H;
|
|
17
13
|
plugin: Plugin;
|
|
@@ -27,20 +23,20 @@ type Options = {
|
|
|
27
23
|
logger: Logger;
|
|
28
24
|
};
|
|
29
25
|
type Events = {
|
|
30
|
-
|
|
26
|
+
executing: [executer: Executer];
|
|
31
27
|
executed: [executer: Executer];
|
|
32
28
|
error: [error: Error];
|
|
33
29
|
};
|
|
34
30
|
type GetFileProps<TOptions = object> = {
|
|
35
31
|
name: string;
|
|
36
32
|
mode?: KubbFile.Mode;
|
|
37
|
-
|
|
33
|
+
extname: KubbFile.Extname;
|
|
38
34
|
pluginKey: Plugin['key'];
|
|
39
35
|
options?: TOptions;
|
|
40
36
|
};
|
|
41
37
|
declare class PluginManager {
|
|
42
38
|
#private;
|
|
43
|
-
readonly plugins:
|
|
39
|
+
readonly plugins: Set<Plugin<PluginFactoryOptions<string, object, object, any, object>>>;
|
|
44
40
|
readonly fileManager: FileManager;
|
|
45
41
|
readonly events: EventEmitter<Events>;
|
|
46
42
|
readonly config: Config;
|
|
@@ -48,7 +44,7 @@ declare class PluginManager {
|
|
|
48
44
|
readonly logger: Logger;
|
|
49
45
|
readonly options: Options;
|
|
50
46
|
constructor(config: Config, options: Options);
|
|
51
|
-
getFile<TOptions = object>({ name, mode,
|
|
47
|
+
getFile<TOptions = object>({ name, mode, extname, pluginKey, options }: GetFileProps<TOptions>): KubbFile.File<{
|
|
52
48
|
pluginKey: Plugin['key'];
|
|
53
49
|
}>;
|
|
54
50
|
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
|
|
@@ -60,69 +56,60 @@ declare class PluginManager {
|
|
|
60
56
|
/**
|
|
61
57
|
* Run a specific hookName for plugin x.
|
|
62
58
|
*/
|
|
63
|
-
hookForPlugin<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, }: {
|
|
59
|
+
hookForPlugin<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, message, }: {
|
|
64
60
|
pluginKey: Plugin['key'];
|
|
65
61
|
hookName: H;
|
|
66
62
|
parameters: PluginParameter<H>;
|
|
63
|
+
message: string;
|
|
67
64
|
}): Promise<Array<ReturnType<ParseResult<H>> | null>>;
|
|
68
65
|
/**
|
|
69
66
|
* Run a specific hookName for plugin x.
|
|
70
67
|
*/
|
|
71
|
-
hookForPluginSync<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, }: {
|
|
68
|
+
hookForPluginSync<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, message, }: {
|
|
72
69
|
pluginKey: Plugin['key'];
|
|
73
70
|
hookName: H;
|
|
74
71
|
parameters: PluginParameter<H>;
|
|
72
|
+
message: string;
|
|
75
73
|
}): Array<ReturnType<ParseResult<H>>> | null;
|
|
76
74
|
/**
|
|
77
75
|
* First non-null result stops and will return it's value.
|
|
78
76
|
*/
|
|
79
|
-
hookFirst<H extends PluginLifecycleHooks>({ hookName, parameters, skipped, }: {
|
|
77
|
+
hookFirst<H extends PluginLifecycleHooks>({ hookName, parameters, skipped, message, }: {
|
|
80
78
|
hookName: H;
|
|
81
79
|
parameters: PluginParameter<H>;
|
|
82
80
|
skipped?: ReadonlySet<Plugin> | null;
|
|
81
|
+
message: string;
|
|
83
82
|
}): Promise<SafeParseResult<H>>;
|
|
84
83
|
/**
|
|
85
84
|
* First non-null result stops and will return it's value.
|
|
86
85
|
*/
|
|
87
|
-
hookFirstSync<H extends PluginLifecycleHooks>({ hookName, parameters, skipped, }: {
|
|
86
|
+
hookFirstSync<H extends PluginLifecycleHooks>({ hookName, parameters, skipped, message, }: {
|
|
88
87
|
hookName: H;
|
|
89
88
|
parameters: PluginParameter<H>;
|
|
90
89
|
skipped?: ReadonlySet<Plugin> | null;
|
|
90
|
+
message: string;
|
|
91
91
|
}): SafeParseResult<H>;
|
|
92
92
|
/**
|
|
93
93
|
* Run all plugins in parallel(order will be based on `this.plugin` and if `pre` or `post` is set).
|
|
94
94
|
*/
|
|
95
|
-
hookParallel<H extends PluginLifecycleHooks, TOuput = void>({ hookName, parameters, }: {
|
|
95
|
+
hookParallel<H extends PluginLifecycleHooks, TOuput = void>({ hookName, parameters, message, }: {
|
|
96
96
|
hookName: H;
|
|
97
97
|
parameters?: Parameters<RequiredPluginLifecycle[H]> | undefined;
|
|
98
|
+
message: string;
|
|
98
99
|
}): Promise<Awaited<TOuput>[]>;
|
|
99
|
-
/**
|
|
100
|
-
* 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.
|
|
101
|
-
*/
|
|
102
|
-
hookReduceArg0<H extends PluginLifecycleHooks>({ hookName, parameters, reduce, }: {
|
|
103
|
-
hookName: H;
|
|
104
|
-
parameters: PluginParameter<H>;
|
|
105
|
-
reduce: (reduction: Argument0<H>, result: ReturnType<ParseResult<H>>, plugin: Plugin) => PossiblePromise<Argument0<H> | null>;
|
|
106
|
-
}): Promise<Argument0<H>>;
|
|
107
100
|
/**
|
|
108
101
|
* Chains plugins
|
|
109
102
|
*/
|
|
110
|
-
hookSeq<H extends PluginLifecycleHooks>({ hookName, parameters }: {
|
|
103
|
+
hookSeq<H extends PluginLifecycleHooks>({ hookName, parameters, message, }: {
|
|
111
104
|
hookName: H;
|
|
112
105
|
parameters?: PluginParameter<H>;
|
|
106
|
+
message: string;
|
|
113
107
|
}): Promise<void>;
|
|
114
108
|
getPluginsByKey(hookName: keyof PluginLifecycle, pluginKey: Plugin['key']): Plugin[];
|
|
115
109
|
static getDependedPlugins<T1 extends PluginFactoryOptions, T2 extends PluginFactoryOptions = never, T3 extends PluginFactoryOptions = never, TOutput = T3 extends never ? (T2 extends never ? [T1: Plugin<T1>] : [T1: Plugin<T1>, T2: Plugin<T2>]) : [T1: Plugin<T1>, T2: Plugin<T2>, T3: Plugin<T3>]>(plugins: Array<Plugin>, dependedPluginNames: string | string[]): TOutput;
|
|
116
110
|
static get hooks(): readonly ["buildStart", "resolvePath", "resolveName", "buildEnd"];
|
|
117
111
|
}
|
|
118
112
|
|
|
119
|
-
interface Cache<TStore extends object = object> {
|
|
120
|
-
delete(id: keyof TStore): boolean;
|
|
121
|
-
get(id: keyof TStore): TStore[keyof TStore] | null;
|
|
122
|
-
has(id: keyof TStore): boolean;
|
|
123
|
-
set(id: keyof TStore, value: unknown): void;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
113
|
/**
|
|
127
114
|
* Config used in `kubb.config.js`
|
|
128
115
|
*
|
|
@@ -145,17 +132,18 @@ type UserConfig = Omit<Config, 'root' | 'plugins'> & {
|
|
|
145
132
|
};
|
|
146
133
|
type InputPath = {
|
|
147
134
|
/**
|
|
148
|
-
*
|
|
135
|
+
* Define your Swagger/OpenAPI file. This can be an absolute path or a path relative to the `root`.
|
|
149
136
|
*/
|
|
150
137
|
path: string;
|
|
151
138
|
};
|
|
152
139
|
type InputData = {
|
|
153
140
|
/**
|
|
154
|
-
* `string` or `object` containing
|
|
141
|
+
* `string` or `object` containing your Swagger/OpenAPI data.
|
|
155
142
|
*/
|
|
156
143
|
data: string | unknown;
|
|
157
144
|
};
|
|
158
145
|
type Input = InputPath | InputData;
|
|
146
|
+
type BarrelType = 'all' | 'named';
|
|
159
147
|
/**
|
|
160
148
|
* @private
|
|
161
149
|
*/
|
|
@@ -165,38 +153,43 @@ type Config<TInput = Input> = {
|
|
|
165
153
|
*/
|
|
166
154
|
name?: string;
|
|
167
155
|
/**
|
|
168
|
-
* Project root directory.
|
|
169
|
-
* the location of the config file itself.
|
|
156
|
+
* Project root directory. This can be an absolute path or a path relative to the location of your `kubb.config.ts` file.
|
|
170
157
|
* @default process.cwd()
|
|
171
158
|
*/
|
|
172
159
|
root: string;
|
|
160
|
+
/**
|
|
161
|
+
* You can use `input.path` or `input.data` depending on the needs you have.
|
|
162
|
+
*/
|
|
173
163
|
input: TInput;
|
|
174
164
|
output: {
|
|
175
165
|
/**
|
|
176
|
-
*
|
|
177
|
-
* This can be an absolute path, or a path relative based of the defined `root` option.
|
|
166
|
+
* The path where all generated files will be exported. This can be an absolute path or a path relative to the specified root option.
|
|
178
167
|
*/
|
|
179
168
|
path: string;
|
|
180
169
|
/**
|
|
181
|
-
* Clean output directory before each build.
|
|
170
|
+
* Clean the output directory before each build.
|
|
182
171
|
*/
|
|
183
172
|
clean?: boolean;
|
|
184
173
|
/**
|
|
185
|
-
*
|
|
186
|
-
* This is being used for the playground.
|
|
174
|
+
* Save files to the file system.
|
|
187
175
|
* @default true
|
|
188
176
|
*/
|
|
189
177
|
write?: boolean;
|
|
190
178
|
/**
|
|
191
|
-
*
|
|
192
|
-
* @default `'
|
|
179
|
+
* Override the extension to the generated imports and exports, by default the plugin will add an extension
|
|
180
|
+
* @default `{ '.ts': '.ts'}`
|
|
193
181
|
*/
|
|
194
|
-
|
|
182
|
+
extension?: Record<KubbFile.Extname, KubbFile.Extname>;
|
|
183
|
+
/**
|
|
184
|
+
* Define what needs to exported, here you can also disable the export of barrel files.
|
|
185
|
+
* @default `'named'`
|
|
186
|
+
*/
|
|
187
|
+
barrelType?: BarrelType | false;
|
|
195
188
|
};
|
|
196
189
|
/**
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
190
|
+
* An array of Kubb plugins that will be used in the generation.
|
|
191
|
+
* Each plugin may include additional configurable options(defined in the plugin itself).
|
|
192
|
+
* If a plugin depends on another plugin, an error will be returned if the required dependency is missing. See pre for more details.
|
|
200
193
|
*/
|
|
201
194
|
plugins?: Array<Plugin>;
|
|
202
195
|
/**
|
|
@@ -281,21 +274,6 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
|
281
274
|
* @private
|
|
282
275
|
*/
|
|
283
276
|
key: TOptions['key'];
|
|
284
|
-
output?: {
|
|
285
|
-
/**
|
|
286
|
-
* Output to save the clients.
|
|
287
|
-
*/
|
|
288
|
-
path: string;
|
|
289
|
-
/**
|
|
290
|
-
* Add an extension to the generated imports and exports, default it will not use an extension
|
|
291
|
-
*/
|
|
292
|
-
extName?: KubbFile.Extname;
|
|
293
|
-
/**
|
|
294
|
-
* Define what needs to exported, here you can also disable the export of barrel files
|
|
295
|
-
* @default `'barrelNamed'`
|
|
296
|
-
*/
|
|
297
|
-
exportType?: 'barrel' | 'barrelNamed' | false;
|
|
298
|
-
};
|
|
299
277
|
/**
|
|
300
278
|
* 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.
|
|
301
279
|
* Can be used to validate dependent plugins.
|
|
@@ -327,7 +305,7 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
|
|
|
327
305
|
* @type hookFirst
|
|
328
306
|
* @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
|
|
329
307
|
*/
|
|
330
|
-
resolvePath?: (this: PluginContext<TOptions>, baseName:
|
|
308
|
+
resolvePath?: (this: PluginContext<TOptions>, baseName: KubbFile.BaseName, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.OptionalPath;
|
|
331
309
|
/**
|
|
332
310
|
* Resolve to a name based on a string.
|
|
333
311
|
* Useful when converting to PascalCase or camelCase.
|
|
@@ -343,10 +321,9 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
|
|
|
343
321
|
};
|
|
344
322
|
type PluginLifecycleHooks = keyof PluginLifecycle;
|
|
345
323
|
type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
|
|
346
|
-
type PluginCache = Record<string, [number, unknown]>;
|
|
347
324
|
type ResolvePathParams<TOptions = object> = {
|
|
348
325
|
pluginKey?: Plugin['key'];
|
|
349
|
-
baseName:
|
|
326
|
+
baseName: KubbFile.BaseName;
|
|
350
327
|
mode?: KubbFile.Mode;
|
|
351
328
|
/**
|
|
352
329
|
* Options to be passed to 'resolvePath' 3th parameter
|
|
@@ -358,14 +335,14 @@ type ResolveNameParams = {
|
|
|
358
335
|
pluginKey?: Plugin['key'];
|
|
359
336
|
/**
|
|
360
337
|
* `file` will be used to customize the name of the created file(use of camelCase)
|
|
361
|
-
* `function` can be used
|
|
338
|
+
* `function` can be used to customize the exported functions(use of camelCase)
|
|
362
339
|
* `type` is a special type for TypeScript(use of PascalCase)
|
|
340
|
+
* `const` can be used for variables(use of camelCase)
|
|
363
341
|
*/
|
|
364
|
-
type?: 'file' | 'function' | 'type';
|
|
342
|
+
type?: 'file' | 'function' | 'type' | 'const';
|
|
365
343
|
};
|
|
366
344
|
type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
367
345
|
config: Config;
|
|
368
|
-
cache: Cache<PluginCache>;
|
|
369
346
|
fileManager: FileManager;
|
|
370
347
|
pluginManager: PluginManager;
|
|
371
348
|
addFile: (...file: Array<KubbFile.File>) => Promise<Array<KubbFile.ResolvedFile>>;
|
|
@@ -381,6 +358,41 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
381
358
|
*/
|
|
382
359
|
plugin: Plugin<TOptions>;
|
|
383
360
|
};
|
|
361
|
+
/**
|
|
362
|
+
* Specify the export location for the files and define the behavior of the output
|
|
363
|
+
*/
|
|
364
|
+
type Output = {
|
|
365
|
+
/**
|
|
366
|
+
* Path to the output folder or file that will contain the generated code
|
|
367
|
+
*/
|
|
368
|
+
path: string;
|
|
369
|
+
/**
|
|
370
|
+
* Define what needs to be exported, here you can also disable the export of barrel files
|
|
371
|
+
* @default `'named'`
|
|
372
|
+
*/
|
|
373
|
+
barrelType?: BarrelType | false;
|
|
374
|
+
/**
|
|
375
|
+
* Add a banner text in the beginning of every file
|
|
376
|
+
*/
|
|
377
|
+
banner?: string;
|
|
378
|
+
/**
|
|
379
|
+
* Add a footer text in the beginning of every file
|
|
380
|
+
*/
|
|
381
|
+
footer?: string;
|
|
382
|
+
};
|
|
383
|
+
type GroupContext = {
|
|
384
|
+
group: string;
|
|
385
|
+
};
|
|
386
|
+
type Group = {
|
|
387
|
+
/**
|
|
388
|
+
* Define a type where to group the files on
|
|
389
|
+
*/
|
|
390
|
+
type: 'tag';
|
|
391
|
+
/**
|
|
392
|
+
* Return the name of a group based on the group name, this will be used for the file and name generation
|
|
393
|
+
*/
|
|
394
|
+
name?: (context: GroupContext) => string;
|
|
395
|
+
};
|
|
384
396
|
|
|
385
397
|
type BarrelData = {
|
|
386
398
|
file?: KubbFile.File;
|
|
@@ -392,17 +404,19 @@ type BarrelData = {
|
|
|
392
404
|
name: string;
|
|
393
405
|
};
|
|
394
406
|
declare class TreeNode {
|
|
407
|
+
#private;
|
|
395
408
|
data: BarrelData;
|
|
396
409
|
parent?: TreeNode;
|
|
397
410
|
children: Array<TreeNode>;
|
|
398
411
|
constructor(data: BarrelData, parent?: TreeNode);
|
|
399
412
|
addChild(data: BarrelData): TreeNode;
|
|
400
|
-
find(data?: BarrelData): TreeNode | null;
|
|
401
|
-
get leaves(): Array<TreeNode>;
|
|
402
413
|
get root(): TreeNode;
|
|
414
|
+
get leaves(): Array<TreeNode>;
|
|
403
415
|
forEach(callback: (treeNode: TreeNode) => void): this;
|
|
404
|
-
|
|
405
|
-
|
|
416
|
+
findDeep(predicate?: (value: TreeNode, index: number, obj: TreeNode[]) => boolean): TreeNode | undefined;
|
|
417
|
+
forEachDeep(callback: (treeNode: TreeNode) => void): void;
|
|
418
|
+
filterDeep(callback: (treeNode: TreeNode) => boolean): Array<TreeNode>;
|
|
419
|
+
mapDeep<T>(callback: (treeNode: TreeNode) => T): Array<T>;
|
|
406
420
|
static build(files: KubbFile.File[], root?: string): TreeNode | null;
|
|
407
421
|
}
|
|
408
422
|
type DirectoryTree = {
|
|
@@ -417,6 +431,7 @@ type FileMetaBase = {
|
|
|
417
431
|
};
|
|
418
432
|
type AddResult<T extends Array<KubbFile.File>> = Promise<Awaited<GreaterThan<T['length'], 1> extends true ? Promise<ResolvedFile[]> : Promise<ResolvedFile>>>;
|
|
419
433
|
type AddIndexesProps = {
|
|
434
|
+
type: BarrelType | false | undefined;
|
|
420
435
|
/**
|
|
421
436
|
* Root based on root and output.path specified in the config
|
|
422
437
|
*/
|
|
@@ -427,9 +442,6 @@ type AddIndexesProps = {
|
|
|
427
442
|
*/
|
|
428
443
|
output: {
|
|
429
444
|
path: string;
|
|
430
|
-
extName?: KubbFile.Extname;
|
|
431
|
-
exportAs?: string;
|
|
432
|
-
exportType?: 'barrel' | 'barrelNamed' | false;
|
|
433
445
|
};
|
|
434
446
|
group?: {
|
|
435
447
|
output: string;
|
|
@@ -450,10 +462,15 @@ declare class FileManager {
|
|
|
450
462
|
getCacheById(id: string): KubbFile.File | undefined;
|
|
451
463
|
getByPath(path: KubbFile.Path): KubbFile.ResolvedFile | undefined;
|
|
452
464
|
deleteByPath(path: KubbFile.Path): void;
|
|
453
|
-
getBarrelFiles({ files, meta, root, output, logger }: AddIndexesProps): Promise<KubbFile.File[]>;
|
|
465
|
+
getBarrelFiles({ type, files, meta, root, output, logger }: AddIndexesProps): Promise<KubbFile.File[]>;
|
|
454
466
|
write(...params: Parameters<typeof write>): ReturnType<typeof write>;
|
|
455
467
|
read(...params: Parameters<typeof read>): ReturnType<typeof read>;
|
|
456
468
|
static getMode(path: string | undefined | null): KubbFile.Mode;
|
|
457
469
|
}
|
|
470
|
+
type GetSourceOptions = {
|
|
471
|
+
extname?: KubbFile.Extname;
|
|
472
|
+
logger?: Logger;
|
|
473
|
+
};
|
|
474
|
+
declare function getSource<TMeta extends FileMetaBase = FileMetaBase>(file: ResolvedFile<TMeta>, { logger, extname }?: GetSourceOptions): Promise<string>;
|
|
458
475
|
|
|
459
|
-
export { type Config as C, FileManager as F, type GetPluginFactoryOptions as G, type InputPath as I, type PluginContext as P, type ResolvePathParams as R, type UserConfig as U, PluginManager as a, type PluginFactoryOptions as b, type UserPluginWithLifeCycle as c, type FileMetaBase as d, type InputData as e, type PluginKey as f,
|
|
476
|
+
export { type BarrelType as B, type Config as C, FileManager as F, type GetPluginFactoryOptions as G, type InputPath as I, type Output as O, type PluginContext as P, type ResolvePathParams as R, type UserConfig as U, PluginManager as a, type PluginFactoryOptions as b, type UserPluginWithLifeCycle as c, type FileMetaBase as d, type InputData as e, type PluginKey as f, getSource as g, type UserPlugin as h, type Plugin as i, type PluginWithLifeCycle as j, type PluginLifecycle as k, type PluginLifecycleHooks as l, type PluginParameter as m, type ResolveNameParams as n, type Group as o };
|