UNPKG

@lunora/cli

Version:

The Lunora CLI: init, dev, deploy, codegen, migrate, seed, doctor, insights, logs, registry, and the rest of the project commands

2 lines (1 loc) 2.21 kB
import{join as l,resolve as u}from"node:path";import{p as m}from"../packem_shared/api-spec-lYyq4vL6.mjs";import{w as f}from"../packem_shared/binding-manifest-file-CQ1eQYy1.mjs";import{d as p}from"../packem_shared/command-DwC11Cwe.mjs";import{v as g,l as w,i as y,p as v}from"../packem_shared/output-format-DfogXx0p.mjs";import{defaultSpawner as b}from"../packem_shared/createRecordingSpawner-DJlNacZ6.mjs";import{runDeployCommand as B}from"./runDeployCommand.mjs";import{readdirSync as S,readFileSync as h}from"node:fs";import{gzipSync as F}from"node:zlib";const D=e=>!e.endsWith(".map")&&e!=="bundle-meta.json"&&e!=="README.md",z=e=>{let t;try{t=S(e,{recursive:!0,withFileTypes:!0})}catch{return}let r=0,i=0,a=0;for(const o of t){if(!o.isFile()||!D(o.name))continue;const n=h(l(o.parentPath,o.name));r+=1,a+=n.byteLength,i+=F(n).byteLength}return r===0?void 0:{files:r,gzipBytes:i,rawBytes:a}},M=".lunora/build",$=async e=>b({...e,stdoutToStderr:!0}),c=e=>`${(e/1024).toFixed(1)} KiB`,E=(e,t,r)=>f({destination:t,logger:r,projectRoot:e}),T=async e=>{const t=e.outDir??M,r=y(e.format),i=w(e.format,e.logger),a=s=>(r&&v(s),s),o=g("build",e.format);if(o!==void 0)return e.logger.error(o),{code:1,descriptor:void 0,error:o,validation:{problems:[],wranglerPath:void 0}};const n=await B({apiSpec:e.apiSpec,cwd:e.cwd,dryRun:!0,format:void 0,interactive:r?!1:void 0,logger:i,outDir:t,spawner:e.spawner??(r?$:void 0),target:e.target});if(n.code!==0)return a(n);i.success(`build complete — bundle written to ${t}`);const d=z(u(e.cwd??process.cwd(),t));if(d===void 0?i.warn(`could not weigh the bundle — nothing uploadable was found in ${t}`):i.info(`bundle: ${c(d.rawBytes)} raw, ${c(d.gzipBytes)} gzipped across ${String(d.files)} file(s) — Cloudflare's Worker size limit (3 MB Free, 10 MB Paid) applies to the gzipped number`),e.emitBindings!==void 0){const{error:s}=E(e.cwd??process.cwd(),e.emitBindings,i);if(s!==void 0)return i.error(s),a({...n,bundle:d,code:1})}return a({...n,bundle:d})},k=p(async({cwd:e,logger:t,options:r})=>({code:(await T({apiSpec:m(r.apiSpec),cwd:e,emitBindings:r.emitBindings,format:r.format,logger:t,outDir:r.outDir,target:r.target})).code}));export{k as execute,T as runBuildCommand};