@kubb/plugin-redoc 3.0.0-alpha.1 → 3.0.0-alpha.10
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 +30 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +34 -22
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
- package/src/plugin.ts +7 -17
package/dist/index.cjs
CHANGED
|
@@ -1,17 +1,39 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
3
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
4
|
}) : x)(function(x) {
|
|
4
5
|
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
6
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
7
|
});
|
|
8
|
+
var __esm = (fn, res) => function __init() {
|
|
9
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// ../../node_modules/.pnpm/tsup@8.2.4_@microsoft+api-extractor@7.47.7_@types+node@20.16.2__jiti@1.21.6_postcss@8.4.41_typescript@5.5.4_yaml@2.4.5/node_modules/tsup/assets/cjs_shims.js
|
|
13
|
+
var init_cjs_shims = __esm({
|
|
14
|
+
"../../node_modules/.pnpm/tsup@8.2.4_@microsoft+api-extractor@7.47.7_@types+node@20.16.2__jiti@1.21.6_postcss@8.4.41_typescript@5.5.4_yaml@2.4.5/node_modules/tsup/assets/cjs_shims.js"() {
|
|
15
|
+
"use strict";
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
// src/index.ts
|
|
20
|
+
init_cjs_shims();
|
|
7
21
|
|
|
8
22
|
// src/plugin.ts
|
|
23
|
+
init_cjs_shims();
|
|
9
24
|
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
10
25
|
var _core = require('@kubb/core');
|
|
11
|
-
|
|
26
|
+
require('@kubb/core/transformers');
|
|
12
27
|
var _pluginoas = require('@kubb/plugin-oas');
|
|
13
28
|
|
|
29
|
+
// ../fs/src/index.ts
|
|
30
|
+
init_cjs_shims();
|
|
31
|
+
function trimExtName(text) {
|
|
32
|
+
return text.replace(/\.[^/.]+$/, "");
|
|
33
|
+
}
|
|
34
|
+
|
|
14
35
|
// src/redoc.tsx
|
|
36
|
+
init_cjs_shims();
|
|
15
37
|
var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
|
|
16
38
|
|
|
17
39
|
var _handlebars = require('handlebars'); var _handlebars2 = _interopRequireDefault(_handlebars);
|
|
@@ -69,27 +91,18 @@ var pluginRedoc = _core.createPlugin.call(void 0, (options) => {
|
|
|
69
91
|
const { output = { path: "docs.html" } } = options;
|
|
70
92
|
return {
|
|
71
93
|
name: pluginRedocName,
|
|
94
|
+
output: {
|
|
95
|
+
exportType: "barrelNamed",
|
|
96
|
+
...output
|
|
97
|
+
},
|
|
72
98
|
options: {
|
|
73
|
-
name:
|
|
99
|
+
name: trimExtName(output.path),
|
|
74
100
|
baseURL: void 0
|
|
75
101
|
},
|
|
76
102
|
pre: [_pluginoas.pluginOasName],
|
|
77
|
-
resolvePath(baseName) {
|
|
78
|
-
const root = _path2.default.resolve(this.config.root, this.config.output.path);
|
|
79
|
-
return _path2.default.resolve(root, baseName);
|
|
80
|
-
},
|
|
81
|
-
resolveName(name, type) {
|
|
82
|
-
return _transformers.camelCase.call(void 0, name, { isFile: type === "file" });
|
|
83
|
-
},
|
|
84
|
-
async writeFile(path3, source) {
|
|
85
|
-
if (!path3.endsWith(".ts") || !source) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
return this.fileManager.write(path3, source, { sanity: false });
|
|
89
|
-
},
|
|
90
103
|
async buildStart() {
|
|
91
104
|
const [swaggerPlugin] = _core.PluginManager.getDependedPlugins(this.plugins, [_pluginoas.pluginOasName]);
|
|
92
|
-
const oas = await swaggerPlugin.
|
|
105
|
+
const oas = await swaggerPlugin.context.getOas();
|
|
93
106
|
await oas.dereference();
|
|
94
107
|
const root = _path2.default.resolve(this.config.root, this.config.output.path);
|
|
95
108
|
const pageHTML = await getPageHTML(oas.api);
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/kubb/kubb/packages/plugin-redoc/dist/index.cjs","../src/plugin.ts","../src/redoc.tsx"],"names":["path"],"mappings":"AAAA,6KAAI,UAAU,kBAAkB,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,QAAQ,IAAI,YAAY,EAAE,QAAQ,EAAE,OAAO,MAAM,IAAI,YAAY,EAAE,IAAI,KAAK,CAAC,CAAC,EAAE;AAC/H,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,OAAO,QAAQ,IAAI,YAAY,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC;AACjE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE;AACpB,EAAE,GAAG,CAAC,OAAO,QAAQ,IAAI,WAAW,EAAE,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC;AAC3E,EAAE,MAAM,KAAK,CAAC,uBAAuB,EAAE,EAAE,EAAE,oBAAoB,CAAC;AAChE,CAAC,CAAC;AACF;AACA;
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/kubb/kubb/packages/plugin-redoc/dist/index.cjs","../../../node_modules/.pnpm/tsup@8.2.4_@microsoft+api-extractor@7.47.7_@types+node@20.16.2__jiti@1.21.6_postcss@8.4.41_typescript@5.5.4_yaml@2.4.5/node_modules/tsup/assets/cjs_shims.js","../src/index.ts","../src/plugin.ts","../../fs/src/index.ts","../src/redoc.tsx"],"names":["path"],"mappings":"AAAA,6KAAI,kBAAkB,EAAE,MAAM,CAAC,mBAAmB;AAClD,IAAI,UAAU,kBAAkB,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,QAAQ,IAAI,YAAY,EAAE,QAAQ,EAAE,OAAO,MAAM,IAAI,YAAY,EAAE,IAAI,KAAK,CAAC,CAAC,EAAE;AAC/H,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,OAAO,QAAQ,IAAI,YAAY,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC;AACjE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE;AACpB,EAAE,GAAG,CAAC,OAAO,QAAQ,IAAI,WAAW,EAAE,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC;AAC3E,EAAE,MAAM,KAAK,CAAC,uBAAuB,EAAE,EAAE,EAAE,oBAAoB,CAAC;AAChE,CAAC,CAAC;AACF,IAAI,MAAM,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,SAAS,MAAM,CAAC,EAAE;AAC3C,EAAE,OAAO,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG;AACrE,CAAC;AACD;AACA;ACXA,IAAA,eAAA,EAAA,KAAA,CAAA;AAAA,EAAA,uLAAA,CAAA,EAAA;AAAA,IAAA,YAAA;AAAA,EAAA;AAAA,CAAA,CAAA;ADiBA;AACA;AElBA,cAAA,CAAA,CAAA;AFoBA;AACA;AGrBA,c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","file":"/home/runner/work/kubb/kubb/packages/plugin-redoc/dist/index.cjs","sourcesContent":[null,"// Shim globals in cjs bundle\n// There's a weird bug that esbuild will always inject importMetaUrl\n// if we export it as `const importMetaUrl = ... __filename ...`\n// But using a function will not cause this issue\n\nconst getImportMetaUrl = () =>\n typeof document === 'undefined'\n ? new URL(`file:${__filename}`).href\n : (document.currentScript && document.currentScript.src) ||\n new URL('main.js', document.baseURI).href\n\nexport const importMetaUrl = /* @__PURE__ */ getImportMetaUrl()\n","export { pluginRedoc, pluginRedocName } from './plugin.ts'\nexport type { PluginRedoc } from './types.ts'\n","import path from 'node:path'\n\nimport { PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { pluginOasName } from '@kubb/plugin-oas'\n\nimport type { Plugin } from '@kubb/core'\nimport { trimExtName } from '@kubb/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 output: {\n exportType: 'barrelNamed',\n ...output,\n },\n options: {\n name: trimExtName(output.path),\n baseURL: undefined,\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.fileManager.write(path.resolve(root, output.path || './docs.html'), pageHTML)\n },\n }\n})\n","export { clean } from './clean.ts'\nexport { getRelativePath, read, readSync } from './read.ts'\nexport { write } from './write.ts'\n\nexport function trimExtName(text: string): string {\n return text.replace(/\\.[^/.]+$/, '')\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\nimport type { OasTypes } from '@kubb/oas'\nimport pkg from 'handlebars'\nimport { renderToString } from 'react-dom/server'\nimport { ServerStyleSheet } from 'styled-components'\nimport redoc from 'redoc'\n\ntype BuildDocsOptions = {\n title?: string\n disableGoogleFont?: boolean\n templateOptions?: any\n redocOptions?: any\n}\n\n// see http://www.thespanner.co.uk/2011/07/25/the-json-specification-is-now-wrong/\nfunction escapeClosingScriptTag(str: string): string {\n return str.replace(/<\\/script>/g, '<\\\\/script>')\n}\n\n// see http://www.thespanner.co.uk/2011/07/25/the-json-specification-is-now-wrong/\nfunction escapeUnicode(str: string): string {\n // biome-ignore lint/style/useTemplate: <explanation>\n return str.replace(/\\u2028|\\u2029/g, (m) => '\\\\u202' + (m === '\\u2028' ? '8' : '9'))\n}\n\nfunction sanitizeJSONString(str: string): string {\n return escapeClosingScriptTag(escapeUnicode(str))\n}\n\nexport async function getPageHTML(api: OasTypes.OASDocument, { title, disableGoogleFont, templateOptions, redocOptions = {} }: BuildDocsOptions = {}) {\n const apiUrl = redocOptions.specUrl\n const { Redoc, createStore } = redoc || require('redoc')\n const store = await createStore(api, apiUrl, redocOptions)\n const sheet = new ServerStyleSheet()\n\n const error = console.error\n console.error = (...args: any) => {\n if (/defaultProps/.test(args[0])) return\n error(...args)\n }\n\n const html = renderToString(sheet.collectStyles(<Redoc store={store} />))\n const state = await store.toJS()\n const css = sheet.getStyleTags()\n\n const templateFileName = path.join(__dirname, '../static/redoc.hbs')\n const template = pkg.compile(fs.readFileSync(templateFileName).toString())\n return template({\n redocHTML: `\n <div id=\"redoc\">${html || ''}</div>\n <script>\n ${`const __redoc_state = ${sanitizeJSONString(JSON.stringify(state))};` || ''}\n\n var container = document.getElementById('redoc');\n Redoc.${'hydrate(__redoc_state, container)'};\n\n </script>`,\n redocHead:\n // biome-ignore lint/style/useTemplate: <explanation>\n `<script src=\"https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js\"></script>` + css,\n title: title || api.info.title || 'ReDoc documentation',\n disableGoogleFont,\n templateOptions,\n })\n}\n"]}
|
package/dist/index.js
CHANGED
|
@@ -1,26 +1,47 @@
|
|
|
1
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
1
2
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
3
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
4
|
}) : x)(function(x) {
|
|
4
5
|
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
6
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
7
|
});
|
|
8
|
+
var __esm = (fn, res) => function __init() {
|
|
9
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
|
+
};
|
|
7
11
|
|
|
8
|
-
// ../../node_modules/.pnpm/tsup@8.2.4_@microsoft+api-extractor@7.47.7_@types+node@20.16.
|
|
12
|
+
// ../../node_modules/.pnpm/tsup@8.2.4_@microsoft+api-extractor@7.47.7_@types+node@20.16.2__jiti@1.21.6_postcss@8.4.41_typescript@5.5.4_yaml@2.4.5/node_modules/tsup/assets/esm_shims.js
|
|
9
13
|
import { fileURLToPath } from "url";
|
|
10
14
|
import path from "path";
|
|
11
|
-
var getFilename
|
|
12
|
-
var
|
|
13
|
-
|
|
15
|
+
var getFilename, getDirname, __dirname;
|
|
16
|
+
var init_esm_shims = __esm({
|
|
17
|
+
"../../node_modules/.pnpm/tsup@8.2.4_@microsoft+api-extractor@7.47.7_@types+node@20.16.2__jiti@1.21.6_postcss@8.4.41_typescript@5.5.4_yaml@2.4.5/node_modules/tsup/assets/esm_shims.js"() {
|
|
18
|
+
"use strict";
|
|
19
|
+
getFilename = () => fileURLToPath(import.meta.url);
|
|
20
|
+
getDirname = () => path.dirname(getFilename());
|
|
21
|
+
__dirname = /* @__PURE__ */ getDirname();
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// src/index.ts
|
|
26
|
+
init_esm_shims();
|
|
14
27
|
|
|
15
28
|
// src/plugin.ts
|
|
16
|
-
|
|
29
|
+
init_esm_shims();
|
|
30
|
+
import path3 from "node:path";
|
|
17
31
|
import { PluginManager, createPlugin } from "@kubb/core";
|
|
18
|
-
import
|
|
32
|
+
import "@kubb/core/transformers";
|
|
19
33
|
import { pluginOasName } from "@kubb/plugin-oas";
|
|
20
34
|
|
|
35
|
+
// ../fs/src/index.ts
|
|
36
|
+
init_esm_shims();
|
|
37
|
+
function trimExtName(text) {
|
|
38
|
+
return text.replace(/\.[^/.]+$/, "");
|
|
39
|
+
}
|
|
40
|
+
|
|
21
41
|
// src/redoc.tsx
|
|
22
|
-
|
|
23
|
-
import
|
|
42
|
+
init_esm_shims();
|
|
43
|
+
import fs from "node:fs";
|
|
44
|
+
import path2 from "node:path";
|
|
24
45
|
import pkg from "handlebars";
|
|
25
46
|
import { renderToString } from "react-dom/server";
|
|
26
47
|
import { ServerStyleSheet } from "styled-components";
|
|
@@ -76,27 +97,18 @@ var pluginRedoc = createPlugin((options) => {
|
|
|
76
97
|
const { output = { path: "docs.html" } } = options;
|
|
77
98
|
return {
|
|
78
99
|
name: pluginRedocName,
|
|
100
|
+
output: {
|
|
101
|
+
exportType: "barrelNamed",
|
|
102
|
+
...output
|
|
103
|
+
},
|
|
79
104
|
options: {
|
|
80
105
|
name: trimExtName(output.path),
|
|
81
106
|
baseURL: void 0
|
|
82
107
|
},
|
|
83
108
|
pre: [pluginOasName],
|
|
84
|
-
resolvePath(baseName) {
|
|
85
|
-
const root = path3.resolve(this.config.root, this.config.output.path);
|
|
86
|
-
return path3.resolve(root, baseName);
|
|
87
|
-
},
|
|
88
|
-
resolveName(name, type) {
|
|
89
|
-
return camelCase(name, { isFile: type === "file" });
|
|
90
|
-
},
|
|
91
|
-
async writeFile(path4, source) {
|
|
92
|
-
if (!path4.endsWith(".ts") || !source) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
return this.fileManager.write(path4, source, { sanity: false });
|
|
96
|
-
},
|
|
97
109
|
async buildStart() {
|
|
98
110
|
const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
|
|
99
|
-
const oas = await swaggerPlugin.
|
|
111
|
+
const oas = await swaggerPlugin.context.getOas();
|
|
100
112
|
await oas.dereference();
|
|
101
113
|
const root = path3.resolve(this.config.root, this.config.output.path);
|
|
102
114
|
const pageHTML = await getPageHTML(oas.api);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../node_modules/.pnpm/tsup@8.2.4_@microsoft+api-extractor@7.47.7_@types+node@20.16.
|
|
1
|
+
{"version":3,"sources":["../../../node_modules/.pnpm/tsup@8.2.4_@microsoft+api-extractor@7.47.7_@types+node@20.16.2__jiti@1.21.6_postcss@8.4.41_typescript@5.5.4_yaml@2.4.5/node_modules/tsup/assets/esm_shims.js","../src/index.ts","../src/plugin.ts","../../fs/src/index.ts","../src/redoc.tsx"],"sourcesContent":["// Shim globals in esm bundle\nimport { fileURLToPath } from 'url'\nimport path from 'path'\n\nconst getFilename = () => fileURLToPath(import.meta.url)\nconst getDirname = () => path.dirname(getFilename())\n\nexport const __dirname = /* @__PURE__ */ getDirname()\nexport const __filename = /* @__PURE__ */ getFilename()\n","export { pluginRedoc, pluginRedocName } from './plugin.ts'\nexport type { PluginRedoc } from './types.ts'\n","import path from 'node:path'\n\nimport { PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { pluginOasName } from '@kubb/plugin-oas'\n\nimport type { Plugin } from '@kubb/core'\nimport { trimExtName } from '@kubb/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 output: {\n exportType: 'barrelNamed',\n ...output,\n },\n options: {\n name: trimExtName(output.path),\n baseURL: undefined,\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.fileManager.write(path.resolve(root, output.path || './docs.html'), pageHTML)\n },\n }\n})\n","export { clean } from './clean.ts'\nexport { getRelativePath, read, readSync } from './read.ts'\nexport { write } from './write.ts'\n\nexport function trimExtName(text: string): string {\n return text.replace(/\\.[^/.]+$/, '')\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\nimport type { OasTypes } from '@kubb/oas'\nimport pkg from 'handlebars'\nimport { renderToString } from 'react-dom/server'\nimport { ServerStyleSheet } from 'styled-components'\nimport redoc from 'redoc'\n\ntype BuildDocsOptions = {\n title?: string\n disableGoogleFont?: boolean\n templateOptions?: any\n redocOptions?: any\n}\n\n// see http://www.thespanner.co.uk/2011/07/25/the-json-specification-is-now-wrong/\nfunction escapeClosingScriptTag(str: string): string {\n return str.replace(/<\\/script>/g, '<\\\\/script>')\n}\n\n// see http://www.thespanner.co.uk/2011/07/25/the-json-specification-is-now-wrong/\nfunction escapeUnicode(str: string): string {\n // biome-ignore lint/style/useTemplate: <explanation>\n return str.replace(/\\u2028|\\u2029/g, (m) => '\\\\u202' + (m === '\\u2028' ? '8' : '9'))\n}\n\nfunction sanitizeJSONString(str: string): string {\n return escapeClosingScriptTag(escapeUnicode(str))\n}\n\nexport async function getPageHTML(api: OasTypes.OASDocument, { title, disableGoogleFont, templateOptions, redocOptions = {} }: BuildDocsOptions = {}) {\n const apiUrl = redocOptions.specUrl\n const { Redoc, createStore } = redoc || require('redoc')\n const store = await createStore(api, apiUrl, redocOptions)\n const sheet = new ServerStyleSheet()\n\n const error = console.error\n console.error = (...args: any) => {\n if (/defaultProps/.test(args[0])) return\n error(...args)\n }\n\n const html = renderToString(sheet.collectStyles(<Redoc store={store} />))\n const state = await store.toJS()\n const css = sheet.getStyleTags()\n\n const templateFileName = path.join(__dirname, '../static/redoc.hbs')\n const template = pkg.compile(fs.readFileSync(templateFileName).toString())\n return template({\n redocHTML: `\n <div id=\"redoc\">${html || ''}</div>\n <script>\n ${`const __redoc_state = ${sanitizeJSONString(JSON.stringify(state))};` || ''}\n\n var container = document.getElementById('redoc');\n Redoc.${'hydrate(__redoc_state, container)'};\n\n </script>`,\n redocHead:\n // biome-ignore lint/style/useTemplate: <explanation>\n `<script src=\"https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js\"></script>` + css,\n title: title || api.info.title || 'ReDoc documentation',\n disableGoogleFont,\n templateOptions,\n })\n}\n"],"mappings":";;;;;;;;;;;;AACA,SAAS,qBAAqB;AAC9B,OAAO,UAAU;AAFjB,IAIM,aACA,YAEO;AAPb;AAAA;AAAA;AAIA,IAAM,cAAc,MAAM,cAAc,YAAY,GAAG;AACvD,IAAM,aAAa,MAAM,KAAK,QAAQ,YAAY,CAAC;AAE5C,IAAM,YAA4B,2BAAW;AAAA;AAAA;;;ACPpD;;;ACAA;AAAA,OAAOA,WAAU;AAEjB,SAAS,eAAe,oBAAoB;AAC5C,OAA0B;AAC1B,SAAS,qBAAqB;;;ACJ9B;AAIO,SAAS,YAAY,MAAsB;AAChD,SAAO,KAAK,QAAQ,aAAa,EAAE;AACrC;;;ACNA;AAAA,OAAO,QAAQ;AACf,OAAOC,WAAU;AAEjB,OAAO,SAAS;AAChB,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AACjC,OAAO,WAAW;AAoCgC;AA1BlD,SAAS,uBAAuB,KAAqB;AACnD,SAAO,IAAI,QAAQ,eAAe,aAAa;AACjD;AAGA,SAAS,cAAc,KAAqB;AAE1C,SAAO,IAAI,QAAQ,kBAAkB,CAAC,MAAM,YAAY,M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,QAAQ;AAAA,MACN,YAAY;AAAA,MACZ,GAAG;AAAA,IACL;AAAA,IACA,SAAS;AAAA,MACP,MAAM,YAAY,OAAO,IAAI;AAAA,MAC7B,SAAS;AAAA,IACX;AAAA,IACA,KAAK,CAAC,aAAa;AAAA,IACnB,MAAM,aAAa;AACjB,YAAM,CAAC,aAAa,IAAyB,cAAc,mBAA8B,KAAK,SAAS,CAAC,aAAa,CAAC;AACtH,YAAM,MAAM,MAAM,cAAc,QAAQ,OAAO;AAE/C,YAAM,IAAI,YAAY;AAEtB,YAAM,OAAOC,MAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,IAAI;AACnE,YAAM,WAAW,MAAM,YAAY,IAAI,GAAG;AAE1C,YAAM,KAAK,YAAY,MAAMA,MAAK,QAAQ,MAAM,OAAO,QAAQ,aAAa,GAAG,QAAQ;AAAA,IACzF;AAAA,EACF;AACF,CAAC;","names":["path","path","path"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-redoc",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.10",
|
|
4
4
|
"description": "Beautiful docs with Redoc",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -46,22 +46,22 @@
|
|
|
46
46
|
"react": "^18.3.1",
|
|
47
47
|
"react-dom": "^18.3.1",
|
|
48
48
|
"redoc": "^2.1.5",
|
|
49
|
-
"styled-components": "^6.1.
|
|
50
|
-
"@kubb/core": "3.0.0-alpha.
|
|
51
|
-
"@kubb/oas": "3.0.0-alpha.
|
|
52
|
-
"@kubb/plugin-oas": "3.0.0-alpha.
|
|
49
|
+
"styled-components": "^6.1.13",
|
|
50
|
+
"@kubb/core": "3.0.0-alpha.10",
|
|
51
|
+
"@kubb/oas": "3.0.0-alpha.10",
|
|
52
|
+
"@kubb/plugin-oas": "3.0.0-alpha.10"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@types/react": "^18.3.
|
|
55
|
+
"@types/react": "^18.3.5",
|
|
56
56
|
"@types/react-dom": "^18.3.0",
|
|
57
57
|
"tsup": "^8.2.4",
|
|
58
58
|
"typescript": "^5.5.4",
|
|
59
|
-
"@kubb/config-biome": "3.0.0-alpha.
|
|
60
|
-
"@kubb/config-ts": "3.0.0-alpha.
|
|
61
|
-
"@kubb/config-tsup": "3.0.0-alpha.
|
|
59
|
+
"@kubb/config-biome": "3.0.0-alpha.10",
|
|
60
|
+
"@kubb/config-ts": "3.0.0-alpha.10",
|
|
61
|
+
"@kubb/config-tsup": "3.0.0-alpha.10"
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
64
|
-
"@kubb/react": "3.0.0-alpha.
|
|
64
|
+
"@kubb/react": "3.0.0-alpha.10"
|
|
65
65
|
},
|
|
66
66
|
"engines": {
|
|
67
67
|
"node": ">=20"
|
package/src/plugin.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
2
|
|
|
3
3
|
import { PluginManager, createPlugin } from '@kubb/core'
|
|
4
|
-
import { camelCase
|
|
4
|
+
import { camelCase } from '@kubb/core/transformers'
|
|
5
5
|
import { pluginOasName } from '@kubb/plugin-oas'
|
|
6
6
|
|
|
7
7
|
import type { Plugin } from '@kubb/core'
|
|
8
|
+
import { trimExtName } from '@kubb/fs'
|
|
8
9
|
import type { PluginOas } from '@kubb/plugin-oas'
|
|
9
10
|
import { getPageHTML } from './redoc.tsx'
|
|
10
11
|
import type { PluginRedoc } from './types.ts'
|
|
@@ -16,29 +17,18 @@ export const pluginRedoc = createPlugin<PluginRedoc>((options) => {
|
|
|
16
17
|
|
|
17
18
|
return {
|
|
18
19
|
name: pluginRedocName,
|
|
20
|
+
output: {
|
|
21
|
+
exportType: 'barrelNamed',
|
|
22
|
+
...output,
|
|
23
|
+
},
|
|
19
24
|
options: {
|
|
20
25
|
name: trimExtName(output.path),
|
|
21
26
|
baseURL: undefined,
|
|
22
27
|
},
|
|
23
28
|
pre: [pluginOasName],
|
|
24
|
-
resolvePath(baseName) {
|
|
25
|
-
const root = path.resolve(this.config.root, this.config.output.path)
|
|
26
|
-
|
|
27
|
-
return path.resolve(root, baseName)
|
|
28
|
-
},
|
|
29
|
-
resolveName(name, type) {
|
|
30
|
-
return camelCase(name, { isFile: type === 'file' })
|
|
31
|
-
},
|
|
32
|
-
async writeFile(path, source) {
|
|
33
|
-
if (!path.endsWith('.ts') || !source) {
|
|
34
|
-
return
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return this.fileManager.write(path, source, { sanity: false })
|
|
38
|
-
},
|
|
39
29
|
async buildStart() {
|
|
40
30
|
const [swaggerPlugin]: [Plugin<PluginOas>] = PluginManager.getDependedPlugins<PluginOas>(this.plugins, [pluginOasName])
|
|
41
|
-
const oas = await swaggerPlugin.
|
|
31
|
+
const oas = await swaggerPlugin.context.getOas()
|
|
42
32
|
|
|
43
33
|
await oas.dereference()
|
|
44
34
|
|