@kubb/plugin-redoc 5.0.0-alpha.31 → 5.0.0-alpha.33
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 +26 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +25 -12
- package/dist/index.js.map +1 -1
- package/package.json +7 -9
- package/src/plugin.ts +14 -16
package/dist/index.cjs
CHANGED
|
@@ -23,15 +23,33 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
//#endregion
|
|
24
24
|
let node_path = require("node:path");
|
|
25
25
|
node_path = __toESM(node_path);
|
|
26
|
-
let _kubb_adapter_oas = require("@kubb/adapter-oas");
|
|
27
|
-
let _kubb_core = require("@kubb/core");
|
|
28
26
|
let node_fs = require("node:fs");
|
|
29
27
|
node_fs = __toESM(node_fs);
|
|
28
|
+
let _kubb_adapter_oas = require("@kubb/adapter-oas");
|
|
29
|
+
let _kubb_ast = require("@kubb/ast");
|
|
30
|
+
let _kubb_core = require("@kubb/core");
|
|
30
31
|
let node_url = require("node:url");
|
|
31
32
|
let handlebars = require("handlebars");
|
|
32
33
|
handlebars = __toESM(handlebars);
|
|
34
|
+
//#region ../../internals/utils/src/string.ts
|
|
35
|
+
/**
|
|
36
|
+
* Strips the file extension from a path or file name.
|
|
37
|
+
* Only removes the last `.ext` segment when the dot is not part of a directory name.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* trimExtName('petStore.ts') // 'petStore'
|
|
41
|
+
* trimExtName('/src/models/pet.ts') // '/src/models/pet'
|
|
42
|
+
* trimExtName('/project.v2/gen/pet.ts') // '/project.v2/gen/pet'
|
|
43
|
+
* trimExtName('noExtension') // 'noExtension'
|
|
44
|
+
*/
|
|
45
|
+
function trimExtName(text) {
|
|
46
|
+
const dotIndex = text.lastIndexOf(".");
|
|
47
|
+
if (dotIndex > 0 && !text.includes("/", dotIndex)) return text.slice(0, dotIndex);
|
|
48
|
+
return text;
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
33
51
|
//#region package.json
|
|
34
|
-
var version = "5.0.0-alpha.
|
|
52
|
+
var version = "5.0.0-alpha.33";
|
|
35
53
|
//#endregion
|
|
36
54
|
//#region src/redoc.tsx
|
|
37
55
|
const __filename$1 = (0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href);
|
|
@@ -56,9 +74,6 @@ async function getPageHTML(api, { title, disableGoogleFont, templateOptions } =
|
|
|
56
74
|
}
|
|
57
75
|
//#endregion
|
|
58
76
|
//#region src/plugin.ts
|
|
59
|
-
function trimExtName(text) {
|
|
60
|
-
return text.replace(/\.[^/.]+$/, "");
|
|
61
|
-
}
|
|
62
77
|
const pluginRedocName = "plugin-redoc";
|
|
63
78
|
const pluginRedoc = (0, _kubb_core.createPlugin)((options) => {
|
|
64
79
|
const { output = { path: "docs.html" } } = options;
|
|
@@ -78,16 +93,14 @@ const pluginRedoc = (0, _kubb_core.createPlugin)((options) => {
|
|
|
78
93
|
if (!document) throw new Error(`[${pluginRedocName}] No OpenAPI document found. The adapterOas did not produce a document — ensure the adapter has run before this plugin.`);
|
|
79
94
|
const root = this.root;
|
|
80
95
|
const pageHTML = await getPageHTML(document);
|
|
81
|
-
await this.addFile({
|
|
96
|
+
await this.addFile((0, _kubb_ast.createFile)({
|
|
82
97
|
baseName: "docs.html",
|
|
83
98
|
path: node_path.default.resolve(root, output.path || "./docs.html"),
|
|
84
|
-
sources: [{
|
|
99
|
+
sources: [(0, _kubb_ast.createSource)({
|
|
85
100
|
name: "docs.html",
|
|
86
|
-
|
|
87
|
-
}]
|
|
88
|
-
|
|
89
|
-
exports: []
|
|
90
|
-
});
|
|
101
|
+
nodes: [(0, _kubb_ast.createText)(pageHTML)]
|
|
102
|
+
})]
|
|
103
|
+
}));
|
|
91
104
|
}
|
|
92
105
|
};
|
|
93
106
|
});
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["__filename","__dirname","path","pkg","fs","adapterOasName","path"],"sources":["../package.json","../src/redoc.tsx","../src/plugin.ts"],"sourcesContent":["","import fs from 'node:fs'\nimport path from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport type { AdapterOas } from '@kubb/adapter-oas'\nimport pkg from 'handlebars'\n\nconst __filename = fileURLToPath(import.meta.url)\nconst __dirname = path.dirname(__filename)\n\ntype BuildDocsOptions = {\n title?: string\n disableGoogleFont?: boolean\n templateOptions?: any\n}\n\nexport async function getPageHTML(api: AdapterOas['document'], { 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 { AdapterOas } from '@kubb/adapter-oas'\nimport { adapterOasName } from '@kubb/adapter-oas'\nimport { type Adapter, createPlugin } from '@kubb/core'\nimport { version } from '../package.json'\nimport { getPageHTML } from './redoc.tsx'\nimport type { PluginRedoc } from './types.ts'\n\
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["__filename","__dirname","path","pkg","fs","adapterOasName","path"],"sources":["../../../internals/utils/src/string.ts","../package.json","../src/redoc.tsx","../src/plugin.ts"],"sourcesContent":["/**\n * Strips a single matching pair of `\"...\"`, `'...'`, or `` `...` `` from both ends of `text`.\n * Returns the string unchanged when no balanced quote pair is found.\n *\n * @example\n * trimQuotes('\"hello\"') // 'hello'\n * trimQuotes('hello') // 'hello'\n */\nexport function trimQuotes(text: string): string {\n if (text.length >= 2) {\n const first = text[0]\n const last = text[text.length - 1]\n if ((first === '\"' && last === '\"') || (first === \"'\" && last === \"'\") || (first === '`' && last === '`')) {\n return text.slice(1, -1)\n }\n }\n return text\n}\n\n/**\n * Escapes characters that are not allowed inside JS string literals.\n * Handles quotes, backslashes, and Unicode line terminators (U+2028 / U+2029).\n *\n * @see http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4\n *\n * @example\n * ```ts\n * jsStringEscape('say \"hi\"\\nbye') // 'say \\\\\"hi\\\\\"\\\\nbye'\n * ```\n */\nexport function jsStringEscape(input: unknown): string {\n return `${input}`.replace(/[\"'\\\\\\n\\r\\u2028\\u2029]/g, (character) => {\n switch (character) {\n case '\"':\n case \"'\":\n case '\\\\':\n return `\\\\${character}`\n case '\\n':\n return '\\\\n'\n case '\\r':\n return '\\\\r'\n case '\\u2028':\n return '\\\\u2028'\n case '\\u2029':\n return '\\\\u2029'\n default:\n return ''\n }\n })\n}\n\n/**\n * Returns a masked version of a string, showing only the first and last few characters.\n * Useful for logging sensitive values (tokens, keys) without exposing the full value.\n *\n * @example\n * maskString('KUBB_STUDIO-abc123-xyz789') // 'KUBB_STUDIO-…789'\n */\nexport function maskString(value: string, start = 8, end = 4): string {\n if (value.length <= start + end) return value\n return `${value.slice(0, start)}…${value.slice(-end)}`\n}\n\n/**\n * Strips the file extension from a path or file name.\n * Only removes the last `.ext` segment when the dot is not part of a directory name.\n *\n * @example\n * trimExtName('petStore.ts') // 'petStore'\n * trimExtName('/src/models/pet.ts') // '/src/models/pet'\n * trimExtName('/project.v2/gen/pet.ts') // '/project.v2/gen/pet'\n * trimExtName('noExtension') // 'noExtension'\n */\nexport function trimExtName(text: string): string {\n const dotIndex = text.lastIndexOf('.')\n if (dotIndex > 0 && !text.includes('/', dotIndex)) {\n return text.slice(0, dotIndex)\n }\n return text\n}\n","","import fs from 'node:fs'\nimport path from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport type { AdapterOas } from '@kubb/adapter-oas'\nimport pkg from 'handlebars'\n\nconst __filename = fileURLToPath(import.meta.url)\nconst __dirname = path.dirname(__filename)\n\ntype BuildDocsOptions = {\n title?: string\n disableGoogleFont?: boolean\n templateOptions?: any\n}\n\nexport async function getPageHTML(api: AdapterOas['document'], { 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 { trimExtName } from '@internals/utils'\nimport type { AdapterOas } from '@kubb/adapter-oas'\nimport { adapterOasName } from '@kubb/adapter-oas'\nimport { createFile, createSource, createText } from '@kubb/ast'\nimport { type Adapter, createPlugin } from '@kubb/core'\nimport { version } from '../package.json'\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 version,\n options: {\n output,\n name: trimExtName(output.path),\n exclude: [],\n override: [],\n },\n async buildStart() {\n const adapter = this.adapter\n\n if (adapter?.name !== adapterOasName) {\n throw new Error(\n `[${pluginRedocName}] plugin-redoc requires the OpenAPI adapter. Make sure you are using adapterOas (e.g. \\`adapter: adapterOas()\\`) in your Kubb config.`,\n )\n }\n\n const document = (adapter as Adapter<AdapterOas>).document\n\n if (!document) {\n throw new Error(\n `[${pluginRedocName}] No OpenAPI document found. The adapterOas did not produce a document — ensure the adapter has run before this plugin.`,\n )\n }\n\n const root = this.root\n const pageHTML = await getPageHTML(document)\n\n await this.addFile(\n createFile({\n baseName: 'docs.html',\n path: path.resolve(root, output.path || './docs.html'),\n sources: [\n createSource({\n name: 'docs.html',\n nodes: [createText(pageHTML)],\n }),\n ],\n }),\n )\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyEA,SAAgB,YAAY,MAAsB;CAChD,MAAM,WAAW,KAAK,YAAY,IAAI;AACtC,KAAI,WAAW,KAAK,CAAC,KAAK,SAAS,KAAK,SAAS,CAC/C,QAAO,KAAK,MAAM,GAAG,SAAS;AAEhC,QAAO;;;;;;;AExET,MAAMA,gBAAAA,GAAAA,SAAAA,eAAAA,QAAAA,MAAAA,CAAAA,cAAAA,WAAAA,CAAAA,KAA2C;AACjD,MAAMC,cAAYC,UAAAA,QAAK,QAAQF,aAAW;AAQ1C,eAAsB,YAAY,KAA6B,EAAE,OAAO,mBAAmB,oBAAsC,EAAE,EAAE;CACnI,MAAM,mBAAmBE,UAAAA,QAAK,KAAKD,aAAW,sBAAsB;AAEpE,QADiBE,WAAAA,QAAI,QAAQC,QAAAA,QAAG,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,MAAa,kBAAkB;AAE/B,MAAa,eAAA,GAAA,WAAA,eAAyC,YAAY;CAChE,MAAM,EAAE,SAAS,EAAE,MAAM,aAAa,KAAK;AAE3C,QAAO;EACL,MAAM;EACN;EACA,SAAS;GACP;GACA,MAAM,YAAY,OAAO,KAAK;GAC9B,SAAS,EAAE;GACX,UAAU,EAAE;GACb;EACD,MAAM,aAAa;GACjB,MAAM,UAAU,KAAK;AAErB,OAAI,SAAS,SAASC,kBAAAA,eACpB,OAAM,IAAI,MACR,IAAI,gBAAgB,uIACrB;GAGH,MAAM,WAAY,QAAgC;AAElD,OAAI,CAAC,SACH,OAAM,IAAI,MACR,IAAI,gBAAgB,yHACrB;GAGH,MAAM,OAAO,KAAK;GAClB,MAAM,WAAW,MAAM,YAAY,SAAS;AAE5C,SAAM,KAAK,SAAA,GAAA,UAAA,YACE;IACT,UAAU;IACV,MAAMC,UAAAA,QAAK,QAAQ,MAAM,OAAO,QAAQ,cAAc;IACtD,SAAS,EAAA,GAAA,UAAA,cACM;KACX,MAAM;KACN,OAAO,EAAA,GAAA,UAAA,YAAY,SAAS,CAAC;KAC9B,CAAC,CACH;IACF,CAAC,CACH;;EAEJ;EACD"}
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,30 @@
|
|
|
1
1
|
import "./chunk--u3MIqq1.js";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import fs from "node:fs";
|
|
3
4
|
import { adapterOasName } from "@kubb/adapter-oas";
|
|
5
|
+
import { createFile, createSource, createText } from "@kubb/ast";
|
|
4
6
|
import { createPlugin } from "@kubb/core";
|
|
5
|
-
import fs from "node:fs";
|
|
6
7
|
import { fileURLToPath } from "node:url";
|
|
7
8
|
import pkg from "handlebars";
|
|
9
|
+
//#region ../../internals/utils/src/string.ts
|
|
10
|
+
/**
|
|
11
|
+
* Strips the file extension from a path or file name.
|
|
12
|
+
* Only removes the last `.ext` segment when the dot is not part of a directory name.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* trimExtName('petStore.ts') // 'petStore'
|
|
16
|
+
* trimExtName('/src/models/pet.ts') // '/src/models/pet'
|
|
17
|
+
* trimExtName('/project.v2/gen/pet.ts') // '/project.v2/gen/pet'
|
|
18
|
+
* trimExtName('noExtension') // 'noExtension'
|
|
19
|
+
*/
|
|
20
|
+
function trimExtName(text) {
|
|
21
|
+
const dotIndex = text.lastIndexOf(".");
|
|
22
|
+
if (dotIndex > 0 && !text.includes("/", dotIndex)) return text.slice(0, dotIndex);
|
|
23
|
+
return text;
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
8
26
|
//#region package.json
|
|
9
|
-
var version = "5.0.0-alpha.
|
|
27
|
+
var version = "5.0.0-alpha.33";
|
|
10
28
|
//#endregion
|
|
11
29
|
//#region src/redoc.tsx
|
|
12
30
|
const __filename = fileURLToPath(import.meta.url);
|
|
@@ -31,9 +49,6 @@ async function getPageHTML(api, { title, disableGoogleFont, templateOptions } =
|
|
|
31
49
|
}
|
|
32
50
|
//#endregion
|
|
33
51
|
//#region src/plugin.ts
|
|
34
|
-
function trimExtName(text) {
|
|
35
|
-
return text.replace(/\.[^/.]+$/, "");
|
|
36
|
-
}
|
|
37
52
|
const pluginRedocName = "plugin-redoc";
|
|
38
53
|
const pluginRedoc = createPlugin((options) => {
|
|
39
54
|
const { output = { path: "docs.html" } } = options;
|
|
@@ -53,16 +68,14 @@ const pluginRedoc = createPlugin((options) => {
|
|
|
53
68
|
if (!document) throw new Error(`[${pluginRedocName}] No OpenAPI document found. The adapterOas did not produce a document — ensure the adapter has run before this plugin.`);
|
|
54
69
|
const root = this.root;
|
|
55
70
|
const pageHTML = await getPageHTML(document);
|
|
56
|
-
await this.addFile({
|
|
71
|
+
await this.addFile(createFile({
|
|
57
72
|
baseName: "docs.html",
|
|
58
73
|
path: path.resolve(root, output.path || "./docs.html"),
|
|
59
|
-
sources: [{
|
|
74
|
+
sources: [createSource({
|
|
60
75
|
name: "docs.html",
|
|
61
|
-
|
|
62
|
-
}]
|
|
63
|
-
|
|
64
|
-
exports: []
|
|
65
|
-
});
|
|
76
|
+
nodes: [createText(pageHTML)]
|
|
77
|
+
})]
|
|
78
|
+
}));
|
|
66
79
|
}
|
|
67
80
|
};
|
|
68
81
|
});
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../package.json","../src/redoc.tsx","../src/plugin.ts"],"sourcesContent":["","import fs from 'node:fs'\nimport path from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport type { AdapterOas } from '@kubb/adapter-oas'\nimport pkg from 'handlebars'\n\nconst __filename = fileURLToPath(import.meta.url)\nconst __dirname = path.dirname(__filename)\n\ntype BuildDocsOptions = {\n title?: string\n disableGoogleFont?: boolean\n templateOptions?: any\n}\n\nexport async function getPageHTML(api: AdapterOas['document'], { 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 { AdapterOas } from '@kubb/adapter-oas'\nimport { adapterOasName } from '@kubb/adapter-oas'\nimport { type Adapter, createPlugin } from '@kubb/core'\nimport { version } from '../package.json'\nimport { getPageHTML } from './redoc.tsx'\nimport type { PluginRedoc } from './types.ts'\n\
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../internals/utils/src/string.ts","../package.json","../src/redoc.tsx","../src/plugin.ts"],"sourcesContent":["/**\n * Strips a single matching pair of `\"...\"`, `'...'`, or `` `...` `` from both ends of `text`.\n * Returns the string unchanged when no balanced quote pair is found.\n *\n * @example\n * trimQuotes('\"hello\"') // 'hello'\n * trimQuotes('hello') // 'hello'\n */\nexport function trimQuotes(text: string): string {\n if (text.length >= 2) {\n const first = text[0]\n const last = text[text.length - 1]\n if ((first === '\"' && last === '\"') || (first === \"'\" && last === \"'\") || (first === '`' && last === '`')) {\n return text.slice(1, -1)\n }\n }\n return text\n}\n\n/**\n * Escapes characters that are not allowed inside JS string literals.\n * Handles quotes, backslashes, and Unicode line terminators (U+2028 / U+2029).\n *\n * @see http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4\n *\n * @example\n * ```ts\n * jsStringEscape('say \"hi\"\\nbye') // 'say \\\\\"hi\\\\\"\\\\nbye'\n * ```\n */\nexport function jsStringEscape(input: unknown): string {\n return `${input}`.replace(/[\"'\\\\\\n\\r\\u2028\\u2029]/g, (character) => {\n switch (character) {\n case '\"':\n case \"'\":\n case '\\\\':\n return `\\\\${character}`\n case '\\n':\n return '\\\\n'\n case '\\r':\n return '\\\\r'\n case '\\u2028':\n return '\\\\u2028'\n case '\\u2029':\n return '\\\\u2029'\n default:\n return ''\n }\n })\n}\n\n/**\n * Returns a masked version of a string, showing only the first and last few characters.\n * Useful for logging sensitive values (tokens, keys) without exposing the full value.\n *\n * @example\n * maskString('KUBB_STUDIO-abc123-xyz789') // 'KUBB_STUDIO-…789'\n */\nexport function maskString(value: string, start = 8, end = 4): string {\n if (value.length <= start + end) return value\n return `${value.slice(0, start)}…${value.slice(-end)}`\n}\n\n/**\n * Strips the file extension from a path or file name.\n * Only removes the last `.ext` segment when the dot is not part of a directory name.\n *\n * @example\n * trimExtName('petStore.ts') // 'petStore'\n * trimExtName('/src/models/pet.ts') // '/src/models/pet'\n * trimExtName('/project.v2/gen/pet.ts') // '/project.v2/gen/pet'\n * trimExtName('noExtension') // 'noExtension'\n */\nexport function trimExtName(text: string): string {\n const dotIndex = text.lastIndexOf('.')\n if (dotIndex > 0 && !text.includes('/', dotIndex)) {\n return text.slice(0, dotIndex)\n }\n return text\n}\n","","import fs from 'node:fs'\nimport path from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport type { AdapterOas } from '@kubb/adapter-oas'\nimport pkg from 'handlebars'\n\nconst __filename = fileURLToPath(import.meta.url)\nconst __dirname = path.dirname(__filename)\n\ntype BuildDocsOptions = {\n title?: string\n disableGoogleFont?: boolean\n templateOptions?: any\n}\n\nexport async function getPageHTML(api: AdapterOas['document'], { 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 { trimExtName } from '@internals/utils'\nimport type { AdapterOas } from '@kubb/adapter-oas'\nimport { adapterOasName } from '@kubb/adapter-oas'\nimport { createFile, createSource, createText } from '@kubb/ast'\nimport { type Adapter, createPlugin } from '@kubb/core'\nimport { version } from '../package.json'\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 version,\n options: {\n output,\n name: trimExtName(output.path),\n exclude: [],\n override: [],\n },\n async buildStart() {\n const adapter = this.adapter\n\n if (adapter?.name !== adapterOasName) {\n throw new Error(\n `[${pluginRedocName}] plugin-redoc requires the OpenAPI adapter. Make sure you are using adapterOas (e.g. \\`adapter: adapterOas()\\`) in your Kubb config.`,\n )\n }\n\n const document = (adapter as Adapter<AdapterOas>).document\n\n if (!document) {\n throw new Error(\n `[${pluginRedocName}] No OpenAPI document found. The adapterOas did not produce a document — ensure the adapter has run before this plugin.`,\n )\n }\n\n const root = this.root\n const pageHTML = await getPageHTML(document)\n\n await this.addFile(\n createFile({\n baseName: 'docs.html',\n path: path.resolve(root, output.path || './docs.html'),\n sources: [\n createSource({\n name: 'docs.html',\n nodes: [createText(pageHTML)],\n }),\n ],\n }),\n )\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAyEA,SAAgB,YAAY,MAAsB;CAChD,MAAM,WAAW,KAAK,YAAY,IAAI;AACtC,KAAI,WAAW,KAAK,CAAC,KAAK,SAAS,KAAK,SAAS,CAC/C,QAAO,KAAK,MAAM,GAAG,SAAS;AAEhC,QAAO;;;;;;;AExET,MAAM,aAAa,cAAc,OAAO,KAAK,IAAI;AACjD,MAAM,YAAY,KAAK,QAAQ,WAAW;AAQ1C,eAAsB,YAAY,KAA6B,EAAE,OAAO,mBAAmB,oBAAsC,EAAE,EAAE;CACnI,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,MAAa,kBAAkB;AAE/B,MAAa,cAAc,cAA2B,YAAY;CAChE,MAAM,EAAE,SAAS,EAAE,MAAM,aAAa,KAAK;AAE3C,QAAO;EACL,MAAM;EACN;EACA,SAAS;GACP;GACA,MAAM,YAAY,OAAO,KAAK;GAC9B,SAAS,EAAE;GACX,UAAU,EAAE;GACb;EACD,MAAM,aAAa;GACjB,MAAM,UAAU,KAAK;AAErB,OAAI,SAAS,SAAS,eACpB,OAAM,IAAI,MACR,IAAI,gBAAgB,uIACrB;GAGH,MAAM,WAAY,QAAgC;AAElD,OAAI,CAAC,SACH,OAAM,IAAI,MACR,IAAI,gBAAgB,yHACrB;GAGH,MAAM,OAAO,KAAK;GAClB,MAAM,WAAW,MAAM,YAAY,SAAS;AAE5C,SAAM,KAAK,QACT,WAAW;IACT,UAAU;IACV,MAAM,KAAK,QAAQ,MAAM,OAAO,QAAQ,cAAc;IACtD,SAAS,CACP,aAAa;KACX,MAAM;KACN,OAAO,CAAC,WAAW,SAAS,CAAC;KAC9B,CAAC,CACH;IACF,CAAC,CACH;;EAEJ;EACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-redoc",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.33",
|
|
4
4
|
"description": "Redoc documentation generator plugin for Kubb, creating beautiful, interactive API documentation from OpenAPI specifications.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"redoc",
|
|
@@ -50,16 +50,14 @@
|
|
|
50
50
|
"gzip": true
|
|
51
51
|
}
|
|
52
52
|
],
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@internals/utils": "0.0.0"
|
|
55
|
+
},
|
|
53
56
|
"dependencies": {
|
|
54
|
-
"@kubb/fabric-core": "0.15.1",
|
|
55
|
-
"@kubb/react-fabric": "0.15.1",
|
|
56
57
|
"handlebars": "^4.7.9",
|
|
57
|
-
"@kubb/adapter-oas": "5.0.0-alpha.
|
|
58
|
-
"@kubb/
|
|
59
|
-
|
|
60
|
-
"peerDependencies": {
|
|
61
|
-
"@kubb/fabric-core": "0.15.1",
|
|
62
|
-
"@kubb/react-fabric": "0.15.1"
|
|
58
|
+
"@kubb/adapter-oas": "5.0.0-alpha.33",
|
|
59
|
+
"@kubb/ast": "5.0.0-alpha.33",
|
|
60
|
+
"@kubb/core": "5.0.0-alpha.33"
|
|
63
61
|
},
|
|
64
62
|
"engines": {
|
|
65
63
|
"node": ">=22"
|
package/src/plugin.ts
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
|
+
import { trimExtName } from '@internals/utils'
|
|
2
3
|
import type { AdapterOas } from '@kubb/adapter-oas'
|
|
3
4
|
import { adapterOasName } from '@kubb/adapter-oas'
|
|
5
|
+
import { createFile, createSource, createText } from '@kubb/ast'
|
|
4
6
|
import { type Adapter, createPlugin } from '@kubb/core'
|
|
5
7
|
import { version } from '../package.json'
|
|
6
8
|
import { getPageHTML } from './redoc.tsx'
|
|
7
9
|
import type { PluginRedoc } from './types.ts'
|
|
8
10
|
|
|
9
|
-
function trimExtName(text: string): string {
|
|
10
|
-
return text.replace(/\.[^/.]+$/, '')
|
|
11
|
-
}
|
|
12
|
-
|
|
13
11
|
export const pluginRedocName = 'plugin-redoc' satisfies PluginRedoc['name']
|
|
14
12
|
|
|
15
13
|
export const pluginRedoc = createPlugin<PluginRedoc>((options) => {
|
|
@@ -44,18 +42,18 @@ export const pluginRedoc = createPlugin<PluginRedoc>((options) => {
|
|
|
44
42
|
const root = this.root
|
|
45
43
|
const pageHTML = await getPageHTML(document)
|
|
46
44
|
|
|
47
|
-
await this.addFile(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
45
|
+
await this.addFile(
|
|
46
|
+
createFile({
|
|
47
|
+
baseName: 'docs.html',
|
|
48
|
+
path: path.resolve(root, output.path || './docs.html'),
|
|
49
|
+
sources: [
|
|
50
|
+
createSource({
|
|
51
|
+
name: 'docs.html',
|
|
52
|
+
nodes: [createText(pageHTML)],
|
|
53
|
+
}),
|
|
54
|
+
],
|
|
55
|
+
}),
|
|
56
|
+
)
|
|
59
57
|
},
|
|
60
58
|
}
|
|
61
59
|
})
|