UNPKG

docusaurus-plugin-react-docgen-typescript

Version:
134 lines (133 loc) 4.69 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var index_exports = {}; __export(index_exports, { default: () => plugin }); module.exports = __toCommonJS(index_exports); var import_node_path = __toESM(require("path")); var import_react_docgen_typescript = require("react-docgen-typescript"); var import_glob = require("glob"); function getParser(config, options, parserOptions) { if (config) { return (0, import_react_docgen_typescript.withCustomConfig)(config, parserOptions ?? {}).parse; } else if (options) { return (0, import_react_docgen_typescript.withCompilerOptions)(options, parserOptions).parse; } return (0, import_react_docgen_typescript.withDefaultConfig)(parserOptions).parse; } function plugin(context, { src, ignore, global = false, route, tsConfig, compilerOptions, parserOptions }) { return { name: "docusaurus-plugin-react-docgen-typescript", async loadContent() { return getParser( tsConfig, compilerOptions, parserOptions )( await (0, import_glob.glob)(src, { absolute: true, ignore }) ); }, configureWebpack(config) { return { resolve: { alias: { "@docgen": import_node_path.default.join( // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access config.resolve.alias["@generated"], "docusaurus-plugin-react-docgen-typescript", "default" ) } } }; }, async contentLoaded({ content, actions }) { const { createData, setGlobalData, addRoute } = actions; if (global) { console.warn( "Using global data can potentially slow down your entire app. Use with care \u2764\uFE0F" ); setGlobalData(content); } else if (route) { addRoute({ ...route, modules: { docgen: await createData("docgen.json", JSON.stringify(content)) } }); } else { const toProcess = content.reduce( ([processed, components], component) => { const componentName = component.displayName; let fileName = componentName; const alreadyProcessed = processed[componentName]; if (alreadyProcessed && alreadyProcessed.length > 0) { console.warn( `Duplicate component '${componentName}' found (existing: ${alreadyProcessed[alreadyProcessed.length - 1]})` ); fileName += `${alreadyProcessed.length}`; console.warn( `'${component.filePath}' will be written to '${fileName}.json'` ); } return [ { ...processed, [componentName]: [ ...alreadyProcessed || [], component.filePath ] }, [...components, { fileName, component }] ]; }, [{}, []] ); toProcess[1].forEach(({ fileName, component }) => { void createData(`${fileName}.json`, JSON.stringify(component.props)); }); } } }; } //# sourceMappingURL=index.js.map