@kubb/plugin-redoc 4.5.1 → 4.5.3

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.
@@ -21,6 +21,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
21
  value: mod,
22
22
  enumerable: true
23
23
  }) : target, mod));
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
25
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
25
26
 
26
27
  //#endregion
package/dist/index.cjs CHANGED
@@ -58,7 +58,7 @@ function trimExtName(text) {
58
58
  return text.replace(/\.[^/.]+$/, "");
59
59
  }
60
60
  const pluginRedocName = "plugin-redoc";
61
- const pluginRedoc = (0, __kubb_core.createPlugin)((options) => {
61
+ const pluginRedoc = (0, __kubb_core.definePlugin)((options) => {
62
62
  const { output = { path: "docs.html" } } = options;
63
63
  return {
64
64
  name: pluginRedocName,
@@ -67,9 +67,8 @@ const pluginRedoc = (0, __kubb_core.createPlugin)((options) => {
67
67
  name: trimExtName(output.path)
68
68
  },
69
69
  pre: [__kubb_plugin_oas.pluginOasName],
70
- async buildStart() {
71
- const [swaggerPlugin] = __kubb_core.PluginManager.getDependedPlugins(this.plugins, [__kubb_plugin_oas.pluginOasName]);
72
- const oas = await swaggerPlugin.context.getOas();
70
+ async install() {
71
+ const oas = await this.getOas();
73
72
  await oas.dereference();
74
73
  const root = node_path.default.resolve(this.config.root, this.config.output.path);
75
74
  const pageHTML = await getPageHTML(oas.api);
@@ -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'\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"}
1
+ {"version":3,"file":"index.cjs","names":["path","pkg","fs","pluginOasName","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 { definePlugin } from '@kubb/core'\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 = definePlugin<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 install() {\n const oas = await this.getOas()\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;;;;;ACtBJ,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,UAAU;GACd,MAAM,MAAM,MAAM,KAAK,QAAQ;AAC/B,SAAM,IAAI,aAAa;GAEvB,MAAM,OAAOC,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,5 @@
1
1
  import { KubbFile } from "@kubb/fabric-core/types";
2
- import { Fabric, FileManager } from "@kubb/react-fabric";
2
+ import { Fabric } from "@kubb/react-fabric";
3
3
  import { ConsolaInstance, LogLevel } from "consola";
4
4
  import * as OasTypes from "oas/types";
5
5
  import { OASDocument, SchemaObject, User } from "oas/types";
@@ -60,6 +60,21 @@ type Logger = {
60
60
  type PossiblePromise<T> = Promise<T> | T;
61
61
  //#endregion
62
62
  //#region ../core/src/types.d.ts
63
+ declare global {
64
+ namespace Kubb {
65
+ interface PluginContext {}
66
+ }
67
+ }
68
+ /**
69
+ * Config used in `kubb.config.ts`
70
+ *
71
+ * @example
72
+ * import { defineConfig } from '@kubb/core'
73
+ * export default defineConfig({
74
+ * ...
75
+ * })
76
+ */
77
+
63
78
  type InputPath = {
64
79
  /**
65
80
  * Specify your Swagger/OpenAPI file, either as an absolute path or a path relative to the root.
@@ -214,11 +229,8 @@ type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
214
229
  * 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.
215
230
  */
216
231
  post?: Array<string>;
217
- } & (TOptions['context'] extends never ? {
218
- context?: never;
219
- } : {
220
- context: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext<TOptions>, 'addFile'>) => TOptions['context'];
221
- });
232
+ inject?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
233
+ };
222
234
  type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>;
223
235
  type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
224
236
  /**
@@ -244,25 +256,26 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
244
256
  * Options set for a specific plugin(see kubb.config.js), passthrough of options.
245
257
  */
246
258
  options: TOptions['resolvedOptions'];
247
- } & (TOptions['context'] extends never ? {
248
- context?: never;
249
- } : {
250
- context: TOptions['context'];
251
- });
259
+ install: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
260
+ /**
261
+ * Define a context that can be used by other plugins, see `PluginManager' where we convert from `UserPlugin` to `Plugin`(used when calling `definePlugin`).
262
+ */
263
+ inject: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
264
+ };
252
265
  type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>;
253
266
  type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
254
267
  /**
255
268
  * Start of the lifecycle of a plugin.
256
269
  * @type hookParallel
257
270
  */
258
- buildStart?: (this: PluginContext<TOptions>, Config: Config) => PossiblePromise<void>;
271
+ install?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
259
272
  /**
260
273
  * Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
261
274
  * Options can als be included.
262
275
  * @type hookFirst
263
276
  * @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
264
277
  */
265
- resolvePath?: (this: PluginContext<TOptions>, baseName: KubbFile.BaseName, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.OptionalPath;
278
+ resolvePath?: (this: PluginContext<TOptions>, baseName: KubbFile.BaseName, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.Path;
266
279
  /**
267
280
  * Resolve to a name based on a string.
268
281
  * Useful when converting to PascalCase or camelCase.
@@ -270,11 +283,6 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
270
283
  * @example ('pet') => 'Pet'
271
284
  */
272
285
  resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
273
- /**
274
- * End of the plugin lifecycle.
275
- * @type hookParallel
276
- */
277
- buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
278
286
  };
279
287
  type PluginLifecycleHooks = keyof PluginLifecycle;
280
288
  type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
@@ -301,24 +309,15 @@ type ResolveNameParams = {
301
309
  type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
302
310
  fabric: Fabric;
303
311
  config: Config;
304
- /**
305
- * @deprecated
306
- */
307
- fileManager: FileManager;
308
312
  pluginManager: PluginManager;
309
- addFile: (...file: Array<KubbFile.File>) => Promise<Array<KubbFile.ResolvedFile>>;
310
- resolvePath: (params: ResolvePathParams<TOptions['resolvePathOptions']>) => KubbFile.OptionalPath;
311
- resolveName: (params: ResolveNameParams) => string;
313
+ addFile: (...file: Array<KubbFile.File>) => Promise<void>;
312
314
  logger: Logger;
313
- /**
314
- * All plugins
315
- */
316
- plugins: Plugin[];
315
+ mode: KubbFile.Mode;
317
316
  /**
318
317
  * Current plugin
319
318
  */
320
319
  plugin: Plugin<TOptions>;
321
- };
320
+ } & Kubb.PluginContext;
322
321
  /**
323
322
  * Specify the export location for the files and define the behavior of the output
324
323
  */
@@ -380,13 +379,14 @@ type GetFileProps<TOptions = object> = {
380
379
  };
381
380
  declare class PluginManager {
382
381
  #private;
383
- readonly plugins: Set<Plugin<PluginFactoryOptions<string, object, object, any, object>>>;
384
382
  readonly events: EventEmitter<Events>;
385
383
  readonly config: Config;
386
384
  readonly executed: Array<Executer>;
387
385
  readonly logger: Logger;
388
386
  readonly options: Options$2;
389
387
  constructor(config: Config, options: Options$2);
388
+ getContext<TOptions extends PluginFactoryOptions>(plugin: Plugin<TOptions>): PluginContext<TOptions> & Record<string, any>;
389
+ get plugins(): Array<Plugin>;
390
390
  getFile<TOptions = object>({
391
391
  name,
392
392
  mode,
@@ -396,7 +396,7 @@ declare class PluginManager {
396
396
  }: GetFileProps<TOptions>): KubbFile.File<{
397
397
  pluginKey: Plugin['key'];
398
398
  }>;
399
- resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
399
+ resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.Path;
400
400
  resolveName: (params: ResolveNameParams) => string;
401
401
  /**
402
402
  * Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
@@ -484,8 +484,6 @@ declare class PluginManager {
484
484
  }): Promise<void>;
485
485
  getPluginByKey(pluginKey: Plugin['key']): Plugin | undefined;
486
486
  getPluginsByKey(hookName: keyof PluginWithLifeCycle, pluginKey: Plugin['key']): Plugin[];
487
- 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;
488
- static get hooks(): readonly ["buildStart", "resolvePath", "resolveName", "buildEnd"];
489
487
  }
490
488
  //#endregion
491
489
  //#region ../oas/src/types.d.ts
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { KubbFile } from "@kubb/fabric-core/types";
2
- import { Fabric, FileManager } from "@kubb/react-fabric";
2
+ import { Fabric } from "@kubb/react-fabric";
3
3
  import { ConsolaInstance, LogLevel } from "consola";
4
4
  import * as OasTypes from "oas/types";
5
5
  import { OASDocument, SchemaObject, User } from "oas/types";
@@ -60,6 +60,21 @@ type Logger = {
60
60
  type PossiblePromise<T> = Promise<T> | T;
61
61
  //#endregion
62
62
  //#region ../core/src/types.d.ts
63
+ declare global {
64
+ namespace Kubb {
65
+ interface PluginContext {}
66
+ }
67
+ }
68
+ /**
69
+ * Config used in `kubb.config.ts`
70
+ *
71
+ * @example
72
+ * import { defineConfig } from '@kubb/core'
73
+ * export default defineConfig({
74
+ * ...
75
+ * })
76
+ */
77
+
63
78
  type InputPath = {
64
79
  /**
65
80
  * Specify your Swagger/OpenAPI file, either as an absolute path or a path relative to the root.
@@ -214,11 +229,8 @@ type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
214
229
  * 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.
215
230
  */
216
231
  post?: Array<string>;
217
- } & (TOptions['context'] extends never ? {
218
- context?: never;
219
- } : {
220
- context: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext<TOptions>, 'addFile'>) => TOptions['context'];
221
- });
232
+ inject?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
233
+ };
222
234
  type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>;
223
235
  type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
224
236
  /**
@@ -244,25 +256,26 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
244
256
  * Options set for a specific plugin(see kubb.config.js), passthrough of options.
245
257
  */
246
258
  options: TOptions['resolvedOptions'];
247
- } & (TOptions['context'] extends never ? {
248
- context?: never;
249
- } : {
250
- context: TOptions['context'];
251
- });
259
+ install: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
260
+ /**
261
+ * Define a context that can be used by other plugins, see `PluginManager' where we convert from `UserPlugin` to `Plugin`(used when calling `definePlugin`).
262
+ */
263
+ inject: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
264
+ };
252
265
  type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>;
253
266
  type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
254
267
  /**
255
268
  * Start of the lifecycle of a plugin.
256
269
  * @type hookParallel
257
270
  */
258
- buildStart?: (this: PluginContext<TOptions>, Config: Config) => PossiblePromise<void>;
271
+ install?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
259
272
  /**
260
273
  * Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
261
274
  * Options can als be included.
262
275
  * @type hookFirst
263
276
  * @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
264
277
  */
265
- resolvePath?: (this: PluginContext<TOptions>, baseName: KubbFile.BaseName, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.OptionalPath;
278
+ resolvePath?: (this: PluginContext<TOptions>, baseName: KubbFile.BaseName, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.Path;
266
279
  /**
267
280
  * Resolve to a name based on a string.
268
281
  * Useful when converting to PascalCase or camelCase.
@@ -270,11 +283,6 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
270
283
  * @example ('pet') => 'Pet'
271
284
  */
272
285
  resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
273
- /**
274
- * End of the plugin lifecycle.
275
- * @type hookParallel
276
- */
277
- buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
278
286
  };
279
287
  type PluginLifecycleHooks = keyof PluginLifecycle;
280
288
  type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
@@ -301,24 +309,15 @@ type ResolveNameParams = {
301
309
  type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
302
310
  fabric: Fabric;
303
311
  config: Config;
304
- /**
305
- * @deprecated
306
- */
307
- fileManager: FileManager;
308
312
  pluginManager: PluginManager;
309
- addFile: (...file: Array<KubbFile.File>) => Promise<Array<KubbFile.ResolvedFile>>;
310
- resolvePath: (params: ResolvePathParams<TOptions['resolvePathOptions']>) => KubbFile.OptionalPath;
311
- resolveName: (params: ResolveNameParams) => string;
313
+ addFile: (...file: Array<KubbFile.File>) => Promise<void>;
312
314
  logger: Logger;
313
- /**
314
- * All plugins
315
- */
316
- plugins: Plugin[];
315
+ mode: KubbFile.Mode;
317
316
  /**
318
317
  * Current plugin
319
318
  */
320
319
  plugin: Plugin<TOptions>;
321
- };
320
+ } & Kubb.PluginContext;
322
321
  /**
323
322
  * Specify the export location for the files and define the behavior of the output
324
323
  */
@@ -380,13 +379,14 @@ type GetFileProps<TOptions = object> = {
380
379
  };
381
380
  declare class PluginManager {
382
381
  #private;
383
- readonly plugins: Set<Plugin<PluginFactoryOptions<string, object, object, any, object>>>;
384
382
  readonly events: EventEmitter<Events>;
385
383
  readonly config: Config;
386
384
  readonly executed: Array<Executer>;
387
385
  readonly logger: Logger;
388
386
  readonly options: Options$2;
389
387
  constructor(config: Config, options: Options$2);
388
+ getContext<TOptions extends PluginFactoryOptions>(plugin: Plugin<TOptions>): PluginContext<TOptions> & Record<string, any>;
389
+ get plugins(): Array<Plugin>;
390
390
  getFile<TOptions = object>({
391
391
  name,
392
392
  mode,
@@ -396,7 +396,7 @@ declare class PluginManager {
396
396
  }: GetFileProps<TOptions>): KubbFile.File<{
397
397
  pluginKey: Plugin['key'];
398
398
  }>;
399
- resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
399
+ resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.Path;
400
400
  resolveName: (params: ResolveNameParams) => string;
401
401
  /**
402
402
  * Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
@@ -484,8 +484,6 @@ declare class PluginManager {
484
484
  }): Promise<void>;
485
485
  getPluginByKey(pluginKey: Plugin['key']): Plugin | undefined;
486
486
  getPluginsByKey(hookName: keyof PluginWithLifeCycle, pluginKey: Plugin['key']): Plugin[];
487
- 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;
488
- static get hooks(): readonly ["buildStart", "resolvePath", "resolveName", "buildEnd"];
489
487
  }
490
488
  //#endregion
491
489
  //#region ../oas/src/types.d.ts
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import path from "node:path";
2
- import { PluginManager, createPlugin } from "@kubb/core";
2
+ import { definePlugin } from "@kubb/core";
3
3
  import { pluginOasName } from "@kubb/plugin-oas";
4
4
  import { fileURLToPath } from "node:url";
5
5
  import fs from "node:fs";
@@ -37,7 +37,7 @@ function trimExtName(text) {
37
37
  return text.replace(/\.[^/.]+$/, "");
38
38
  }
39
39
  const pluginRedocName = "plugin-redoc";
40
- const pluginRedoc = createPlugin((options) => {
40
+ const pluginRedoc = definePlugin((options) => {
41
41
  const { output = { path: "docs.html" } } = options;
42
42
  return {
43
43
  name: pluginRedocName,
@@ -46,9 +46,8 @@ const pluginRedoc = createPlugin((options) => {
46
46
  name: trimExtName(output.path)
47
47
  },
48
48
  pre: [pluginOasName],
49
- async buildStart() {
50
- const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
51
- const oas = await swaggerPlugin.context.getOas();
49
+ async install() {
50
+ const oas = await this.getOas();
52
51
  await oas.dereference();
53
52
  const root = path.resolve(this.config.root, this.config.output.path);
54
53
  const pageHTML = await getPageHTML(oas.api);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../node_modules/.pnpm/tsdown@0.15.12_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"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../node_modules/.pnpm/tsdown@0.15.12_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 { definePlugin } from '@kubb/core'\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 = definePlugin<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 install() {\n const oas = await this.getOas()\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;;;;;ACtBJ,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,UAAU;GACd,MAAM,MAAM,MAAM,KAAK,QAAQ;AAC/B,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.5.1",
3
+ "version": "4.5.3",
4
4
  "description": "Beautiful docs with Redoc",
5
5
  "keywords": [
6
6
  "typescript",
@@ -46,15 +46,15 @@
46
46
  }
47
47
  ],
48
48
  "dependencies": {
49
- "@kubb/react-fabric": "0.2.14",
49
+ "@kubb/react-fabric": "0.2.19",
50
50
  "handlebars": "^4.7.8",
51
- "@kubb/core": "4.5.1",
52
- "@kubb/oas": "4.5.1",
53
- "@kubb/plugin-oas": "4.5.1"
51
+ "@kubb/core": "4.5.3",
52
+ "@kubb/oas": "4.5.3",
53
+ "@kubb/plugin-oas": "4.5.3"
54
54
  },
55
55
  "devDependencies": {},
56
56
  "peerDependencies": {
57
- "@kubb/react-fabric": "0.2.14"
57
+ "@kubb/react-fabric": "0.2.19"
58
58
  },
59
59
  "engines": {
60
60
  "node": ">=20"
package/src/plugin.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  import path from 'node:path'
2
- import type { Plugin } from '@kubb/core'
3
- import { createPlugin, PluginManager } from '@kubb/core'
4
- import type { PluginOas } from '@kubb/plugin-oas'
2
+ import { definePlugin } from '@kubb/core'
5
3
  import { pluginOasName } from '@kubb/plugin-oas'
6
4
  import { getPageHTML } from './redoc.tsx'
7
5
  import type { PluginRedoc } from './types.ts'
@@ -12,7 +10,7 @@ function trimExtName(text: string): string {
12
10
 
13
11
  export const pluginRedocName = 'plugin-redoc' satisfies PluginRedoc['name']
14
12
 
15
- export const pluginRedoc = createPlugin<PluginRedoc>((options) => {
13
+ export const pluginRedoc = definePlugin<PluginRedoc>((options) => {
16
14
  const { output = { path: 'docs.html' } } = options
17
15
 
18
16
  return {
@@ -22,10 +20,8 @@ export const pluginRedoc = createPlugin<PluginRedoc>((options) => {
22
20
  name: trimExtName(output.path),
23
21
  },
24
22
  pre: [pluginOasName],
25
- async buildStart() {
26
- const [swaggerPlugin]: [Plugin<PluginOas>] = PluginManager.getDependedPlugins<PluginOas>(this.plugins, [pluginOasName])
27
- const oas = await swaggerPlugin.context.getOas()
28
-
23
+ async install() {
24
+ const oas = await this.getOas()
29
25
  await oas.dereference()
30
26
 
31
27
  const root = path.resolve(this.config.root, this.config.output.path)