@kubb/plugin-redoc 4.4.0 → 4.5.0

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/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: (0, __kubb_core_fs.trimExtName)(output.path)
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 (0, __kubb_core_fs.write)(node_path.default.resolve(root, output.path || "./docs.html"), pageHTML);
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
  });
@@ -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'\n\nimport { PluginManager, createPlugin } from '@kubb/core'\nimport { pluginOasName } from '@kubb/plugin-oas'\n\nimport type { Plugin } from '@kubb/core'\nimport { trimExtName, write } from '@kubb/core/fs'\nimport type { PluginOas } from '@kubb/plugin-oas'\nimport { getPageHTML } from './redoc.tsx'\nimport type { PluginRedoc } from './types.ts'\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 write(path.resolve(root, output.path || './docs.html'), pageHTML)\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;;;;;ACjBJ,MAAa,kBAAkB;AAE/B,MAAa,6CAAyC,YAAY;CAChE,MAAM,EAAE,SAAS,EAAE,MAAM,aAAa,KAAK;AAE3C,QAAO;EACL,MAAM;EACN,SAAS;GACP;GACA,sCAAkB,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,mCAAYA,kBAAK,QAAQ,MAAM,OAAO,QAAQ,cAAc,EAAE,SAAS;;EAE1E;EACD"}
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,3 +1,4 @@
1
+ import { KubbFile } from "@kubb/fabric-core/types";
1
2
  import { Fabric, FileManager } from "@kubb/react-fabric";
2
3
  import { ConsolaInstance, LogLevel } from "consola";
3
4
  import * as OasTypes from "oas/types";
@@ -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'
@@ -376,7 +262,7 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
376
262
  * @type hookFirst
377
263
  * @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
378
264
  */
379
- resolvePath?: (this: PluginContext<TOptions>, baseName: BaseName, mode?: Mode, options?: TOptions['resolvePathOptions']) => OptionalPath;
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.
@@ -394,8 +280,8 @@ type PluginLifecycleHooks = keyof PluginLifecycle;
394
280
  type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
395
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
  */
@@ -420,8 +306,8 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
420
306
  */
421
307
  fileManager: FileManager;
422
308
  pluginManager: PluginManager;
423
- addFile: (...file: Array<File>) => Promise<Array<ResolvedFile>>;
424
- resolvePath: (params: ResolvePathParams<TOptions['resolvePathOptions']>) => OptionalPath;
309
+ addFile: (...file: Array<KubbFile.File>) => Promise<Array<KubbFile.ResolvedFile>>;
310
+ resolvePath: (params: ResolvePathParams<TOptions['resolvePathOptions']>) => KubbFile.OptionalPath;
425
311
  resolveName: (params: ResolveNameParams) => string;
426
312
  logger: Logger;
427
313
  /**
@@ -487,8 +373,8 @@ type Events = {
487
373
  };
488
374
  type GetFileProps<TOptions = object> = {
489
375
  name: string;
490
- mode?: Mode;
491
- extname: Extname;
376
+ mode?: KubbFile.Mode;
377
+ extname: KubbFile.Extname;
492
378
  pluginKey: Plugin['key'];
493
379
  options?: TOptions;
494
380
  };
@@ -507,10 +393,10 @@ declare class PluginManager {
507
393
  extname,
508
394
  pluginKey,
509
395
  options
510
- }: GetFileProps<TOptions>): File<{
396
+ }: GetFileProps<TOptions>): KubbFile.File<{
511
397
  pluginKey: Plugin['key'];
512
398
  }>;
513
- resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => OptionalPath;
399
+ resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
514
400
  resolveName: (params: ResolveNameParams) => string;
515
401
  /**
516
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,3 +1,4 @@
1
+ import { KubbFile } from "@kubb/fabric-core/types";
1
2
  import { Fabric, FileManager } from "@kubb/react-fabric";
2
3
  import { ConsolaInstance, LogLevel } from "consola";
3
4
  import * as OasTypes from "oas/types";
@@ -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'
@@ -376,7 +262,7 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
376
262
  * @type hookFirst
377
263
  * @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
378
264
  */
379
- resolvePath?: (this: PluginContext<TOptions>, baseName: BaseName, mode?: Mode, options?: TOptions['resolvePathOptions']) => OptionalPath;
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.
@@ -394,8 +280,8 @@ type PluginLifecycleHooks = keyof PluginLifecycle;
394
280
  type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
