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.16 kB
import{join as u,resolve as m}from"node:path";import{p as f}from"../packem_shared/deploy-target-DCWwiuAe.mjs";import{d as p}from"../packem_shared/command-CAXl2A1S.mjs";import{defaultSpawner as w}from"../packem_shared/createRecordingSpawner-CYhdPBD5.mjs";import{runDeployCommand as y}from"./runDeployCommand.mjs";import{readdirSync as g,readFileSync as S}from"node:fs";import{gzipSync as b}from"node:zlib";const d=64*1024*1024,h=e=>!e.endsWith(".map")&&e!=="bundle-meta.json"&&e!=="README.md",v=e=>{let n;try{n=g(e,{recursive:!0,withFileTypes:!0})}catch{return}let o=0,r=0,t=0;for(const i of n){if(!i.isFile()||!h(i.name))continue;const a=S(u(i.parentPath,i.name));o+=1,t+=a.byteLength,r+=b(a).byteLength}return o===0?void 0:{files:o,gzipBytes:r,rawBytes:t}},l=".lunora/build",B=async e=>w({...e,stdoutToStderr:!0}),c=e=>`${(e/1024).toFixed(1)} KiB`,D=async e=>{const n=e.outDir??l,o=e.format==="json",{logger:r}=e,t=await y({allowSchemaDrift:e.allowSchemaDrift,apiSpec:e.apiSpec,commandName:"build",cwd:e.cwd,dryRun:!0,emitBindings:e.emitBindings,format:void 0,interactive:o?!1:void 0,logger:r,outDir:n,spawner:e.spawner??(o?B:void 0),strictAdvisories:e.strictAdvisories,target:e.target});if(t.code!==0)return t;r.success(`build complete — bundle written to ${n}`);const i=v(m(e.cwd??process.cwd(),n));if(i===void 0)r.warn(`could not weigh the bundle — nothing uploadable was found in ${n}`);else{const a=(i.rawBytes/d*100).toFixed(1),s=`bundle: ${c(i.rawBytes)} raw across ${String(i.files)} file(s) — ${a}% of Cloudflare's 64 MiB uncompressed Worker size limit (${c(i.gzipBytes)} gzipped, for reference; there is no compressed limit)`;i.rawBytes>d?r.warn(`${s} — Cloudflare will reject this upload`):r.info(s)}return{...t,bundle:i}},R=p(async({cwd:e,format:n,logger:o,options:r})=>{const t=await D({allowSchemaDrift:r.allowSchemaDrift===!0,apiSpec:f(r.apiSpec),cwd:e,emitBindings:r.emitBindings,format:n,logger:o,outDir:r.outDir,strictAdvisories:r.strictAdvisories,target:r.target});return{code:t.code,data:{bundle:t.bundle,deployment:t.deployment,outDir:r.outDir??l,validation:t.validation},error:t.error}});export{R as execute,D as runBuildCommand};