UNPKG

@visulima/packem

Version:

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

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