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) • 3.15 kB
import{randomUUID as $}from"node:crypto";import{readdirSync as D,readFileSync as b,existsSync as d,rmSync as l,mkdirSync as S,copyFileSync as z,writeFileSync as A,lstatSync as j}from"node:fs";import{join as f,resolve as m,dirname as v}from"node:path";import{resolveLazyFunctions as F,DEFAULT_BUNDLE_META_PATH as E}from"@lunora/config";import{p as M}from"../packem_shared/api-spec-lYyq4vL6.mjs";import{d as T}from"../packem_shared/command-B6vu47iR.mjs";import{p as _,v as R,r as U}from"./handler.mjs";import{defaultSpawner as x}from"../packem_shared/createRecordingSpawner-01ZngIwK.mjs";import{gzipSync as I}from"node:zlib";const g=64*1024*1024,P=e=>!e.endsWith(".map")&&e!=="bundle-meta.json"&&e!=="README.md",C=e=>{let i;try{i=D(e,{recursive:!0,withFileTypes:!0})}catch{return}let o=0,r=0,n=0;for(const t of i){if(!t.isFile()||!P(t.name))continue;const c=b(f(t.parentPath,t.name));o+=1,n+=c.byteLength,r+=I(c).byteLength}return o===0?void 0:{files:o,gzipBytes:r,rawBytes:n}},k=".lunora/build",O=async e=>x({...e,stdoutToStderr:!0}),B=e=>`${(e/1024).toFixed(1)} KiB`,h=e=>d(e)?D(e,{encoding:"utf8",recursive:!0}).map(i=>{try{const o=j(f(e,i));return`${i}:${String(o.size)}:${String(o.mtimeMs)}`}catch{return`${i}:gone`}}).join(` `):"",W=async e=>{const i=e.outDir??k,o=e.format==="json",{logger:r}=e,n=e.cwd??process.cwd(),t=m(n,i,"bundle-meta.json"),c=R(n,$()),y=d(t)?b(t):void 0;l(t,{force:!0}),l(c,{force:!0});const w=m(n,i),L=h(w);let s;try{s=await U({allowSchemaDrift:e.allowSchemaDrift,apiSpec:e.apiSpec,bundleMetaPath:c,frameworkBuild:e.frameworkBuild,lazyFunctions:F(e.lazyFunctions),commandName:"build",clientBuildOutputJson:o,cwd:e.cwd,dryRun:!0,emitBindings:e.emitBindings,format:void 0,interactive:o?!1:void 0,logger:r,outDir:i,smokeLauncher:e.smokeLauncher,smokeLoad:e.smokeLoad,spawner:e.spawner??(o?O:void 0),strictAdvisories:e.strictAdvisories,target:e.target});const u=e.frameworkBuild===!1?f(n,E):c;s.code===0&&!d(t)&&d(u)&&(S(v(t),{recursive:!0}),z(u,t))}finally{l(c,{force:!0}),y!==void 0&&!d(t)&&h(w)===L&&s?.code!==0&&(S(v(t),{recursive:!0}),A(t,y))}if(s.code!==0)return s;r.success(`build complete — bundle written to ${i}`);const a=C(m(e.cwd??process.cwd(),i));if(a===void 0)r.warn(`could not weigh the bundle — nothing uploadable was found in ${i}`);else{const u=(a.rawBytes/g*100).toFixed(1),p=`bundle: ${B(a.rawBytes)} raw across ${String(a.files)} file(s) — ${u}% of Cloudflare's 64 MiB uncompressed Worker size limit (${B(a.gzipBytes)} gzipped, for reference; there is no compressed limit)`;a.rawBytes>g?r.warn(`${p} — Cloudflare will reject this upload`):r.info(p)}return{...s,bundle:a}},V=T(async({cwd:e,format:i,logger:o,options:r})=>{const n=_(e,r.root),t=await W({allowSchemaDrift:r.allowSchemaDrift===!0,apiSpec:M(r.apiSpec),lazyFunctions:F(r.lazyFunctions),cwd:n,emitBindings:r.emitBindings,format:i,frameworkBuild:r.frameworkBuild,logger:o,outDir:r.outDir,smokeLoad:r.smokeLoad,strictAdvisories:r.strictAdvisories,target:r.target});return{code:t.code,data:{bundle:t.bundle,deployment:t.deployment,outDir:r.outDir??k,validation:t.validation},error:t.error}});export{V as execute,W as runBuildCommand};