@every-app/cli 0.0.24 → 0.0.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
- import{a as o,b as s}from"./chunk-BAI6ILH4.js";import{proposeCompletions as r}from"@stricli/core";var t=process.argv.slice(3);process.env.COMP_LINE?.endsWith(" ")&&t.push("");await r(s,t,o(process));try{for(let{completion:p}of await r(s,t,o(process)))process.stdout.write(`${p}
2
+ import{a as o,b as s}from"./chunk-HHGWXJ27.js";import{proposeCompletions as r}from"@stricli/core";var t=process.argv.slice(3);process.env.COMP_LINE?.endsWith(" ")&&t.push("");await r(s,t,o(process));try{for(let{completion:p}of await r(s,t,o(process)))process.stdout.write(`${p}
3
3
  `)}catch{}
@@ -0,0 +1,6 @@
1
+ import{i as l}from"./chunk-OFG6XV6S.js";import r from"node:fs/promises";import n from"node:path";import f from"node:os";import p from"chalk";async function u(e,t,i={}){let a=i.exclude||[];await r.mkdir(t,{recursive:!0});let m=await r.readdir(e,{withFileTypes:!0});for(let o of m){let s=n.join(e,o.name),c=n.join(t,o.name);a.some(y=>o.name===y)||(o.isDirectory()?await u(s,c,i):await r.copyFile(s,c))}}async function P(e){try{return(await r.stat(e)).isDirectory()}catch{return!1}}async function x({targetDir:e,appId:t}){let i=await l("every-app-gateway"),a=`# Vite client-side secrets
2
+ VITE_APP_ID=${t}
3
+ VITE_GATEWAY_URL=${i}
4
+ # Set Cloudflare secrets locally
5
+ GATEWAY_URL=${i}
6
+ `;await Promise.all([r.writeFile(n.join(e,".env.local"),a)])}async function T(e){return await r.mkdtemp(n.join(f.tmpdir(),e))}async function C({tmpDir:e,verbose:t=!1}){try{await r.rm(e,{recursive:!0,force:!0}),t&&console.log(p.dim(` Removed: ${e}`))}catch{console.warn(p.yellow("\u26A0\uFE0F Warning: Failed to clean up temporary directory:"),e)}}export{u as a,P as b,x as c,T as d,C as e};
@@ -1,30 +1,30 @@
1
- import{c as g,d as k,e as N}from"./chunk-BRCQN4SN.js";import{a as C,b as I,c as v,d as x,e as P,g as R,i as D,j as $,n as T}from"./chunk-OFG6XV6S.js";import S from"node:fs/promises";import _ from"node:path";import*as O from"jsonc-parser";import{z as u}from"zod";var G="every-app.jsonc",M=u.object({appId:u.string().min(1,"appId cannot be empty"),displayName:u.string().min(1,"displayName cannot be empty").optional(),description:u.string().optional()});async function b(t){let r=_.join(t,G);try{let e=await S.readFile(r,"utf-8"),o=O.parse(e);return M.parse(o)}catch(e){if(e instanceof Error&&"code"in e&&e.code==="ENOENT")throw new Error("every-app.jsonc not found. Make sure you're running this command from an Every App project directory.");if(e instanceof u.ZodError){let o=e.issues.map(n=>n.message).join(", ");throw new Error(`Invalid every-app.jsonc: ${o}`)}throw e}}function K(t){return t.split("-").map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join(" ")}async function ne(t,r){let e=_.join(t,G),o={...r,displayName:r.displayName??K(r.appId)},n=JSON.stringify(o,null,2)+`
2
- `;await S.writeFile(e,n)}async function se(t){return(await b(t)).appId}import{execa as q}from"execa";async function Q(){try{return await q("pnpm",["--version"],{stdio:"pipe"}),!0}catch{return!1}}async function j(t,r,e=!1){let o=await Q();try{o?await g("pnpm",["install"],{cwd:t,verbose:e,description:r}):await g("npx",["pnpm","install"],{cwd:t,verbose:e,description:r})}catch(n){throw new Error(`Failed to install dependencies with pnpm: ${n instanceof Error?n.message:"Unknown error"}`)}}import c from"chalk";async function F(t,r=!1){console.log(`
1
+ import{c as u,d as O,e as T}from"./chunk-KWOW5OHX.js";import{a as I,b as C,c as v,d as x,e as R,g as P,i as b,j as S,n as $}from"./chunk-OFG6XV6S.js";import k from"node:fs/promises";import N from"node:path";import*as _ from"jsonc-parser";import{z as g}from"zod";var G="every-app.jsonc",W=g.object({appId:g.string().min(1,"appId cannot be empty"),displayName:g.string().min(1,"displayName cannot be empty").optional(),description:g.string().optional()});async function D(t){let r=N.join(t,G);try{let e=await k.readFile(r,"utf-8"),o=_.parse(e);return W.parse(o)}catch(e){if(e instanceof Error&&"code"in e&&e.code==="ENOENT")throw new Error("every-app.jsonc not found. Make sure you're running this command from an Every App project directory.");if(e instanceof g.ZodError){let o=e.issues.map(n=>n.message).join(", ");throw new Error(`Invalid every-app.jsonc: ${o}`)}throw e}}function K(t){return t.split("-").map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join(" ")}async function ne(t,r){let e=N.join(t,G),o={...r,displayName:r.displayName??K(r.appId)},n=JSON.stringify(o,null,2)+`
2
+ `;await k.writeFile(e,n)}async function se(t){return(await D(t)).appId}import{execa as q}from"execa";async function Q(){try{return await q("pnpm",["--version"],{stdio:"pipe"}),!0}catch{return!1}}async function j({cwd:t,description:r,verbose:e=!1}){let o=await Q();try{o?await u("pnpm",["install"],{cwd:t,verbose:e,description:r}):await u("npx",["pnpm","install"],{cwd:t,verbose:e,description:r})}catch(n){throw new Error(`Failed to install dependencies with pnpm: ${n instanceof Error?n.message:"Unknown error"}`)}}import c from"chalk";async function F({appId:t,verbose:r=!1}){console.log(`
3
3
  Setting up your Cloudflare D1 Database and KV Store...
4
- `);let e=C(t),o=await Y(e,r),n=await B(e,r);return{d1DatabaseId:o,kvNamespaceId:n,resourceName:e}}async function Y(t,r){r&&(console.log(c.bold(`Processing D1 database...
4
+ `);let e=I(t),o=await Y(e,r),n=await B(e,r);return{d1DatabaseId:o,kvNamespaceId:n,resourceName:e}}async function Y(t,r){r&&(console.log(c.bold(`Processing D1 database...
5
5
  `)),console.log(` Checking D1 database: ${t}`));let e=await v(t);return r?e.wasCreated?console.log(c.green(` Created D1 database: ${t} (${e.id})
6
6
  `)):console.log(c.dim(` Linking to existing D1 database: ${t} (${e.id})
7
7
  `)):e.wasCreated?console.log(c.green(` D1 successfully created.
8
8
  `)):console.log(" D1 already set up."),e.id}async function B(t,r){r&&(console.log(c.bold(`Processing KV namespace...
9
9
  `)),console.log(` Checking KV namespace: ${t}`));let e=await x(t);return r?e.wasCreated?console.log(c.green(` Created KV namespace: ${t} (${e.id})
10
10
  `)):console.log(c.dim(` Linking to existing KV namespace: ${t} (${e.id})
11
- `)):e.wasCreated?console.log(c.green(" KV successfully created.")):console.log(" KV already set up."),e.id}import A from"chalk";async function V(t,r=!1){try{console.log(),console.log(A.dim(" Running any pending migrations against your remote D1 Database...")),await T("npx",["drizzle-kit","migrate","--config=drizzle-prod.config.ts"],{cwd:t,verbose:r}),console.log(A.green(`
11
+ `)):e.wasCreated?console.log(c.green(" KV successfully created.")):console.log(" KV already set up."),e.id}import A from"chalk";async function V({cwd:t,verbose:r=!1}){try{console.log(),console.log(A.dim(" Running any pending migrations against your remote D1 Database...")),await $("npx",["drizzle-kit","migrate","--config=drizzle-prod.config.ts"],{cwd:t,verbose:r}),console.log(A.green(`
12
12
  Migrations completed!
13
13
  `))}catch{console.warn(A.yellow(`Failed to run migrations. You may need to run them manually:
14
14
  npx drizzle-kit migrate --config=drizzle-prod.config.ts
15
- `))}}import J from"chalk";async function L({cwd:t,gatewayUrl:r,appId:e,verbose:o}){let n={...process.env,VITE_GATEWAY_URL:r,VITE_APP_ID:e};try{await g("npx",["vite","build"],{cwd:t,description:`Building your application...
16
- `,env:n,verbose:o}),await g("npx",["wrangler","deploy"],{cwd:t,description:`Deploying your application to Cloudflare workers...
15
+ `))}}import J from"chalk";async function L({cwd:t,gatewayUrl:r,appId:e,verbose:o}){let n={...process.env,VITE_GATEWAY_URL:r,VITE_APP_ID:e};try{await u("npx",["vite","build"],{cwd:t,description:`Building your application...
16
+ `,env:n,verbose:o}),await u("npx",["wrangler","deploy"],{cwd:t,description:`Deploying your application to Cloudflare workers...
17
17
 
18
18
  This could take up to a minute.`,env:n,verbose:o})}catch(i){throw console.error(J.red(`
19
- Failed to build or deploy`)),i}}import w from"chalk";var H="every-app-gateway";async function U(){let t=await R(),e=(await I()).find(o=>o.name===H);return e?{accountId:t,databaseId:e.uuid}:null}import m from"chalk";async function f(t,r,e,o){try{let n=await P(),i={sql:e};o&&o.length>0&&(i.params=o);let p=await fetch(`https://api.cloudflare.com/client/v4/accounts/${t}/d1/database/${r}/query`,{method:"POST",headers:{Authorization:`Bearer ${n}`,"Content-Type":"application/json"},body:JSON.stringify(i)}),s=await p.json();if(!p.ok||!s.success){let d=s.errors?s.errors.map(y=>`[${y.code}] ${y.message}`).join(", "):p.statusText;throw console.error(m.red(`
19
+ Failed to build or deploy`)),i}}import w from"chalk";var H="every-app-gateway";async function U(){let t=await P(),e=(await C()).find(o=>o.name===H);return e?{accountId:t,databaseId:e.uuid}:null}import m from"chalk";async function f(t,r,e,o){try{let n=await R(),i={sql:e};o&&o.length>0&&(i.params=o);let p=await fetch(`https://api.cloudflare.com/client/v4/accounts/${t}/d1/database/${r}/query`,{method:"POST",headers:{Authorization:`Bearer ${n}`,"Content-Type":"application/json"},body:JSON.stringify(i)}),s=await p.json();if(!p.ok||!s.success){let d=s.errors?s.errors.map(y=>`[${y.code}] ${y.message}`).join(", "):p.statusText;throw console.error(m.red(`
20
20
  D1 Query Error:`)),console.error(m.dim(`SQL: ${e}`)),console.error(m.dim(`Error: ${d}`)),new Error(`D1 query failed: ${d}`)}let a=s.result;if(!a||a.length===0)throw new Error("No results returned from D1 query");let l=a[0];if(!l)throw new Error("First result is undefined");return l.results}catch(n){throw n instanceof Error&&!n.message.includes("D1 query failed")&&(console.error(m.red(`
21
21
  D1 Query Error:`)),console.error(m.dim(`SQL: ${e}`))),n}}async function h(t){return f(t.accountId,t.databaseId,"SELECT id, name, email FROM users")}import{randomUUID as Z}from"node:crypto";async function X(t,r,e){return(await f(t.accountId,t.databaseId,"SELECT id FROM user_apps WHERE user_id = ? AND app_id = ?",[r,e])).length>0}async function E(t,r,e){if(await X(t,r.id,e.appId))return{created:!1};let n=Math.floor(Date.now()/1e3),i=Z(),p=`
22
22
  INSERT INTO user_apps (id, user_id, app_id, name, description, app_url, dev_url, created_at, updated_at)
23
23
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
24
- `;return await f(t.accountId,t.databaseId,p,[i,r.id,e.appId,e.name,e.description,e.appUrl,e.devUrl??null,n,n]),{created:!0}}async function z(t){let{appId:r,appUrl:e,verbose:o=!1,appName:n,appDescription:i,devUrl:p}=t;try{console.log(""),o&&console.log("Adding apps to user gateways...");let s=await U();if(!s){console.warn(w.yellow(`every-app-gateway database not found. Skipping UserApp record creation.
24
+ `;return await f(t.accountId,t.databaseId,p,[i,r.id,e.appId,e.name,e.description,e.appUrl,e.devUrl??null,n,n]),{created:!0}}async function M(t){let{appId:r,appUrl:e,verbose:o=!1,appName:n,appDescription:i,devUrl:p}=t;try{console.log(""),o&&console.log("Adding apps to user gateways...");let s=await U();if(!s){console.warn(w.yellow(`every-app-gateway database not found. Skipping UserApp record creation.
25
25
  `));return}let a=await h(s);if(a.length===0)throw new Error("No users found in the database. Please create a user first before deploying apps.");let l=n||r,d=i||r;o&&a.length>1&&console.log(w.yellow(`Multiple users found (${a.length}). Adding app to all users...
26
26
  `));for(let y of a)await ee(s,y,{appId:r,appUrl:e,name:l,description:d,devUrl:p,verbose:o});o&&a.length>1&&console.log(` UserApp records processed for ${a.length} users
27
- `)}catch(s){throw console.error(w.red("Failed to insert UserApp records:"),s instanceof Error?s.message:s),s}}async function ee(t,r,e){let{verbose:o,...n}=e;(await E(t,r,n)).created?console.log(` UserApp record created for user ${r.name} (${r.email})`):o&&console.log(w.dim(` UserApp record already exists for user ${r.name} (${r.email})`))}async function W(t,r,e=!1){e&&console.log("Configuring Secrets...");try{await k("GATEWAY_URL",r,e)||await N("GATEWAY_URL",t,r,e,`Setting GATEWAY_URL to: ${t}`),e&&console.log(`Secret setup complete!
27
+ `)}catch(s){throw console.error(w.red("Failed to insert UserApp records:"),s instanceof Error?s.message:s),s}}async function ee(t,r,e){let{verbose:o,...n}=e;(await E(t,r,n)).created?console.log(` UserApp record created for user ${r.name} (${r.email})`):o&&console.log(w.dim(` UserApp record already exists for user ${r.name} (${r.email})`))}async function z({gatewayUrl:t,appPath:r,verbose:e=!1}){e&&console.log("Configuring Secrets...");try{await O({secretName:"GATEWAY_URL",cwd:r,verbose:e})||await T({secretName:"GATEWAY_URL",secretValue:t,cwd:r,verbose:e,description:`Setting GATEWAY_URL to: ${t}`}),e&&console.log(`Secret setup complete!
28
28
  `)}catch(o){throw console.error(`
29
29
  Failed to setup secrets`,o instanceof Error?`
30
- ${o.message}`:""),o}}async function Qe(t){let{cwd:r,appId:e,verbose:o,devUrl:n}=t,{d1DatabaseId:i,kvNamespaceId:p,resourceName:s}=await F(e,o);await $({configPath:r,name:s,d1DatabaseId:i,d1DatabaseName:s,kvNamespaceId:p,verbose:o});let a=await D("every-app-gateway");console.log(),await j(r,"Installing dependencies for Cloudflare deployment...",o),await V(r,o),await L({cwd:r,gatewayUrl:a,appId:e,verbose:o}),await W(a,r,o);let l=await D(s),d=await b(r);return await z({appId:e,appUrl:l,verbose:o,appName:d.displayName,appDescription:d.description,devUrl:n}),{workerUrl:l,gatewayUrl:a}}export{ne as a,se as b,Qe as c};
30
+ ${o.message}`:""),o}}async function Qe(t){let{cwd:r,appId:e,verbose:o,devUrl:n}=t,{d1DatabaseId:i,kvNamespaceId:p,resourceName:s}=await F({appId:e,verbose:o});await S({configPath:r,name:s,d1DatabaseId:i,d1DatabaseName:s,kvNamespaceId:p,verbose:o});let a=await b("every-app-gateway");console.log(),await j({cwd:r,description:"Installing dependencies for Cloudflare deployment...",verbose:o}),await V({cwd:r,verbose:o}),await L({cwd:r,gatewayUrl:a,appId:e,verbose:o}),await z({gatewayUrl:a,appPath:r,verbose:o});let l=await b(s),d=await D(r);return await M({appId:e,appUrl:l,verbose:o,appName:d.displayName,appDescription:d.description,devUrl:n}),{workerUrl:l,gatewayUrl:a}}export{ne as a,se as b,Qe as c};
@@ -1,5 +1,5 @@
1
- import p from"node:fs";import l from"node:os";import d from"node:path";function A(e){return{process:e,os:l,fs:p,path:d}}import{buildApplication as g,buildRouteMap as C}from"@stricli/core";import{buildInstallCommand as D,buildUninstallCommand as v}from"@stricli/auto-complete";var r="@every-app/cli";var n="Every App CLI - Deploy and manage apps.";var a="0.0.24";import{buildCommand as t,buildRouteMap as m}from"@stricli/core";var c=t({loader:async()=>import("./create-QG5K6DQZ.js"),parameters:{positional:{kind:"tuple",parameters:[{brief:"App ID (kebab-case format)",parse:String,optional:!0}]},flags:{verbose:{kind:"boolean",brief:"Show detailed output during creation",optional:!0}}},docs:{brief:"Create a new app from the starter template",fullDescription:["Copies the simple-todo starter template, deploys to Cloudflare, and configures local development.","","Usage: every app create [name]","","The command will:"," 1. Prompt for app ID (or use provided name)"," 2. Deploy to Cloudflare (D1 database, KV namespace, Worker)"," 3. Configure wrangler.jsonc, package.json, and .env files"," 4. Install dependencies and run local migrations","","After creation, run 'pnpm run dev' to start developing."].join(`
2
- `)}}),u=t({loader:async()=>{let{deploy:e}=await import("./deploy-5NIQDBII.js");return e},parameters:{positional:{kind:"tuple",parameters:[]},flags:{verbose:{kind:"boolean",brief:"Show detailed output during deployment",optional:!0}}},docs:{brief:"Deploy an app to Cloudflare",fullDescription:["Deploys the current app to Cloudflare Workers from the current directory.","The deployment process:"," 1. Reads wrangler.jsonc to determine required resources"," 2. Creates or links D1 databases and KV namespaces"," 3. Updates wrangler.jsonc with resource IDs"," 4. Installs dependencies if needed"," 5. Runs database migrations against production D1"," 6. Builds and deploys using wrangler deploy"].join(`
1
+ import p from"node:fs";import l from"node:os";import d from"node:path";function A(e){return{process:e,os:l,fs:p,path:d}}import{buildApplication as g,buildRouteMap as C}from"@stricli/core";import{buildInstallCommand as D,buildUninstallCommand as v}from"@stricli/auto-complete";var r="@every-app/cli";var n="Every App CLI - Deploy and manage apps.";var a="0.0.25";import{buildCommand as t,buildRouteMap as m}from"@stricli/core";var c=t({loader:async()=>import("./create-KG5YX2NF.js"),parameters:{positional:{kind:"tuple",parameters:[{brief:"App ID (kebab-case format)",parse:String,optional:!0}]},flags:{verbose:{kind:"boolean",brief:"Show detailed output during creation",optional:!0}}},docs:{brief:"Create a new app from the starter template",fullDescription:["Copies the simple-todo starter template, deploys to Cloudflare, and configures local development.","","Usage: every app create [name]","","The command will:"," 1. Prompt for app ID (or use provided name)"," 2. Deploy to Cloudflare (D1 database, KV namespace, Worker)"," 3. Configure wrangler.jsonc, package.json, and .env files"," 4. Install dependencies and run local migrations","","After creation, run 'pnpm run dev' to start developing."].join(`
2
+ `)}}),u=t({loader:async()=>{let{deploy:e}=await import("./deploy-TM6LW2KB.js");return e},parameters:{positional:{kind:"tuple",parameters:[]},flags:{verbose:{kind:"boolean",brief:"Show detailed output during deployment",optional:!0}}},docs:{brief:"Deploy an app to Cloudflare",fullDescription:["Deploys the current app to Cloudflare Workers from the current directory.","The deployment process:"," 1. Reads wrangler.jsonc to determine required resources"," 2. Creates or links D1 databases and KV namespaces"," 3. Updates wrangler.jsonc with resource IDs"," 4. Installs dependencies if needed"," 5. Runs database migrations against production D1"," 6. Builds and deploys using wrangler deploy"].join(`
3
3
  `)}}),y=t({loader:async()=>{let{remoteD1Shell:e}=await import("./remoteD1Shell-PRLMRCDA.js");return e},parameters:{flags:{},positional:{kind:"array",parameter:{brief:"Command and arguments to run with environment variables",parse:String}}},docs:{brief:"Run a command with Cloudflare D1 connection environment variables",fullDescription:["Sets environment variables needed to connect to remote Cloudflare D1 and runs any command that requires D1 access.","","The command will:"," 1. Get the Cloudflare account ID"," 2. Look up the database ID from the database name in wrangler.jsonc"," 3. Get a valid OAuth token"," 4. Run the provided command with CLOUDFLARE_ACCOUNT_ID, CLOUDFLARE_DATABASE_ID, CLOUDFLARE_API_TOKEN, and MIGRATE_REMOTE set","","Common use cases:"," - Running Drizzle migrations: npx @every-app/cli app remote-d1-shell -- npx drizzle-kit migrate"," - Opening Drizzle Studio: npx @every-app/cli app remote-d1-shell -- npx drizzle-kit studio"," - Pushing schema changes: npx @every-app/cli app remote-d1-shell -- npx drizzle-kit push","","This command is useful for any operation that needs direct access to your production D1 database."].join(`
4
- `)}}),i=m({routes:{create:c,deploy:u,"remote-d1-shell":y},docs:{brief:"App management commands"}});import{buildCommand as f,buildRouteMap as b}from"@stricli/core";var h=f({loader:async()=>{let{deploy:e}=await import("./deploy-UZDGYJ6R.js");return e},parameters:{positional:{kind:"tuple",parameters:[]},flags:{repo:{kind:"parsed",parse:String,brief:"Git repository URL to deploy",optional:!0},verbose:{kind:"boolean",brief:"Show detailed output during deployment",optional:!0}}},docs:{brief:"Deploy the gateway application to Cloudflare",fullDescription:["Clones the gateway repository, installs dependencies, runs migrations, and deploys to Cloudflare Workers.","The deployment process:"," 1. Clones the repository to a temporary directory"," 2. Installs npm dependencies"," 3. Runs database migrations against production D1"," 4. Runs wrangler deploy"," 5. Cleans up temporary files"].join(`
4
+ `)}}),i=m({routes:{create:c,deploy:u,"remote-d1-shell":y},docs:{brief:"App management commands"}});import{buildCommand as f,buildRouteMap as b}from"@stricli/core";var h=f({loader:async()=>{let{deploy:e}=await import("./deploy-2MRRQLIF.js");return e},parameters:{positional:{kind:"tuple",parameters:[]},flags:{repo:{kind:"parsed",parse:String,brief:"Git repository URL to deploy",optional:!0},verbose:{kind:"boolean",brief:"Show detailed output during deployment",optional:!0}}},docs:{brief:"Deploy the gateway application to Cloudflare",fullDescription:["Clones the gateway repository, installs dependencies, runs migrations, and deploys to Cloudflare Workers.","The deployment process:"," 1. Clones the repository to a temporary directory"," 2. Installs npm dependencies"," 3. Runs database migrations against production D1"," 4. Runs wrangler deploy"," 5. Cleans up temporary files"].join(`
5
5
  `)}}),s=b({routes:{deploy:h},docs:{brief:"Gateway management commands"}});var x=C({routes:{app:i,gateway:s,install:D("every",{bash:"__every_bash_complete"}),uninstall:v("every",{bash:!0})},docs:{brief:n,hideRoute:{install:!0,uninstall:!0}}}),G=g(x,{name:r,versionInfo:{currentVersion:a},scanner:{allowArgumentEscapeSequence:!0}});export{A as a,G as b};
@@ -0,0 +1,19 @@
1
+ import{f as g,g as p,h as b}from"./chunk-OFG6XV6S.js";import i from"chalk";import w from"enquirer";import{execa as y}from"execa";async function W(n="Do you want to deploy to Cloudflare?"){console.log(`Checking Cloudflare account...
2
+ `);try{let{stdout:e}=await y("npx",["wrangler","whoami"],{reject:!1}),r=e.split(`
3
+ `),t=[],o=!1;for(let a of r)if(t.push(a),a.includes("\u2514\u2500")&&a.includes("\u2534\u2500")&&a.includes("\u2518")){o=!0;break}let s=o?t.join(`
4
+ `):e;return console.log(i.dim(s)),console.log(),(await w.prompt({type:"confirm",name:"confirm",message:n,initial:!1})).confirm}catch(e){throw console.error(i.red(`
5
+ Failed to retrieve Cloudflare account information`)),console.error(i.dim(` Make sure you're logged in with: npx wrangler login
6
+ `)),e}}async function k(n,e){try{let r=e?{subdomain:e}:{},t=await g(`/accounts/${n}/workers/subdomain`,{method:"PUT",body:JSON.stringify(r)});if(!t||!t.subdomain)throw new Error("Failed to initialize workers.dev subdomain");return t.subdomain}catch(r){throw new Error(`Failed to initialize workers.dev subdomain: ${r instanceof Error?r.message:"Unknown error"}`)}}async function O(){let n=await p();try{return await b(n)}catch{console.log(i.yellow(`No workers.dev subdomain found for this account.
7
+ `)),console.log(i.dim("A workers.dev subdomain is required to deploy Workers applications.")),console.log(i.dim(`This subdomain will be used for all Workers you deploy: [worker-name].[subdomain].workers.dev
8
+ `));let t=(await w.prompt({type:"input",name:"subdomain",message:"Choose a subdomain name (alphanumeric and hyphens only):",validate:o=>!o||o.trim()===""?"Subdomain cannot be empty":/^[a-z0-9-]+$/.test(o)?o.startsWith("-")||o.endsWith("-")?"Subdomain cannot start or end with a hyphen":!0:"Subdomain must contain only lowercase letters, numbers, and hyphens"})).subdomain.trim();console.log(i.dim(`
9
+ Creating workers.dev subdomain: ${t}...
10
+ `));try{let o=await k(n,t);return console.log(i.green(`Successfully created subdomain: ${i.cyan(o)}
11
+ `)),o}catch(o){throw console.error(i.red(`
12
+ Failed to create workers.dev subdomain`),i.dim(`
13
+ ${o instanceof Error?o.message:"Unknown error"}`)),o}}}import{execa as m}from"execa";import l from"chalk";async function D(n,e,r){let{env:t,cwd:o,verbose:s=!1,description:d,logCommandToConsole:a=!0}=r;return s?S(n,e,r):a?(console.log(`Running: ${n} ${e.join(" ")}`),d&&console.log(l.dim(` ${d}`)),await m(n,e,{cwd:o,env:t,stdio:"pipe"})):await m(n,e,{cwd:o,env:t,stdio:"pipe"})}async function S(n,e,{description:r,cwd:t,env:o}){console.log(l.dim(` \u250C\u2500 Running: ${n} ${e.join(" ")}`)),r&&console.log(l.dim(` \u2502 ${r}`));let s=m(n,e,{cwd:t,env:o,stdio:void 0,all:!0});s.stdout&&s.stdout.on("data",a=>{a.toString().split(`
14
+ `).forEach(c=>{c.trim()&&console.log(l.dim(` \u2502 ${c}`))})}),s.stderr&&s.stderr.on("data",a=>{a.toString().split(`
15
+ `).forEach(c=>{c.trim()&&console.error(l.dim(` \u2502 ${c}`))})});let d=await s;return console.log(l.dim(` \u2514\u2500 Complete
16
+ `)),d}import{execa as h}from"execa";import u from"chalk";async function x(n){let{stdout:e}=await h("npx",["wrangler","secret","list","--format","json"],{cwd:n});return JSON.parse(e)}async function z({secretName:n,cwd:e,verbose:r=!1}){r&&console.log(u.dim(` Checking secret: ${n}`));let o=(await x(e)).some(s=>s.name===n);return o&&r&&console.log(u.dim(` Secret already exists
17
+ `)),o}async function A({secretName:n,secretValue:e,cwd:r,verbose:t=!1,description:o}){t&&o&&console.log(u.dim(` ${o}
18
+ `));let s=h("npx",["wrangler","secret","put",n],{cwd:r});s.stdin&&(s.stdin.write(e),s.stdin.end()),await s,t&&console.log(u.green(`Created secret: ${n}
19
+ `))}export{W as a,O as b,D as c,z as d,A as e};
@@ -0,0 +1,24 @@
1
+ import{a as h,c as b}from"./chunk-AIGWZNYN.js";import{a as g,b as d,c as f,d as u,e as y}from"./chunk-A5W7ONYS.js";import{a as w,c as i}from"./chunk-KWOW5OHX.js";import"./chunk-OFG6XV6S.js";import m from"chalk";import C from"chalk";import{execa as $}from"execa";async function k(){try{await $("pnpm",["--version"],{stdio:"pipe"})}catch{console.error(C.red(`
2
+ Error: pnpm is required but not installed. Please install it first:`)),console.error(C.cyan(` npm i -g pnpm
3
+ `)),process.exit(1)}}import F from"enquirer";function U(o){return!o||o.trim().length===0?"App ID cannot be empty":o.length>64?"App ID must be 64 characters or less":/^[a-z][a-z0-9-]*$/.test(o)?!0:"App ID must be in kebab-case format (lowercase letters, numbers, and hyphens only, starting with a letter)"}async function v(o){console.log(`Project Configuration
4
+ `);let e=await F.prompt({type:"input",name:"appId",message:"Enter your app ID (kebab-case format)",initial:o,validate:U});return console.log(),{appId:e.appId}}import P from"node:path";import L from"chalk";async function x({url:o,targetDir:e,verbose:n=!1}){try{await i("git",["clone",o,e],{verbose:n,logCommandToConsole:!1})}catch(t){throw new Error(`Failed to clone repository from ${o}: ${t instanceof Error?t.message:"Unknown error"}`)}}var j="https://github.com/every-app/every-app.git",J="templates/simple-todo";async function D({appId:o,verbose:e=!1}){e&&console.log(`Cloning template repository...
5
+ `);let n=await u("every-app-create-");await x({url:j,targetDir:n,verbose:e}),e&&console.log(`Extracting template...
6
+ `);let t=P.join(n,J),l=P.join(process.cwd(),o);if(await d(l))throw new Error(`Directory "${o}" already exists in the current location`);return await g(t,l,{exclude:["node_modules",".git","pnpm-lock.yaml","package-lock.json",".env.local",".env.production",".dev.vars","manual-steps.md"]}),e&&console.log(L.dim(` Template copied to ${l}
7
+ `)),{tempDir:n,targetDir:l}}import T from"node:fs/promises";import S from"node:path";async function E({targetDir:o,appId:e}){let n=S.join(o,"package.json"),t=JSON.parse(await T.readFile(n,"utf-8"));t.name=e,await T.writeFile(n,JSON.stringify(t,null,2)+`
8
+ `,"utf-8")}import c from"chalk";async function I({targetDir:o,verbose:e=!1}){try{e||console.log(`
9
+ Setting up Cloudflare for local dev...`),await i("pnpm",["run","cf-typegen"],{cwd:o,verbose:e,logCommandToConsole:!1}),await i("pnpm",["run","build"],{cwd:o,verbose:e,logCommandToConsole:!1}),e||console.log(c.dim(` Finished.
10
+ `)),await i("pnpm",["run","db:migrate:local"],{cwd:o,verbose:e}),console.log(`
11
+ Local database migrations complete.
12
+ `)}catch{console.warn(c.yellow(`
13
+ Failed to run local migrations. You can run them manually with:`)),console.warn(c.dim(` pnpm run db:migrate:local
14
+ `))}}import r from"chalk";function R({appId:o,targetDir:e,gatewayUrl:n,workerUrl:t}){console.log(r.green(`Project created and deployed successfully!
15
+ `)),console.log(r.dim(` Location: ${e}`)),console.log(r.dim(` App URL: ${r.cyan(t)}`)),console.log(r.dim(` Gateway: ${r.cyan(n)}`)),console.log(),console.log(`For local development:
16
+ `),console.log(r.dim(` ${r.bold(`cd ${o}`)}`)),console.log(r.dim(` ${r.bold("pnpm run dev")}`)),console.log(r.dim(` ${r.bold(`
17
+ Then, go to the Gateway and click the "Dev" button on the app to go to the app running locally instead of on cloudflare.`)}`)),console.log(),console.log(`To deploy updates after changes:
18
+ `),console.log(r.dim(` ${r.bold("npx @every-app/cli app deploy")}`)),console.log()}async function wo(o,e){let n=o.verbose||!1;await k(),console.log(`
19
+ Create a new Every App project
20
+ `);let{appId:t}=await v(e);if(console.log(m.dim(`.
21
+ `)),!await w("Deploy this app to the above account? We deploy during app creation for smoother local dev with Cloudflare.")){console.log(m.yellow(`
22
+ App creation cancelled.
23
+ `));return}let s=null;try{let{tempDir:p,targetDir:a}=await D({appId:t,verbose:n});s=p,await E({targetDir:a,appId:t}),await h(a,{appId:t});let{workerUrl:A,gatewayUrl:O}=await b({cwd:a,appId:t,verbose:n,devUrl:"http://localhost:3001"});await f({targetDir:a,appId:t}),await I({targetDir:a,verbose:n}),R({appId:t,targetDir:a,gatewayUrl:O,workerUrl:A})}catch(p){throw console.error(m.red(`
24
+ Failed to create project:`),p instanceof Error?p.message:"Unknown error"),p}finally{s&&await y({tmpDir:s})}}export{wo as default};
@@ -0,0 +1,27 @@
1
+ import{d as h,e as C}from"./chunk-A5W7ONYS.js";import{a as k,b as T,c as A,d as l,e as p}from"./chunk-KWOW5OHX.js";import{c as u,d as y,g as w,i as E,j as R,k as S,l as D,n as x}from"./chunk-OFG6XV6S.js";import g from"chalk";import oe from"node:path";import c from"chalk";var N="every-app-gateway",V="every-app-gateway";async function _({verbose:o=!1}={}){console.log(`
2
+ Setting up your Cloudflare D1 Database and KV Store...
3
+ `);let t=await w(),e=await I(N,o),r=await v(V,o);return{d1DatabaseId:e,kvNamespaceId:r,accountId:t}}async function I(o,t){t&&console.log(` Checking D1 database: ${o}`);let e=await u(o);return t?e.wasCreated?console.log(c.green(` Created D1 database: ${o} (${e.id})
4
+ `)):console.log(c.dim(` Linking to existing D1 database: ${o} (${e.id})
5
+ `)):e.wasCreated?console.log(c.green(` D1 successfully created.
6
+ `)):console.log(" D1 already set up."),e.id}async function v(o,t){t&&console.log(` Checking KV namespace: ${o}`);let e=await y(o);return t?e.wasCreated?console.log(c.green(` Created KV namespace: ${o} (${e.id})
7
+ `)):console.log(c.dim(` Linking to existing KV namespace: ${o} (${e.id})
8
+ `)):e.wasCreated?console.log(c.green(" KV successfully created.")):console.log(" KV already set up."),e.id}import B from"node:crypto";import M from"node:path";import b from"node:crypto";import d from"chalk";function J(){return b.randomBytes(32).toString("base64")}function O(){let{privateKey:o,publicKey:t}=b.generateKeyPairSync("rsa",{modulusLength:2048,publicKeyEncoding:{type:"spki",format:"pem"},privateKeyEncoding:{type:"pkcs8",format:"pem"}});return{privateKey:o,publicKey:t}}async function K({gatewayUrl:o,gatewayPath:t,verbose:e=!1}){console.log("Configuring Secrets...");try{if(await l({secretName:"GATEWAY_URL",cwd:t,verbose:e})||await p({secretName:"GATEWAY_URL",secretValue:o,cwd:t,verbose:e,description:`Setting GATEWAY_URL to: ${o}`}),!await l({secretName:"BETTER_AUTH_SECRET",cwd:t,verbose:e})){let s=J();await p({secretName:"BETTER_AUTH_SECRET",secretValue:s,cwd:t,verbose:e,description:"Generating new Better Auth secret..."})}let n=await l({secretName:"JWT_PRIVATE_KEY",cwd:t,verbose:e}),i=await l({secretName:"JWT_PUBLIC_KEY",cwd:t,verbose:e});if(n&&i)e&&console.log(d.dim(` JWT key pair already exists
9
+ `));else if(!n&&!i){e&&console.log(d.dim(` Generating new JWT key pair...
10
+ `));let s=O();await p({secretName:"JWT_PRIVATE_KEY",secretValue:s.privateKey,cwd:t,verbose:e}),await p({secretName:"JWT_PUBLIC_KEY",secretValue:s.publicKey,cwd:t,verbose:e}),e&&console.log(d.green(`Created JWT key pair secrets
11
+ `))}else throw new Error("JWT key pair is incomplete. Both JWT_PRIVATE_KEY and JWT_PUBLIC_KEY must exist together. Please delete the existing key and redeploy.");console.log(e?`Secret setup complete!
12
+ `:` Finished.
13
+ `)}catch(r){throw console.error(`
14
+ Failed to setup secrets`,r instanceof Error?`
15
+ ${r.message}`:""),r}}async function W({gatewayPath:o,resources:t,workerUrl:e,verbose:r=!1}){let a=M.join(o,"dist","server","wrangler.json");await R({configPath:a,d1DatabaseId:t.d1DatabaseId,kvNamespaceId:t.kvNamespaceId,verbose:r});let n=B.randomUUID();console.log(),await A("npx",["wrangler","deploy"],{cwd:o,description:`Deploying your Gateway to Cloudflare workers...
16
+
17
+ This could take up to a minute.`,env:{...process.env,BETTER_AUTH_SECRET:n},verbose:r}),console.log(),await K({gatewayUrl:e,gatewayPath:o,verbose:r})}import f from"chalk";import{execa as Y}from"execa";async function P({gatewayPath:o,verbose:t=!1}){let e=await D(o);if(!e.d1_databases||e.d1_databases.length===0){t&&console.log(f.dim(`No D1 databases configured, skipping migrations
18
+ `));return}console.log(f.dim("Running database migrations..."));try{await Y("npm",["install","--no-save","--legacy-peer-deps","drizzle-kit"],{cwd:o,stdio:t?"inherit":"pipe"}),await x("npx",["drizzle-kit","migrate","--config=drizzle-prod.config.ts"],{cwd:o,verbose:t}),console.log(f.green(`Migrations completed!
19
+ `))}catch(r){console.error(r)}}import U from"node:fs";import z from"node:path";import{Readable as F}from"node:stream";import{pipeline as j}from"node:stream/promises";import{createWriteStream as H}from"node:fs";import{spawn as q}from"node:child_process";import m from"chalk";var Q="every-app",X="every-app",$="every-app-gateway-build.tar.gz";function Z(){return`https://github.com/${Q}/${X}/releases/download/gateway-latest/${$}`}async function ee(o,t){let e=await fetch(o,{redirect:"follow"});if(!e.ok)throw new Error(`Failed to download file: ${e.status} ${e.statusText}`);if(!e.body)throw new Error("Response body is null");let r=H(t),a=F.fromWeb(e.body);await j(a,r)}async function te(o,t){return new Promise((e,r)=>{let a=q("tar",["-xzf",o,"-C",t]);a.on("error",r),a.on("close",n=>{n===0?e():r(new Error(`tar extraction failed with code ${n}`))})})}async function G(o,t=!1){let e=Z();console.log(`
20
+ Getting latest gateway release...`),t&&console.log(m.dim(`URL: ${e}`)),U.mkdirSync(o,{recursive:!0});let r=z.join(o,$);try{await ee(e,r)}catch(a){throw a instanceof Error&&a.message.includes("404")?new Error("Gateway release not found. Make sure a release has been published."):a}return t&&(console.log(m.dim(`Downloaded to: ${r}`)),console.log(m.dim("Extracting archive..."))),await te(r,o),U.unlinkSync(r),t&&console.log(m.dim("Extraction complete")),o}async function Ie(o){let t=o.verbose||!1;if(!await k("Do you want to deploy EveryApp Gateway into this Cloudflare account?")){console.log(`
21
+ Deployment cancelled by user
22
+ `);return}await T();let r=await _({verbose:t}),a=await h("gateway-deploy-");t&&console.log(g.dim(`Working directory: ${a}
23
+ `));let n=null;try{let i=await G(a,t),s=oe.join(i,"wrangler.jsonc"),L=await S(s);n=await E(L),await W({gatewayPath:i,resources:r,workerUrl:n,verbose:t}),await P({gatewayPath:i,verbose:t})}catch(i){throw console.error(`
24
+ Deployment failed:`,i instanceof Error?i.message:i),i}finally{await C({tmpDir:a,verbose:t})}if(!n)throw new Error("Worker URL not set properly during deployment");console.log(g.green(`
25
+ Gateway deployment successful!
26
+ `)),console.log(`Your Gateway is now live at: ${g.cyan(n)}
27
+ `)}export{Ie as deploy};
@@ -1,4 +1,4 @@
1
- import{b as l,c as r}from"./chunk-ADBKSFD4.js";import{a as t}from"./chunk-BRCQN4SN.js";import"./chunk-OFG6XV6S.js";import o from"chalk";async function g(c){let e=process.cwd(),a=c.verbose||!1,n=await l(e);if(console.log(o.bold(`
1
+ import{b as l,c as r}from"./chunk-AIGWZNYN.js";import{a as t}from"./chunk-KWOW5OHX.js";import"./chunk-OFG6XV6S.js";import o from"chalk";async function g(c){let e=process.cwd(),a=c.verbose||!1,n=await l(e);if(console.log(o.bold(`
2
2
  Project: ${n}
3
3
  `)),!await t("Do you want to deploy this app to Cloudflare?")){console.log(o.red(`
4
4
  Deployment cancelled by user
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{a as r,b as o}from"./chunk-BAI6ILH4.js";import{run as i}from"@stricli/core";await i(o,process.argv.slice(2),r(process));
2
+ import{a as r,b as o}from"./chunk-HHGWXJ27.js";import{run as i}from"@stricli/core";await i(o,process.argv.slice(2),r(process));
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "description": "Every App CLI - Deploy and manage apps.",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
- "version": "0.0.24",
7
+ "version": "0.0.25",
8
8
  "files": [
9
9
  "dist"
10
10
  ],
@@ -1,19 +0,0 @@
1
- import{f as g,g as p,h as b}from"./chunk-OFG6XV6S.js";import s from"chalk";import w from"enquirer";import{execa as y}from"execa";async function W(e="Do you want to deploy to Cloudflare?"){console.log(`Checking Cloudflare account...
2
- `);try{let{stdout:n}=await y("npx",["wrangler","whoami"],{reject:!1}),r=n.split(`
3
- `),t=[],o=!1;for(let a of r)if(t.push(a),a.includes("\u2514\u2500")&&a.includes("\u2534\u2500")&&a.includes("\u2518")){o=!0;break}let i=o?t.join(`
4
- `):n;return console.log(s.dim(i)),console.log(),(await w.prompt({type:"confirm",name:"confirm",message:e,initial:!1})).confirm}catch(n){throw console.error(s.red(`
5
- Failed to retrieve Cloudflare account information`)),console.error(s.dim(` Make sure you're logged in with: npx wrangler login
6
- `)),n}}async function k(e,n){try{let r=n?{subdomain:n}:{},t=await g(`/accounts/${e}/workers/subdomain`,{method:"PUT",body:JSON.stringify(r)});if(!t||!t.subdomain)throw new Error("Failed to initialize workers.dev subdomain");return t.subdomain}catch(r){throw new Error(`Failed to initialize workers.dev subdomain: ${r instanceof Error?r.message:"Unknown error"}`)}}async function P(){let e=await p();try{return await b(e)}catch{console.log(s.yellow(`No workers.dev subdomain found for this account.
7
- `)),console.log(s.dim("A workers.dev subdomain is required to deploy Workers applications.")),console.log(s.dim(`This subdomain will be used for all Workers you deploy: [worker-name].[subdomain].workers.dev
8
- `));let t=(await w.prompt({type:"input",name:"subdomain",message:"Choose a subdomain name (alphanumeric and hyphens only):",validate:o=>!o||o.trim()===""?"Subdomain cannot be empty":/^[a-z0-9-]+$/.test(o)?o.startsWith("-")||o.endsWith("-")?"Subdomain cannot start or end with a hyphen":!0:"Subdomain must contain only lowercase letters, numbers, and hyphens"})).subdomain.trim();console.log(s.dim(`
9
- Creating workers.dev subdomain: ${t}...
10
- `));try{let o=await k(e,t);return console.log(s.green(`Successfully created subdomain: ${s.cyan(o)}
11
- `)),o}catch(o){throw console.error(s.red(`
12
- Failed to create workers.dev subdomain`),s.dim(`
13
- ${o instanceof Error?o.message:"Unknown error"}`)),o}}}import{execa as m}from"execa";import l from"chalk";async function j(e,n,r){let{env:t,cwd:o,verbose:i=!1,description:d,logCommandToConsole:a=!0}=r;return i?x(e,n,r):a?(console.log(`Running: ${e} ${n.join(" ")}`),d&&console.log(l.dim(` ${d}`)),await m(e,n,{cwd:o,env:t,stdio:"pipe"})):await m(e,n,{cwd:o,env:t,stdio:"pipe"})}async function x(e,n,{description:r,cwd:t,env:o}){console.log(l.dim(` \u250C\u2500 Running: ${e} ${n.join(" ")}`)),r&&console.log(l.dim(` \u2502 ${r}`));let i=m(e,n,{cwd:t,env:o,stdio:void 0,all:!0});i.stdout&&i.stdout.on("data",a=>{a.toString().split(`
14
- `).forEach(c=>{c.trim()&&console.log(l.dim(` \u2502 ${c}`))})}),i.stderr&&i.stderr.on("data",a=>{a.toString().split(`
15
- `).forEach(c=>{c.trim()&&console.error(l.dim(` \u2502 ${c}`))})});let d=await i;return console.log(l.dim(` \u2514\u2500 Complete
16
- `)),d}import{execa as h}from"execa";import u from"chalk";async function C(e){let{stdout:n}=await h("npx",["wrangler","secret","list","--format","json"],{cwd:e});return JSON.parse(n)}async function A(e,n,r=!1){r&&console.log(u.dim(` Checking secret: ${e}`));let o=(await C(n)).some(i=>i.name===e);return o&&r&&console.log(u.dim(` Secret already exists
17
- `)),o}async function q(e,n,r,t=!1,o){t&&o&&console.log(u.dim(` ${o}
18
- `));let i=h("npx",["wrangler","secret","put",e],{cwd:r});i.stdin&&(i.stdin.write(n),i.stdin.end()),await i,t&&console.log(u.green(`Created secret: ${e}
19
- `))}export{W as a,P as b,j as c,A as d,q as e};
@@ -1,6 +0,0 @@
1
- import{i as l}from"./chunk-OFG6XV6S.js";import r from"node:fs/promises";import n from"node:path";import f from"node:os";import m from"chalk";async function u(e,t,o={}){let a=o.exclude||[];await r.mkdir(t,{recursive:!0});let p=await r.readdir(e,{withFileTypes:!0});for(let i of p){let s=n.join(e,i.name),c=n.join(t,i.name);a.some(y=>i.name===y)||(i.isDirectory()?await u(s,c,o):await r.copyFile(s,c))}}async function x(e){try{return(await r.stat(e)).isDirectory()}catch{return!1}}async function h(e,t){let o=await l("every-app-gateway"),a=`# Vite client-side secrets
2
- VITE_APP_ID=${t}
3
- VITE_GATEWAY_URL=${o}
4
- # Set Cloudflare secrets locally
5
- GATEWAY_URL=${o}
6
- `;await Promise.all([r.writeFile(n.join(e,".env.local"),a)])}async function T(e){return await r.mkdtemp(n.join(f.tmpdir(),e))}async function D(e,t=!1){try{await r.rm(e,{recursive:!0,force:!0}),t&&console.log(m.dim(` Removed: ${e}`))}catch{console.warn(m.yellow("\u26A0\uFE0F Warning: Failed to clean up temporary directory:"),e)}}export{u as a,x as b,h as c,T as d,D as e};
@@ -1,24 +0,0 @@
1
- import{a as h,c as b}from"./chunk-ADBKSFD4.js";import{a as d,b as g,c as f,d as u,e as y}from"./chunk-XO5N5XVK.js";import{a as w,c as i}from"./chunk-BRCQN4SN.js";import"./chunk-OFG6XV6S.js";import m from"chalk";import x from"chalk";import{execa as j}from"execa";async function k(){try{await j("pnpm",["--version"],{stdio:"pipe"})}catch{console.error(x.red(`
2
- Error: pnpm is required but not installed. Please install it first:`)),console.error(x.cyan(` npm i -g pnpm
3
- `)),process.exit(1)}}import L from"enquirer";function R(o){return!o||o.trim().length===0?"App ID cannot be empty":o.length>64?"App ID must be 64 characters or less":/^[a-z][a-z0-9-]*$/.test(o)?!0:"App ID must be in kebab-case format (lowercase letters, numbers, and hyphens only, starting with a letter)"}async function v(o){console.log(`Project Configuration
4
- `);let e=await L.prompt({type:"input",name:"appId",message:"Enter your app ID (kebab-case format)",initial:o,validate:R});return console.log(),{appId:e.appId}}import P from"node:path";import U from"chalk";async function C(o,e,n=!1){try{await i("git",["clone",o,e],{verbose:n,logCommandToConsole:!1})}catch(t){throw new Error(`Failed to clone repository from ${o}: ${t instanceof Error?t.message:"Unknown error"}`)}}var J="https://github.com/every-app/every-app.git",S="templates/simple-todo";async function E(o,e){e&&console.log(`Cloning template repository...
5
- `);let n=await u("every-app-create-");await C(J,n,e),e&&console.log(`Extracting template...
6
- `);let t=P.join(n,S),l=P.join(process.cwd(),o);if(await g(l))throw new Error(`Directory "${o}" already exists in the current location`);return await d(t,l,{exclude:["node_modules",".git","pnpm-lock.yaml","package-lock.json",".env.local",".env.production",".dev.vars","manual-steps.md"]}),e&&console.log(U.dim(` Template copied to ${l}
7
- `)),{tempDir:n,targetDir:l}}import D from"node:fs/promises";import _ from"node:path";async function T(o,e){let n=_.join(o,"package.json"),t=JSON.parse(await D.readFile(n,"utf-8"));t.name=e,await D.writeFile(n,JSON.stringify(t,null,2)+`
8
- `,"utf-8")}import s from"chalk";async function A(o,e){try{e||console.log(`
9
- Setting up Cloudflare for local dev...`),await i("pnpm",["run","cf-typegen"],{cwd:o,verbose:e,logCommandToConsole:!1}),await i("pnpm",["run","build"],{cwd:o,verbose:e,logCommandToConsole:!1}),e||console.log(s.dim(` Finished.
10
- `)),await i("pnpm",["run","db:migrate:local"],{cwd:o,verbose:e}),console.log(`
11
- Local database migrations complete.
12
- `)}catch{console.warn(s.yellow(`
13
- Failed to run local migrations. You can run them manually with:`)),console.warn(s.dim(` pnpm run db:migrate:local
14
- `))}}import r from"chalk";function I(o,e,n,t){console.log(r.green(`Project created and deployed successfully!
15
- `)),console.log(r.dim(` Location: ${e}`)),console.log(r.dim(` App URL: ${r.cyan(t)}`)),console.log(r.dim(` Gateway: ${r.cyan(n)}`)),console.log(),console.log(`For local development:
16
- `),console.log(r.dim(` ${r.bold(`cd ${o}`)}`)),console.log(r.dim(` ${r.bold("pnpm run dev")}`)),console.log(r.dim(` ${r.bold(`
17
- Then, go to the Gateway and click the "Dev" button on the app to go to the app running locally instead of on cloudflare.`)}`)),console.log(),console.log(`To deploy updates after changes:
18
- `),console.log(r.dim(` ${r.bold("npx @every-app/cli app deploy")}`)),console.log()}async function wo(o,e){let n=o.verbose||!1;await k(),console.log(`
19
- Create a new Every App project
20
- `);let{appId:t}=await v(e);if(console.log(m.dim(`.
21
- `)),!await w("Deploy this app to the above account? We deploy during app creation for smoother local dev with Cloudflare.")){console.log(m.yellow(`
22
- App creation cancelled.
23
- `));return}let p=null;try{let{tempDir:c,targetDir:a}=await E(t,n);p=c,await T(a,t),await h(a,{appId:t});let{workerUrl:$,gatewayUrl:F}=await b({cwd:a,appId:t,verbose:n,devUrl:"http://localhost:3001"});await f(a,t),await A(a,n),I(t,a,F,$)}catch(c){throw console.error(m.red(`
24
- Failed to create project:`),c instanceof Error?c.message:"Unknown error"),c}finally{p&&await y(p)}}export{wo as default};
@@ -1,27 +0,0 @@
1
- import{d as C,e as T}from"./chunk-XO5N5XVK.js";import{a as k,b as h,c as A,d as c,e as p}from"./chunk-BRCQN4SN.js";import{c as y,d as u,g as w,i as E,j as x,k as D,l as _,n as R}from"./chunk-OFG6XV6S.js";import f from"chalk";import te from"node:path";import l from"chalk";var I="every-app-gateway",J="every-app-gateway";async function S(t=!1){console.log(`
2
- Setting up your Cloudflare D1 Database and KV Store...
3
- `);let o=await w(),e=await V(I,t),r=await B(J,t);return{d1DatabaseId:e,kvNamespaceId:r,accountId:o}}async function V(t,o){o&&console.log(` Checking D1 database: ${t}`);let e=await y(t);return o?e.wasCreated?console.log(l.green(` Created D1 database: ${t} (${e.id})
4
- `)):console.log(l.dim(` Linking to existing D1 database: ${t} (${e.id})
5
- `)):e.wasCreated?console.log(l.green(` D1 successfully created.
6
- `)):console.log(" D1 already set up."),e.id}async function B(t,o){o&&console.log(` Checking KV namespace: ${t}`);let e=await u(t);return o?e.wasCreated?console.log(l.green(` Created KV namespace: ${t} (${e.id})
7
- `)):console.log(l.dim(` Linking to existing KV namespace: ${t} (${e.id})
8
- `)):e.wasCreated?console.log(l.green(" KV successfully created.")):console.log(" KV already set up."),e.id}import z from"node:crypto";import M from"node:path";import K from"node:crypto";import d from"chalk";function Y(){return K.randomBytes(32).toString("base64")}function v(){let{privateKey:t,publicKey:o}=K.generateKeyPairSync("rsa",{modulusLength:2048,publicKeyEncoding:{type:"spki",format:"pem"},privateKeyEncoding:{type:"pkcs8",format:"pem"}});return{privateKey:t,publicKey:o}}async function W(t,o,e=!1){console.log("Configuring Secrets...");try{if(await c("GATEWAY_URL",o,e)||await p("GATEWAY_URL",t,o,e,`Setting GATEWAY_URL to: ${t}`),!await c("BETTER_AUTH_SECRET",o,e)){let s=Y();await p("BETTER_AUTH_SECRET",s,o,e,"Generating new Better Auth secret...")}let a=await c("JWT_PRIVATE_KEY",o,e),i=await c("JWT_PUBLIC_KEY",o,e);if(a&&i)e&&console.log(d.dim(` JWT key pair already exists
9
- `));else if(!a&&!i){e&&console.log(d.dim(` Generating new JWT key pair...
10
- `));let s=v();await p("JWT_PRIVATE_KEY",s.privateKey,o,e),await p("JWT_PUBLIC_KEY",s.publicKey,o,e),e&&console.log(d.green(`Created JWT key pair secrets
11
- `))}else throw new Error("JWT key pair is incomplete. Both JWT_PRIVATE_KEY and JWT_PUBLIC_KEY must exist together. Please delete the existing key and redeploy.");console.log(e?`Secret setup complete!
12
- `:` Finished.
13
- `)}catch(r){throw console.error(`
14
- Failed to setup secrets`,r instanceof Error?`
15
- ${r.message}`:""),r}}async function $(t,o,e,r=!1){let n=M.join(t,"dist","server","wrangler.json");await x({configPath:n,d1DatabaseId:o.d1DatabaseId,kvNamespaceId:o.kvNamespaceId,verbose:r});let a=z.randomUUID();console.log(),await A("npx",["wrangler","deploy"],{cwd:t,description:`Deploying your Gateway to Cloudflare workers...
16
-
17
- This could take up to a minute.`,env:{...process.env,BETTER_AUTH_SECRET:a},verbose:r}),console.log(),await W(e,t,r)}import g from"chalk";import{execa as N}from"execa";async function P(t,o=!1){let e=await _(t);if(!e.d1_databases||e.d1_databases.length===0){o&&console.log(g.dim(`No D1 databases configured, skipping migrations
18
- `));return}console.log(g.dim("Running database migrations..."));try{await N("npm",["install","--no-save","--legacy-peer-deps","drizzle-kit"],{cwd:t,stdio:o?"inherit":"pipe"}),await R("npx",["drizzle-kit","migrate","--config=drizzle-prod.config.ts"],{cwd:t,verbose:o}),console.log(g.green(`Migrations completed!
19
- `))}catch(r){console.error(r)}}import U from"node:fs";import F from"node:path";import{Readable as O}from"node:stream";import{pipeline as j}from"node:stream/promises";import{createWriteStream as H}from"node:fs";import{spawn as q}from"node:child_process";import m from"chalk";var Q="every-app",X="every-app",b="every-app-gateway-build.tar.gz";function Z(){return`https://github.com/${Q}/${X}/releases/download/gateway-latest/${b}`}async function ee(t,o){let e=await fetch(t,{redirect:"follow"});if(!e.ok)throw new Error(`Failed to download file: ${e.status} ${e.statusText}`);if(!e.body)throw new Error("Response body is null");let r=H(o),n=O.fromWeb(e.body);await j(n,r)}async function oe(t,o){return new Promise((e,r)=>{let n=q("tar",["-xzf",t,"-C",o]);n.on("error",r),n.on("close",a=>{a===0?e():r(new Error(`tar extraction failed with code ${a}`))})})}async function G(t,o=!1){let e=Z();console.log(`
20
- Getting latest gateway release...`),o&&console.log(m.dim(`URL: ${e}`)),U.mkdirSync(t,{recursive:!0});let r=F.join(t,b);try{await ee(e,r)}catch(n){throw n instanceof Error&&n.message.includes("404")?new Error("Gateway release not found. Make sure a release has been published."):n}return o&&(console.log(m.dim(`Downloaded to: ${r}`)),console.log(m.dim("Extracting archive..."))),await oe(r,t),U.unlinkSync(r),o&&console.log(m.dim("Extraction complete")),t}async function Ve(t){let o=t.verbose||!1;if(!await k("Do you want to deploy EveryApp Gateway into this Cloudflare account?")){console.log(`
21
- Deployment cancelled by user
22
- `);return}await h();let r=await S(o),n=await C("gateway-deploy-");o&&console.log(f.dim(`Working directory: ${n}
23
- `));let a=null;try{let i=await G(n,o),s=te.join(i,"wrangler.jsonc"),L=await D(s);a=await E(L),await $(i,r,a,o),await P(i,o)}catch(i){throw console.error(`
24
- Deployment failed:`,i instanceof Error?i.message:i),i}finally{await T(n,o)}if(!a)throw new Error("Worker URL not set properly during deployment");console.log(f.green(`
25
- Gateway deployment successful!
26
- `)),console.log(`Your Gateway is now live at: ${f.cyan(a)}
27
- `)}export{Ve as deploy};