@kubb/plugin-redoc 3.0.0-alpha.10 → 3.0.0-alpha.12
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 +36 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +18 -22
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var path2 = require('path');
|
|
4
|
+
var core = require('@kubb/core');
|
|
5
|
+
require('@kubb/core/transformers');
|
|
6
|
+
var pluginOas = require('@kubb/plugin-oas');
|
|
7
|
+
var fs = require('fs');
|
|
8
|
+
var pkg = require('handlebars');
|
|
9
|
+
var server = require('react-dom/server');
|
|
10
|
+
var styledComponents = require('styled-components');
|
|
11
|
+
var redoc = require('redoc');
|
|
12
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
13
|
+
|
|
14
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
+
|
|
16
|
+
var path2__default = /*#__PURE__*/_interopDefault(path2);
|
|
17
|
+
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
18
|
+
var pkg__default = /*#__PURE__*/_interopDefault(pkg);
|
|
19
|
+
var redoc__default = /*#__PURE__*/_interopDefault(redoc);
|
|
20
|
+
|
|
21
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
22
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
3
23
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
4
24
|
}) : x)(function(x) {
|
|
@@ -9,10 +29,9 @@ var __esm = (fn, res) => function __init() {
|
|
|
9
29
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
30
|
};
|
|
11
31
|
|
|
12
|
-
// ../../node_modules/.pnpm/tsup@8.2.4_@microsoft+api-extractor@7.47.7_@types+node@20.16.
|
|
32
|
+
// ../../node_modules/.pnpm/tsup@8.2.4_@microsoft+api-extractor@7.47.7_@types+node@20.16.2__@swc+core@1.7.22_jiti@1.21.6__vls2oipdlkyfowb7gcil3cs6ye/node_modules/tsup/assets/cjs_shims.js
|
|
13
33
|
var init_cjs_shims = __esm({
|
|
14
|
-
"../../node_modules/.pnpm/tsup@8.2.4_@microsoft+api-extractor@7.47.7_@types+node@20.16.
|
|
15
|
-
"use strict";
|
|
34
|
+
"../../node_modules/.pnpm/tsup@8.2.4_@microsoft+api-extractor@7.47.7_@types+node@20.16.2__@swc+core@1.7.22_jiti@1.21.6__vls2oipdlkyfowb7gcil3cs6ye/node_modules/tsup/assets/cjs_shims.js"() {
|
|
16
35
|
}
|
|
17
36
|
});
|
|
18
37
|
|
|
@@ -21,10 +40,6 @@ init_cjs_shims();
|
|
|
21
40
|
|
|
22
41
|
// src/plugin.ts
|
|
23
42
|
init_cjs_shims();
|
|
24
|
-
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
25
|
-
var _core = require('@kubb/core');
|
|
26
|
-
require('@kubb/core/transformers');
|
|
27
|
-
var _pluginoas = require('@kubb/plugin-oas');
|
|
28
43
|
|
|
29
44
|
// ../fs/src/index.ts
|
|
30
45
|
init_cjs_shims();
|
|
@@ -34,13 +49,6 @@ function trimExtName(text) {
|
|
|
34
49
|
|
|
35
50
|
// src/redoc.tsx
|
|
36
51
|
init_cjs_shims();
|
|
37
|
-
var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
|
|
38
|
-
|
|
39
|
-
var _handlebars = require('handlebars'); var _handlebars2 = _interopRequireDefault(_handlebars);
|
|
40
|
-
var _server = require('react-dom/server');
|
|
41
|
-
var _styledcomponents = require('styled-components');
|
|
42
|
-
var _redoc = require('redoc'); var _redoc2 = _interopRequireDefault(_redoc);
|
|
43
|
-
var _jsxruntime = require('react/jsx-runtime');
|
|
44
52
|
function escapeClosingScriptTag(str) {
|
|
45
53
|
return str.replace(/<\/script>/g, "<\\/script>");
|
|
46
54
|
}
|
|
@@ -52,19 +60,19 @@ function sanitizeJSONString(str) {
|
|
|
52
60
|
}
|
|
53
61
|
async function getPageHTML(api, { title, disableGoogleFont, templateOptions, redocOptions = {} } = {}) {
|
|
54
62
|
const apiUrl = redocOptions.specUrl;
|
|
55
|
-
const { Redoc, createStore } =
|
|
63
|
+
const { Redoc, createStore } = redoc__default.default || __require("redoc");
|
|
56
64
|
const store = await createStore(api, apiUrl, redocOptions);
|
|
57
|
-
const sheet = new
|
|
65
|
+
const sheet = new styledComponents.ServerStyleSheet();
|
|
58
66
|
const error = console.error;
|
|
59
67
|
console.error = (...args) => {
|
|
60
68
|
if (/defaultProps/.test(args[0])) return;
|
|
61
69
|
error(...args);
|
|
62
70
|
};
|
|
63
|
-
const html =
|
|
71
|
+
const html = server.renderToString(sheet.collectStyles(/* @__PURE__ */ jsxRuntime.jsx(Redoc, { store })));
|
|
64
72
|
const state = await store.toJS();
|
|
65
73
|
const css = sheet.getStyleTags();
|
|
66
|
-
const templateFileName =
|
|
67
|
-
const template =
|
|
74
|
+
const templateFileName = path2__default.default.join(__dirname, "../static/redoc.hbs");
|
|
75
|
+
const template = pkg__default.default.compile(fs__default.default.readFileSync(templateFileName).toString());
|
|
68
76
|
return template({
|
|
69
77
|
redocHTML: `
|
|
70
78
|
<div id="redoc">${html || ""}</div>
|
|
@@ -87,7 +95,7 @@ async function getPageHTML(api, { title, disableGoogleFont, templateOptions, red
|
|
|
87
95
|
|
|
88
96
|
// src/plugin.ts
|
|
89
97
|
var pluginRedocName = "plugin-redoc";
|
|
90
|
-
var pluginRedoc =
|
|
98
|
+
var pluginRedoc = core.createPlugin((options) => {
|
|
91
99
|
const { output = { path: "docs.html" } } = options;
|
|
92
100
|
return {
|
|
93
101
|
name: pluginRedocName,
|
|
@@ -99,19 +107,19 @@ var pluginRedoc = _core.createPlugin.call(void 0, (options) => {
|
|
|
99
107
|
name: trimExtName(output.path),
|
|
100
108
|
baseURL: void 0
|
|
101
109
|
},
|
|
102
|
-
pre: [
|
|
110
|
+
pre: [pluginOas.pluginOasName],
|
|
103
111
|
async buildStart() {
|
|
104
|
-
const [swaggerPlugin] =
|
|
112
|
+
const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]);
|
|
105
113
|
const oas = await swaggerPlugin.context.getOas();
|
|
106
114
|
await oas.dereference();
|
|
107
|
-
const root =
|
|
115
|
+
const root = path2__default.default.resolve(this.config.root, this.config.output.path);
|
|
108
116
|
const pageHTML = await getPageHTML(oas.api);
|
|
109
|
-
await this.fileManager.write(
|
|
117
|
+
await this.fileManager.write(path2__default.default.resolve(root, output.path || "./docs.html"), pageHTML);
|
|
110
118
|
}
|
|
111
119
|
};
|
|
112
120
|
});
|
|
113
121
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
122
|
+
exports.pluginRedoc = pluginRedoc;
|
|
123
|
+
exports.pluginRedocName = pluginRedocName;
|
|
124
|
+
//# sourceMappingURL=index.cjs.map
|
|
117
125
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["
|
|
1
|
+
{"version":3,"sources":["../../../node_modules/.pnpm/tsup@8.2.4_@microsoft+api-extractor@7.47.7_@types+node@20.16.2__@swc+core@1.7.22_jiti@1.21.6__vls2oipdlkyfowb7gcil3cs6ye/node_modules/tsup/assets/cjs_shims.js","../src/index.ts","../src/plugin.ts","../../fs/src/index.ts","../src/redoc.tsx"],"names":["redoc","ServerStyleSheet","renderToString","path","pkg","fs","createPlugin","pluginOasName","PluginManager"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAA,cAAA,GAAA,KAAA,CAAA;AAAA,EAAA,yLAAA,GAAA;AAAA,GAAA;AAAA,CAAA,CAAA,CAAA;;;ACAA,c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,IACL,IAAM,EAAA,eAAA;AAAA,IACN,MAAQ,EAAA;AAAA,MACN,UAAY,EAAA,aAAA;AAAA,MACZ,GAAG,MAAA;AAAA,KACL;AAAA,IACA,OAAS,EAAA;AAAA,MACP,IAAA,EAAM,WAAY,CAAA,MAAA,CAAO,IAAI,CAAA;AAAA,MAC7B,OAAS,EAAA,KAAA,CAAA;AAAA,KACX;AAAA,IACA,GAAA,EAAK,CAACC,uBAAa,CAAA;AAAA,IACnB,MAAM,UAAa,GAAA;AACjB,MAAM,MAAA,CAAC,aAAa,CAAyB,GAAAC,kBAAA,CAAc,mBAA8B,IAAK,CAAA,OAAA,EAAS,CAACD,uBAAa,CAAC,CAAA,CAAA;AACtH,MAAA,MAAM,GAAM,GAAA,MAAM,aAAc,CAAA,OAAA,CAAQ,MAAO,EAAA,CAAA;AAE/C,MAAA,MAAM,IAAI,WAAY,EAAA,CAAA;AAEtB,MAAM,MAAA,IAAA,GAAOJ,uBAAK,OAAQ,CAAA,IAAA,CAAK,OAAO,IAAM,EAAA,IAAA,CAAK,MAAO,CAAA,MAAA,CAAO,IAAI,CAAA,CAAA;AACnE,MAAA,MAAM,QAAW,GAAA,MAAM,WAAY,CAAA,GAAA,CAAI,GAAG,CAAA,CAAA;AAE1C,MAAM,MAAA,IAAA,CAAK,WAAY,CAAA,KAAA,CAAMA,sBAAK,CAAA,OAAA,CAAQ,MAAM,MAAO,CAAA,IAAA,IAAQ,aAAa,CAAA,EAAG,QAAQ,CAAA,CAAA;AAAA,KACzF;AAAA,GACF,CAAA;AACF,CAAC","file":"index.cjs","sourcesContent":["// 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,3 +1,16 @@
|
|
|
1
|
+
import { fileURLToPath } from 'url';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import path3 from 'node:path';
|
|
4
|
+
import { createPlugin, PluginManager } from '@kubb/core';
|
|
5
|
+
import '@kubb/core/transformers';
|
|
6
|
+
import { pluginOasName } from '@kubb/plugin-oas';
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import pkg from 'handlebars';
|
|
9
|
+
import { renderToString } from 'react-dom/server';
|
|
10
|
+
import { ServerStyleSheet } from 'styled-components';
|
|
11
|
+
import redoc from 'redoc';
|
|
12
|
+
import { jsx } from 'react/jsx-runtime';
|
|
13
|
+
|
|
1
14
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
15
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
3
16
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
@@ -8,14 +21,9 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
8
21
|
var __esm = (fn, res) => function __init() {
|
|
9
22
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
23
|
};
|
|
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/esm_shims.js
|
|
13
|
-
import { fileURLToPath } from "url";
|
|
14
|
-
import path from "path";
|
|
15
24
|
var getFilename, getDirname, __dirname;
|
|
16
25
|
var init_esm_shims = __esm({
|
|
17
|
-
"../../node_modules/.pnpm/tsup@8.2.4_@microsoft+api-extractor@7.47.7_@types+node@20.16.
|
|
18
|
-
"use strict";
|
|
26
|
+
"../../node_modules/.pnpm/tsup@8.2.4_@microsoft+api-extractor@7.47.7_@types+node@20.16.2__@swc+core@1.7.22_jiti@1.21.6__vls2oipdlkyfowb7gcil3cs6ye/node_modules/tsup/assets/esm_shims.js"() {
|
|
19
27
|
getFilename = () => fileURLToPath(import.meta.url);
|
|
20
28
|
getDirname = () => path.dirname(getFilename());
|
|
21
29
|
__dirname = /* @__PURE__ */ getDirname();
|
|
@@ -27,10 +35,6 @@ init_esm_shims();
|
|
|
27
35
|
|
|
28
36
|
// src/plugin.ts
|
|
29
37
|
init_esm_shims();
|
|
30
|
-
import path3 from "node:path";
|
|
31
|
-
import { PluginManager, createPlugin } from "@kubb/core";
|
|
32
|
-
import "@kubb/core/transformers";
|
|
33
|
-
import { pluginOasName } from "@kubb/plugin-oas";
|
|
34
38
|
|
|
35
39
|
// ../fs/src/index.ts
|
|
36
40
|
init_esm_shims();
|
|
@@ -40,13 +44,6 @@ function trimExtName(text) {
|
|
|
40
44
|
|
|
41
45
|
// src/redoc.tsx
|
|
42
46
|
init_esm_shims();
|
|
43
|
-
import fs from "node:fs";
|
|
44
|
-
import path2 from "node:path";
|
|
45
|
-
import pkg from "handlebars";
|
|
46
|
-
import { renderToString } from "react-dom/server";
|
|
47
|
-
import { ServerStyleSheet } from "styled-components";
|
|
48
|
-
import redoc from "redoc";
|
|
49
|
-
import { jsx } from "react/jsx-runtime";
|
|
50
47
|
function escapeClosingScriptTag(str) {
|
|
51
48
|
return str.replace(/<\/script>/g, "<\\/script>");
|
|
52
49
|
}
|
|
@@ -69,7 +66,7 @@ async function getPageHTML(api, { title, disableGoogleFont, templateOptions, red
|
|
|
69
66
|
const html = renderToString(sheet.collectStyles(/* @__PURE__ */ jsx(Redoc, { store })));
|
|
70
67
|
const state = await store.toJS();
|
|
71
68
|
const css = sheet.getStyleTags();
|
|
72
|
-
const templateFileName =
|
|
69
|
+
const templateFileName = path3.join(__dirname, "../static/redoc.hbs");
|
|
73
70
|
const template = pkg.compile(fs.readFileSync(templateFileName).toString());
|
|
74
71
|
return template({
|
|
75
72
|
redocHTML: `
|
|
@@ -116,8 +113,7 @@ var pluginRedoc = createPlugin((options) => {
|
|
|
116
113
|
}
|
|
117
114
|
};
|
|
118
115
|
});
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
};
|
|
116
|
+
|
|
117
|
+
export { pluginRedoc, pluginRedocName };
|
|
118
|
+
//# sourceMappingURL=index.js.map
|
|
123
119
|
//# sourceMappingURL=index.js.map
|
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__@swc+core@1.7.22_jiti@1.21.6__vls2oipdlkyfowb7gcil3cs6ye/node_modules/tsup/assets/esm_shims.js","../src/index.ts","../src/plugin.ts","../../fs/src/index.ts","../src/redoc.tsx"],"names":["path"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,IAIM,aACA,UAEO,EAAA,SAAA,CAAA;AAPb,IAAA,cAAA,GAAA,KAAA,CAAA;AAAA,EAAA,yLAAA,GAAA;AAIA,IAAM,WAAc,GAAA,MAAM,aAAc,CAAA,MAAA,CAAA,IAAA,CAAY,GAAG,CAAA,CAAA;AACvD,IAAM,UAAa,GAAA,MAAM,IAAK,CAAA,OAAA,CAAQ,aAAa,CAAA,CAAA;AAE5C,IAAM,4BAAuC,UAAA,EAAA,CAAA;AAAA,GAAA;AAAA,CAAA,CAAA,CAAA;;;ACPpD,cAAA,EAAA,CAAA;;;ACAA,cAAA,EAAA,CAAA;;;ACAA,cAAA,EAAA,CAAA;AAIO,SAAS,YAAY,IAAsB,EAAA;AAChD,EAAO,OAAA,IAAA,CAAK,OAAQ,CAAA,WAAA,EAAa,EAAE,CAAA,CAAA;AACrC,CAAA;;;ACNA,cAAA,EAAA,CAAA;AAgBA,SAAS,uBAAuB,GAAqB,EAAA;AACnD,EAAO,OAAA,GAAA,CAAI,OAAQ,CAAA,aAAA,EAAe,aAAa,CAAA,CAAA;AACjD,CAAA;AAGA,SAAS,cAAc,GAAqB,EAAA;AAE1C,EAAO,OAAA,GAAA,CAAI,QAAQ,gBAAkB,EAAA,CAAC,MAAM,QAAY,IAAA,CAAA,KAAM,QAAW,GAAA,GAAA,GAAM,GAAI,CAAA,CAAA,CAAA;AACrF,CAAA;AAEA,SAA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WAAY,EAAA,CAAA;AAEtB,MAAM,MAAA,IAAA,GAAOA,MAAK,OAAQ,CAAA,IAAA,CAAK,OAAO,IAAM,EAAA,IAAA,CAAK,MAAO,CAAA,MAAA,CAAO,IAAI,CAAA,CAAA;AACnE,MAAA,MAAM,QAAW,GAAA,MAAM,WAAY,CAAA,GAAA,CAAI,GAAG,CAAA,CAAA;AAE1C,MAAM,MAAA,IAAA,CAAK,WAAY,CAAA,KAAA,CAAMA,KAAK,CAAA,OAAA,CAAQ,MAAM,MAAO,CAAA,IAAA,IAAQ,aAAa,CAAA,EAAG,QAAQ,CAAA,CAAA;AAAA,KACzF;AAAA,GACF,CAAA;AACF,CAAC","file":"index.js","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"]}
|
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.12",
|
|
4
4
|
"description": "Beautiful docs with Redoc",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -47,21 +47,21 @@
|
|
|
47
47
|
"react-dom": "^18.3.1",
|
|
48
48
|
"redoc": "^2.1.5",
|
|
49
49
|
"styled-components": "^6.1.13",
|
|
50
|
-
"@kubb/core": "3.0.0-alpha.
|
|
51
|
-
"@kubb/oas": "3.0.0-alpha.
|
|
52
|
-
"@kubb/plugin-oas": "3.0.0-alpha.
|
|
50
|
+
"@kubb/core": "3.0.0-alpha.12",
|
|
51
|
+
"@kubb/oas": "3.0.0-alpha.12",
|
|
52
|
+
"@kubb/plugin-oas": "3.0.0-alpha.12"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
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.12",
|
|
60
|
+
"@kubb/config-ts": "3.0.0-alpha.12",
|
|
61
|
+
"@kubb/config-tsup": "3.0.0-alpha.12"
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
64
|
-
"@kubb/react": "3.0.0-alpha.
|
|
64
|
+
"@kubb/react": "3.0.0-alpha.12"
|
|
65
65
|
},
|
|
66
66
|
"engines": {
|
|
67
67
|
"node": ">=20"
|