@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.11 kB
JavaScript
import{existsSync as k,readFileSync as A}from"node:fs";import{applyLintIgnores as I,detectLintTools as N}from"@lunora/config";import{findWranglerFile as U}from"@lunora/config/cloudflare";import{join as w,basename as h}from"@visulima/path";import{d as S}from"../packem_shared/command-Mmxzxyr5.mjs";import{EXIT_CODE as o}from"../packem_shared/EXIT_CODE-08cwt3MK.mjs";import{r as D}from"../packem_shared/lint-ignore-report-DKZagpqk.mjs";import{t as y,a as E}from"../packem_shared/tui-prompts-B3YwUhGw.mjs";import{i as _}from"../packem_shared/resolve-DUCSc7jQ.mjs";import{r as L}from"../packem_shared/commands-CdVObzRk.mjs";import{n as M,i as O,A as P,E as R,s as j,d as f,p as $,r as g,M as F,a as C,b as v,c as p,D as m,e as x,f as H,g as i,h as z,j as B,w as G,k as W,l as V}from"../packem_shared/storage-2MQBGhKZ.mjs";const q=e=>{const r=e.trim().toLowerCase();return B.find(a=>a.value===r||a.label.toLowerCase()===r||r==="auth0"&&a.value==="auth-auth0"||r==="clerk"&&a.value==="auth-clerk")?.value},T=e=>{try{const r=JSON.parse(A(w(e,"package.json"),"utf8"));return{...r.dependencies,...r.devDependencies}}catch{return{}}},J=async e=>{const r=e.cwd??process.cwd(),t=H(T(r));return t!==void 0?t:e.yes===!0?(e.logger.warn(`add: couldn't detect your framework — using "${i}". Pass a specific item (e.g. \`lunora add auth-ui-vue\`) to override.`),i):await(e.promptSelect??((c,n,d)=>y(c,n,d)))("Which framework is your app?",z,{default:i})??i},X=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 "${m}" (email & password).`),m):t}if(e.yes===!0)return m;const r=e.promptSelect??((t,a,c)=>y(t,a,c));return x(r)},l=e=>e.promptText??((r,t)=>E(r,t)),K=async e=>{const r=h(e.cwd??process.cwd());if(e.bucket!==void 0&&e.bucket!==""){const t=j(e.bucket);if(t!==void 0)return t;const a=f(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?f(r):$(l(e),r)},Q=async e=>{const r=t=>{e.logger.warn(`add: ${t}`)};if(e.mailTo!==void 0&&e.mailTo!=="")return g(e.mailTo,r);if(e.yes!==!0)return g(await l(e)(F,{placeholder:"you@yourdomain.com"}),r)},Y=async e=>{const r=h(e.cwd??process.cwd());if(e.db!==void 0&&e.db!==""){const t=C(e.db);if(t!==void 0)return t;const a=v(r);return e.logger.warn(`add: "${e.db}" isn't a usable D1 database name — using "${a}".`),a}return e.yes===!0?v(r):p(l(e),r)},Z=async(e,r)=>e.kind==="auth"?[await X(r)]:e.kind==="auth-ui"?[await J(r)]:e.kind==="email"?[R]:[e.item],ee=(e,r)=>{D(I(e,N(e)),r)},re=e=>!_(e)||e.yes===!0,ae=async e=>{const r=e.cwd??process.cwd(),t=e.feature===void 0?void 0:M(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:o.USAGE,items:[]};if(!k(w(r,"lunora"))||U(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:o.USAGE,items:[]};if(t.kind==="auth-ui"&&O(T(r)))return e.logger.error(`add: ${P}`),{code:o.USAGE,items:[]};const a=await Z(t,e),c=[];if(a.includes("storage")){const s=await K(e);c.push(u=>G(u,s))}if(a.includes("mail")){const s=await Q(e);s!==void 0&&c.push(u=>W(u,s))}if(a.some(s=>s==="auth"||s.startsWith("auth-"))){const s=await Y(e);c.push(u=>V(u,s))}const n=c.length>0?s=>{let u=s;for(const b of c)u=b(u);return u}:void 0,d=await L({allowUnsafeSource:e.allowUnsafeSource,confirm:e.confirm,cwd:r,from:e.from,logger:e.logger,names:[...a],ref:e.ref,source:e.source,transformManifest:n,yes:re(e)});return d.code===0&&ee(r,e.logger),{code:d.code,items:a}},ge=S(async({argument:e,cwd:r,logger:t,options:a})=>{const c=await ae({allowUnsafeSource:a.allowUnsafeSource===!0,bucket:a.bucket,cwd:r,db:a.db,feature:e[0],from:a.from,logger:t,mailTo:a.mailTo,provider:a.provider,ref:a.ref,source:a.source,yes:a.yes===!0});return{code:c.code,data:{items:c.items},...c.error===void 0?{}:{error:c.error}}});export{ge as execute,ae as runAddFeature};