@kubb/plugin-redoc 0.0.0-canary-20240509211223

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Stijn Van Hulle
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,44 @@
1
+ <div align="center">
2
+
3
+ <!-- <img src="assets/logo.png" alt="logo" width="200" height="auto" /> -->
4
+ <h1>@kubb/plugin-redoc</h1>
5
+
6
+ <p>
7
+ Create beautiful docs with Redoc.
8
+ </p>
9
+ <img src="https://raw.githubusercontent.com/kubb-labs/kubb/main/assets/banner.png" alt="logo" height="auto" />
10
+
11
+ [![npm version][npm-version-src]][npm-version-href]
12
+ [![npm downloads][npm-downloads-src]][npm-downloads-href]
13
+ [![Coverage][coverage-src]][coverage-href]
14
+ [![License][license-src]][license-href]
15
+
16
+ <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
17
+ <!-- ALL-CONTRIBUTORS-BADGE:END -->
18
+ </p>
19
+
20
+ <h4>
21
+ <a href="https://codesandbox.io/s/github/kubb-labs/kubb/tree/alpha/examples/typescript" target="_blank">View Demo</a>
22
+ <span> · </span>
23
+ <a href="https://kubb.dev/" target="_blank">Documentation</a>
24
+ <span> · </span>
25
+ <a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Report Bug</a>
26
+ <span> · </span>
27
+ <a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Request Feature</a>
28
+ </h4>
29
+ </div>
30
+
31
+ <!-- Badges -->
32
+
33
+ [npm-version-src]: https://img.shields.io/npm/v/@kubb/plugin-redoc?flat&colorA=18181B&colorB=f58517
34
+ [npm-version-href]: https://npmjs.com/package/@kubb/plugin-redoc
35
+ [npm-downloads-src]: https://img.shields.io/npm/dm/@kubb/plugin-redoc?flat&colorA=18181B&colorB=f58517
36
+ [npm-downloads-href]: https://npmjs.com/package/@kubb/plugin-redoc
37
+ [license-src]: https://img.shields.io/github/license/kubb-labs/kubb.svg?flat&colorA=18181B&colorB=f58517
38
+ [license-href]: https://github.com/kubb-labs/kubb/blob/main/LICENSE
39
+ [build-src]: https://img.shields.io/github/actions/workflow/status/kubb-labs/kubb/ci.yaml?style=flat&colorA=18181B&colorB=f58517
40
+ [build-href]: https://www.npmjs.com/package/@kubb/plugin-redoc
41
+ [minified-src]: https://img.shields.io/bundlephobia/min/@kubb/plugin-redoc?style=flat&colorA=18181B&colorB=f58517
42
+ [minified-href]: https://www.npmjs.com/package/@kubb/plugin-redoc
43
+ [coverage-src]: https://img.shields.io/codecov/c/github/kubb-labs/kubb?style=flat&colorA=18181B&colorB=f58517
44
+ [coverage-href]: https://www.npmjs.com/package/@kubb/plugin-redoc
package/dist/index.cjs ADDED
@@ -0,0 +1,106 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined")
5
+ return require.apply(this, arguments);
6
+ throw Error('Dynamic require of "' + x + '" is not supported');
7
+ });
8
+
9
+ // src/plugin.ts
10
+ var _path = require('path'); var _path2 = _interopRequireDefault(_path);
11
+ var _core = require('@kubb/core');
12
+ var _transformers = require('@kubb/core/transformers');
13
+ var _pluginoas = require('@kubb/plugin-oas');
14
+
15
+ // src/redoc.tsx
16
+ var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
17
+
18
+ var _handlebars = require('handlebars'); var _handlebars2 = _interopRequireDefault(_handlebars);
19
+ var _server = require('react-dom/server');
20
+ var _styledcomponents = require('styled-components');
21
+ var _redoc = require('redoc'); var _redoc2 = _interopRequireDefault(_redoc);
22
+ var _jsxruntime = require('react/jsx-runtime');
23
+ function escapeClosingScriptTag(str) {
24
+ return str.replace(/<\/script>/g, "<\\/script>");
25
+ }
26
+ function escapeUnicode(str) {
27
+ return str.replace(/\u2028|\u2029/g, (m) => "\\u202" + (m === "\u2028" ? "8" : "9"));
28
+ }
29
+ function sanitizeJSONString(str) {
30
+ return escapeClosingScriptTag(escapeUnicode(str));
31
+ }
32
+ async function getPageHTML(api, { title, disableGoogleFont, templateOptions, redocOptions = {} } = {}) {
33
+ const apiUrl = redocOptions.specUrl;
34
+ const { Redoc, createStore } = _redoc2.default || __require("redoc");
35
+ const store = await createStore(api, apiUrl, redocOptions);
36
+ const sheet = new (0, _styledcomponents.ServerStyleSheet)();
37
+ const error = console.error;
38
+ console.error = (...args) => {
39
+ if (/defaultProps/.test(args[0]))
40
+ return;
41
+ error(...args);
42
+ };
43
+ const html = _server.renderToString.call(void 0, sheet.collectStyles(/* @__PURE__ */ _jsxruntime.jsx.call(void 0, Redoc, { store })));
44
+ const state = await store.toJS();
45
+ const css = sheet.getStyleTags();
46
+ const templateFileName = _path2.default.join(__dirname, "../static/redoc.hbs");
47
+ const template = _handlebars2.default.compile(_fs2.default.readFileSync(templateFileName).toString());
48
+ return template({
49
+ redocHTML: `
50
+ <div id="redoc">${html || ""}</div>
51
+ <script>
52
+ ${`const __redoc_state = ${sanitizeJSONString(JSON.stringify(state))};` || ""}
53
+
54
+ var container = document.getElementById('redoc');
55
+ Redoc.${"hydrate(__redoc_state, container)"};
56
+
57
+ </script>`,
58
+ redocHead: (
59
+ // biome-ignore lint/style/useTemplate: <explanation>
60
+ `<script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"></script>` + css
61
+ ),
62
+ title: title || api.info.title || "ReDoc documentation",
63
+ disableGoogleFont,
64
+ templateOptions
65
+ });
66
+ }
67
+
68
+ // src/plugin.ts
69
+ var pluginRedocName = "plugin-redoc";
70
+ var pluginRedoc = _core.createPlugin.call(void 0, (options) => {
71
+ const { output = { path: "docs.html" } } = options;
72
+ return {
73
+ name: pluginRedocName,
74
+ options: {
75
+ name: _transformers.trimExtName.call(void 0, output.path),
76
+ baseURL: void 0
77
+ },
78
+ pre: [_pluginoas.pluginOasName],
79
+ resolvePath(baseName) {
80
+ const root = _path2.default.resolve(this.config.root, this.config.output.path);
81
+ return _path2.default.resolve(root, baseName);
82
+ },
83
+ resolveName(name, type) {
84
+ return _transformers.camelCase.call(void 0, name, { isFile: type === "file" });
85
+ },
86
+ async writeFile(source, writePath) {
87
+ if (!writePath.endsWith(".ts") || !source) {
88
+ return;
89
+ }
90
+ return this.fileManager.write(source, writePath, { sanity: false });
91
+ },
92
+ async buildStart() {
93
+ const [swaggerPlugin] = _core.PluginManager.getDependedPlugins(this.plugins, [_pluginoas.pluginOasName]);
94
+ const oas = await swaggerPlugin.api.getOas();
95
+ await oas.dereference();
96
+ const root = _path2.default.resolve(this.config.root, this.config.output.path);
97
+ const pageHTML = await getPageHTML(oas.api);
98
+ await this.fileManager.write(pageHTML, _path2.default.resolve(root, output.path || "./docs.html"));
99
+ }
100
+ };
101
+ });
102
+
103
+
104
+
105
+ exports.pluginRedoc = pluginRedoc; exports.pluginRedocName = pluginRedocName;
106
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/plugin.ts","../src/redoc.tsx"],"names":["path"],"mappings":";;;;;;;;;AAAA,OAAOA,WAAU;AAEjB,SAAS,eAAe,oBAAoB;AAC5C,SAAS,WAAW,mBAAmB;AACvC,SAAS,qBAAqB;;;ACJ9B,OAAO,QAAQ;AACf,OAAO,UAAU;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,MAAM,WAAW,MAAM,IAAI;AACrF;AAEA,SAAS,mBAAmB,KAAqB;AAC/C,SAAO,uBAAuB,cAAc,GAAG,CAAC;AAClD;AAEA,eAAsB,YAAY,KAA2B,EAAE,OAAO,mBAAmB,iBAAiB,eAAe,CAAC,EAAE,IAAsB,CAAC,GAAG;AACpJ,QAAM,SAAS,aAAa;AAC5B,QAAM,EAAE,OAAO,YAAY,IAAI,SAAS,UAAQ,OAAO;AACvD,QAAM,QAAQ,MAAM,YAAY,KAAK,QAAQ,YAAY;AACzD,QAAM,QAAQ,IAAI,iBAAiB;AAEnC,QAAM,QAAQ,QAAQ;AACtB,UAAQ,QAAQ,IAAI,SAAc;AAChC,QAAI,eAAe,KAAK,KAAK,CAAC,CAAC;AAAG;AAClC,UAAM,GAAG,IAAI;AAAA,EACf;AAEA,QAAM,OAAO,eAAe,MAAM,cAAc,oBAAC,SAAM,OAAc,CAAE,CAAC;AACxE,QAAM,QAAQ,MAAM,MA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AA8B,KAAK,SAAS,CAAC,aAAa,CAAC;AACtH,YAAM,MAAM,MAAM,cAAc,IAAI,OAAO;AAE3C,YAAM,IAAI,YAAY;AAEtB,YAAM,OAAOA,MAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,IAAI;AACnE,YAAM,WAAW,MAAM,YAAY,IAAI,GAAG;AAE1C,YAAM,KAAK,YAAY,MAAM,UAAUA,MAAK,QAAQ,MAAM,OAAO,QAAQ,aAAa,CAAC;AAAA,IACzF;AAAA,EACF;AACF,CAAC","sourcesContent":["import path from 'node:path'\n\nimport { PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, trimExtName } from '@kubb/core/transformers'\nimport { pluginOasName } from '@kubb/plugin-oas'\n\nimport type { Plugin } from '@kubb/core'\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 name: trimExtName(output.path),\n baseURL: undefined,\n },\n pre: [pluginOasName],\n resolvePath(baseName) {\n const root = path.resolve(this.config.root, this.config.output.path)\n\n return path.resolve(root, baseName)\n },\n resolveName(name, type) {\n return camelCase(name, { isFile: type === 'file' })\n },\n async writeFile(source, writePath) {\n if (!writePath.endsWith('.ts') || !source) {\n return\n }\n\n return this.fileManager.write(source, writePath, { sanity: false })\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<PluginOas>] = PluginManager.getDependedPlugins<PluginOas>(this.plugins, [pluginOasName])\n const oas = await swaggerPlugin.api.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(pageHTML, path.resolve(root, output.path || './docs.html'))\n },\n }\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"]}
@@ -0,0 +1,24 @@
1
+ import * as _kubb_core from '@kubb/core';
2
+ import { PluginFactoryOptions } from '@kubb/core';
3
+
4
+ type Options = {
5
+ output?: {
6
+ /**
7
+ * Output for the generated doc, we are using [https://redocly.com/](https://redocly.com/) for the generation
8
+ * @default 'docs.html'
9
+ */
10
+ path: string;
11
+ };
12
+ };
13
+ type ResolveOptions = {};
14
+ type PluginRedoc = PluginFactoryOptions<'plugin-redoc', Options, ResolveOptions, never>;
15
+ declare module '@kubb/core' {
16
+ interface _Register {
17
+ ['@kubb/plugin-redoc']: PluginRedoc;
18
+ }
19
+ }
20
+
21
+ declare const pluginRedocName = "plugin-redoc";
22
+ declare const pluginRedoc: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginRedoc>;
23
+
24
+ export { type PluginRedoc, pluginRedoc, pluginRedocName };
@@ -0,0 +1,24 @@
1
+ import * as _kubb_core from '@kubb/core';
2
+ import { PluginFactoryOptions } from '@kubb/core';
3
+
4
+ type Options = {
5
+ output?: {
6
+ /**
7
+ * Output for the generated doc, we are using [https://redocly.com/](https://redocly.com/) for the generation
8
+ * @default 'docs.html'
9
+ */
10
+ path: string;
11
+ };
12
+ };
13
+ type ResolveOptions = {};
14
+ type PluginRedoc = PluginFactoryOptions<'plugin-redoc', Options, ResolveOptions, never>;
15
+ declare module '@kubb/core' {
16
+ interface _Register {
17
+ ['@kubb/plugin-redoc']: PluginRedoc;
18
+ }
19
+ }
20
+
21
+ declare const pluginRedocName = "plugin-redoc";
22
+ declare const pluginRedoc: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginRedoc>;
23
+
24
+ export { type PluginRedoc, pluginRedoc, pluginRedocName };
package/dist/index.js ADDED
@@ -0,0 +1,113 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined")
5
+ return require.apply(this, arguments);
6
+ throw Error('Dynamic require of "' + x + '" is not supported');
7
+ });
8
+
9
+ // ../../node_modules/.pnpm/tsup@8.0.2_@microsoft+api-extractor@7.43.3_@types+node@20.12.11__postcss@8.4.38_ts-node@10.9._m3ved7kneisj6uq6vsf2lw6r5q/node_modules/tsup/assets/esm_shims.js
10
+ import { fileURLToPath } from "url";
11
+ import path from "path";
12
+ var getFilename = () => fileURLToPath(import.meta.url);
13
+ var getDirname = () => path.dirname(getFilename());
14
+ var __dirname = /* @__PURE__ */ getDirname();
15
+
16
+ // src/plugin.ts
17
+ import path3 from "path";
18
+ import { PluginManager, createPlugin } from "@kubb/core";
19
+ import { camelCase, trimExtName } from "@kubb/core/transformers";
20
+ import { pluginOasName } from "@kubb/plugin-oas";
21
+
22
+ // src/redoc.tsx
23
+ import fs from "fs";
24
+ import path2 from "path";
25
+ import pkg from "handlebars";
26
+ import { renderToString } from "react-dom/server";
27
+ import { ServerStyleSheet } from "styled-components";
28
+ import redoc from "redoc";
29
+ import { jsx } from "react/jsx-runtime";
30
+ function escapeClosingScriptTag(str) {
31
+ return str.replace(/<\/script>/g, "<\\/script>");
32
+ }
33
+ function escapeUnicode(str) {
34
+ return str.replace(/\u2028|\u2029/g, (m) => "\\u202" + (m === "\u2028" ? "8" : "9"));
35
+ }
36
+ function sanitizeJSONString(str) {
37
+ return escapeClosingScriptTag(escapeUnicode(str));
38
+ }
39
+ async function getPageHTML(api, { title, disableGoogleFont, templateOptions, redocOptions = {} } = {}) {
40
+ const apiUrl = redocOptions.specUrl;
41
+ const { Redoc, createStore } = redoc || __require("redoc");
42
+ const store = await createStore(api, apiUrl, redocOptions);
43
+ const sheet = new ServerStyleSheet();
44
+ const error = console.error;
45
+ console.error = (...args) => {
46
+ if (/defaultProps/.test(args[0]))
47
+ return;
48
+ error(...args);
49
+ };
50
+ const html = renderToString(sheet.collectStyles(/* @__PURE__ */ jsx(Redoc, { store })));
51
+ const state = await store.toJS();
52
+ const css = sheet.getStyleTags();
53
+ const templateFileName = path2.join(__dirname, "../static/redoc.hbs");
54
+ const template = pkg.compile(fs.readFileSync(templateFileName).toString());
55
+ return template({
56
+ redocHTML: `
57
+ <div id="redoc">${html || ""}</div>
58
+ <script>
59
+ ${`const __redoc_state = ${sanitizeJSONString(JSON.stringify(state))};` || ""}
60
+
61
+ var container = document.getElementById('redoc');
62
+ Redoc.${"hydrate(__redoc_state, container)"};
63
+
64
+ </script>`,
65
+ redocHead: (
66
+ // biome-ignore lint/style/useTemplate: <explanation>
67
+ `<script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"></script>` + css
68
+ ),
69
+ title: title || api.info.title || "ReDoc documentation",
70
+ disableGoogleFont,
71
+ templateOptions
72
+ });
73
+ }
74
+
75
+ // src/plugin.ts
76
+ var pluginRedocName = "plugin-redoc";
77
+ var pluginRedoc = createPlugin((options) => {
78
+ const { output = { path: "docs.html" } } = options;
79
+ return {
80
+ name: pluginRedocName,
81
+ options: {
82
+ name: trimExtName(output.path),
83
+ baseURL: void 0
84
+ },
85
+ pre: [pluginOasName],
86
+ resolvePath(baseName) {
87
+ const root = path3.resolve(this.config.root, this.config.output.path);
88
+ return path3.resolve(root, baseName);
89
+ },
90
+ resolveName(name, type) {
91
+ return camelCase(name, { isFile: type === "file" });
92
+ },
93
+ async writeFile(source, writePath) {
94
+ if (!writePath.endsWith(".ts") || !source) {
95
+ return;
96
+ }
97
+ return this.fileManager.write(source, writePath, { sanity: false });
98
+ },
99
+ async buildStart() {
100
+ const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
101
+ const oas = await swaggerPlugin.api.getOas();
102
+ await oas.dereference();
103
+ const root = path3.resolve(this.config.root, this.config.output.path);
104
+ const pageHTML = await getPageHTML(oas.api);
105
+ await this.fileManager.write(pageHTML, path3.resolve(root, output.path || "./docs.html"));
106
+ }
107
+ };
108
+ });
109
+ export {
110
+ pluginRedoc,
111
+ pluginRedocName
112
+ };
113
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../node_modules/.pnpm/tsup@8.0.2_@microsoft+api-extractor@7.43.3_@types+node@20.12.11__postcss@8.4.38_ts-node@10.9._m3ved7kneisj6uq6vsf2lw6r5q/node_modules/tsup/assets/esm_shims.js","../src/plugin.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","import path from 'node:path'\n\nimport { PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, trimExtName } from '@kubb/core/transformers'\nimport { pluginOasName } from '@kubb/plugin-oas'\n\nimport type { Plugin } from '@kubb/core'\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 name: trimExtName(output.path),\n baseURL: undefined,\n },\n pre: [pluginOasName],\n resolvePath(baseName) {\n const root = path.resolve(this.config.root, this.config.output.path)\n\n return path.resolve(root, baseName)\n },\n resolveName(name, type) {\n return camelCase(name, { isFile: type === 'file' })\n },\n async writeFile(source, writePath) {\n if (!writePath.endsWith('.ts') || !source) {\n return\n }\n\n return this.fileManager.write(source, writePath, { sanity: false })\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<PluginOas>] = PluginManager.getDependedPlugins<PluginOas>(this.plugins, [pluginOasName])\n const oas = await swaggerPlugin.api.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(pageHTML, path.resolve(root, output.path || './docs.html'))\n },\n }\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;AAEjB,IAAM,cAAc,MAAM,cAAc,YAAY,GAAG;AACvD,IAAM,aAAa,MAAM,KAAK,QAAQ,YAAY,CAAC;AAE5C,IAAM,YAA4B,2BAAW;;;ACPpD,OAAOA,WAAU;AAEjB,SAAS,eAAe,oBAAoB;AAC5C,SAAS,WAAW,mBAAmB;AACvC,SAAS,qBAAqB;;;ACJ9B,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,MAAM,WAAW,MAAM,IAAI;AACrF;AAEA,SAAS,mBAAmB,KAAqB;AAC/C,SAAO,uBAAuB,cAAc,GAAG,CAAC;AAClD;AAEA,eAAsB,YAAY,KAA2B,EAAE,OAAO,mBAAmB,iBAAiB,eAAe,CAAC,EAAE,IAAsB,CAAC,GAAG;AACpJ,QAAM,SAAS,aAAa;AAC5B,QAAM,EAAE,OAAO,YAAY,IAAI,SAAS,UAAQ,OAAO;AACvD,QAAM,QAAQ,MAAM,YAAY,KAAK,QAAQ,YAAY;AACzD,QAAM,QAAQ,IAAI,iBAAiB;AAEnC,QAAM,QAAQ,QAAQ;AACtB,UAAQ,QAAQ,IAAI,SAAc;AAChC,QAAI,eAAe,KAAK,KAAK,CAAC,CAAC;AAAG;AAClC,UAAM,GAAG,IAAI;AAAA,EACf;AAEA,QAAM,OAAO,eAAe,MAAM,cA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;AAAA,IACA,MAAM,aAAa;AACjB,YAAM,CAAC,aAAa,IAAyB,cAAc,mBAA8B,KAAK,SAAS,CAAC,aAAa,CAAC;AACtH,YAAM,MAAM,MAAM,cAAc,IAAI,OAAO;AAE3C,YAAM,IAAI,YAAY;AAEtB,YAAM,OAAOA,MAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,IAAI;AACnE,YAAM,WAAW,MAAM,YAAY,IAAI,GAAG;AAE1C,YAAM,KAAK,YAAY,MAAM,UAAUA,MAAK,QAAQ,MAAM,OAAO,QAAQ,aAAa,CAAC;AAAA,IACzF;AAAA,EACF;AACF,CAAC;","names":["path","path","path"]}
package/package.json ADDED
@@ -0,0 +1,85 @@
1
+ {
2
+ "name": "@kubb/plugin-redoc",
3
+ "version": "0.0.0-canary-20240509211223",
4
+ "description": "Beautiful docs with Redoc",
5
+ "keywords": [
6
+ "typescript",
7
+ "plugins",
8
+ "kubb",
9
+ "codegen",
10
+ "redoc"
11
+ ],
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git://github.com/kubb-labs/kubb.git",
15
+ "directory": "packages/plugin-redoc"
16
+ },
17
+ "license": "MIT",
18
+ "author": "Stijn Van Hulle <stijn@stijnvanhulle.be",
19
+ "sideEffects": false,
20
+ "type": "module",
21
+ "exports": {
22
+ ".": {
23
+ "import": "./dist/index.js",
24
+ "require": "./dist/index.cjs",
25
+ "default": "./dist/index.cjs"
26
+ },
27
+ "./package.json": "./package.json",
28
+ "./*": "./*"
29
+ },
30
+ "main": "dist/index.cjs",
31
+ "module": "dist/index.js",
32
+ "types": "./dist/index.d.ts",
33
+ "typesVersions": {
34
+ "*": {}
35
+ },
36
+ "files": [
37
+ "src",
38
+ "dist",
39
+ "static",
40
+ "!/**/**.test.**",
41
+ "!/**/__tests__/**"
42
+ ],
43
+ "dependencies": {
44
+ "handlebars": "^4.7.8",
45
+ "mobx": "^6.12.3",
46
+ "react": "^18.3.1",
47
+ "react-dom": "^18.3.1",
48
+ "redoc": "^2.1.4",
49
+ "styled-components": "^6.1.10",
50
+ "@kubb/core": "0.0.0-canary-20240509211223",
51
+ "@kubb/oas": "0.0.0-canary-20240509211223",
52
+ "@kubb/plugin-oas": "0.0.0-canary-20240509211223"
53
+ },
54
+ "devDependencies": {
55
+ "@types/react": "^18.3.1",
56
+ "@types/react-dom": "^18.3.0",
57
+ "tsup": "^8.0.2",
58
+ "typescript": "^5.4.5",
59
+ "@kubb/config-biome": "0.0.0-canary-20240509211223",
60
+ "@kubb/config-ts": "0.0.0-canary-20240509211223",
61
+ "@kubb/config-tsup": "0.0.0-canary-20240509211223"
62
+ },
63
+ "peerDependencies": {
64
+ "@kubb/react": "0.0.0-canary-20240509211223"
65
+ },
66
+ "engines": {
67
+ "node": ">=18",
68
+ "pnpm": ">=8.15.0"
69
+ },
70
+ "publishConfig": {
71
+ "access": "public",
72
+ "registry": "https://registry.npmjs.org/"
73
+ },
74
+ "scripts": {
75
+ "build": "tsup",
76
+ "clean": "npx rimraf ./dist",
77
+ "lint": "bun biome lint .",
78
+ "lint:fix": "bun biome lint --apply-unsafe .",
79
+ "release": "pnpm publish --no-git-check",
80
+ "release:canary": "bash ../../.github/canary.sh && node ../../scripts/build.js canary && pnpm publish --no-git-check",
81
+ "start": "tsup --watch",
82
+ "test": "vitest --passWithNoTests",
83
+ "typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
84
+ }
85
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { pluginRedoc, pluginRedocName } from './plugin.ts'
2
+ export type { PluginRedoc } from './types.ts'
package/src/plugin.ts ADDED
@@ -0,0 +1,51 @@
1
+ import path from 'node:path'
2
+
3
+ import { PluginManager, createPlugin } from '@kubb/core'
4
+ import { camelCase, trimExtName } from '@kubb/core/transformers'
5
+ import { pluginOasName } from '@kubb/plugin-oas'
6
+
7
+ import type { Plugin } from '@kubb/core'
8
+ import type { PluginOas } from '@kubb/plugin-oas'
9
+ import { getPageHTML } from './redoc.tsx'
10
+ import type { PluginRedoc } from './types.ts'
11
+
12
+ export const pluginRedocName = 'plugin-redoc' satisfies PluginRedoc['name']
13
+
14
+ export const pluginRedoc = createPlugin<PluginRedoc>((options) => {
15
+ const { output = { path: 'docs.html' } } = options
16
+
17
+ return {
18
+ name: pluginRedocName,
19
+ options: {
20
+ name: trimExtName(output.path),
21
+ baseURL: undefined,
22
+ },
23
+ 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(source, writePath) {
33
+ if (!writePath.endsWith('.ts') || !source) {
34
+ return
35
+ }
36
+
37
+ return this.fileManager.write(source, writePath, { sanity: false })
38
+ },
39
+ async buildStart() {
40
+ const [swaggerPlugin]: [Plugin<PluginOas>] = PluginManager.getDependedPlugins<PluginOas>(this.plugins, [pluginOasName])
41
+ const oas = await swaggerPlugin.api.getOas()
42
+
43
+ await oas.dereference()
44
+
45
+ const root = path.resolve(this.config.root, this.config.output.path)
46
+ const pageHTML = await getPageHTML(oas.api)
47
+
48
+ await this.fileManager.write(pageHTML, path.resolve(root, output.path || './docs.html'))
49
+ },
50
+ }
51
+ })
package/src/redoc.tsx ADDED
@@ -0,0 +1,66 @@
1
+ import fs from 'node:fs'
2
+ import path from 'node:path'
3
+ import type { OasTypes } from '@kubb/oas'
4
+ import pkg from 'handlebars'
5
+ import { renderToString } from 'react-dom/server'
6
+ import { ServerStyleSheet } from 'styled-components'
7
+ import redoc from 'redoc'
8
+
9
+ type BuildDocsOptions = {
10
+ title?: string
11
+ disableGoogleFont?: boolean
12
+ templateOptions?: any
13
+ redocOptions?: any
14
+ }
15
+
16
+ // see http://www.thespanner.co.uk/2011/07/25/the-json-specification-is-now-wrong/
17
+ function escapeClosingScriptTag(str: string): string {
18
+ return str.replace(/<\/script>/g, '<\\/script>')
19
+ }
20
+
21
+ // see http://www.thespanner.co.uk/2011/07/25/the-json-specification-is-now-wrong/
22
+ function escapeUnicode(str: string): string {
23
+ // biome-ignore lint/style/useTemplate: <explanation>
24
+ return str.replace(/\u2028|\u2029/g, (m) => '\\u202' + (m === '\u2028' ? '8' : '9'))
25
+ }
26
+
27
+ function sanitizeJSONString(str: string): string {
28
+ return escapeClosingScriptTag(escapeUnicode(str))
29
+ }
30
+
31
+ export async function getPageHTML(api: OasTypes.OASDocument, { title, disableGoogleFont, templateOptions, redocOptions = {} }: BuildDocsOptions = {}) {
32
+ const apiUrl = redocOptions.specUrl
33
+ const { Redoc, createStore } = redoc || require('redoc')
34
+ const store = await createStore(api, apiUrl, redocOptions)
35
+ const sheet = new ServerStyleSheet()
36
+
37
+ const error = console.error
38
+ console.error = (...args: any) => {
39
+ if (/defaultProps/.test(args[0])) return
40
+ error(...args)
41
+ }
42
+
43
+ const html = renderToString(sheet.collectStyles(<Redoc store={store} />))
44
+ const state = await store.toJS()
45
+ const css = sheet.getStyleTags()
46
+
47
+ const templateFileName = path.join(__dirname, '../static/redoc.hbs')
48
+ const template = pkg.compile(fs.readFileSync(templateFileName).toString())
49
+ return template({
50
+ redocHTML: `
51
+ <div id="redoc">${html || ''}</div>
52
+ <script>
53
+ ${`const __redoc_state = ${sanitizeJSONString(JSON.stringify(state))};` || ''}
54
+
55
+ var container = document.getElementById('redoc');
56
+ Redoc.${'hydrate(__redoc_state, container)'};
57
+
58
+ </script>`,
59
+ redocHead:
60
+ // biome-ignore lint/style/useTemplate: <explanation>
61
+ `<script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"></script>` + css,
62
+ title: title || api.info.title || 'ReDoc documentation',
63
+ disableGoogleFont,
64
+ templateOptions,
65
+ })
66
+ }
package/src/types.ts ADDED
@@ -0,0 +1,26 @@
1
+ import type { Plugin, PluginFactoryOptions } from '@kubb/core'
2
+
3
+ export type Options = {
4
+ output?: {
5
+ /**
6
+ * Output for the generated doc, we are using [https://redocly.com/](https://redocly.com/) for the generation
7
+ * @default 'docs.html'
8
+ */
9
+ path: string
10
+ }
11
+ }
12
+
13
+ type ResolveOptions = {}
14
+
15
+ export type FileMeta = {
16
+ pluginKey?: Plugin['key']
17
+ tag?: string
18
+ }
19
+
20
+ export type PluginRedoc = PluginFactoryOptions<'plugin-redoc', Options, ResolveOptions, never>
21
+
22
+ declare module '@kubb/core' {
23
+ export interface _Register {
24
+ ['@kubb/plugin-redoc']: PluginRedoc
25
+ }
26
+ }
@@ -0,0 +1,23 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+
4
+ <head>
5
+ <meta charset="utf8" />
6
+ <title>{{title}}</title>
7
+ <!-- needed for adaptive design -->
8
+ <meta name="viewport" content="width=device-width, initial-scale=1">
9
+ <style>
10
+ body {
11
+ padding: 0;
12
+ margin: 0;
13
+ }
14
+ </style>
15
+ {{{redocHead}}}
16
+ {{#unless disableGoogleFont}}<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet">{{/unless}}
17
+ </head>
18
+
19
+ <body>
20
+ {{{redocHTML}}}
21
+ </body>
22
+
23
+ </html>