UNPKG

@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.29 kB
import{existsSync as k,readFileSync as T}from"node:fs";import{applyLintIgnores as N,detectLintTools as I}from"@lunora/config";import{findWranglerFile as A}from"@lunora/config/cloudflare";import{join as v,basename as g}from"@visulima/path";import{d as D}from"../packem_shared/command-DwC11Cwe.mjs";import{n as S,i as U,E as L,s as M,d as m,p as _,r as f,M as F,a as O,b as h,c as E,e as P,D as o,f as j,g as R,h as d,A as $,j as p,w as x,k as B,l as z}from"../packem_shared/lint-ignore-report-0sVOnXcO.mjs";import{v as H,l as C,i as J,p as W}from"../packem_shared/output-format-DfogXx0p.mjs";import{t as w,a as q}from"../packem_shared/tui-prompts-Dd0pDuNr.mjs";import{r as V}from"../packem_shared/commands-B-YnEi2t.mjs";const G=e=>{const r=e.trim().toLowerCase();return p.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{}}},K=async e=>{const r=e.cwd??process.cwd(),t=R(y(r));return t!==void 0?t:e.yes===!0?(e.logger.warn(`add: couldn't detect your framework — using "${d}". Pass a specific item (e.g. \`lunora add auth-ui-vue\`) to override.`),d):await(e.promptSelect??((s,i,n)=>w(s,i,n)))("Which framework is your app?",$,{default:d})??d},Q=async e=>{if(e.provider!==void 0&&e.provider!==""){const t=G(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,s)=>w(t,a,s));return j(r)},l=e=>e.promptText??((r,t)=>q(r,t)),X=async e=>{const r=g(e.cwd??process.cwd());if(e.bucket!==void 0&&e.bucket!==""){const t=M(e.bucket);if(t!==void 0)return t;const a=m(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?m(r):_(l(e),r)},Y=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 l(e)(F,{placeholder:"you@yourdomain.com"}),r)},Z=async e=>{const r=g(e.cwd??process.cwd());if(e.db!==void 0&&e.db!==""){const t=O(e.db);if(t!==void 0)return t;const a=h(r);return e.logger.warn(`add: "${e.db}" isn't a usable D1 database name — using "${a}".`),a}return e.yes===!0?h(r):E(l(e),r)},ee=async(e,r)=>e.kind==="auth"?[await Q(r)]:e.kind==="auth-ui"?[await K(r)]:e.kind==="email"?[L]:[e.item],re=(e,r)=>{P(N(e,I(e)),r)},ae=async e=>{const r=e.cwd??process.cwd(),t=e.feature===void 0?void 0:S(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"))||A(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"&&U(y(r)))return e.logger.error("add: auth-ui has no React Native port — the screens render DOM elements and a stylesheet, which Metro has nothing to mount. Build the screens with React Native primitives against the same better-auth client (`@lunora/react-native/auth`); `lunora add auth` still installs the server half."),{code:1,items:[]};const a=await ee(t,e),s=[];if(a.includes("storage")){const c=await X(e);s.push(u=>x(u,c))}if(a.includes("mail")){const c=await Y(e);c!==void 0&&s.push(u=>B(u,c))}if(a.some(c=>c==="auth"||c.startsWith("auth-"))){const c=await Z(e);s.push(u=>z(u,c))}const i=s.length>0?c=>{let u=c;for(const b of s)u=b(u);return u}:void 0,n=await V({allowUnsafeSource:e.allowUnsafeSource,cwd:r,from:e.from,logger:e.logger,names:[...a],ref:e.ref,source:e.source,transformManifest:i,yes:!0});return n.code===0&&re(r,e.logger),{code:n.code,items:a}},me=D(async({argument:e,cwd:r,logger:t,options:a})=>{const s=H("add",a.format);if(s!==void 0)return t.error(s),{code:1};const i=C(a.format,t),n=await ae({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 J(a.format)&&W({code:n.code,items:n.items}),{code:n.code}});export{me as execute,ae as runAddFeature};