395
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
  */
@@ -420,8 +306,8 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
420
306
  */
421
307
  fileManager: FileManager;
422
308
  pluginManager: PluginManager;
423
- addFile: (...file: Array<File>) => Promise<Array<ResolvedFile>>;
424
- resolvePath: (params: ResolvePathParams<TOptions['resolvePathOptions']>) => OptionalPath;
309
+ addFile: (...file: Array<KubbFile.File>) => Promise<Array<KubbFile.ResolvedFile>>;
310
+ resolvePath: (params: ResolvePathParams<TOptions['resolvePathOptions']>) => KubbFile.OptionalPath;
425
311
  resolveName: (params: ResolveNameParams) => string;
426
312
  logger: Logger;
427
313
  /**
@@ -487,8 +373,8 @@ type Events = {
487
373
  };
488
374
  type GetFileProps<TOptions = object> = {
489
375
  name: string;
490
- mode?: Mode;
491
- extname: Extname;
376
+ mode?: KubbFile.Mode;
377
+ extname: KubbFile.Extname;
492
378
  pluginKey: Plugin['key'];
493
379
  options?: TOptions;
494
380
  };
@@ -507,10 +393,10 @@ declare class PluginManager {
507
393
  extname,
508
394
  pluginKey,
509
395
  options
510
- }: GetFileProps<TOptions>): File<{
396
+ }: GetFileProps<TOptions>): KubbFile.File<{
511
397
  pluginKey: Plugin['key'];
512
398
  }>;
513
- resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => OptionalPath;
399
+ resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
514
400
  resolveName: (params: ResolveNameParams) => string;
515
401
  /**
516
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.11_typescript@5.9.3/node_modules/tsdown/esm-shims.js
8
+ //#region ../../node_modules/.pnpm/tsdown@0.15.12_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 write(path.resolve(root, output.path || "./docs.html"), pageHTML);
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.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'\n\nimport { PluginManager, createPlugin } from '@kubb/core'\nimport { pluginOasName } from '@kubb/plugin-oas'\n\nimport type { Plugin } from '@kubb/core'\nimport { trimExtName, write } from '@kubb/core/fs'\nimport type { PluginOas } from '@kubb/plugin-oas'\nimport { getPageHTML } from './redoc.tsx'\nimport type { PluginRedoc } from './types.ts'\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 write(path.resolve(root, output.path || './docs.html'), pageHTML)\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;;;;;ACjBJ,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,MAAM,KAAK,QAAQ,MAAM,OAAO,QAAQ,cAAc,EAAE,SAAS;;EAE1E;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 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.4.0",
3
+ "version": "4.5.0",
4
4
  "description": "Beautiful docs with Redoc",
5
5
  "keywords": [
6
6
  "typescript",
@@ -38,19 +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": {
42
- "@kubb/react-fabric": "0.2.8",
49
+ "@kubb/react-fabric": "0.2.14",
43
50
  "handlebars": "^4.7.8",
44
- "@kubb/core": "4.4.0",
45
- "@kubb/oas": "4.4.0",
46
- "@kubb/plugin-oas": "4.4.0"
47
- },
48
- "devDependencies": {
49
- "tsdown": "^0.15.11",
50
- "typescript": "^5.9.3"
51
+ "@kubb/core": "4.5.0",
52
+ "@kubb/plugin-oas": "4.5.0",
53
+ "@kubb/oas": "4.5.0"
51
54
  },
55
+ "devDependencies": {},
52
56
  "peerDependencies": {
53
- "@kubb/react-fabric": "0.2.8"
57
+ "@kubb/react-fabric": "0.2.14"
54
58
  },
55
59
  "engines": {
56
60
  "node": ">=20"
@@ -60,7 +64,7 @@
60
64
  "registry": "https://registry.npmjs.org/"
61
65
  },
62
66
  "scripts": {
63
- "build": "tsdown",
67
+ "build": "tsdown && size-limit",
64
68
  "clean": "npx rimraf ./dist",
65
69
  "lint": "bun biome lint .",
66
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 { trimExtName, write } from '@kubb/core/fs'
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 write(path.resolve(root, output.path || './docs.html'), pageHTML)
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
  })