@visulima/packem
Version:
A fast and modern bundler for Node.js and TypeScript.
4 lines (3 loc) • 3.41 kB
JavaScript
;var v=Object.defineProperty;var g=(e,t)=>v(e,"name",{value:t,configurable:!0});const P=require("@visulima/colorize"),h=require("@visulima/path"),k=require("../../packem_shared/create-or-update-key-storage-mzqiq3Nk.cjs"),A=require("node:fs"),y=require("@visulima/fs"),F=require("typedoc");var $=Object.defineProperty,b=g((e,t)=>$(e,"name",{value:t,configurable:!0}),"w");const q=b(async(e,t,r,a)=>{if(t.length===0)return;const{format:n,marker:o,output:R,plugin:j,readmePath:s,jsonFileName:p,...w}=e;if(n==="inline"&&s===void 0)throw new Error("The `readmePath` option is required when using the `inline` format.");if(n!=="inline"&&typeof s=="string"&&a.warn({message:"The `readmePath` option is only used when the `inline` format is used.",prefix:"typedoc"}),n==="json"){if(p===void 0)throw new Error("The `jsonFileName` option is required when using the `json` format.");if(p.endsWith(".json")===!1)throw new Error("The `jsonFileName` option must end with `.json`.")}n!=="json"&&typeof p=="string"&&a.warn({message:"The `jsonFileName` option is only used when the `json` format is used.",prefix:"typedoc"});const E=t.map(f=>f.input),u=j??[];u.push("typedoc-plugin-rename-defaults"),(n==="inline"||n==="markdown")&&u.push("typedoc-plugin-markdown");const l=await F.Application.bootstrapWithPlugins({...w,compilerOptions:{allowJs:!0,declaration:!1,declarationMap:!1,esModuleInterop:!0,module:99,moduleResolution:100,noEmit:!0,noImplicitAny:!1,skipLibCheck:!0,sourceMap:!1,target:99,...w.compilerOptions},entryPoints:E,hideGenerator:!0,plugin:u,out:r,...n==="inline"?{hideBreadcrumbs:!0,hidePageHeader:!0,navigation:!1,outputFileStrategy:"modules",useCodeBlocks:!0}:{}},[]),d=await l.convert();if(d){if(n==="json")await l.generateJson(d,p);else if(n==="html")await l.generateDocs(d,r);else if(await l.generateOutputs(d),n==="inline"){if(o===void 0)throw new Error("The `marker` option is required when using the `inline` format.");const f=A.readdirSync(r,{withFileTypes:!0}).filter(i=>i.isFile());let m="";for(const i of f)i.name==="README.md"&&t.length>1||(m+=y.readFileSync(h.join(r,i.name)).replaceAll(`<!-- ${o}`,`<!-- _REPLACE_${o}`).replaceAll("<!-- ${marker}",`<!-- _REPLACE_\\${o}`));if(m!==""){const i=y.readFileSync(s),c=k.g(i,o,`
`+m);if(!c){a.error({message:`Could not find the typedoc marker: <!-- ${o} --><!-- /${o} --> in ${s}`,prefix:"typedoc"});return}if(i===c)return;c&&y.writeFileSync(s,c.replaceAll(`<!-- _REPLACE_${o}`,`<!-- ${o}`).replaceAll(`<!-- _REPLACE_\\${o}`,"<!-- ${marker}"),{overwrite:!0})}}}},"generateReferenceDocumentation");var _=Object.defineProperty,T=g((e,t)=>_(e,"name",{value:t,configurable:!0}),"r");const C=T(async(e,t,r,a)=>{if(e.options.typedoc&&e.options.typedoc.format!==void 0){let n="unknown";e.pkg.dependencies?.typedoc?n=e.pkg.dependencies.typedoc:e.pkg.devDependencies?.typedoc&&(n=e.pkg.devDependencies.typedoc),t&&k.d("typedoc",t,e.logger,!0),a&&e.logger.raw(`
`),e.logger.info({message:"Using "+P.cyan("typedoc")+" "+n+" to generate reference documentation",prefix:"typedoc"}),await e.hooks.callHook("typedoc:before",e);let o=e.options.rootDir;e.options.typedoc.output?o=e.options.typedoc.output:e.options.typedoc.format==="inline"&&t?o=h.join(t,"typedoc"):e.options.typedoc.format!=="json"&&(o=h.join(o,"api-docs")),await q(e.options.typedoc,e.options.entries,o,e.logger),await e.hooks.callHook("typedoc:done",e)}},"builder");module.exports=C;