@every-app/cli 0.0.13 → 0.0.15

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-ZBPM4ZWH.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-VCCHKIQU.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{}
@@ -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 v,buildUninstallCommand as D}from"@stricli/auto-complete";var r="@every-app/cli";var n="Every App CLI - Deploy and manage apps.";var a="0.0.13";import{buildCommand as o,buildRouteMap as m}from"@stricli/core";var c=o({loader:async()=>import("./create-ZQQ5K45E.js"),parameters:{positional:{kind:"tuple",parameters:[]},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 and configures your local development environment.","","The command will:"," 1. Prompt for app ID (kebab-case) and package manager"," 2. Copy the template to a new directory"," 3. Create Cloudflare D1 database and KV namespace"," 4. Configure wrangler.jsonc, package.json, and .env files"," 5. Install dependencies and run local migrations","","After creation, run 'npm run dev' to start developing."].join(`
2
- `)}}),u=o({loader:async()=>{let{deploy:e}=await import("./deploy-XLA22GPF.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 v,buildUninstallCommand as D}from"@stricli/auto-complete";var r="@every-app/cli";var n="Every App CLI - Deploy and manage apps.";var a="0.0.15";import{buildCommand as o,buildRouteMap as m}from"@stricli/core";var c=o({loader:async()=>import("./create-VJJX2DP5.js"),parameters:{positional:{kind:"tuple",parameters:[]},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 and configures your local development environment.","","The command will:"," 1. Prompt for app ID (kebab-case) and package manager"," 2. Copy the template to a new directory"," 3. Create Cloudflare D1 database and KV namespace"," 4. Configure wrangler.jsonc, package.json, and .env files"," 5. Install dependencies and run local migrations","","After creation, run 'npm run dev' to start developing."].join(`
2
+ `)}}),u=o({loader:async()=>{let{deploy:e}=await import("./deploy-GYS5YEN7.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=o({loader:async()=>{let{remoteD1Shell:e}=await import("./remoteD1Shell-MWQWKJA4.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: every app remote-d1-shell -- npx drizzle-kit migrate"," - Opening Drizzle Studio: every app remote-d1-shell -- npx drizzle-kit studio"," - Pushing schema changes: every 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
- `)}}),s=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-Z5667ULH.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
+ `)}}),s=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-63XDLKWH.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
  `)}}),i=b({routes:{deploy:h},docs:{brief:"Gateway management commands"}});var w=C({routes:{app:s,gateway:i,install:v("every",{bash:"__every_bash_complete"}),uninstall:D("every",{bash:!0})},docs:{brief:n,hideRoute:{install:!0,uninstall:!0}}}),G=g(w,{name:r,versionInfo:{currentVersion:a},scanner:{allowArgumentEscapeSequence:!0}});export{A as a,G as b};
