@dovenv/docs
Version:
Documentation utils for dovenv
2 lines (1 loc) • 2.87 kB
JavaScript
import{defineConfig as n}from"@dovenv/core";import{h as d,s as l,v as g,n as r,c as u,V as h,d as m}from"./docs.Dz5HiI3p.mjs";import{deprecatedAlerts as v,replaceStd as f}from"@dovenv/core/utils";class p{utils;opts;constructor({utils:s,opts:a}){this.opts=a,this.utils=s,this.utils.title="docs",this.utils.helpURL=d,console.debug({opts:a})}async#e(){l({configPath:this.opts?.configPath,packageJsonPath:this.opts?.packageJsonPath})}async#s(s,a){v().hide();const e=f({params:{vitepress:r,[`/.${r}`]:"/.vitepress",[`v${u}`]:`v${g}`},type:["stderr","stdout"]});try{e.start(),await this.#e();const o=h,t=process.argv;this.utils.process.argv=[...this.utils.process.argv.slice(0,2),s,o,...a??[],...this.opts?.port?[`--port=${this.opts.port}`]:[]],console.debug({"docs-cli-argv":this.utils.process.argv}),await import("vitepress/dist/node/cli.js"),this.utils.process.argv=t}catch(o){console.error(o.message),e.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 i={port:{type:"number",desc:"Port to listen on"},"config-path":{type:"string",desc:"Docs config path"},"pkg-path":{type:"string",desc:"Custom packageJSON path"}},w=(c={})=>n({const:{[m.DOVENV_DOCS_CONFIG]:c},custom:{docs:{desc:"Create documentation pages",cmds:{dev:{desc:"Run the documentation dev server",opts:i},build:{desc:"Build the documentation",opts:i},preview:{desc:"Preview the documentation",opts:i},"publish-cf":{desc:"Publish documentation to Cloudflare pages",opts:{dir:{desc:"Directory of documentation build"},name:{desc:"Project name"}}},"generate-assets":{desc:"Generate assets for PWA",opts:{flag:{type:"array",alias:"f",desc:'flags for pass to "@vite-pwa/assets-generator" cli'}},examples:[{cmd:'$0 docs generate-assets --flag="--preset=minimal" --flag=public/logo.svg',desc:"Generate assets"},{cmd:"https://vite-pwa-org.netlify.app/assets-generator/cli.html",desc:"View docs"}]}},examples:[{cmd:"$0 docs dev --port 1312",desc:"Run dev server with custom port"},{cmd:'$0 docs generate-assets --flag="--preset=minimal" --flag=public/logo.svg',desc:"Generate assets"}],fn:async({cmds:s,showHelp:a,opts:e,utils:o})=>{const t=new p({utils:o,opts:{port:e?.port,configPath:e?.["config-path"],packageJsonPath:e?.["package-path"],debug:e?.verbose}});s?.includes("dev")?await t.dev():s?.includes("build")?await t.build():s?.includes("preview")?await t.preview():s?.includes("publish-cf")&&e?.dir&&e?.name?await t.publishToCloudflare({dir:e.dir,name:e.name}):s?.includes("generate-assets")?await t.generatePWAassets(e?.flag):a()}}}});export{p as D,w as d};