@kubb/plugin-redoc 4.3.1 → 4.4.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/dist/chunk-BEV-X5tz.js +27 -0
- package/dist/index.cjs +12 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +48 -164
- package/dist/index.d.ts +48 -164
- package/dist/index.js +12 -3
- package/dist/index.js.map +1 -1
- package/package.json +15 -10
- package/src/plugin.ts +16 -6
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
//#region rolldown:runtime
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
+
key = keys[i];
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
21
|
+
value: mod,
|
|
22
|
+
enumerable: true
|
|
23
|
+
}) : target, mod));
|
|
24
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { };
|
package/dist/index.cjs
CHANGED
|
@@ -27,8 +27,6 @@ let __kubb_core = require("@kubb/core");
|
|
|
27
27
|
__kubb_core = __toESM(__kubb_core);
|
|
28
28
|
let __kubb_plugin_oas = require("@kubb/plugin-oas");
|
|
29
29
|
__kubb_plugin_oas = __toESM(__kubb_plugin_oas);
|
|
30
|
-
let __kubb_core_fs = require("@kubb/core/fs");
|
|
31
|
-
__kubb_core_fs = __toESM(__kubb_core_fs);
|
|
32
30
|
let node_fs = require("node:fs");
|
|
33
31
|
node_fs = __toESM(node_fs);
|
|
34
32
|
let handlebars = require("handlebars");
|
|
@@ -56,6 +54,9 @@ async function getPageHTML(api, { title, disableGoogleFont, templateOptions } =
|
|
|
56
54
|
|
|
57
55
|
//#endregion
|
|
58
56
|
//#region src/plugin.ts
|
|
57
|
+
function trimExtName(text) {
|
|
58
|
+
return text.replace(/\.[^/.]+$/, "");
|
|
59
|
+
}
|
|
59
60
|
const pluginRedocName = "plugin-redoc";
|
|
60
61
|
const pluginRedoc = (0, __kubb_core.createPlugin)((options) => {
|
|
61
62
|
const { output = { path: "docs.html" } } = options;
|
|
@@ -63,7 +64,7 @@ const pluginRedoc = (0, __kubb_core.createPlugin)((options) => {
|
|
|
63
64
|
name: pluginRedocName,
|
|
64
65
|
options: {
|
|
65
66
|
output,
|
|
66
|
-
name:
|
|
67
|
+
name: trimExtName(output.path)
|
|
67
68
|
},
|
|
68
69
|
pre: [__kubb_plugin_oas.pluginOasName],
|
|
69
70
|
async buildStart() {
|
|
@@ -72,7 +73,14 @@ const pluginRedoc = (0, __kubb_core.createPlugin)((options) => {
|
|
|
72
73
|
await oas.dereference();
|
|
73
74
|
const root = node_path.default.resolve(this.config.root, this.config.output.path);
|
|
74
75
|
const pageHTML = await getPageHTML(oas.api);
|
|
75
|
-
await
|
|
76
|
+
await this.addFile({
|
|
77
|
+
baseName: "docs.html",
|
|
78
|
+
path: node_path.default.resolve(root, output.path || "./docs.html"),
|
|
79
|
+
sources: [{
|
|
80
|
+
name: "docs.html",
|
|
81
|
+
value: pageHTML
|
|
82
|
+
}]
|
|
83
|
+
});
|
|
76
84
|
}
|
|
77
85
|
};
|
|
78
86
|
});
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["path","pkg","fs","pluginOasName","PluginManager","path"],"sources":["../src/redoc.tsx","../src/plugin.ts"],"sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\nimport type { OasTypes } from '@kubb/oas'\nimport pkg from 'handlebars'\n\ntype BuildDocsOptions = {\n title?: string\n disableGoogleFont?: boolean\n templateOptions?: any\n}\n\nexport async function getPageHTML(api: OasTypes.OASDocument, { title, disableGoogleFont, templateOptions }: BuildDocsOptions = {}) {\n const templateFileName = path.join(__dirname, '../static/redoc.hbs')\n const template = pkg.compile(fs.readFileSync(templateFileName).toString())\n return template({\n title: title || api.info.title || 'ReDoc documentation',\n redocHTML: `\n <script src=\"https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js\"> </script>\n <div id=\"redoc-container\"></div>\n <script>\n const data = ${JSON.stringify(api, null, 2)};\n Redoc.init(data, {\n \"expandResponses\": \"200,400\"\n }, document.getElementById('redoc-container'))\n </script>\n `,\n disableGoogleFont,\n templateOptions,\n })\n}\n","import path from 'node:path'\
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["path","pkg","fs","pluginOasName","PluginManager","path"],"sources":["../src/redoc.tsx","../src/plugin.ts"],"sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\nimport type { OasTypes } from '@kubb/oas'\nimport pkg from 'handlebars'\n\ntype BuildDocsOptions = {\n title?: string\n disableGoogleFont?: boolean\n templateOptions?: any\n}\n\nexport async function getPageHTML(api: OasTypes.OASDocument, { title, disableGoogleFont, templateOptions }: BuildDocsOptions = {}) {\n const templateFileName = path.join(__dirname, '../static/redoc.hbs')\n const template = pkg.compile(fs.readFileSync(templateFileName).toString())\n return template({\n title: title || api.info.title || 'ReDoc documentation',\n redocHTML: `\n <script src=\"https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js\"> </script>\n <div id=\"redoc-container\"></div>\n <script>\n const data = ${JSON.stringify(api, null, 2)};\n Redoc.init(data, {\n \"expandResponses\": \"200,400\"\n }, document.getElementById('redoc-container'))\n </script>\n `,\n disableGoogleFont,\n templateOptions,\n })\n}\n","import path from 'node:path'\nimport type { Plugin } from '@kubb/core'\nimport { createPlugin, PluginManager } from '@kubb/core'\nimport type { PluginOas } from '@kubb/plugin-oas'\nimport { pluginOasName } from '@kubb/plugin-oas'\nimport { getPageHTML } from './redoc.tsx'\nimport type { PluginRedoc } from './types.ts'\n\nfunction trimExtName(text: string): string {\n return text.replace(/\\.[^/.]+$/, '')\n}\n\nexport const pluginRedocName = 'plugin-redoc' satisfies PluginRedoc['name']\n\nexport const pluginRedoc = createPlugin<PluginRedoc>((options) => {\n const { output = { path: 'docs.html' } } = options\n\n return {\n name: pluginRedocName,\n options: {\n output,\n name: trimExtName(output.path),\n },\n pre: [pluginOasName],\n async buildStart() {\n const [swaggerPlugin]: [Plugin<PluginOas>] = PluginManager.getDependedPlugins<PluginOas>(this.plugins, [pluginOasName])\n const oas = await swaggerPlugin.context.getOas()\n\n await oas.dereference()\n\n const root = path.resolve(this.config.root, this.config.output.path)\n const pageHTML = await getPageHTML(oas.api)\n\n await this.addFile({\n baseName: 'docs.html',\n path: path.resolve(root, output.path || './docs.html'),\n sources: [\n {\n name: 'docs.html',\n value: pageHTML,\n },\n ],\n })\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,eAAsB,YAAY,KAA2B,EAAE,OAAO,mBAAmB,oBAAsC,EAAE,EAAE;CACjI,MAAM,mBAAmBA,kBAAK,KAAK,WAAW,sBAAsB;AAEpE,QADiBC,mBAAI,QAAQC,gBAAG,aAAa,iBAAiB,CAAC,UAAU,CAAC,CAC1D;EACd,OAAO,SAAS,IAAI,KAAK,SAAS;EAClC,WAAW;;;;kBAIG,KAAK,UAAU,KAAK,MAAM,EAAE,CAAC;;;;;;EAM3C;EACA;EACD,CAAC;;;;;ACpBJ,SAAS,YAAY,MAAsB;AACzC,QAAO,KAAK,QAAQ,aAAa,GAAG;;AAGtC,MAAa,kBAAkB;AAE/B,MAAa,6CAAyC,YAAY;CAChE,MAAM,EAAE,SAAS,EAAE,MAAM,aAAa,KAAK;AAE3C,QAAO;EACL,MAAM;EACN,SAAS;GACP;GACA,MAAM,YAAY,OAAO,KAAK;GAC/B;EACD,KAAK,CAACC,gCAAc;EACpB,MAAM,aAAa;GACjB,MAAM,CAAC,iBAAsCC,0BAAc,mBAA8B,KAAK,SAAS,CAACD,gCAAc,CAAC;GACvH,MAAM,MAAM,MAAM,cAAc,QAAQ,QAAQ;AAEhD,SAAM,IAAI,aAAa;GAEvB,MAAM,OAAOE,kBAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,KAAK;GACpE,MAAM,WAAW,MAAM,YAAY,IAAI,IAAI;AAE3C,SAAM,KAAK,QAAQ;IACjB,UAAU;IACV,MAAMA,kBAAK,QAAQ,MAAM,OAAO,QAAQ,cAAc;IACtD,SAAS,CACP;KACE,MAAM;KACN,OAAO;KACR,CACF;IACF,CAAC;;EAEL;EACD"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { KubbFile } from "@kubb/fabric-core/types";
|
|
2
|
+
import { Fabric, FileManager } from "@kubb/react-fabric";
|
|
1
3
|
import { ConsolaInstance, LogLevel } from "consola";
|
|
2
|
-
import { FileManager } from "@kubb/fabric-core";
|
|
3
4
|
import * as OasTypes from "oas/types";
|
|
4
5
|
import { OASDocument, SchemaObject, User } from "oas/types";
|
|
5
6
|
import { Operation } from "oas/operation";
|
|
@@ -7,121 +8,6 @@ import { OpenAPIV3 } from "openapi-types";
|
|
|
7
8
|
import * as oas_normalize_lib_types0 from "oas-normalize/lib/types";
|
|
8
9
|
import BaseOas from "oas";
|
|
9
10
|
|
|
10
|
-
//#region ../core/src/fs/types.d.ts
|
|
11
|
-
type BasePath<T extends string = string> = `${T}/`;
|
|
12
|
-
type Import = {
|
|
13
|
-
/**
|
|
14
|
-
* Import name to be used
|
|
15
|
-
* @example ["useState"]
|
|
16
|
-
* @example "React"
|
|
17
|
-
*/
|
|
18
|
-
name: string | Array<string | {
|
|
19
|
-
propertyName: string;
|
|
20
|
-
name?: string;
|
|
21
|
-
}>;
|
|
22
|
-
/**
|
|
23
|
-
* Path for the import
|
|
24
|
-
* @example '@kubb/core'
|
|
25
|
-
*/
|
|
26
|
-
path: string;
|
|
27
|
-
/**
|
|
28
|
-
* Add `type` prefix to the import, this will result in: `import type { Type } from './path'`.
|
|
29
|
-
*/
|
|
30
|
-
isTypeOnly?: boolean;
|
|
31
|
-
isNameSpace?: boolean;
|
|
32
|
-
/**
|
|
33
|
-
* When root is set it will get the path with relative getRelativePath(root, path).
|
|
34
|
-
*/
|
|
35
|
-
root?: string;
|
|
36
|
-
};
|
|
37
|
-
type Source = {
|
|
38
|
-
name?: string;
|
|
39
|
-
value?: string;
|
|
40
|
-
isTypeOnly?: boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Has const or type 'export'
|
|
43
|
-
* @default false
|
|
44
|
-
*/
|
|
45
|
-
isExportable?: boolean;
|
|
46
|
-
/**
|
|
47
|
-
* When set, barrel generation will add this
|
|
48
|
-
* @default false
|
|
49
|
-
*/
|
|
50
|
-
isIndexable?: boolean;
|
|
51
|
-
};
|
|
52
|
-
type Export = {
|
|
53
|
-
/**
|
|
54
|
-
* Export name to be used.
|
|
55
|
-
* @example ["useState"]
|
|
56
|
-
* @example "React"
|
|
57
|
-
*/
|
|
58
|
-
name?: string | Array<string>;
|
|
59
|
-
/**
|
|
60
|
-
* Path for the import.
|
|
61
|
-
* @example '@kubb/core'
|
|
62
|
-
*/
|
|
63
|
-
path: string;
|
|
64
|
-
/**
|
|
65
|
-
* Add `type` prefix to the export, this will result in: `export type { Type } from './path'`.
|
|
66
|
-
*/
|
|
67
|
-
isTypeOnly?: boolean;
|
|
68
|
-
/**
|
|
69
|
-
* Make it possible to override the name, this will result in: `export * as aliasName from './path'`.
|
|
70
|
-
*/
|
|
71
|
-
asAlias?: boolean;
|
|
72
|
-
};
|
|
73
|
-
type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`;
|
|
74
|
-
type Mode = 'single' | 'split';
|
|
75
|
-
/**
|
|
76
|
-
* Name to be used to dynamicly create the baseName(based on input.path)
|
|
77
|
-
* Based on UNIX basename
|
|
78
|
-
* @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
|
|
79
|
-
*/
|
|
80
|
-
type BaseName = `${string}.${string}`;
|
|
81
|
-
/**
|
|
82
|
-
* Path will be full qualified path to a specified file
|
|
83
|
-
*/
|
|
84
|
-
type Path = string;
|
|
85
|
-
type AdvancedPath<T extends BaseName = BaseName> = `${BasePath}${T}`;
|
|
86
|
-
type OptionalPath = Path | undefined | null;
|
|
87
|
-
type File<TMeta extends object = object> = {
|
|
88
|
-
/**
|
|
89
|
-
* Name to be used to create the path
|
|
90
|
-
* Based on UNIX basename, `${name}.extname`
|
|
91
|
-
* @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
|
|
92
|
-
*/
|
|
93
|
-
baseName: BaseName;
|
|
94
|
-
/**
|
|
95
|
-
* Path will be full qualified path to a specified file
|
|
96
|
-
*/
|
|
97
|
-
path: AdvancedPath<BaseName> | Path;
|
|
98
|
-
sources: Array<Source>;
|
|
99
|
-
imports?: Array<Import>;
|
|
100
|
-
exports?: Array<Export>;
|
|
101
|
-
/**
|
|
102
|
-
* Use extra meta, this is getting used to generate the barrel/index files.
|
|
103
|
-
*/
|
|
104
|
-
meta?: TMeta;
|
|
105
|
-
banner?: string;
|
|
106
|
-
footer?: string;
|
|
107
|
-
};
|
|
108
|
-
type ResolvedImport = Import;
|
|
109
|
-
type ResolvedExport = Export;
|
|
110
|
-
type ResolvedFile<TMeta extends object = object> = File<TMeta> & {
|
|
111
|
-
/**
|
|
112
|
-
* @default object-hash
|
|
113
|
-
*/
|
|
114
|
-
id: string;
|
|
115
|
-
/**
|
|
116
|
-
* Contains the first part of the baseName, generated based on baseName
|
|
117
|
-
* @link https://nodejs.org/api/path.html#pathformatpathobject
|
|
118
|
-
*/
|
|
119
|
-
name: string;
|
|
120
|
-
extname: Extname;
|
|
121
|
-
imports: Array<ResolvedImport>;
|
|
122
|
-
exports: Array<ResolvedExport>;
|
|
123
|
-
};
|
|
124
|
-
//#endregion
|
|
125
11
|
//#region ../core/src/utils/EventEmitter.d.ts
|
|
126
12
|
declare class EventEmitter<TEvents extends Record<string, any>> {
|
|
127
13
|
#private;
|
|
@@ -245,7 +131,7 @@ type Config<TInput = Input> = {
|
|
|
245
131
|
* Override the extension to the generated imports and exports, by default each plugin will add an extension
|
|
246
132
|
* @default { '.ts': '.ts'}
|
|
247
133
|
*/
|
|
248
|
-
extension?: Record<Extname, Extname | ''>;
|
|
134
|
+
extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>;
|
|
249
135
|
/**
|
|
250
136
|
* Specify how `index.ts` files should be created. You can also disable the generation of barrel files here. While each plugin has its own `barrelType` option, this setting controls the creation of the root barrel file, such as` src/gen/index.ts`.
|
|
251
137
|
* @default 'named'
|
|
@@ -284,11 +170,11 @@ TName extends string = string,
|
|
|
284
170
|
/**
|
|
285
171
|
* Options of the plugin.
|
|
286
172
|
*/
|
|
287
|
-
TOptions
|
|
173
|
+
TOptions extends object = object,
|
|
288
174
|
/**
|
|
289
175
|
* Options of the plugin that can be used later on, see `options` inside your plugin config.
|
|
290
176
|
*/
|
|
291
|
-
TResolvedOptions extends object = TOptions
|
|
177
|
+
TResolvedOptions extends object = TOptions,
|
|
292
178
|
/**
|
|
293
179
|
* Context that you want to expose to other plugins.
|
|
294
180
|
*/
|
|
@@ -302,23 +188,23 @@ TResolvePathOptions extends object = object> = {
|
|
|
302
188
|
* Same behaviour like what has been done with `QueryKey` in `@tanstack/react-query`
|
|
303
189
|
*/
|
|
304
190
|
key: PluginKey<TName | string>;
|
|
305
|
-
options: TOptions
|
|
191
|
+
options: TOptions;
|
|
306
192
|
resolvedOptions: TResolvedOptions;
|
|
307
193
|
context: TContext;
|
|
308
194
|
resolvePathOptions: TResolvePathOptions;
|
|
309
195
|
};
|
|
310
196
|
type PluginKey<TName> = [name: TName, identifier?: string | number];
|
|
311
|
-
type UserPlugin<TOptions
|
|
197
|
+
type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
312
198
|
/**
|
|
313
199
|
* Unique name used for the plugin
|
|
314
200
|
* The name of the plugin follows the format scope:foo-bar or foo-bar, adding scope: can avoid naming conflicts with other plugins.
|
|
315
201
|
* @example @kubb/typescript
|
|
316
202
|
*/
|
|
317
|
-
name: TOptions
|
|
203
|
+
name: TOptions['name'];
|
|
318
204
|
/**
|
|
319
205
|
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
320
206
|
*/
|
|
321
|
-
options: TOptions
|
|
207
|
+
options: TOptions['resolvedOptions'];
|
|
322
208
|
/**
|
|
323
209
|
* 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.
|
|
324
210
|
* Can be used to validate dependent plugins.
|
|
@@ -328,23 +214,23 @@ type UserPlugin<TOptions$1 extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
328
214
|
* 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.
|
|
329
215
|
*/
|
|
330
216
|
post?: Array<string>;
|
|
331
|
-
} & (TOptions
|
|
217
|
+
} & (TOptions['context'] extends never ? {
|
|
332
218
|
context?: never;
|
|
333
219
|
} : {
|
|
334
|
-
context: (this: TOptions
|
|
220
|
+
context: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext<TOptions>, 'addFile'>) => TOptions['context'];
|
|
335
221
|
});
|
|
336
|
-
type UserPluginWithLifeCycle<TOptions
|
|
337
|
-
type Plugin<TOptions
|
|
222
|
+
type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>;
|
|
223
|
+
type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
338
224
|
/**
|
|
339
225
|
* Unique name used for the plugin
|
|
340
226
|
* @example @kubb/typescript
|
|
341
227
|
*/
|
|
342
|
-
name: TOptions
|
|
228
|
+
name: TOptions['name'];
|
|
343
229
|
/**
|
|
344
230
|
* Internal key used when a developer uses more than one of the same plugin
|
|
345
231
|
* @private
|
|
346
232
|
*/
|
|
347
|
-
key: TOptions
|
|
233
|
+
key: TOptions['key'];
|
|
348
234
|
/**
|
|
349
235
|
* 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.
|
|
350
236
|
* Can be used to validate dependent plugins.
|
|
@@ -357,49 +243,49 @@ type Plugin<TOptions$1 extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
|
357
243
|
/**
|
|
358
244
|
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
359
245
|
*/
|
|
360
|
-
options: TOptions
|
|
361
|
-
} & (TOptions
|
|
246
|
+
options: TOptions['resolvedOptions'];
|
|
247
|
+
} & (TOptions['context'] extends never ? {
|
|
362
248
|
context?: never;
|
|
363
249
|
} : {
|
|
364
|
-
context: TOptions
|
|
250
|
+
context: TOptions['context'];
|
|
365
251
|
});
|
|
366
|
-
type PluginWithLifeCycle<TOptions
|
|
367
|
-
type PluginLifecycle<TOptions
|
|
252
|
+
type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>;
|
|
253
|
+
type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
368
254
|
/**
|
|
369
255
|
* Start of the lifecycle of a plugin.
|
|
370
256
|
* @type hookParallel
|
|
371
257
|
*/
|
|
372
|
-
buildStart?: (this: PluginContext<TOptions
|
|
258
|
+
buildStart?: (this: PluginContext<TOptions>, Config: Config) => PossiblePromise<void>;
|
|
373
259
|
/**
|
|
374
260
|
* Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
|
|
375
261
|
* Options can als be included.
|
|
376
262
|
* @type hookFirst
|
|
377
263
|
* @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
|
|
378
264
|
*/
|
|
379
|
-
resolvePath?: (this: PluginContext<TOptions
|
|
265
|
+
resolvePath?: (this: PluginContext<TOptions>, baseName: KubbFile.BaseName, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.OptionalPath;
|
|
380
266
|
/**
|
|
381
267
|
* Resolve to a name based on a string.
|
|
382
268
|
* Useful when converting to PascalCase or camelCase.
|
|
383
269
|
* @type hookFirst
|
|
384
270
|
* @example ('pet') => 'Pet'
|
|
385
271
|
*/
|
|
386
|
-
resolveName?: (this: PluginContext<TOptions
|
|
272
|
+
resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
387
273
|
/**
|
|
388
274
|
* End of the plugin lifecycle.
|
|
389
275
|
* @type hookParallel
|
|
390
276
|
*/
|
|
391
|
-
buildEnd?: (this: PluginContext<TOptions
|
|
277
|
+
buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
392
278
|
};
|
|
393
279
|
type PluginLifecycleHooks = keyof PluginLifecycle;
|
|
394
|
-
type PluginParameter<H
|
|
395
|
-
type ResolvePathParams<TOptions
|
|
280
|
+
type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
|
|
281
|
+
type ResolvePathParams<TOptions = object> = {
|
|
396
282
|
pluginKey?: Plugin['key'];
|
|
397
|
-
baseName: BaseName;
|
|
398
|
-
mode?: Mode;
|
|
283
|
+
baseName: KubbFile.BaseName;
|
|
284
|
+
mode?: KubbFile.Mode;
|
|
399
285
|
/**
|
|
400
286
|
* Options to be passed to 'resolvePath' 3th parameter
|
|
401
287
|
*/
|
|
402
|
-
options?: TOptions
|
|
288
|
+
options?: TOptions;
|
|
403
289
|
};
|
|
404
290
|
type ResolveNameParams = {
|
|
405
291
|
name: string;
|
|
@@ -412,15 +298,16 @@ type ResolveNameParams = {
|
|
|
412
298
|
*/
|
|
413
299
|
type?: 'file' | 'function' | 'type' | 'const';
|
|
414
300
|
};
|
|
415
|
-
type PluginContext<TOptions
|
|
301
|
+
type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
302
|
+
fabric: Fabric;
|
|
416
303
|
config: Config;
|
|
417
304
|
/**
|
|
418
305
|
* @deprecated
|
|
419
306
|
*/
|
|
420
307
|
fileManager: FileManager;
|
|
421
308
|
pluginManager: PluginManager;
|
|
422
|
-
addFile: (...file: Array<File>) => Promise<Array<ResolvedFile>>;
|
|
423
|
-
resolvePath: (params: ResolvePathParams<TOptions
|
|
309
|
+
addFile: (...file: Array<KubbFile.File>) => Promise<Array<KubbFile.ResolvedFile>>;
|
|
310
|
+
resolvePath: (params: ResolvePathParams<TOptions['resolvePathOptions']>) => KubbFile.OptionalPath;
|
|
424
311
|
resolveName: (params: ResolveNameParams) => string;
|
|
425
312
|
logger: Logger;
|
|
426
313
|
/**
|
|
@@ -430,12 +317,12 @@ type PluginContext<TOptions$1 extends PluginFactoryOptions = PluginFactoryOption
|
|
|
430
317
|
/**
|
|
431
318
|
* Current plugin
|
|
432
319
|
*/
|
|
433
|
-
plugin: Plugin<TOptions
|
|
320
|
+
plugin: Plugin<TOptions>;
|
|
434
321
|
};
|
|
435
322
|
/**
|
|
436
323
|
* Specify the export location for the files and define the behavior of the output
|
|
437
324
|
*/
|
|
438
|
-
type Output<TOptions
|
|
325
|
+
type Output<TOptions> = {
|
|
439
326
|
/**
|
|
440
327
|
* Path to the output folder or file that will contain the generated code
|
|
441
328
|
*/
|
|
@@ -448,30 +335,31 @@ type Output<TOptions$1> = {
|
|
|
448
335
|
/**
|
|
449
336
|
* Add a banner text in the beginning of every file
|
|
450
337
|
*/
|
|
451
|
-
banner?: string | ((options: TOptions
|
|
338
|
+
banner?: string | ((options: TOptions) => string);
|
|
452
339
|
/**
|
|
453
340
|
* Add a footer text in the beginning of every file
|
|
454
341
|
*/
|
|
455
|
-
footer?: string | ((options: TOptions
|
|
342
|
+
footer?: string | ((options: TOptions) => string);
|
|
456
343
|
};
|
|
457
344
|
//#endregion
|
|
458
345
|
//#region ../core/src/PluginManager.d.ts
|
|
459
346
|
type RequiredPluginLifecycle = Required<PluginLifecycle>;
|
|
460
347
|
type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookSeq';
|
|
461
|
-
type Executer<H
|
|
348
|
+
type Executer<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
462
349
|
message: string;
|
|
463
350
|
strategy: Strategy;
|
|
464
|
-
hookName: H
|
|
351
|
+
hookName: H;
|
|
465
352
|
plugin: Plugin;
|
|
466
353
|
parameters?: unknown[] | undefined;
|
|
467
354
|
output?: unknown;
|
|
468
355
|
};
|
|
469
|
-
type ParseResult<H
|
|
470
|
-
type SafeParseResult<H
|
|
356
|
+
type ParseResult<H extends PluginLifecycleHooks> = RequiredPluginLifecycle[H];
|
|
357
|
+
type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = {
|
|
471
358
|
result: Result;
|
|
472
359
|
plugin: Plugin;
|
|
473
360
|
};
|
|
474
361
|
type Options$2 = {
|
|
362
|
+
fabric: Fabric;
|
|
475
363
|
logger: Logger;
|
|
476
364
|
/**
|
|
477
365
|
* @default Number.POSITIVE_INFINITY
|
|
@@ -483,20 +371,16 @@ type Events = {
|
|
|
483
371
|
executed: [executer: Executer];
|
|
484
372
|
error: [error: Error];
|
|
485
373
|
};
|
|
486
|
-
type GetFileProps<TOptions
|
|
374
|
+
type GetFileProps<TOptions = object> = {
|
|
487
375
|
name: string;
|
|
488
|
-
mode?: Mode;
|
|
489
|
-
extname: Extname;
|
|
376
|
+
mode?: KubbFile.Mode;
|
|
377
|
+
extname: KubbFile.Extname;
|
|
490
378
|
pluginKey: Plugin['key'];
|
|
491
|
-
options?: TOptions
|
|
379
|
+
options?: TOptions;
|
|
492
380
|
};
|
|
493
381
|
declare class PluginManager {
|
|
494
382
|
#private;
|
|
495
383
|
readonly plugins: Set<Plugin<PluginFactoryOptions<string, object, object, any, object>>>;
|
|
496
|
-
/**
|
|
497
|
-
* @deprecated do not use from pluginManager
|
|
498
|
-
*/
|
|
499
|
-
readonly fileManager: FileManager;
|
|
500
384
|
readonly events: EventEmitter<Events>;
|
|
501
385
|
readonly config: Config;
|
|
502
386
|
readonly executed: Array<Executer>;
|
|
@@ -509,10 +393,10 @@ declare class PluginManager {
|
|
|
509
393
|
extname,
|
|
510
394
|
pluginKey,
|
|
511
395
|
options
|
|
512
|
-
}: GetFileProps<TOptions>): File<{
|
|
396
|
+
}: GetFileProps<TOptions>): KubbFile.File<{
|
|
513
397
|
pluginKey: Plugin['key'];
|
|
514
398
|
}>;
|
|
515
|
-
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => OptionalPath;
|
|
399
|
+
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
|
|
516
400
|
resolveName: (params: ResolveNameParams) => string;
|
|
517
401
|
/**
|
|
518
402
|
* Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { KubbFile } from "@kubb/fabric-core/types";
|
|
2
|
+
import { Fabric, FileManager } from "@kubb/react-fabric";
|
|
1
3
|
import { ConsolaInstance, LogLevel } from "consola";
|
|
2
|
-
import { FileManager } from "@kubb/fabric-core";
|
|
3
4
|
import * as OasTypes from "oas/types";
|
|
4
5
|
import { OASDocument, SchemaObject, User } from "oas/types";
|
|
5
6
|
import { Operation } from "oas/operation";
|
|
@@ -7,121 +8,6 @@ import { OpenAPIV3 } from "openapi-types";
|
|
|
7
8
|
import * as oas_normalize_lib_types0 from "oas-normalize/lib/types";
|
|
8
9
|
import BaseOas from "oas";
|
|
9
10
|
|
|
10
|
-
//#region ../core/src/fs/types.d.ts
|
|
11
|
-
type BasePath<T extends string = string> = `${T}/`;
|
|
12
|
-
type Import = {
|
|
13
|
-
/**
|
|
14
|
-
* Import name to be used
|
|
15
|
-
* @example ["useState"]
|
|
16
|
-
* @example "React"
|
|
17
|
-
*/
|
|
18
|
-
name: string | Array<string | {
|
|
19
|
-
propertyName: string;
|
|
20
|
-
name?: string;
|
|
21
|
-
}>;
|
|
22
|
-
/**
|
|
23
|
-
* Path for the import
|
|
24
|
-
* @example '@kubb/core'
|
|
25
|
-
*/
|
|
26
|
-
path: string;
|
|
27
|
-
/**
|
|
28
|
-
* Add `type` prefix to the import, this will result in: `import type { Type } from './path'`.
|
|
29
|
-
*/
|
|
30
|
-
isTypeOnly?: boolean;
|
|
31
|
-
isNameSpace?: boolean;
|
|
32
|
-
/**
|
|
33
|
-
* When root is set it will get the path with relative getRelativePath(root, path).
|
|
34
|
-
*/
|
|
35
|
-
root?: string;
|
|
36
|
-
};
|
|
37
|
-
type Source = {
|
|
38
|
-
name?: string;
|
|
39
|
-
value?: string;
|
|
40
|
-
isTypeOnly?: boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Has const or type 'export'
|
|
43
|
-
* @default false
|
|
44
|
-
*/
|
|
45
|
-
isExportable?: boolean;
|
|
46
|
-
/**
|
|
47
|
-
* When set, barrel generation will add this
|
|
48
|
-
* @default false
|
|
49
|
-
*/
|
|
50
|
-
isIndexable?: boolean;
|
|
51
|
-
};
|
|
52
|
-
type Export = {
|
|
53
|
-
/**
|
|
54
|
-
* Export name to be used.
|
|
55
|
-
* @example ["useState"]
|
|
56
|
-
* @example "React"
|
|
57
|
-
*/
|
|
58
|
-
name?: string | Array<string>;
|
|
59
|
-
/**
|
|
60
|
-
* Path for the import.
|
|
61
|
-
* @example '@kubb/core'
|
|
62
|
-
*/
|
|
63
|
-
path: string;
|
|
64
|
-
/**
|
|
65
|
-
* Add `type` prefix to the export, this will result in: `export type { Type } from './path'`.
|
|
66
|
-
*/
|
|
67
|
-
isTypeOnly?: boolean;
|
|
68
|
-
/**
|
|
69
|
-
* Make it possible to override the name, this will result in: `export * as aliasName from './path'`.
|
|
70
|
-
*/
|
|
71
|
-
asAlias?: boolean;
|
|
72
|
-
};
|
|
73
|
-
type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`;
|
|
74
|
-
type Mode = 'single' | 'split';
|
|
75
|
-
/**
|
|
76
|
-
* Name to be used to dynamicly create the baseName(based on input.path)
|
|
77
|
-
* Based on UNIX basename
|
|
78
|
-
* @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
|
|
79
|
-
*/
|
|
80
|
-
type BaseName = `${string}.${string}`;
|
|
81
|
-
/**
|
|
82
|
-
* Path will be full qualified path to a specified file
|
|
83
|
-
*/
|
|
84
|
-
type Path = string;
|
|
85
|
-
type AdvancedPath<T extends BaseName = BaseName> = `${BasePath}${T}`;
|
|
86
|
-
type OptionalPath = Path | undefined | null;
|
|
87
|
-
type File<TMeta extends object = object> = {
|
|
88
|
-
/**
|
|
89
|
-
* Name to be used to create the path
|
|
90
|
-
* Based on UNIX basename, `${name}.extname`
|
|
91
|
-
* @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
|
|
92
|
-
*/
|
|
93
|
-
baseName: BaseName;
|
|
94
|
-
/**
|
|
95
|
-
* Path will be full qualified path to a specified file
|
|
96
|
-
*/
|
|
97
|
-
path: AdvancedPath<BaseName> | Path;
|
|
98
|
-
sources: Array<Source>;
|
|
99
|
-
imports?: Array<Import>;
|
|
100
|
-
exports?: Array<Export>;
|
|
101
|
-
/**
|
|
102
|
-
* Use extra meta, this is getting used to generate the barrel/index files.
|
|
103
|
-
*/
|
|
104
|
-
meta?: TMeta;
|
|
105
|
-
banner?: string;
|
|
106
|
-
footer?: string;
|
|
107
|
-
};
|
|
108
|
-
type ResolvedImport = Import;
|
|
109
|
-
type ResolvedExport = Export;
|
|
110
|
-
type ResolvedFile<TMeta extends object = object> = File<TMeta> & {
|
|
111
|
-
/**
|
|
112
|
-
* @default object-hash
|
|
113
|
-
*/
|
|
114
|
-
id: string;
|
|
115
|
-
/**
|
|
116
|
-
* Contains the first part of the baseName, generated based on baseName
|
|
117
|
-
* @link https://nodejs.org/api/path.html#pathformatpathobject
|
|
118
|
-
*/
|
|
119
|
-
name: string;
|
|
120
|
-
extname: Extname;
|
|
121
|
-
imports: Array<ResolvedImport>;
|
|
122
|
-
exports: Array<ResolvedExport>;
|
|
123
|
-
};
|
|
124
|
-
//#endregion
|
|
125
11
|
//#region ../core/src/utils/EventEmitter.d.ts
|
|
126
12
|
declare class EventEmitter<TEvents extends Record<string, any>> {
|
|
127
13
|
#private;
|
|
@@ -245,7 +131,7 @@ type Config<TInput = Input> = {
|
|
|
245
131
|
* Override the extension to the generated imports and exports, by default each plugin will add an extension
|
|
246
132
|
* @default { '.ts': '.ts'}
|
|
247
133
|
*/
|
|
248
|
-
extension?: Record<Extname, Extname | ''>;
|
|
134
|
+
extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>;
|
|
249
135
|
/**
|
|
250
136
|
* Specify how `index.ts` files should be created. You can also disable the generation of barrel files here. While each plugin has its own `barrelType` option, this setting controls the creation of the root barrel file, such as` src/gen/index.ts`.
|
|
251
137
|
* @default 'named'
|
|
@@ -284,11 +170,11 @@ TName extends string = string,
|
|
|
284
170
|
/**
|
|
285
171
|
* Options of the plugin.
|
|
286
172
|
*/
|
|
287
|
-
TOptions
|
|
173
|
+
TOptions extends object = object,
|
|
288
174
|
/**
|
|
289
175
|
* Options of the plugin that can be used later on, see `options` inside your plugin config.
|
|
290
176
|
*/
|
|
291
|
-
TResolvedOptions extends object = TOptions
|
|
177
|
+
TResolvedOptions extends object = TOptions,
|
|
292
178
|
/**
|
|
293
179
|
* Context that you want to expose to other plugins.
|
|
294
180
|
*/
|
|
@@ -302,23 +188,23 @@ TResolvePathOptions extends object = object> = {
|
|
|
302
188
|
* Same behaviour like what has been done with `QueryKey` in `@tanstack/react-query`
|
|
303
189
|
*/
|
|
304
190
|
key: PluginKey<TName | string>;
|
|
305
|
-
options: TOptions
|
|
191
|
+
options: TOptions;
|
|
306
192
|
resolvedOptions: TResolvedOptions;
|
|
307
193
|
context: TContext;
|
|
308
194
|
resolvePathOptions: TResolvePathOptions;
|
|
309
195
|
};
|
|
310
196
|
type PluginKey<TName> = [name: TName, identifier?: string | number];
|
|
311
|
-
type UserPlugin<TOptions
|
|
197
|
+
type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
312
198
|
/**
|
|
313
199
|
* Unique name used for the plugin
|
|
314
200
|
* The name of the plugin follows the format scope:foo-bar or foo-bar, adding scope: can avoid naming conflicts with other plugins.
|
|
315
201
|
* @example @kubb/typescript
|
|
316
202
|
*/
|
|
317
|
-
name: TOptions
|
|
203
|
+
name: TOptions['name'];
|
|
318
204
|
/**
|
|
319
205
|
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
320
206
|
*/
|
|
321
|
-
options: TOptions
|
|
207
|
+
options: TOptions['resolvedOptions'];
|
|
322
208
|
/**
|
|
323
209
|
* 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.
|
|
324
210
|
* Can be used to validate dependent plugins.
|
|
@@ -328,23 +214,23 @@ type UserPlugin<TOptions$1 extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
328
214
|
* 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.
|
|
329
215
|
*/
|
|
330
216
|
post?: Array<string>;
|
|
331
|
-
} & (TOptions
|
|
217
|
+
} & (TOptions['context'] extends never ? {
|
|
332
218
|
context?: never;
|
|
333
219
|
} : {
|
|
334
|
-
context: (this: TOptions
|
|
220
|
+
context: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext<TOptions>, 'addFile'>) => TOptions['context'];
|
|
335
221
|
});
|
|
336
|
-
type UserPluginWithLifeCycle<TOptions
|
|
337
|
-
type Plugin<TOptions
|
|
222
|
+
type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>;
|
|
223
|
+
type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
338
224
|
/**
|
|
339
225
|
* Unique name used for the plugin
|
|
340
226
|
* @example @kubb/typescript
|
|
341
227
|
*/
|
|
342
|
-
name: TOptions
|
|
228
|
+
name: TOptions['name'];
|
|
343
229
|
/**
|
|
344
230
|
* Internal key used when a developer uses more than one of the same plugin
|
|
345
231
|
* @private
|
|
346
232
|
*/
|
|
347
|
-
key: TOptions
|
|
233
|
+
key: TOptions['key'];
|
|
348
234
|
/**
|
|
349
235
|
* 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.
|
|
350
236
|
* Can be used to validate dependent plugins.
|
|
@@ -357,49 +243,49 @@ type Plugin<TOptions$1 extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
|
357
243
|
/**
|
|
358
244
|
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
359
245
|
*/
|
|
360
|
-
options: TOptions
|
|
361
|
-
} & (TOptions
|
|
246
|
+
options: TOptions['resolvedOptions'];
|
|
247
|
+
} & (TOptions['context'] extends never ? {
|
|
362
248
|
context?: never;
|
|
363
249
|
} : {
|
|
364
|
-
context: TOptions
|
|
250
|
+
context: TOptions['context'];
|
|
365
251
|
});
|
|
366
|
-
type PluginWithLifeCycle<TOptions
|
|
367
|
-
type PluginLifecycle<TOptions
|
|
252
|
+
type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>;
|
|
253
|
+
type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
368
254
|
/**
|
|
369
255
|
* Start of the lifecycle of a plugin.
|
|
370
256
|
* @type hookParallel
|
|
371
257
|
*/
|
|
372
|
-
buildStart?: (this: PluginContext<TOptions
|
|
258
|
+
buildStart?: (this: PluginContext<TOptions>, Config: Config) => PossiblePromise<void>;
|
|
373
259
|
/**
|
|
374
260
|
* Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
|
|
375
261
|
* Options can als be included.
|
|
376
262
|
* @type hookFirst
|
|
377
263
|
* @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
|
|
378
264
|
*/
|
|
379
|
-
resolvePath?: (this: PluginContext<TOptions
|
|
265
|
+
resolvePath?: (this: PluginContext<TOptions>, baseName: KubbFile.BaseName, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.OptionalPath;
|
|
380
266
|
/**
|
|
381
267
|
* Resolve to a name based on a string.
|
|
382
268
|
* Useful when converting to PascalCase or camelCase.
|
|
383
269
|
* @type hookFirst
|
|
384
270
|
* @example ('pet') => 'Pet'
|
|
385
271
|
*/
|
|
386
|
-
resolveName?: (this: PluginContext<TOptions
|
|
272
|
+
resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
387
273
|
/**
|
|
388
274
|
* End of the plugin lifecycle.
|
|
389
275
|
* @type hookParallel
|
|
390
276
|
*/
|
|
391
|
-
buildEnd?: (this: PluginContext<TOptions
|
|
277
|
+
buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
392
278
|
};
|
|
393
279
|
type PluginLifecycleHooks = keyof PluginLifecycle;
|
|
394
|
-
type PluginParameter<H
|
|
395
|
-
type ResolvePathParams<TOptions
|
|
280
|
+
type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
|
|
281
|
+
type ResolvePathParams<TOptions = object> = {
|
|
396
282
|
pluginKey?: Plugin['key'];
|
|
397
|
-
baseName: BaseName;
|
|
398
|
-
mode?: Mode;
|
|
283
|
+
baseName: KubbFile.BaseName;
|
|
284
|
+
mode?: KubbFile.Mode;
|
|
399
285
|
/**
|
|
400
286
|
* Options to be passed to 'resolvePath' 3th parameter
|
|
401
287
|
*/
|
|
402
|
-
options?: TOptions
|
|
288
|
+
options?: TOptions;
|
|
403
289
|
};
|
|
404
290
|
type ResolveNameParams = {
|
|
405
291
|
name: string;
|
|
@@ -412,15 +298,16 @@ type ResolveNameParams = {
|
|
|
412
298
|
*/
|
|
413
299
|
type?: 'file' | 'function' | 'type' | 'const';
|
|
414
300
|
};
|
|
415
|
-
type PluginContext<TOptions
|
|
301
|
+
type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
302
|
+
fabric: Fabric;
|
|
416
303
|
config: Config;
|
|
417
304
|
/**
|
|
418
305
|
* @deprecated
|
|
419
306
|
*/
|
|
420
307
|
fileManager: FileManager;
|
|
421
308
|
pluginManager: PluginManager;
|
|
422
|
-
addFile: (...file: Array<File>) => Promise<Array<ResolvedFile>>;
|
|
423
|
-
resolvePath: (params: ResolvePathParams<TOptions
|
|
309
|
+
addFile: (...file: Array<KubbFile.File>) => Promise<Array<KubbFile.ResolvedFile>>;
|
|
310
|
+
resolvePath: (params: ResolvePathParams<TOptions['resolvePathOptions']>) => KubbFile.OptionalPath;
|
|
424
311
|
resolveName: (params: ResolveNameParams) => string;
|
|
425
312
|
logger: Logger;
|
|
426
313
|
/**
|
|
@@ -430,12 +317,12 @@ type PluginContext<TOptions$1 extends PluginFactoryOptions = PluginFactoryOption
|
|
|
430
317
|
/**
|
|
431
318
|
* Current plugin
|
|
432
319
|
*/
|
|
433
|
-
plugin: Plugin<TOptions
|
|
320
|
+
plugin: Plugin<TOptions>;
|
|
434
321
|
};
|
|
435
322
|
/**
|
|
436
323
|
* Specify the export location for the files and define the behavior of the output
|
|
437
324
|
*/
|
|
438
|
-
type Output<TOptions
|
|
325
|
+
type Output<TOptions> = {
|
|
439
326
|
/**
|
|
440
327
|
* Path to the output folder or file that will contain the generated code
|
|
441
328
|
*/
|
|
@@ -448,30 +335,31 @@ type Output<TOptions$1> = {
|
|
|
448
335
|
/**
|
|
449
336
|
* Add a banner text in the beginning of every file
|
|
450
337
|
*/
|
|
451
|
-
banner?: string | ((options: TOptions
|
|
338
|
+
banner?: string | ((options: TOptions) => string);
|
|
452
339
|
/**
|
|
453
340
|
* Add a footer text in the beginning of every file
|
|
454
341
|
*/
|
|
455
|
-
footer?: string | ((options: TOptions
|
|
342
|
+
footer?: string | ((options: TOptions) => string);
|
|
456
343
|
};
|
|
457
344
|
//#endregion
|
|
458
345
|
//#region ../core/src/PluginManager.d.ts
|
|
459
346
|
type RequiredPluginLifecycle = Required<PluginLifecycle>;
|
|
460
347
|
type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookSeq';
|
|
461
|
-
type Executer<H
|
|
348
|
+
type Executer<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
462
349
|
message: string;
|
|
463
350
|
strategy: Strategy;
|
|
464
|
-
hookName: H
|
|
351
|
+
hookName: H;
|
|
465
352
|
plugin: Plugin;
|
|
466
353
|
parameters?: unknown[] | undefined;
|
|
467
354
|
output?: unknown;
|
|
468
355
|
};
|
|
469
|
-
type ParseResult<H
|
|
470
|
-
type SafeParseResult<H
|
|
356
|
+
type ParseResult<H extends PluginLifecycleHooks> = RequiredPluginLifecycle[H];
|
|
357
|
+
type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = {
|
|
471
358
|
result: Result;
|
|
472
359
|
plugin: Plugin;
|
|
473
360
|
};
|
|
474
361
|
type Options$2 = {
|
|
362
|
+
fabric: Fabric;
|
|
475
363
|
logger: Logger;
|
|
476
364
|
/**
|
|
477
365
|
* @default Number.POSITIVE_INFINITY
|
|
@@ -483,20 +371,16 @@ type Events = {
|
|
|
483
371
|
executed: [executer: Executer];
|
|
484
372
|
error: [error: Error];
|
|
485
373
|
};
|
|
486
|
-
type GetFileProps<TOptions
|
|
374
|
+
type GetFileProps<TOptions = object> = {
|
|
487
375
|
name: string;
|
|
488
|
-
mode?: Mode;
|
|
489
|
-
extname: Extname;
|
|
376
|
+
mode?: KubbFile.Mode;
|
|
377
|
+
extname: KubbFile.Extname;
|
|
490
378
|
pluginKey: Plugin['key'];
|
|
491
|
-
options?: TOptions
|
|
379
|
+
options?: TOptions;
|
|
492
380
|
};
|
|
493
381
|
declare class PluginManager {
|
|
494
382
|
#private;
|
|
495
383
|
readonly plugins: Set<Plugin<PluginFactoryOptions<string, object, object, any, object>>>;
|
|
496
|
-
/**
|
|
497
|
-
* @deprecated do not use from pluginManager
|
|
498
|
-
*/
|
|
499
|
-
readonly fileManager: FileManager;
|
|
500
384
|
readonly events: EventEmitter<Events>;
|
|
501
385
|
readonly config: Config;
|
|
502
386
|
readonly executed: Array<Executer>;
|
|
@@ -509,10 +393,10 @@ declare class PluginManager {
|
|
|
509
393
|
extname,
|
|
510
394
|
pluginKey,
|
|
511
395
|
options
|
|
512
|
-
}: GetFileProps<TOptions>): File<{
|
|
396
|
+
}: GetFileProps<TOptions>): KubbFile.File<{
|
|
513
397
|
pluginKey: Plugin['key'];
|
|
514
398
|
}>;
|
|
515
|
-
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => OptionalPath;
|
|
399
|
+
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
|
|
516
400
|
resolveName: (params: ResolveNameParams) => string;
|
|
517
401
|
/**
|
|
518
402
|
* Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { PluginManager, createPlugin } from "@kubb/core";
|
|
3
3
|
import { pluginOasName } from "@kubb/plugin-oas";
|
|
4
|
-
import { trimExtName, write } from "@kubb/core/fs";
|
|
5
4
|
import { fileURLToPath } from "node:url";
|
|
6
5
|
import fs from "node:fs";
|
|
7
6
|
import pkg from "handlebars";
|
|
8
7
|
|
|
9
|
-
//#region ../../node_modules/.pnpm/tsdown@0.15.
|
|
8
|
+
//#region ../../node_modules/.pnpm/tsdown@0.15.11_typescript@5.9.3/node_modules/tsdown/esm-shims.js
|
|
10
9
|
const getFilename = () => fileURLToPath(import.meta.url);
|
|
11
10
|
const getDirname = () => path.dirname(getFilename());
|
|
12
11
|
const __dirname = /* @__PURE__ */ getDirname();
|
|
@@ -34,6 +33,9 @@ async function getPageHTML(api, { title, disableGoogleFont, templateOptions } =
|
|
|
34
33
|
|
|
35
34
|
//#endregion
|
|
36
35
|
//#region src/plugin.ts
|
|
36
|
+
function trimExtName(text) {
|
|
37
|
+
return text.replace(/\.[^/.]+$/, "");
|
|
38
|
+
}
|
|
37
39
|
const pluginRedocName = "plugin-redoc";
|
|
38
40
|
const pluginRedoc = createPlugin((options) => {
|
|
39
41
|
const { output = { path: "docs.html" } } = options;
|
|
@@ -50,7 +52,14 @@ const pluginRedoc = createPlugin((options) => {
|
|
|
50
52
|
await oas.dereference();
|
|
51
53
|
const root = path.resolve(this.config.root, this.config.output.path);
|
|
52
54
|
const pageHTML = await getPageHTML(oas.api);
|
|
53
|
-
await
|
|
55
|
+
await this.addFile({
|
|
56
|
+
baseName: "docs.html",
|
|
57
|
+
path: path.resolve(root, output.path || "./docs.html"),
|
|
58
|
+
sources: [{
|
|
59
|
+
name: "docs.html",
|
|
60
|
+
value: pageHTML
|
|
61
|
+
}]
|
|
62
|
+
});
|
|
54
63
|
}
|
|
55
64
|
};
|
|
56
65
|
});
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../node_modules/.pnpm/tsdown@0.15.
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../node_modules/.pnpm/tsdown@0.15.11_typescript@5.9.3/node_modules/tsdown/esm-shims.js","../src/redoc.tsx","../src/plugin.ts"],"sourcesContent":["// Shim globals in esm bundle\nimport path from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nconst getFilename = () => fileURLToPath(import.meta.url)\nconst getDirname = () => path.dirname(getFilename())\n\nexport const __dirname = /* @__PURE__ */ getDirname()\nexport const __filename = /* @__PURE__ */ getFilename()\n","import fs from 'node:fs'\nimport path from 'node:path'\nimport type { OasTypes } from '@kubb/oas'\nimport pkg from 'handlebars'\n\ntype BuildDocsOptions = {\n title?: string\n disableGoogleFont?: boolean\n templateOptions?: any\n}\n\nexport async function getPageHTML(api: OasTypes.OASDocument, { title, disableGoogleFont, templateOptions }: BuildDocsOptions = {}) {\n const templateFileName = path.join(__dirname, '../static/redoc.hbs')\n const template = pkg.compile(fs.readFileSync(templateFileName).toString())\n return template({\n title: title || api.info.title || 'ReDoc documentation',\n redocHTML: `\n <script src=\"https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js\"> </script>\n <div id=\"redoc-container\"></div>\n <script>\n const data = ${JSON.stringify(api, null, 2)};\n Redoc.init(data, {\n \"expandResponses\": \"200,400\"\n }, document.getElementById('redoc-container'))\n </script>\n `,\n disableGoogleFont,\n templateOptions,\n })\n}\n","import path from 'node:path'\nimport type { Plugin } from '@kubb/core'\nimport { createPlugin, PluginManager } from '@kubb/core'\nimport type { PluginOas } from '@kubb/plugin-oas'\nimport { pluginOasName } from '@kubb/plugin-oas'\nimport { getPageHTML } from './redoc.tsx'\nimport type { PluginRedoc } from './types.ts'\n\nfunction trimExtName(text: string): string {\n return text.replace(/\\.[^/.]+$/, '')\n}\n\nexport const pluginRedocName = 'plugin-redoc' satisfies PluginRedoc['name']\n\nexport const pluginRedoc = createPlugin<PluginRedoc>((options) => {\n const { output = { path: 'docs.html' } } = options\n\n return {\n name: pluginRedocName,\n options: {\n output,\n name: trimExtName(output.path),\n },\n pre: [pluginOasName],\n async buildStart() {\n const [swaggerPlugin]: [Plugin<PluginOas>] = PluginManager.getDependedPlugins<PluginOas>(this.plugins, [pluginOasName])\n const oas = await swaggerPlugin.context.getOas()\n\n await oas.dereference()\n\n const root = path.resolve(this.config.root, this.config.output.path)\n const pageHTML = await getPageHTML(oas.api)\n\n await this.addFile({\n baseName: 'docs.html',\n path: path.resolve(root, output.path || './docs.html'),\n sources: [\n {\n name: 'docs.html',\n value: pageHTML,\n },\n ],\n })\n },\n }\n})\n"],"x_google_ignoreList":[0],"mappings":";;;;;;;;AAIA,MAAM,oBAAoB,cAAc,OAAO,KAAK,IAAI;AACxD,MAAM,mBAAmB,KAAK,QAAQ,aAAa,CAAC;AAEpD,MAAa,YAA4B,4BAAY;;;;ACIrD,eAAsB,YAAY,KAA2B,EAAE,OAAO,mBAAmB,oBAAsC,EAAE,EAAE;CACjI,MAAM,mBAAmB,KAAK,KAAK,WAAW,sBAAsB;AAEpE,QADiB,IAAI,QAAQ,GAAG,aAAa,iBAAiB,CAAC,UAAU,CAAC,CAC1D;EACd,OAAO,SAAS,IAAI,KAAK,SAAS;EAClC,WAAW;;;;kBAIG,KAAK,UAAU,KAAK,MAAM,EAAE,CAAC;;;;;;EAM3C;EACA;EACD,CAAC;;;;;ACpBJ,SAAS,YAAY,MAAsB;AACzC,QAAO,KAAK,QAAQ,aAAa,GAAG;;AAGtC,MAAa,kBAAkB;AAE/B,MAAa,cAAc,cAA2B,YAAY;CAChE,MAAM,EAAE,SAAS,EAAE,MAAM,aAAa,KAAK;AAE3C,QAAO;EACL,MAAM;EACN,SAAS;GACP;GACA,MAAM,YAAY,OAAO,KAAK;GAC/B;EACD,KAAK,CAAC,cAAc;EACpB,MAAM,aAAa;GACjB,MAAM,CAAC,iBAAsC,cAAc,mBAA8B,KAAK,SAAS,CAAC,cAAc,CAAC;GACvH,MAAM,MAAM,MAAM,cAAc,QAAQ,QAAQ;AAEhD,SAAM,IAAI,aAAa;GAEvB,MAAM,OAAO,KAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,KAAK;GACpE,MAAM,WAAW,MAAM,YAAY,IAAI,IAAI;AAE3C,SAAM,KAAK,QAAQ;IACjB,UAAU;IACV,MAAM,KAAK,QAAQ,MAAM,OAAO,QAAQ,cAAc;IACtD,SAAS,CACP;KACE,MAAM;KACN,OAAO;KACR,CACF;IACF,CAAC;;EAEL;EACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-redoc",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.1",
|
|
4
4
|
"description": "Beautiful docs with Redoc",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -38,18 +38,23 @@
|
|
|
38
38
|
"!/**/**.test.**",
|
|
39
39
|
"!/**/__tests__/**"
|
|
40
40
|
],
|
|
41
|
+
"size-limit": [
|
|
42
|
+
{
|
|
43
|
+
"path": "./dist/*.js",
|
|
44
|
+
"limit": "510 KiB",
|
|
45
|
+
"gzip": true
|
|
46
|
+
}
|
|
47
|
+
],
|
|
41
48
|
"dependencies": {
|
|
49
|
+
"@kubb/react-fabric": "0.2.10",
|
|
42
50
|
"handlebars": "^4.7.8",
|
|
43
|
-
"@kubb/core": "4.
|
|
44
|
-
"@kubb/oas": "4.
|
|
45
|
-
"@kubb/plugin-oas": "4.
|
|
46
|
-
},
|
|
47
|
-
"devDependencies": {
|
|
48
|
-
"tsdown": "^0.15.9",
|
|
49
|
-
"typescript": "^5.9.3"
|
|
51
|
+
"@kubb/core": "4.4.1",
|
|
52
|
+
"@kubb/oas": "4.4.1",
|
|
53
|
+
"@kubb/plugin-oas": "4.4.1"
|
|
50
54
|
},
|
|
55
|
+
"devDependencies": {},
|
|
51
56
|
"peerDependencies": {
|
|
52
|
-
"@kubb/react": "
|
|
57
|
+
"@kubb/react-fabric": "0.2.10"
|
|
53
58
|
},
|
|
54
59
|
"engines": {
|
|
55
60
|
"node": ">=20"
|
|
@@ -59,7 +64,7 @@
|
|
|
59
64
|
"registry": "https://registry.npmjs.org/"
|
|
60
65
|
},
|
|
61
66
|
"scripts": {
|
|
62
|
-
"build": "tsdown",
|
|
67
|
+
"build": "tsdown && size-limit",
|
|
63
68
|
"clean": "npx rimraf ./dist",
|
|
64
69
|
"lint": "bun biome lint .",
|
|
65
70
|
"lint:fix": "bun biome lint --fix --unsafe .",
|
package/src/plugin.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
|
-
|
|
3
|
-
import { PluginManager, createPlugin } from '@kubb/core'
|
|
4
|
-
import { pluginOasName } from '@kubb/plugin-oas'
|
|
5
|
-
|
|
6
2
|
import type { Plugin } from '@kubb/core'
|
|
7
|
-
import {
|
|
3
|
+
import { createPlugin, PluginManager } from '@kubb/core'
|
|
8
4
|
import type { PluginOas } from '@kubb/plugin-oas'
|
|
5
|
+
import { pluginOasName } from '@kubb/plugin-oas'
|
|
9
6
|
import { getPageHTML } from './redoc.tsx'
|
|
10
7
|
import type { PluginRedoc } from './types.ts'
|
|
11
8
|
|
|
9
|
+
function trimExtName(text: string): string {
|
|
10
|
+
return text.replace(/\.[^/.]+$/, '')
|
|
11
|
+
}
|
|
12
|
+
|
|
12
13
|
export const pluginRedocName = 'plugin-redoc' satisfies PluginRedoc['name']
|
|
13
14
|
|
|
14
15
|
export const pluginRedoc = createPlugin<PluginRedoc>((options) => {
|
|
@@ -30,7 +31,16 @@ export const pluginRedoc = createPlugin<PluginRedoc>((options) => {
|
|
|
30
31
|
const root = path.resolve(this.config.root, this.config.output.path)
|
|
31
32
|
const pageHTML = await getPageHTML(oas.api)
|
|
32
33
|
|
|
33
|
-
await
|
|
34
|
+
await this.addFile({
|
|
35
|
+
baseName: 'docs.html',
|
|
36
|
+
path: path.resolve(root, output.path || './docs.html'),
|
|
37
|
+
sources: [
|
|
38
|
+
{
|
|
39
|
+
name: 'docs.html',
|
|
40
|
+
value: pageHTML,
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
})
|
|
34
44
|
},
|
|
35
45
|
}
|
|
36
46
|
})
|