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