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