UNPKG

@visulima/packem

Version:

A fast and modern bundler for Node.js and TypeScript.

4 lines (3 loc) 3.41 kB
var j=Object.defineProperty;var g=(e,t)=>j(e,"name",{value:t,configurable:!0});import{cyan as v}from"@visulima/colorize";import{join as h}from"@visulima/path";import{g as P,d as A}from"../../packem_shared/create-or-update-key-storage-Bm-Xu0uJ.mjs";import{readdirSync as $}from"node:fs";import{readFileSync as w,writeFileSync as F}from"@visulima/fs";import{Application as b}from"typedoc";var T=Object.defineProperty,_=g((e,t)=>T(e,"name",{value:t,configurable:!0}),"w");const C=_(async(e,t,r,a)=>{if(t.length===0)return;const{format:n,marker:o,output:x,plugin:k,readmePath:s,jsonFileName:p,...y}=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(m=>m.input),u=k??[];u.push("typedoc-plugin-rename-defaults"),(n==="inline"||n==="markdown")&&u.push("typedoc-plugin-markdown");const l=await b.bootstrapWithPlugins({...y,compilerOptions:{allowJs:!0,declaration:!1,declarationMap:!1,esModuleInterop:!0,module:99,moduleResolution:100,noEmit:!0,noImplicitAny:!1,skipLibCheck:!0,sourceMap:!1,target:99,...y.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 m=$(r,{withFileTypes:!0}).filter(i=>i.isFile());let f="";for(const i of m)i.name==="README.md"&&t.length>1||(f+=w(h(r,i.name)).replaceAll(`<!-- ${o}`,`<!-- _REPLACE_${o}`).replaceAll("<!-- ${marker}",`<!-- _REPLACE_\\${o}`));if(f!==""){const i=w(s),c=P(i,o,` `+f);if(!c){a.error({message:`Could not find the typedoc marker: <!-- ${o} --><!-- /${o} --> in ${s}`,prefix:"typedoc"});return}if(i===c)return;c&&F(s,c.replaceAll(`<!-- _REPLACE_${o}`,`<!-- ${o}`).replaceAll(`<!-- _REPLACE_\\${o}`,"<!-- ${marker}"),{overwrite:!0})}}}},"generateReferenceDocumentation");var R=Object.defineProperty,D=g((e,t)=>R(e,"name",{value:t,configurable:!0}),"r");const B=D(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&&A("typedoc",t,e.logger,!0),a&&e.logger.raw(` `),e.logger.info({message:"Using "+v("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(t,"typedoc"):e.options.typedoc.format!=="json"&&(o=h(o,"api-docs")),await C(e.options.typedoc,e.options.entries,o,e.logger),await e.hooks.callHook("typedoc:done",e)}},"builder");export{B as default};