@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) • 4.17 kB
JavaScript
import{existsSync as k,readFileSync as T}from"node:fs";import{applyLintIgnores as A,detectLintTools as I}from"@lunora/config";import{findWranglerFile as N}from"@lunora/config/cloudflare";import{join as v,basename as w}from"@visulima/path";import{d as U}from"../packem_shared/command-DwC11Cwe.mjs";import{r as S}from"../packem_shared/lint-ignore-report-DKZagpqk.mjs";import{v as D,l as _,i as E,p as L}from"../packem_shared/output-format-DfogXx0p.mjs";import{t as h,a as F}from"../packem_shared/tui-prompts-DzYd2fL3.mjs";import{i as M}from"../packem_shared/resolve-B9ReA3FV.mjs";import{n as O,i as P,A as R,E as j,s as $,d as l,p,r as f,M as x,a as C,b as g,c as H,D as o,e as z,f as B,g as n,h as J,j as W,w as V,k as q,l as G}from"../packem_shared/storage-B0ixDDxG.mjs";import{r as K}from"../packem_shared/commands-I18aR_DJ.mjs";const Q=e=>{const r=e.trim().toLowerCase();return W.find(a=>a.value===r||a.label.toLowerCase()===r||r==="auth0"&&a.value==="auth-auth0"||r==="clerk"&&a.value==="auth-clerk")?.value},y=e=>{try{const r=JSON.parse(T(v(e,"package.json"),"utf8"));return{...r.dependencies,...r.devDependencies}}catch{return{}}},X=async e=>{const r=e.cwd??process.cwd(),t=B(y(r));return t!==void 0?t:e.yes===!0?(e.logger.warn(`add: couldn't detect your framework — using "${n}". Pass a specific item (e.g. \`lunora add auth-ui-vue\`) to override.`),n):await(e.promptSelect??((c,i,d)=>h(c,i,d)))("Which framework is your app?",J,{default:n})??n},Y=async e=>{if(e.provider!==void 0&&e.provider!==""){const t=Q(e.provider);return t===void 0?(e.logger.warn(`add: unknown --provider "${e.provider}" — using "${o}" (email & password).`),o):t}if(e.yes===!0)return o;const r=e.promptSelect??((t,a,c)=>h(t,a,c));return z(r)},m=e=>e.promptText??((r,t)=>F(r,t)),Z=async e=>{const r=w(e.cwd??process.cwd());if(e.bucket!==void 0&&e.bucket!==""){const t=$(e.bucket);if(t!==void 0)return t;const a=l(r);return e.logger.warn(`add: "${e.bucket}" isn't a valid R2 bucket name (lowercase alphanumeric + hyphens, 3–63 chars) — using "${a}".`),a}return e.yes===!0?l(r):p(m(e),r)},ee=async e=>{const r=t=>{e.logger.warn(`add: ${t}`)};if(e.mailTo!==void 0&&e.mailTo!=="")return f(e.mailTo,r);if(e.yes!==!0)return f(await m(e)(x,{placeholder:"you@yourdomain.com"}),r)},re=async e=>{const r=w(e.cwd??process.cwd());if(e.db!==void 0&&e.db!==""){const t=C(e.db);if(t!==void 0)return t;const a=g(r);return e.logger.warn(`add: "${e.db}" isn't a usable D1 database name — using "${a}".`),a}return e.yes===!0?g(r):H(m(e),r)},ae=async(e,r)=>e.kind==="auth"?[await Y(r)]:e.kind==="auth-ui"?[await X(r)]:e.kind==="email"?[j]:[e.item],te=(e,r)=>{S(A(e,I(e)),r)},ce=e=>!M(e)||e.yes===!0,se=async e=>{const r=e.cwd??process.cwd(),t=e.feature===void 0?void 0:O(e.feature);if(t===void 0)return e.logger.error("add requires a feature or registry item. Usage: lunora add <auth|email|storage|crons|presence|…>"),{code:1,items:[]};if(!k(v(r,"lunora"))||N(r)===void 0)return e.logger.error("add: not a Lunora project here (need a lunora/ directory and a wrangler.jsonc). Run `lunora init` first."),{code:1,items:[]};if(t.kind==="auth-ui"&&P(y(r)))return e.logger.error(`add: ${R}`),{code:1,items:[]};const a=await ae(t,e),c=[];if(a.includes("storage")){const s=await Z(e);c.push(u=>V(u,s))}if(a.includes("mail")){const s=await ee(e);s!==void 0&&c.push(u=>q(u,s))}if(a.some(s=>s==="auth"||s.startsWith("auth-"))){const s=await re(e);c.push(u=>G(u,s))}const i=c.length>0?s=>{let u=s;for(const b of c)u=b(u);return u}:void 0,d=await K({allowUnsafeSource:e.allowUnsafeSource,confirm:e.confirm,cwd:r,from:e.from,logger:e.logger,names:[...a],ref:e.ref,source:e.source,transformManifest:i,yes:ce(e)});return d.code===0&&te(r,e.logger),{code:d.code,items:a}},he=U(async({argument:e,cwd:r,logger:t,options:a})=>{const c=D("add",a.format);if(c!==void 0)return t.error(c),{code:1};const i=_(a.format,t),d=await se({allowUnsafeSource:a.allowUnsafeSource===!0,bucket:a.bucket,cwd:r,db:a.db,feature:e[0],from:a.from,logger:i,mailTo:a.mailTo,provider:a.provider,ref:a.ref,source:a.source,yes:a.yes===!0});return E(a.format)&&L({code:d.code,items:d.items}),{code:d.code}});export{he as execute,se as runAddFeature};