@kubb/plugin-redoc 2.18.3 → 2.18.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -83,11 +83,11 @@ var pluginRedoc = _core.createPlugin.call(void 0, (options) => {
83
83
  resolveName(name, type) {
84
84
  return _transformers.camelCase.call(void 0, name, { isFile: type === "file" });
85
85
  },
86
- async writeFile(source, writePath) {
87
- if (!writePath.endsWith(".ts") || !source) {
86
+ async writeFile(path3, source) {
87
+ if (!path3.endsWith(".ts") || !source) {
88
88
  return;
89
89
  }
90
- return this.fileManager.write(source, writePath, { sanity: false });
90
+ return this.fileManager.write(path3, source, { sanity: false });
91
91
  },
92
92
  async buildStart() {
93
93
  const [swaggerPlugin] = _core.PluginManager.getDependedPlugins(this.plugins, [_pluginoas.pluginOasName]);
@@ -95,7 +95,7 @@ var pluginRedoc = _core.createPlugin.call(void 0, (options) => {
95
95
  await oas.dereference();
96
96
  const root = _path2.default.resolve(this.config.root, this.config.output.path);
97
97
  const pageHTML = await getPageHTML(oas.api);
98
- await this.fileManager.write(pageHTML, _path2.default.resolve(root, output.path || "./docs.html"));
98
+ await this.fileManager.write(_path2.default.resolve(root, output.path || "./docs.html"), pageHTML);
99
99
  }
100
100
  };
101
101
  });
@@ -1 +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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;AAE3C,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,MACP,MAAM,YAAY,OAAO,IAAI;AAAA,MAC7B,SAAS;AAAA,IACX;AAAA,IACA,KAAK,CAAC,aAAa;AAAA,IACnB,YAAY,UAAU;AACpB,YAAM,OAAOA,MAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,IAAI;AAEnE,aAAOA,MAAK,QAAQ,MAAM,QAAQ;AAAA,IACpC;AAAA,IACA,YAAY,MAAM,MAAM;AACtB,aAAO,UAAU,MAAM,EAAE,QAAQ,SAAS,OAAO,CAAC;AAAA,IACpD;AAAA,IACA,MAAM,UAAU,QAAQ,WAAW;AACjC,UAAI,CAAC,UAAU,SAAS,KAAK,KAAK,CAAC,QAAQ;AACzC;AAAA,MACF;AAEA,aAAO,KAAK,YAAY,MAAM,QAAQ,WAAW,EAAE,QAAQ,MAAM,CAAC;AAAA,IACpE;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","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"]}
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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ACnB,YAAY,UAAU;AACpB,YAAM,OAAOA,MAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,IAAI;AAEnE,aAAOA,MAAK,QAAQ,MAAM,QAAQ;AAAA,IACpC;AAAA,IACA,YAAY,MAAM,MAAM;AACtB,aAAO,UAAU,MAAM,EAAE,QAAQ,SAAS,OAAO,CAAC;AAAA,IACpD;AAAA,IACA,MAAM,UAAUA,OAAM,QAAQ;AAC5B,UAAI,CAACA,MAAK,SAAS,KAAK,KAAK,CAAC,QAAQ;AACpC;AAAA,MACF;AAEA,aAAO,KAAK,YAAY,MAAMA,OAAM,QAAQ,EAAE,QAAQ,MAAM,CAAC;AAAA,IAC/D;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,MAAMA,MAAK,QAAQ,MAAM,OAAO,QAAQ,aAAa,GAAG,QAAQ;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(path, source) {\n if (!path.endsWith('.ts') || !source) {\n return\n }\n\n return this.fileManager.write(path, source, { 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(path.resolve(root, output.path || './docs.html'), pageHTML)\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"]}
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
6
6
  throw Error('Dynamic require of "' + x + '" is not supported');
7
7
  });
8
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
9
+ // ../../node_modules/.pnpm/tsup@8.0.2_@microsoft+api-extractor@7.43.4_@types+node@20.12.11__postcss@8.4.38_ts-node@10.9._vnyhfq7fulozpuwbvh64t7gkvm/node_modules/tsup/assets/esm_shims.js
10
10
  import { fileURLToPath } from "url";
11
11
  import path from "path";
12
12
  var getFilename = () => fileURLToPath(import.meta.url);
@@ -90,11 +90,11 @@ var pluginRedoc = createPlugin((options) => {
90
90
  resolveName(name, type) {
91
91
  return camelCase(name, { isFile: type === "file" });
92
92
  },
93
- async writeFile(source, writePath) {
94
- if (!writePath.endsWith(".ts") || !source) {
93
+ async writeFile(path4, source) {
94
+ if (!path4.endsWith(".ts") || !source) {
95
95
  return;
96
96
  }
97
- return this.fileManager.write(source, writePath, { sanity: false });
97
+ return this.fileManager.write(path4, source, { sanity: false });
98
98
  },
99
99
  async buildStart() {
100
100
  const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
@@ -102,7 +102,7 @@ var pluginRedoc = createPlugin((options) => {
102
102
  await oas.dereference();
103
103
  const root = path3.resolve(this.config.root, this.config.output.path);
104
104
  const pageHTML = await getPageHTML(oas.api);
105
- await this.fileManager.write(pageHTML, path3.resolve(root, output.path || "./docs.html"));
105
+ await this.fileManager.write(path3.resolve(root, output.path || "./docs.html"), pageHTML);
106
106
  }
107
107
  };
108
108
  });
package/dist/index.js.map CHANGED
@@ -1 +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,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KAAK,OAAO,OAAO,IAAI;AAEnE,aAAOA,MAAK,QAAQ,MAAM,QAAQ;AAAA,IACpC;AAAA,IACA,YAAY,MAAM,MAAM;AACtB,aAAO,UAAU,MAAM,EAAE,QAAQ,SAAS,OAAO,CAAC;AAAA,IACpD;AAAA,IACA,MAAM,UAAU,QAAQ,WAAW;AACjC,UAAI,CAAC,UAAU,SAAS,KAAK,KAAK,CAAC,QAAQ;AACzC;AAAA,MACF;AAEA,aAAO,KAAK,YAAY,MAAM,QAAQ,WAAW,EAAE,QAAQ,MAAM,CAAC;AAAA,IACpE;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"]}
1
+ {"version":3,"sources":["../../../node_modules/.pnpm/tsup@8.0.2_@microsoft+api-extractor@7.43.4_@types+node@20.12.11__postcss@8.4.38_ts-node@10.9._vnyhfq7fulozpuwbvh64t7gkvm/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(path, source) {\n if (!path.endsWith('.ts') || !source) {\n return\n }\n\n return this.fileManager.write(path, source, { 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(path.resolve(root, output.path || './docs.html'), pageHTML)\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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iful 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.4",
49
- "styled-components": "^6.1.10",
50
- "@kubb/core": "2.18.3",
51
- "@kubb/oas": "2.18.3",
52
- "@kubb/plugin-oas": "2.18.3"
49
+ "styled-components": "^6.1.11",
50
+ "@kubb/core": "2.18.5",
51
+ "@kubb/oas": "2.18.5",
52
+ "@kubb/plugin-oas": "2.18.5"
53
53
  },
54
54
  "devDependencies": {
55
- "@types/react": "^18.3.1",
55
+ "@types/react": "^18.3.2",
56
56
  "@types/react-dom": "^18.3.0",
57
57
  "tsup": "^8.0.2",
58
58
  "typescript": "^5.4.5",
59
- "@kubb/config-biome": "2.18.3",
60
- "@kubb/config-ts": "2.18.3",
61
- "@kubb/config-tsup": "2.18.3"
59
+ "@kubb/config-biome": "2.18.5",
60
+ "@kubb/config-ts": "2.18.5",
61
+ "@kubb/config-tsup": "2.18.5"
62
62
  },
63
63
  "peerDependencies": {
64
- "@kubb/react": "2.18.3"
64
+ "@kubb/react": "2.18.5"
65
65
  },
66
66
  "engines": {
67
67
  "node": ">=18",
package/src/plugin.ts CHANGED
@@ -29,12 +29,12 @@ export const pluginRedoc = createPlugin<PluginRedoc>((options) => {
29
29
  resolveName(name, type) {
30
30
  return camelCase(name, { isFile: type === 'file' })
31
31
  },
32
- async writeFile(source, writePath) {
33
- if (!writePath.endsWith('.ts') || !source) {
32
+ async writeFile(path, source) {
33
+ if (!path.endsWith('.ts') || !source) {
34
34
  return
35
35
  }
36
36
 
37
- return this.fileManager.write(source, writePath, { sanity: false })
37
+ return this.fileManager.write(path, source, { sanity: false })
38
38
  },
39
39
  async buildStart() {
40
40
  const [swaggerPlugin]: [Plugin<PluginOas>] = PluginManager.getDependedPlugins<PluginOas>(this.plugins, [pluginOasName])
@@ -45,7 +45,7 @@ export const pluginRedoc = createPlugin<PluginRedoc>((options) => {
45
45
  const root = path.resolve(this.config.root, this.config.output.path)
46
46
  const pageHTML = await getPageHTML(oas.api)
47
47
 
48
- await this.fileManager.write(pageHTML, path.resolve(root, output.path || './docs.html'))
48
+ await this.fileManager.write(path.resolve(root, output.path || './docs.html'), pageHTML)
49
49
  },
50
50
  }
51
51
  })