UNPKG

@lunora/cli

Version:

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

3 lines (2 loc) 2.95 kB
import{readdirSync as m,readFileSync as u,mkdirSync as g,writeFileSync as p}from"node:fs";import{join as f,resolve as l,isAbsolute as w,dirname as b}from"node:path";import{findWranglerFile as h,readWranglerJsonc as y,buildBindingManifest as v}from"@lunora/config/cloudflare";import{r as $}from"../packem_shared/api-spec-BENwiyUa.mjs";import{i as S}from"../packem_shared/command-0l-ZPhIX.mjs";import{i as B,s as z,t as F,d as D}from"../packem_shared/output-format-Cv3aLqhP.mjs";import{defaultSpawner as k}from"../packem_shared/createRecordingSpawner-SKs4R1fc.mjs";import{runDeployCommand as x}from"./runDeployCommand.mjs";import{gzipSync as M}from"node:zlib";const W=e=>!e.endsWith(".map")&&e!=="bundle-meta.json"&&e!=="README.md",j=e=>{let t;try{t=m(e,{recursive:!0,withFileTypes:!0})}catch{return}let r=0,o=0,d=0;for(const i of t){if(!i.isFile()||!W(i.name))continue;const n=u(f(i.parentPath,i.name));r+=1,d+=n.byteLength,o+=M(n).byteLength}return r===0?void 0:{files:r,gzipBytes:o,rawBytes:d}},A=".lunora/build",C=async e=>k({...e,stdoutToStderr:!0}),c=e=>`${(e/1024).toFixed(1)} KiB`,P=(e,t,r)=>{const o=h(e),d=o===void 0?void 0:y(o).parsed;if(d===void 0)return{error:`--emit-bindings found no readable wrangler config in ${e}. The manifest is derived from it, and an empty one would tell a deployer this Worker needs nothing.`};const i=v(d),n=w(t)?t:l(e,t);return g(b(n),{recursive:!0}),p(n,`${JSON.stringify(i,void 0,2)} `,"utf8"),r.success(`binding manifest written to ${n} (${i.bindings.length.toString()} bindings, ${i.crons.length.toString()} crons)`),i.unknown.length>0&&r.warn(`binding manifest does not model these wrangler sections: ${i.unknown.join(", ")}. Anything they bind must be provisioned by hand — please report them so the manifest can cover them.`),{}},R=async e=>{const t=e.outDir??A,r=F(e.format),o=z(e.format,e.logger),d=a=>(r&&D(a),a),i=B("build",e.format);if(i!==void 0)return e.logger.error(i),{code:1,descriptor:void 0,error:i,validation:{problems:[],wranglerPath:void 0}};const n=await x({apiSpec:e.apiSpec,cwd:e.cwd,dryRun:!0,format:void 0,interactive:r?!1:void 0,logger:o,outDir:t,spawner:e.spawner??(r?C:void 0),target:e.target});if(n.code!==0)return d(n);o.success(`build complete — bundle written to ${t}`);const s=j(l(e.cwd??process.cwd(),t));if(s===void 0?o.warn(`could not weigh the bundle — nothing uploadable was found in ${t}`):o.info(`bundle: ${c(s.rawBytes)} raw, ${c(s.gzipBytes)} gzipped across ${String(s.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:a}=P(e.cwd??process.cwd(),e.emitBindings,o);if(a!==void 0)return o.error(a),d({...n,bundle:s,code:1})}return d({...n,bundle:s})},H=S(async({cwd:e,logger:t,options:r})=>({code:(await R({apiSpec:$(r.apiSpec),cwd:e,emitBindings:r.emitBindings,format:r.format,logger:t,outDir:r.outDir,target:r.target})).code}));export{H as execute,R as runBuildCommand};