@dovenv/docs
Version:
Documentation utils for dovenv
3 lines (2 loc) • 3.27 kB
JavaScript
import{getCommandUtils as u,defineConfig as g}from"@dovenv/core";import{h,s as m,v as P,n as p,c as v,V as E,e as f}from"./docs.DT25A5VU.mjs";import{deprecatedAlerts as w,replaceStd as S}from"@dovenv/core/utils";class d{utils;opts;constructor({utils:s,opts:r}){this.opts=r,this.utils=s,this.utils.title="docs",this.utils.helpURL=h,console.debug({opts:r})}async#e(){m({configPath:this.opts?.configPath,packageJsonPath:this.opts?.packageJsonPath})}async#s(s,r){w().hide();const t=S({params:{vitepress:p,[`/.${p}`]:"/.vitepress",[`v${v}`]:`v${P}`},type:["stderr","stdout"]});try{t.start(),await this.#e();const i=E,o=process.argv;this.utils.process.argv=[...this.utils.process.argv.slice(0,2),s,i,...r??[],...this.opts?.port?[`--port=${this.opts.port}`]:[]],console.debug({"docs-cli-argv":this.utils.process.argv}),this.utils.prompt.log.info(`${this.utils.style.info.b(s)} process starting...
`),await import("vitepress/dist/node/cli.js"),this.utils.process.argv=o}catch(i){console.error(i instanceof Error?i.message:i),t.stop(),this.utils.process.exit(0)}}async dev(s){await this.#s("dev",[...s??[],"--force"])}async build(s){await this.#s("build",s)}async preview(s){await this.#s("preview",s)}async generatePWAassets(s){await this.utils.execPkgBin("@vite-pwa/assets-generator",s,{forceExec:!0})}async publishToCloudflare(s){await this.utils.execPkgBin("wrangler",["pages","deploy",s.dir,`--project-name=${s.name}`])}}const A=async(c,s)=>new d({...c,utils:await u(s)}),a={PORT:"port",CONFIG_PATH:"config-path",PKG_PATH:"package-path",FLAG:"flag"},e={DOCS:"docs",DEV:"dev",BUILD:"build",PREVIEW:"preview",PUBLISH_CF:"publish-cf",GENERATE_ASSETS:"generate-assets"},n={[a.PORT]:{type:"number",desc:"Port to listen on"},[a.CONFIG_PATH]:{type:"string",desc:"Docs config path"},[a.PKG_PATH]:{type:"string",desc:"Custom packageJSON path"}},l=`$0 ${e.DOCS} ${e.GENERATE_ASSETS} --${a.FLAG}="--preset=minimal" --${a.FLAG}=public/logo.svg`,y=(c={})=>g({const:{[f.DOVENV_DOCS_CONFIG]:typeof c=="function"?s=>s?c(s):void 0:c},custom:{[e.DOCS]:{desc:"Create documentation pages",cmds:{[e.DEV]:{desc:"Run the documentation dev server",opts:n},[e.BUILD]:{desc:"Build the documentation",opts:n},[e.PREVIEW]:{desc:"Preview the documentation",opts:n},[e.PUBLISH_CF]:{desc:"Publish documentation to Cloudflare pages",opts:{dir:{desc:"Directory of documentation build"},name:{desc:"Project name"}}},[e.GENERATE_ASSETS]:{desc:"Generate assets for PWA",opts:{[a.FLAG]:{type:"array",alias:"f",desc:'flags for pass to "@vite-pwa/assets-generator" cli'}},examples:[{cmd:l,desc:"Generate assets"},{cmd:"https://vite-pwa-org.netlify.app/assets-generator/cli.html",desc:"View docs"}]}},examples:[{cmd:`$0 ${e.DOCS} ${e.DEV} --${a.PORT}=1312`,desc:"Run dev server with custom port"},{cmd:l,desc:"Generate assets"}],fn:async({cmds:s,showHelp:r,opts:t,utils:i})=>{const o=new d({utils:i,opts:{port:t?.[a.PORT],configPath:t?.[a.CONFIG_PATH],packageJsonPath:t?.[a.PKG_PATH],debug:t?.verbose}});s?.includes(e.DEV)?await o.dev():s?.includes(e.BUILD)?await o.build():s?.includes(e.PREVIEW)?await o.preview():s?.includes(e.PUBLISH_CF)&&t?.dir&&t?.name?await o.publishToCloudflare({dir:t.dir,name:t.name}):s?.includes(e.GENERATE_ASSETS)?await o.generatePWAassets(t?.[a.FLAG]):r()}}}});export{A as a,y as d};