@kubb/core 3.0.0-alpha.3 → 3.0.0-alpha.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -4
- package/dist/{FileManager-BW--rO8q.d.ts → FileManager-Dnafk2I5.d.ts} +146 -92
- package/dist/{FileManager-Bw-FNS3q.d.cts → FileManager-U5yCmg00.d.cts} +146 -92
- package/dist/chunk-2EU7DMPM.js +96 -0
- package/dist/chunk-2EU7DMPM.js.map +1 -0
- package/dist/{chunk-34BPAXR2.cjs → chunk-2UQARE2O.cjs} +54 -37
- package/dist/chunk-2UQARE2O.cjs.map +1 -0
- package/dist/chunk-4X5FFJPJ.js +8 -13
- package/dist/chunk-4X5FFJPJ.js.map +1 -1
- package/dist/{chunk-3OXCZ5DJ.js → chunk-E6CN2CZC.js} +63 -54
- package/dist/chunk-E6CN2CZC.js.map +1 -0
- package/dist/{chunk-25NKJ3DV.js → chunk-HBQM723K.js} +13 -27
- package/dist/chunk-HBQM723K.js.map +1 -0
- package/dist/{chunk-LM2YQC3T.cjs → chunk-LLKRRIBF.cjs} +81 -51
- package/dist/chunk-LLKRRIBF.cjs.map +1 -0
- package/dist/chunk-MD2LDZ3Z.js +889 -0
- package/dist/chunk-MD2LDZ3Z.js.map +1 -0
- package/dist/chunk-OX2X7B4Z.cjs +101 -0
- package/dist/chunk-OX2X7B4Z.cjs.map +1 -0
- package/dist/{chunk-67C6RBGQ.cjs → chunk-RIW2LFFQ.cjs} +28 -29
- package/dist/chunk-RIW2LFFQ.cjs.map +1 -0
- package/dist/chunk-SX5FHSVT.cjs +1532 -0
- package/dist/chunk-SX5FHSVT.cjs.map +1 -0
- package/dist/chunk-VBGWLAET.cjs +42 -0
- package/dist/chunk-VBGWLAET.cjs.map +1 -0
- package/dist/index.cjs +553 -619
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -22
- package/dist/index.d.ts +7 -22
- package/dist/index.js +444 -525
- package/dist/index.js.map +1 -1
- package/dist/{logger-DChjnJMn.d.cts → logger-DvbHXjIO.d.cts} +29 -19
- package/dist/{logger-DChjnJMn.d.ts → logger-DvbHXjIO.d.ts} +29 -19
- package/dist/logger.cjs +25 -15
- package/dist/logger.cjs.map +1 -1
- package/dist/logger.d.cts +1 -2
- package/dist/logger.d.ts +1 -2
- package/dist/logger.js +3 -15
- package/dist/logger.js.map +1 -1
- package/dist/mocks.cjs +42 -31
- package/dist/mocks.cjs.map +1 -1
- package/dist/mocks.d.cts +7 -9
- package/dist/mocks.d.ts +7 -9
- package/dist/mocks.js +35 -33
- package/dist/mocks.js.map +1 -1
- package/dist/{prompt-6FWP747F.cjs → prompt-2PN2F25D.cjs} +89 -89
- package/dist/prompt-2PN2F25D.cjs.map +1 -0
- package/dist/{prompt-HK3MWREM.js → prompt-WQQUN22Z.js} +9 -15
- package/dist/prompt-WQQUN22Z.js.map +1 -0
- package/dist/transformers.cjs +216 -49
- package/dist/transformers.cjs.map +1 -1
- package/dist/transformers.d.cts +2 -4
- package/dist/transformers.d.ts +2 -4
- package/dist/transformers.js +149 -35
- package/dist/transformers.js.map +1 -1
- package/dist/utils.cjs +65 -26
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +29 -3
- package/dist/utils.d.ts +29 -3
- package/dist/utils.js +3 -26
- package/dist/utils.js.map +1 -1
- package/package.json +11 -14
- package/src/BarrelManager.ts +95 -109
- package/src/{Generator.ts → BaseGenerator.ts} +1 -1
- package/src/FileManager.ts +199 -304
- package/src/PackageManager.ts +1 -1
- package/src/PluginManager.ts +152 -93
- package/src/PromiseManager.ts +1 -1
- package/src/__snapshots__/barrel.json +73 -0
- package/src/__snapshots__/grouped.json +120 -0
- package/src/__snapshots__/ordered.json +68 -0
- package/src/build.ts +86 -131
- package/src/config.ts +2 -4
- package/src/errors.ts +0 -11
- package/src/index.ts +2 -3
- package/src/logger.ts +76 -34
- package/src/plugin.ts +2 -5
- package/src/transformers/escape.ts +0 -10
- package/src/transformers/index.ts +2 -3
- package/src/transformers/stringify.ts +1 -1
- package/src/transformers/trim.ts +0 -4
- package/src/types.ts +77 -22
- package/src/utils/TreeNode.ts +132 -50
- package/src/utils/executeStrategies.ts +3 -3
- package/src/utils/index.ts +2 -1
- package/src/utils/parser.ts +156 -0
- package/dist/chunk-25NKJ3DV.js.map +0 -1
- package/dist/chunk-34BPAXR2.cjs.map +0 -1
- package/dist/chunk-3OXCZ5DJ.js.map +0 -1
- package/dist/chunk-5JZNFPUP.js +0 -309
- package/dist/chunk-5JZNFPUP.js.map +0 -1
- package/dist/chunk-67C6RBGQ.cjs.map +0 -1
- package/dist/chunk-ADC5UNZ5.cjs +0 -1227
- package/dist/chunk-ADC5UNZ5.cjs.map +0 -1
- package/dist/chunk-HMLY7DHA.js +0 -16
- package/dist/chunk-HMLY7DHA.js.map +0 -1
- package/dist/chunk-JKZG2IJR.js +0 -283
- package/dist/chunk-JKZG2IJR.js.map +0 -1
- package/dist/chunk-LM2YQC3T.cjs.map +0 -1
- package/dist/chunk-PZT4CTBV.cjs +0 -299
- package/dist/chunk-PZT4CTBV.cjs.map +0 -1
- package/dist/chunk-SA2GZKXS.js +0 -596
- package/dist/chunk-SA2GZKXS.js.map +0 -1
- package/dist/chunk-XCPFG6DO.cjs +0 -66
- package/dist/chunk-XCPFG6DO.cjs.map +0 -1
- package/dist/chunk-YTSNYMHW.cjs +0 -320
- package/dist/chunk-YTSNYMHW.cjs.map +0 -1
- package/dist/prompt-6FWP747F.cjs.map +0 -1
- package/dist/prompt-HK3MWREM.js.map +0 -1
- package/schema.json +0 -86
- package/src/utils/cache.ts +0 -35
- package/src/utils/getParser.ts +0 -17
package/README.md
CHANGED
|
@@ -13,10 +13,6 @@
|
|
|
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
17
|
<a href="https://codesandbox.io/s/github/kubb-labs/kubb/tree/alpha/examples/typescript" target="_blank">View Demo</a>
|
|
22
18
|
<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
|
|
@@ -1,19 +1,8 @@
|
|
|
1
|
-
import PQueue from 'p-queue';
|
|
2
1
|
import { write, read } from '@kubb/fs';
|
|
3
2
|
import * as KubbFile from '@kubb/fs/types';
|
|
4
|
-
import {
|
|
3
|
+
import { ResolvedFile } from '@kubb/fs/types';
|
|
5
4
|
import { PossiblePromise, GreaterThan } from '@kubb/types';
|
|
6
|
-
import {
|
|
7
|
-
import { E as EventEmitter, L as Logger } from './logger-DChjnJMn.js';
|
|
8
|
-
|
|
9
|
-
type BarrelManagerOptions = {
|
|
10
|
-
treeNode?: DirectoryTreeOptions;
|
|
11
|
-
isTypeOnly?: boolean;
|
|
12
|
-
/**
|
|
13
|
-
* Add .ts or .js
|
|
14
|
-
*/
|
|
15
|
-
extName?: KubbFile.Extname;
|
|
16
|
-
};
|
|
5
|
+
import { E as EventEmitter, L as Logger } from './logger-DvbHXjIO.js';
|
|
17
6
|
|
|
18
7
|
type RequiredPluginLifecycle = Required<PluginLifecycle>;
|
|
19
8
|
/**
|
|
@@ -23,6 +12,7 @@ type RequiredPluginLifecycle = Required<PluginLifecycle>;
|
|
|
23
12
|
type Argument0<H extends keyof PluginLifecycle> = Parameters<RequiredPluginLifecycle[H]>[0];
|
|
24
13
|
type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookReduceArg0' | 'hookSeq';
|
|
25
14
|
type Executer<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
15
|
+
message: string;
|
|
26
16
|
strategy: Strategy;
|
|
27
17
|
hookName: H;
|
|
28
18
|
plugin: Plugin;
|
|
@@ -34,36 +24,32 @@ type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseRe
|
|
|
34
24
|
result: Result;
|
|
35
25
|
plugin: Plugin;
|
|
36
26
|
};
|
|
37
|
-
type Options
|
|
27
|
+
type Options = {
|
|
38
28
|
logger: Logger;
|
|
39
|
-
/**
|
|
40
|
-
* Task for the FileManager
|
|
41
|
-
*/
|
|
42
|
-
task: (file: ResolvedFile) => Promise<ResolvedFile>;
|
|
43
29
|
};
|
|
44
30
|
type Events = {
|
|
45
|
-
|
|
31
|
+
executing: [executer: Executer];
|
|
46
32
|
executed: [executer: Executer];
|
|
47
33
|
error: [error: Error];
|
|
48
34
|
};
|
|
49
35
|
type GetFileProps<TOptions = object> = {
|
|
50
36
|
name: string;
|
|
51
37
|
mode?: KubbFile.Mode;
|
|
52
|
-
|
|
38
|
+
extname: KubbFile.Extname;
|
|
53
39
|
pluginKey: Plugin['key'];
|
|
54
40
|
options?: TOptions;
|
|
55
41
|
};
|
|
56
42
|
declare class PluginManager {
|
|
57
43
|
#private;
|
|
58
|
-
readonly plugins:
|
|
44
|
+
readonly plugins: Set<Plugin<PluginFactoryOptions<string, object, object, any, object>>>;
|
|
59
45
|
readonly fileManager: FileManager;
|
|
60
46
|
readonly events: EventEmitter<Events>;
|
|
61
47
|
readonly config: Config;
|
|
62
48
|
readonly executed: Array<Executer>;
|
|
63
49
|
readonly logger: Logger;
|
|
64
|
-
readonly
|
|
65
|
-
constructor(config: Config, options: Options
|
|
66
|
-
getFile<TOptions = object>({ name, mode,
|
|
50
|
+
readonly options: Options;
|
|
51
|
+
constructor(config: Config, options: Options);
|
|
52
|
+
getFile<TOptions = object>({ name, mode, extname, pluginKey, options }: GetFileProps<TOptions>): KubbFile.File<{
|
|
67
53
|
pluginKey: Plugin['key'];
|
|
68
54
|
}>;
|
|
69
55
|
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
|
|
@@ -75,69 +61,69 @@ declare class PluginManager {
|
|
|
75
61
|
/**
|
|
76
62
|
* Run a specific hookName for plugin x.
|
|
77
63
|
*/
|
|
78
|
-
hookForPlugin<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, }: {
|
|
64
|
+
hookForPlugin<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, message, }: {
|
|
79
65
|
pluginKey: Plugin['key'];
|
|
80
66
|
hookName: H;
|
|
81
67
|
parameters: PluginParameter<H>;
|
|
82
|
-
|
|
68
|
+
message: string;
|
|
69
|
+
}): Promise<Array<ReturnType<ParseResult<H>> | null>>;
|
|
83
70
|
/**
|
|
84
71
|
* Run a specific hookName for plugin x.
|
|
85
72
|
*/
|
|
86
|
-
hookForPluginSync<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, }: {
|
|
73
|
+
hookForPluginSync<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, message, }: {
|
|
87
74
|
pluginKey: Plugin['key'];
|
|
88
75
|
hookName: H;
|
|
89
76
|
parameters: PluginParameter<H>;
|
|
77
|
+
message: string;
|
|
90
78
|
}): Array<ReturnType<ParseResult<H>>> | null;
|
|
91
79
|
/**
|
|
92
80
|
* First non-null result stops and will return it's value.
|
|
93
81
|
*/
|
|
94
|
-
hookFirst<H extends PluginLifecycleHooks>({ hookName, parameters, skipped, }: {
|
|
82
|
+
hookFirst<H extends PluginLifecycleHooks>({ hookName, parameters, skipped, message, }: {
|
|
95
83
|
hookName: H;
|
|
96
84
|
parameters: PluginParameter<H>;
|
|
97
85
|
skipped?: ReadonlySet<Plugin> | null;
|
|
86
|
+
message: string;
|
|
98
87
|
}): Promise<SafeParseResult<H>>;
|
|
99
88
|
/**
|
|
100
89
|
* First non-null result stops and will return it's value.
|
|
101
90
|
*/
|
|
102
|
-
hookFirstSync<H extends PluginLifecycleHooks>({ hookName, parameters, skipped, }: {
|
|
91
|
+
hookFirstSync<H extends PluginLifecycleHooks>({ hookName, parameters, skipped, message, }: {
|
|
103
92
|
hookName: H;
|
|
104
93
|
parameters: PluginParameter<H>;
|
|
105
94
|
skipped?: ReadonlySet<Plugin> | null;
|
|
95
|
+
message: string;
|
|
106
96
|
}): SafeParseResult<H>;
|
|
107
97
|
/**
|
|
108
98
|
* Run all plugins in parallel(order will be based on `this.plugin` and if `pre` or `post` is set).
|
|
109
99
|
*/
|
|
110
|
-
hookParallel<H extends PluginLifecycleHooks, TOuput = void>({ hookName, parameters, }: {
|
|
100
|
+
hookParallel<H extends PluginLifecycleHooks, TOuput = void>({ hookName, parameters, message, }: {
|
|
111
101
|
hookName: H;
|
|
112
102
|
parameters?: Parameters<RequiredPluginLifecycle[H]> | undefined;
|
|
103
|
+
message: string;
|
|
113
104
|
}): Promise<Awaited<TOuput>[]>;
|
|
114
105
|
/**
|
|
115
106
|
* 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.
|
|
116
107
|
*/
|
|
117
|
-
hookReduceArg0<H extends PluginLifecycleHooks>({ hookName, parameters, reduce, }: {
|
|
108
|
+
hookReduceArg0<H extends PluginLifecycleHooks>({ hookName, parameters, reduce, message, }: {
|
|
118
109
|
hookName: H;
|
|
119
110
|
parameters: PluginParameter<H>;
|
|
120
111
|
reduce: (reduction: Argument0<H>, result: ReturnType<ParseResult<H>>, plugin: Plugin) => PossiblePromise<Argument0<H> | null>;
|
|
112
|
+
message: string;
|
|
121
113
|
}): Promise<Argument0<H>>;
|
|
122
114
|
/**
|
|
123
115
|
* Chains plugins
|
|
124
116
|
*/
|
|
125
|
-
hookSeq<H extends PluginLifecycleHooks>({ hookName, parameters }: {
|
|
117
|
+
hookSeq<H extends PluginLifecycleHooks>({ hookName, parameters, message, }: {
|
|
126
118
|
hookName: H;
|
|
127
119
|
parameters?: PluginParameter<H>;
|
|
120
|
+
message: string;
|
|
128
121
|
}): Promise<void>;
|
|
129
122
|
getPluginsByKey(hookName: keyof PluginLifecycle, pluginKey: Plugin['key']): Plugin[];
|
|
130
123
|
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;
|
|
131
124
|
static get hooks(): readonly ["buildStart", "resolvePath", "resolveName", "buildEnd"];
|
|
132
125
|
}
|
|
133
126
|
|
|
134
|
-
interface Cache<TStore extends object = object> {
|
|
135
|
-
delete(id: keyof TStore): boolean;
|
|
136
|
-
get(id: keyof TStore): TStore[keyof TStore] | null;
|
|
137
|
-
has(id: keyof TStore): boolean;
|
|
138
|
-
set(id: keyof TStore, value: unknown): void;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
127
|
/**
|
|
142
128
|
* Config used in `kubb.config.js`
|
|
143
129
|
*
|
|
@@ -160,17 +146,20 @@ type UserConfig = Omit<Config, 'root' | 'plugins'> & {
|
|
|
160
146
|
};
|
|
161
147
|
type InputPath = {
|
|
162
148
|
/**
|
|
163
|
-
*
|
|
149
|
+
* Define your Swagger/OpenAPI file. This can be an absolute path or a path relative to the `root`.
|
|
164
150
|
*/
|
|
165
151
|
path: string;
|
|
166
152
|
};
|
|
167
153
|
type InputData = {
|
|
168
154
|
/**
|
|
169
|
-
* `string` or `object` containing
|
|
155
|
+
* `string` or `object` containing your Swagger/OpenAPI data.
|
|
170
156
|
*/
|
|
171
157
|
data: string | unknown;
|
|
172
158
|
};
|
|
173
159
|
type Input = InputPath | InputData;
|
|
160
|
+
type OutContext = {};
|
|
161
|
+
type OutExtension = (context: OutContext) => Record<KubbFile.Extname, KubbFile.Extname>;
|
|
162
|
+
type BarrelType = 'all' | 'named';
|
|
174
163
|
/**
|
|
175
164
|
* @private
|
|
176
165
|
*/
|
|
@@ -180,33 +169,43 @@ type Config<TInput = Input> = {
|
|
|
180
169
|
*/
|
|
181
170
|
name?: string;
|
|
182
171
|
/**
|
|
183
|
-
* Project root directory.
|
|
184
|
-
* the location of the config file itself.
|
|
172
|
+
* Project root directory. This can be an absolute path or a path relative to the location of your `kubb.config.ts` file.
|
|
185
173
|
* @default process.cwd()
|
|
186
174
|
*/
|
|
187
175
|
root: string;
|
|
176
|
+
/**
|
|
177
|
+
* You can use `input.path` or `input.data` depending on the needs you have.
|
|
178
|
+
*/
|
|
188
179
|
input: TInput;
|
|
189
180
|
output: {
|
|
190
181
|
/**
|
|
191
|
-
*
|
|
192
|
-
* This can be an absolute path, or a path relative based of the defined `root` option.
|
|
182
|
+
* The path where all generated files will be exported. This can be an absolute path or a path relative to the specified root option.
|
|
193
183
|
*/
|
|
194
184
|
path: string;
|
|
195
185
|
/**
|
|
196
|
-
* Clean output directory before each build.
|
|
186
|
+
* Clean the output directory before each build.
|
|
197
187
|
*/
|
|
198
188
|
clean?: boolean;
|
|
199
189
|
/**
|
|
200
|
-
*
|
|
201
|
-
* This is being used for the playground.
|
|
190
|
+
* Save files to the file system.
|
|
202
191
|
* @default true
|
|
203
192
|
*/
|
|
204
193
|
write?: boolean;
|
|
194
|
+
/**
|
|
195
|
+
* Override the extension to the generated imports and exports, default the plugin will add an extension
|
|
196
|
+
* @default `() => ({ '.ts': '.ts'})`
|
|
197
|
+
*/
|
|
198
|
+
extension?: OutExtension;
|
|
199
|
+
/**
|
|
200
|
+
* Define what needs to exported, here you can also disable the export of barrel files.
|
|
201
|
+
* @default `'named'`
|
|
202
|
+
*/
|
|
203
|
+
barrelType?: BarrelType | false;
|
|
205
204
|
};
|
|
206
205
|
/**
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
206
|
+
* An array of Kubb plugins that will be used in the generation.
|
|
207
|
+
* Each plugin may include additional configurable options(defined in the plugin itself).
|
|
208
|
+
* If a plugin depends on another plugin, an error will be returned if the required dependency is missing. See pre for more details.
|
|
210
209
|
*/
|
|
211
210
|
plugins?: Array<Plugin>;
|
|
212
211
|
/**
|
|
@@ -266,7 +265,7 @@ type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
|
|
|
266
265
|
options: TOptions['resolvedOptions'];
|
|
267
266
|
/**
|
|
268
267
|
* 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.
|
|
269
|
-
* Can be used to validate
|
|
268
|
+
* Can be used to validate dependent plugins.
|
|
270
269
|
*/
|
|
271
270
|
pre?: Array<string>;
|
|
272
271
|
/**
|
|
@@ -293,7 +292,7 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
|
293
292
|
key: TOptions['key'];
|
|
294
293
|
/**
|
|
295
294
|
* 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.
|
|
296
|
-
* Can be used to validate
|
|
295
|
+
* Can be used to validate dependent plugins.
|
|
297
296
|
*/
|
|
298
297
|
pre?: Array<string>;
|
|
299
298
|
/**
|
|
@@ -322,7 +321,7 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
|
|
|
322
321
|
* @type hookFirst
|
|
323
322
|
* @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
|
|
324
323
|
*/
|
|
325
|
-
resolvePath?: (this: PluginContext<TOptions>, baseName:
|
|
324
|
+
resolvePath?: (this: PluginContext<TOptions>, baseName: KubbFile.BaseName, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.OptionalPath;
|
|
326
325
|
/**
|
|
327
326
|
* Resolve to a name based on a string.
|
|
328
327
|
* Useful when converting to PascalCase or camelCase.
|
|
@@ -338,10 +337,9 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
|
|
|
338
337
|
};
|
|
339
338
|
type PluginLifecycleHooks = keyof PluginLifecycle;
|
|
340
339
|
type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
|
|
341
|
-
type PluginCache = Record<string, [number, unknown]>;
|
|
342
340
|
type ResolvePathParams<TOptions = object> = {
|
|
343
341
|
pluginKey?: Plugin['key'];
|
|
344
|
-
baseName:
|
|
342
|
+
baseName: KubbFile.BaseName;
|
|
345
343
|
mode?: KubbFile.Mode;
|
|
346
344
|
/**
|
|
347
345
|
* Options to be passed to 'resolvePath' 3th parameter
|
|
@@ -356,14 +354,13 @@ type ResolveNameParams = {
|
|
|
356
354
|
* `function` can be used used to customize the exported functions(use of camelCase)
|
|
357
355
|
* `type` is a special type for TypeScript(use of PascalCase)
|
|
358
356
|
*/
|
|
359
|
-
type?: 'file' | 'function' | 'type';
|
|
357
|
+
type?: 'file' | 'function' | 'type' | 'const';
|
|
360
358
|
};
|
|
361
359
|
type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
362
360
|
config: Config;
|
|
363
|
-
cache: Cache<PluginCache>;
|
|
364
361
|
fileManager: FileManager;
|
|
365
362
|
pluginManager: PluginManager;
|
|
366
|
-
addFile: (...file: Array<KubbFile.File>) => Promise<Array<KubbFile.
|
|
363
|
+
addFile: (...file: Array<KubbFile.File>) => Promise<Array<KubbFile.ResolvedFile>>;
|
|
367
364
|
resolvePath: (params: ResolvePathParams<TOptions['resolvePathOptions']>) => KubbFile.OptionalPath;
|
|
368
365
|
resolveName: (params: ResolveNameParams) => string;
|
|
369
366
|
logger: Logger;
|
|
@@ -376,62 +373,119 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
376
373
|
*/
|
|
377
374
|
plugin: Plugin<TOptions>;
|
|
378
375
|
};
|
|
379
|
-
|
|
380
|
-
|
|
376
|
+
type Output = {
|
|
377
|
+
/**
|
|
378
|
+
* Output to save the generated files.
|
|
379
|
+
*/
|
|
380
|
+
path: string;
|
|
381
|
+
/**
|
|
382
|
+
* Define what needs to exported, here you can also disable the export of barrel files.
|
|
383
|
+
* @default `'named'`
|
|
384
|
+
*/
|
|
385
|
+
barrelType?: BarrelType | false;
|
|
381
386
|
/**
|
|
382
|
-
*
|
|
387
|
+
* Add a banner text in the beginning of every file
|
|
383
388
|
*/
|
|
384
|
-
|
|
389
|
+
banner?: string;
|
|
385
390
|
/**
|
|
386
|
-
*
|
|
387
|
-
* @link https://nodejs.org/api/path.html#pathformatpathobject
|
|
391
|
+
* Add a footer text in the beginning of every file
|
|
388
392
|
*/
|
|
393
|
+
footer?: string;
|
|
394
|
+
};
|
|
395
|
+
type GroupContext = {
|
|
396
|
+
group: string;
|
|
397
|
+
};
|
|
398
|
+
type Group = {
|
|
399
|
+
/**
|
|
400
|
+
* Tag will group based on the operation tag inside the Swagger file
|
|
401
|
+
*/
|
|
402
|
+
type: 'tag';
|
|
403
|
+
/**
|
|
404
|
+
* Relative path to save the grouped clients.
|
|
405
|
+
*
|
|
406
|
+
* @example `${output}/{{tag}}Controller` => `clients/PetController`
|
|
407
|
+
* @default `({ group }) => `${group}Controller``
|
|
408
|
+
*/
|
|
409
|
+
name?: (context: GroupContext) => string;
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
type BarrelData = {
|
|
413
|
+
file?: KubbFile.File;
|
|
414
|
+
/**
|
|
415
|
+
* @deprecated use file instead
|
|
416
|
+
*/
|
|
417
|
+
type: KubbFile.Mode;
|
|
418
|
+
path: string;
|
|
389
419
|
name: string;
|
|
390
420
|
};
|
|
421
|
+
declare class TreeNode {
|
|
422
|
+
#private;
|
|
423
|
+
data: BarrelData;
|
|
424
|
+
parent?: TreeNode;
|
|
425
|
+
children: Array<TreeNode>;
|
|
426
|
+
constructor(data: BarrelData, parent?: TreeNode);
|
|
427
|
+
addChild(data: BarrelData): TreeNode;
|
|
428
|
+
get root(): TreeNode;
|
|
429
|
+
get leaves(): Array<TreeNode>;
|
|
430
|
+
forEach(callback: (treeNode: TreeNode) => void): this;
|
|
431
|
+
findDeep(predicate?: (value: TreeNode, index: number, obj: TreeNode[]) => boolean): TreeNode | undefined;
|
|
432
|
+
forEachDeep(callback: (treeNode: TreeNode) => void): void;
|
|
433
|
+
filterDeep(callback: (treeNode: TreeNode) => boolean): Array<TreeNode>;
|
|
434
|
+
mapDeep<T>(callback: (treeNode: TreeNode) => T): Array<T>;
|
|
435
|
+
static build(files: KubbFile.File[], root?: string): TreeNode | null;
|
|
436
|
+
}
|
|
437
|
+
type DirectoryTree = {
|
|
438
|
+
name: string;
|
|
439
|
+
path: string;
|
|
440
|
+
file?: KubbFile.File;
|
|
441
|
+
children: Array<DirectoryTree>;
|
|
442
|
+
};
|
|
443
|
+
|
|
391
444
|
type FileMetaBase = {
|
|
392
445
|
pluginKey?: Plugin['key'];
|
|
393
446
|
};
|
|
394
|
-
type
|
|
395
|
-
type AddResult<T extends Array<FileWithMeta>> = Promise<Awaited<GreaterThan<T['length'], 1> extends true ? Promise<ResolvedFile[]> : Promise<ResolvedFile>>>;
|
|
447
|
+
type AddResult<T extends Array<KubbFile.File>> = Promise<Awaited<GreaterThan<T['length'], 1> extends true ? Promise<ResolvedFile[]> : Promise<ResolvedFile>>>;
|
|
396
448
|
type AddIndexesProps = {
|
|
449
|
+
type: BarrelType | false | undefined;
|
|
397
450
|
/**
|
|
398
451
|
* Root based on root and output.path specified in the config
|
|
399
452
|
*/
|
|
400
453
|
root: string;
|
|
454
|
+
files: KubbFile.File[];
|
|
401
455
|
/**
|
|
402
456
|
* Output for plugin
|
|
403
457
|
*/
|
|
404
458
|
output: {
|
|
405
459
|
path: string;
|
|
406
|
-
exportAs?: string;
|
|
407
|
-
extName?: KubbFile.Extname;
|
|
408
|
-
exportType?: 'barrel' | 'barrelNamed' | false;
|
|
409
460
|
};
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
};
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
task?: (file: ResolvedFile) => Promise<ResolvedFile>;
|
|
461
|
+
group?: {
|
|
462
|
+
output: string;
|
|
463
|
+
exportAs: string;
|
|
464
|
+
};
|
|
465
|
+
logger?: Logger;
|
|
466
|
+
meta?: FileMetaBase;
|
|
417
467
|
};
|
|
418
468
|
declare class FileManager {
|
|
419
469
|
#private;
|
|
420
|
-
constructor(
|
|
421
|
-
get files(): Array<
|
|
422
|
-
get
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
470
|
+
constructor();
|
|
471
|
+
get files(): Array<KubbFile.ResolvedFile>;
|
|
472
|
+
get orderedFiles(): Array<KubbFile.ResolvedFile>;
|
|
473
|
+
get groupedFiles(): DirectoryTree | null;
|
|
474
|
+
get treeNode(): TreeNode | null;
|
|
475
|
+
add<T extends Array<KubbFile.File> = Array<KubbFile.File>>(...files: T): AddResult<T>;
|
|
476
|
+
clear(): void;
|
|
477
|
+
getCacheById(id: string): KubbFile.File | undefined;
|
|
478
|
+
getByPath(path: KubbFile.Path): KubbFile.ResolvedFile | undefined;
|
|
479
|
+
deleteByPath(path: KubbFile.Path): void;
|
|
480
|
+
getBarrelFiles({ type, files, meta, root, output, logger }: AddIndexesProps): Promise<KubbFile.File[]>;
|
|
481
|
+
write(...params: Parameters<typeof write>): ReturnType<typeof write>;
|
|
482
|
+
read(...params: Parameters<typeof read>): ReturnType<typeof read>;
|
|
432
483
|
static getMode(path: string | undefined | null): KubbFile.Mode;
|
|
433
|
-
static get extensions(): Array<KubbFile.Extname>;
|
|
434
|
-
static isJavascript(baseName: string): boolean;
|
|
435
484
|
}
|
|
485
|
+
type GetSourceOptions = {
|
|
486
|
+
extname?: KubbFile.Extname;
|
|
487
|
+
logger?: Logger;
|
|
488
|
+
};
|
|
489
|
+
declare function getSource<TMeta extends FileMetaBase = FileMetaBase>(file: ResolvedFile<TMeta>, { logger, extname }?: GetSourceOptions): Promise<string>;
|
|
436
490
|
|
|
437
|
-
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,
|
|
491
|
+
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 };
|