@@ -1,18 +1,16 @@
1
- import{a as m,b as d,c as g,d as f,e as u,f as y}from"./chunk-MOGNJRIZ.js";import{a as l,b as c,c as h}from"./chunk-5PTHALCD.js";import{e as p,g as w,h as k}from"./chunk-65T2UMWS.js";import M from"chalk";import C from"chalk";import{execa as S}from"execa";async function b(){try{await S("pnpm",["--version"],{stdio:"pipe"})}catch{console.error(C.red(`
1
+ import{a as m,b as d,c as g,d as f,e as u,f as y}from"./chunk-MOGNJRIZ.js";import{a as l,b as c,c as h}from"./chunk-5PTHALCD.js";import{e as p,g as w,h as k}from"./chunk-65T2UMWS.js";import Y from"chalk";import C from"chalk";import{execa as U}from"execa";async function b(){try{await U("pnpm",["--version"],{stdio:"pipe"})}catch{console.error(C.red(`
2
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 P from"enquirer";function U(e){return!e||e.trim().length===0?"App ID cannot be empty":e.length>64?"App ID must be 64 characters or less":/^[a-z][a-z0-9-]*$/.test(e)?!0:"App ID must be in kebab-case format (lowercase letters, numbers, and hyphens only, starting with a letter)"}async function O(){let e=!1,o=null;for(;!e;)o=await P.prompt({type:"confirm",name:"acknowledged",message:o?`You must acknowledge this to proceed. Press y to continue.
4
- `:"pnpm has been chosen as the package manager for Every App projects. Other package managers will not work with `every app deploy` currently.\n\n Press y to acknowledge this.",initial:!1}),o.acknowledged?e=!0:console.log()}async function D(){console.log(`Project Configuration
5
- `);let e=await P.prompt({type:"input",name:"appId",message:"Enter your app ID (kebab-case format)",validate:U});return console.log(),await O(),{appId:e.appId}}import v from"node:path";import J from"chalk";var V="git@github.com:every-app/every-app.git",_="templates/simple-todo";async function x(e,o){o&&console.log(`Cloning template repository...
6
- `);let n=await f("every-app-create-");await y(V,n,o),o&&console.log(`Extracting template...
7
- `);let a=v.join(n,_),r=v.join(process.cwd(),e);if(await d(r))throw new Error(`Directory "${e}" already exists in the current location`);return await m(a,r,{exclude:["node_modules",".git","pnpm-lock.yaml","package-lock.json",".env.local",".env.production",".dev.vars","manual-steps.md"]}),o&&console.log(J.dim(` Template copied to ${r}
8
- `)),{tempDir:n,targetDir:r}}import A from"chalk";async function E(e,o){console.log(o?`Creating Cloudflare resources...
9
- `:`
10
- Creating Cloudflare resources...
3
+ `)),process.exit(1)}}import P from"enquirer";function O(e){return!e||e.trim().length===0?"App ID cannot be empty":e.length>64?"App ID must be 64 characters or less":/^[a-z][a-z0-9-]*$/.test(e)?!0:"App ID must be in kebab-case format (lowercase letters, numbers, and hyphens only, starting with a letter)"}async function J(){let e=!1,o=null;for(;!e;)o=await P.prompt({type:"confirm",name:"acknowledged",message:o?`You must acknowledge this to proceed. Press y to continue.
4
+ `:"pnpm has been chosen as the package manager for Every App projects. Other package managers will not work with `every app deploy` currently.\n\n Press y to acknowledge this.",initial:!1}),o.acknowledged?e=!0:console.log()}async function v(){console.log(`Project Configuration
5
+ `);let e=await P.prompt({type:"input",name:"appId",message:"Enter your app ID (kebab-case format)",validate:O});return console.log(),await J(),{appId:e.appId}}import D from"node:path";import S from"chalk";var _="git@github.com:every-app/every-app.git",V="templates/simple-todo";async function x(e,o){o&&console.log(`Cloning template repository...
6
+ `);let n=await f("every-app-create-");await y(_,n,o),o&&console.log(`Extracting template...
7
+ `);let a=D.join(n,V),r=D.join(process.cwd(),e);if(await d(r))throw new Error(`Directory "${e}" already exists in the current location`);return await m(a,r,{exclude:["node_modules",".git","pnpm-lock.yaml","package-lock.json",".env.local",".env.production",".dev.vars","manual-steps.md"]}),o&&console.log(S.dim(` Template copied to ${r}
8
+ `)),{tempDir:n,targetDir:r}}import A from"chalk";async function E(e,o){console.log(`Creating Cloudflare resources...
11
9
  `);let n=await w(e,o),a=await h(e,o);return o&&(console.log(`Cloudflare resources ready:
12
10
  `),console.log(A.dim(` D1 Database: ${e} (${n})`)),console.log(A.dim(` KV Namespace: ${e} (${a})
13
- `))),{d1DatabaseId:n,kvNamespaceId:a}}import I from"node:fs/promises";import $ from"node:path";import W from"chalk";async function K(e,o){let n=$.join(e,"package.json"),a=JSON.parse(await I.readFile(n,"utf-8"));a.name=o,await I.writeFile(n,JSON.stringify(a,null,2)+`
11
+ `))),{d1DatabaseId:n,kvNamespaceId:a}}import I from"node:fs/promises";import $ from"node:path";import M from"chalk";async function W(e,o){let n=$.join(e,"package.json"),a=JSON.parse(await I.readFile(n,"utf-8"));a.name=o,await I.writeFile(n,JSON.stringify(a,null,2)+`
14
12
  `,"utf-8")}async function j(e,o,n,a,r){r&&console.log(`Updating configuration files...
15
- `);let i=$.join(e,"wrangler.jsonc");await k({configPath:i,name:o,d1DatabaseId:n,d1DatabaseName:o,kvNamespaceId:a,verbose:r}),await K(e,o),await g(e,o),r&&console.log(W.dim(" Configuration updated"))}import s from"chalk";async function N(e,o){try{o||console.log(`
13
+ `);let i=$.join(e,"wrangler.jsonc");await k({configPath:i,name:o,d1DatabaseId:n,d1DatabaseName:o,kvNamespaceId:a,verbose:r}),await W(e,o),await g(e,o),r&&console.log(M.dim(" Configuration updated"))}import s from"chalk";async function N(e,o){try{o||console.log(`
16
14
  Setting up Cloudflare for local dev...`),await l("pnpm",["run","cf-typegen"],{cwd:e,verbose:o,logCommandToConsole:!1}),await l("pnpm",["run","build"],{cwd:e,verbose:o,logCommandToConsole:!1}),o||console.log(s.dim(` Finished.
17
15
  `)),await l("pnpm",["run","db:migrate:local"],{cwd:e,verbose:o}),console.log(`
18
16
  Local database migrations complete.
@@ -23,8 +21,7 @@ Failed to run local migrations. You can run them manually with:`)),console.warn(
23
21
  `)),console.log(`Next steps:
24
22
  `),console.log(t.dim(` 1. ${t.bold(t.italic(`cd ${e}`))}`)),console.log(t.dim(` 2. ${t.bold(t.italic("pnpm run dev"))}`)),console.log(t.dim(` 3. Click "Add App" in your gateway: ${t.reset(t.cyan(n))}`)),console.log(t.dim(" 4. Configure App")),console.log(t.dim(` - App ID: ${t.bold(t.italic(`${e}`))}`)),console.log(t.dim(` - App URL: ${t.bold(t.italic("http://localhost:3001"))} (or whatever your dev url is)`)),console.log(t.dim(` 5. Click the app in the gateway and start building
25
23
  `)),console.log(`Deploy to production:
26
- `),console.log(t.dim(t.bold(t.italic(" every app deploy # Spin up KV Store, run migrations on prod db, deploy app to Cloudflare Workers.")))),console.log(t.dim(t.bold(t.italic(` pnpm run deploy # Deploy to Cloudflare
27
- `))))}async function Io(e){let o=e.verbose||!1;await b(),console.log(`
24
+ `),console.log(t.dim(t.bold(t.italic(" every app deploy # Deploys made easy using the Every App CLI"))))}async function Io(e){let o=e.verbose||!1;await b(),console.log(`
28
25
  Create a new Every App project
29
- `);let n=null;try{let{appId:a}=await D(),{tempDir:r,targetDir:i}=await x(a,o);n=r;let{d1DatabaseId:F,kvNamespaceId:L}=await E(a,o);await j(i,a,F,L,o),console.log(),await c(i,"Installing dependencies for local dev...",o);let[,R]=await Promise.all([N(i,o),p("every-app-gateway")]);T(a,i,R)}catch(a){throw console.error(M.red(`
26
+ `);let n=null;try{let{appId:a}=await v(),{tempDir:r,targetDir:i}=await x(a,o);n=r;let{d1DatabaseId:L,kvNamespaceId:F}=await E(a,o);await j(i,a,L,F,o),console.log(),await c(i,"Installing dependencies for local dev...",o);let[,R]=await Promise.all([N(i,o),p("every-app-gateway")]);T(a,i,R)}catch(a){throw console.error(Y.red(`
30
27
  Failed to create project:`),a instanceof Error?a.message:"Unknown error"),a}finally{n&&await u(n)}}export{Io as default};
@@ -7,9 +7,9 @@ Setting up Cloudflare your D1 Database and KV Store...
7
7
  `:` Finished.
8
8
  `)}catch(r){throw console.error(`
9
9
  Failed to setup secrets`,r instanceof Error?`
10
- ${r.message}`:""),r}}async function x(o,e,t,r=!1){await C({configPath:o,d1DatabaseId:e.d1DatabaseId,kvNamespaceId:e.kvNamespaceId,verbose:r}),await W(t,o,r);let i=G.randomUUID();await y("npm",["run","deploy"],{cwd:o,description:`Deploying your Gateway to Cloudflare workers...
10
+ ${r.message}`:""),r}}async function x(o,e,t,r=!1){await C({configPath:o,d1DatabaseId:e.d1DatabaseId,kvNamespaceId:e.kvNamespaceId,verbose:r});let i=G.randomUUID();console.log(),await y("npm",["run","deploy"],{cwd:o,description:`Deploying your Gateway to Cloudflare workers...
11
11
 
12
- This could take up to a minute.`,env:{...process.env,BETTER_AUTH_SECRET:i},verbose:r})}async function ye(o){let e=o.verbose||!1;if(!await D("Do you want to deploy EveryApp Gateway into this Cloudflare account?")){console.log(`
12
+ This could take up to a minute.`,env:{...process.env,BETTER_AUTH_SECRET:i},verbose:r}),console.log(),await W(t,o,r)}async function ye(o){let e=o.verbose||!1;if(!await D("Do you want to deploy EveryApp Gateway into this Cloudflare account?")){console.log(`
13
13
  Deployment cancelled by user
14
14
  `);return}await R();let r=await k(e),i=await g("gateway-deploy-");e&&console.log(m.dim(`Working directory: ${i}
15
15
  `));let n=null;try{let a=await K(i,e),s=N.join(a,"wrangler.jsonc"),I=await _(s);n=await u(I),await x(a,r,n,e)}catch(a){throw console.error(`
@@ -1,31 +1,31 @@
1
- import{a as v,c as T,d as x}from"./chunk-FQY6RMLS.js";import{a as u,b,c as $}from"./chunk-5PTHALCD.js";import{a as D,c as E,e as f,f as _,g as A,h as C,j as k}from"./chunk-65T2UMWS.js";import h from"chalk";import U from"chalk";async function R(r,a,e=!1){if(console.log(`
1
+ import{a as T,c as v,d as x}from"./chunk-FQY6RMLS.js";import{a as f,b,c as $}from"./chunk-5PTHALCD.js";import{a as D,c as E,e as y,f as _,g as A,h as C,j as k}from"./chunk-65T2UMWS.js";import m from"chalk";import U from"chalk";async function R(r,a,e=!1){if(console.log(`
2
2
  Setting up Cloudflare your D1 Database and KV Store...
3
3
  `),!r.d1_databases||r.d1_databases.length===0)throw new Error("No D1 databases found in wrangler.jsonc. Every app must have exactly one D1 database.");if(r.d1_databases.length>1)throw new Error(`Found ${r.d1_databases.length} D1 databases in wrangler.jsonc. Every app must have exactly one D1 database.`);if(!r.kv_namespaces||r.kv_namespaces.length===0)throw new Error("No KV namespaces found in wrangler.jsonc. Every app must have exactly one KV namespace.");if(r.kv_namespaces.length>1)throw new Error(`Found ${r.kv_namespaces.length} KV namespaces in wrangler.jsonc. Every app must have exactly one KV namespace.`);let n=r.d1_databases[0].database_name;if(!n)throw new Error("D1 database in wrangler.jsonc must have a database_name.");e&&console.log(U.bold(`Processing D1 database...
4
4
  `));let t=await A(n,e);e&&console.log(U.bold(`Processing KV namespace...
5
5
  `));let l=await $(a,e);return{d1DatabaseId:t,kvNamespaceId:l}}import P from"chalk";async function S(r,a,e=!1){if(!a.d1_databases||a.d1_databases.length===0){e&&console.log(P.dim(`No D1 databases configured, skipping migrations
6
- `));return}try{console.log(),await u("npm",["run","db:migrate:prod"],{cwd:r,description:"Running any pending migrations against your remote D1 Database...",verbose:e}),console.log(`
6
+ `));return}try{console.log(),await f("npm",["run","db:migrate:prod"],{cwd:r,description:"Running any pending migrations against your remote D1 Database...",verbose:e}),console.log(`
7
7
  Migrations completed!
8
8
  `)}catch{console.warn(P.yellow(`Failed to run migrations. You may need to run them manually with: npm run db:migrate:prod
9
- `))}}import L from"chalk";async function N(r,a,e,o){try{let n={...process.env,VITE_GATEWAY_URL:a,VITE_APP_ID:e};await u("npm",["run","deploy"],{cwd:r,description:`Deploying your application to Cloudflare workers...
9
+ `))}}import L from"chalk";async function N(r,a,e,o){try{let n={...process.env,VITE_GATEWAY_URL:a,VITE_APP_ID:e};await f("npm",["run","deploy"],{cwd:r,description:`Deploying your application to Cloudflare workers...
10
10
 
11
11
  15s to 1m depending on how long the app build takes
12
12
  `,env:n,verbose:o})}catch(n){throw console.error(L.red(`
13
- Failed to build or deploy`)),n}}import w from"chalk";import{randomUUID as V}from"node:crypto";import g from"chalk";async function y(r,a,e){try{let o=await D(),n=await fetch(`https://api.cloudflare.com/client/v4/accounts/${r}/d1/database/${a}/query`,{method:"POST",headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json"},body:JSON.stringify({sql:e})}),t=await n.json();if(!n.ok||!t.success){let s=t.errors?t.errors.map(i=>`[${i.code}] ${i.message}`).join(", "):n.statusText;throw console.error(g.red(`
14
- D1 Query Error:`)),console.error(g.dim(`SQL: ${e}`)),console.error(g.dim(`Error: ${s}`)),new Error(`D1 query failed: ${s}`)}let l=t.result;if(!l||l.length===0)throw new Error("No results returned from D1 query");let c=l[0];if(!c)throw new Error("First result is undefined");return c.results}catch(o){throw o instanceof Error&&!o.message.includes("D1 query failed")&&(console.error(g.red(`
15
- D1 Query Error:`)),console.error(g.dim(`SQL: ${e}`))),o}}async function W(r,a,e=!1,o,n){try{e&&console.log("Adding apps to user gateways...");let t=await E(),c=(await _()).find(m=>m.name==="every-app-gateway");if(!c){console.warn(w.yellow(`every-app-gateway database not found. Skipping UserApp record creation.
16
- `));return}let s=c.uuid,i=await y(t,s,"SELECT id, name, email FROM users");if(i.length===0)throw new Error("No users found in the database. Please create a user first before deploying apps.");let p=o||r,d=n||r;if(i.length===1)await F(t,s,i[0],r,a,p,d,e);else{e&&console.log(w.yellow(`Multiple users found (${i.length}). Adding app to all users...
17
- `));for(let m of i)await F(t,s,m,r,a,p,d,e);e&&console.log(` UserApp records processed for ${i.length} users
18
- `)}}catch(t){throw console.error(w.red("Failed to insert UserApp records:"),t instanceof Error?t.message:t),t}}async function F(r,a,e,o,n,t,l,c){let s=Math.floor(Date.now()/1e3);if((await y(r,a,`SELECT id FROM user_apps WHERE user_id = '${e.id}' AND app_id = '${o}'`)).length>0)c&&console.log(w.dim(` UserApp record already exists for user ${e.name} (${e.email})`));else{let d=`
13
+ Failed to build or deploy`)),n}}import h from"chalk";import{randomUUID as V}from"node:crypto";import u from"chalk";async function w(r,a,e){try{let o=await D(),n=await fetch(`https://api.cloudflare.com/client/v4/accounts/${r}/d1/database/${a}/query`,{method:"POST",headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json"},body:JSON.stringify({sql:e})}),t=await n.json();if(!n.ok||!t.success){let i=t.errors?t.errors.map(s=>`[${s.code}] ${s.message}`).join(", "):n.statusText;throw console.error(u.red(`
14
+ D1 Query Error:`)),console.error(u.dim(`SQL: ${e}`)),console.error(u.dim(`Error: ${i}`)),new Error(`D1 query failed: ${i}`)}let l=t.result;if(!l||l.length===0)throw new Error("No results returned from D1 query");let c=l[0];if(!c)throw new Error("First result is undefined");return c.results}catch(o){throw o instanceof Error&&!o.message.includes("D1 query failed")&&(console.error(u.red(`
15
+ D1 Query Error:`)),console.error(u.dim(`SQL: ${e}`))),o}}async function F(r,a,e=!1,o,n){try{e&&console.log("Adding apps to user gateways...");let t=await E(),c=(await _()).find(g=>g.name==="every-app-gateway");if(!c){console.warn(h.yellow(`every-app-gateway database not found. Skipping UserApp record creation.
16
+ `));return}let i=c.uuid,s=await w(t,i,"SELECT id, name, email FROM users");if(s.length===0)throw new Error("No users found in the database. Please create a user first before deploying apps.");let p=o||r,d=n||r;if(s.length===1)await W(t,i,s[0],r,a,p,d,e);else{e&&console.log(h.yellow(`Multiple users found (${s.length}). Adding app to all users...
17
+ `));for(let g of s)await W(t,i,g,r,a,p,d,e);e&&console.log(` UserApp records processed for ${s.length} users
18
+ `)}}catch(t){throw console.error(h.red("Failed to insert UserApp records:"),t instanceof Error?t.message:t),t}}async function W(r,a,e,o,n,t,l,c){let i=Math.floor(Date.now()/1e3);if((await w(r,a,`SELECT id FROM user_apps WHERE user_id = '${e.id}' AND app_id = '${o}'`)).length>0)c&&console.log(h.dim(` UserApp record already exists for user ${e.name} (${e.email})`));else{let d=`
19
19
  INSERT INTO user_apps (id, user_id, app_id, name, description, app_url, created_at, updated_at)
20
- VALUES ('${V()}', '${e.id}', '${o}', '${t}', '${l}', '${n}', ${s}, ${s})
21
- `;await y(r,a,d),console.log(` UserApp record created for user ${e.name} (${e.email})`)}}async function I(r,a,e=!1){console.log("Configuring Secrets...");try{await T("GATEWAY_URL",a,e)||await x("GATEWAY_URL",r,a,e,`Setting GATEWAY_URL to: ${r}`),console.log(e?`Secret setup complete!
22
- `:` Finished.
20
+ VALUES ('${V()}', '${e.id}', '${o}', '${t}', '${l}', '${n}', ${i}, ${i})
21
+ `;await w(r,a,d),console.log(` UserApp record created for user ${e.name} (${e.email})`)}}async function I(r,a,e=!1){e&&console.log("Configuring Secrets...");try{await v("GATEWAY_URL",a,e)||await x("GATEWAY_URL",r,a,e,`Setting GATEWAY_URL to: ${r}`),e&&console.log(`Secret setup complete!
23
22
  `)}catch(o){throw console.error(`
24
23
  Failed to setup secrets`,o instanceof Error?`
25
- ${o.message}`:""),o}}async function we(r){let a=process.cwd(),e=r.verbose||!1,o=await k(a);if(!o.name)throw new Error("Worker name not found in wrangler.jsonc. Please add a 'name' field.");let n=o.name;if(console.log(h.bold(`
24
+ ${o.message}`:""),o}}async function we(r){let a=process.cwd(),e=r.verbose||!1,o=await k(a);if(!o.name)throw new Error("Worker name not found in wrangler.jsonc. Please add a 'name' field.");let n=o.name;if(console.log(m.bold(`
26
25
  Project name: ${n}
27
- `)),!await v("Do you want to deploy this app to Cloudflare?")){console.log(h.red(`
26
+ `)),!await T("Do you want to deploy this app to Cloudflare?")){console.log(m.red(`
28
27
  Deployment cancelled by user
29
- `));return}let{d1DatabaseId:l,kvNamespaceId:c}=await R(o,n,e),s=await f("every-app-gateway");await C({configPath:a,d1DatabaseId:l,kvNamespaceId:c,verbose:e}),console.log(),await b(a,"Installing dependencies for Cloudflare deployment...",e),await S(a,o,e),await N(a,s,n,e),await I(s,a,e);let i=await f(o.name),p,d;o.name==="every-todo-app"&&(p="Todos",d="Minimal todo list"),await W(o.name,i,e,p,d),console.log(h.green(`Deployment successful!
30
- `));let m=await f("every-app-gateway");console.log(`Try it out in your gateway: ${h.cyan(m)}
28
+ `));return}let{d1DatabaseId:l,kvNamespaceId:c}=await R(o,n,e),i=await y("every-app-gateway");await C({configPath:a,d1DatabaseId:l,kvNamespaceId:c,verbose:e}),console.log(),await b(a,"Installing dependencies for Cloudflare deployment...",e),await S(a,o,e),await N(a,i,n,e),await I(i,a,e);let s=await y(o.name),p,d;o.name==="every-todo-app"&&(p="Todos",d="Minimal todo list"),await F(o.name,s,e,p,d),console.log(m.green(`
29
+ Deployment successful!`)),console.log(m.dim(` This app's url: ${m.cyan(s)}
30
+ `));let g=await y("every-app-gateway");console.log(`Access it on your gateway: ${m.cyan(g)}
31
31
  `)}export{we as deploy};
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-ZBPM4ZWH.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-VCCHKIQU.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.13",
7
+ "version": "0.0.15",
8
8
  "files": [
9
9
  "dist"
10
10
  ],