@every-app/cli 0.0.23 → 0.0.24

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-EVUGQ5V6.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-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}
3
3
  `)}catch{}
@@ -1,30 +1,30 @@
1
- import{c as u,d as k,e as N}from"./chunk-F3TYA4CA.js";import{a as C,b as x,c as I,d as v,e as P,g as R,i as b,j as $,n as T}from"./chunk-6P7AGKFE.js";import S from"node:fs/promises";import _ from"node:path";import*as G from"jsonc-parser";import{z as g}from"zod";var O="every-app.jsonc",K=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=_.join(t,O);try{let e=await S.readFile(r,"utf-8"),o=G.parse(e);return K.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 q(t){return t.split("-").map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join(" ")}async function ne(t,r){let e=_.join(t,O),o={...r,displayName:r.displayName??q(r.appId)},n=JSON.stringify(o,null,2)+`
2
- `;await S.writeFile(e,n)}async function se(t){return(await D(t)).appId}import{execa as Q}from"execa";async function Y(){try{return await Q("pnpm",["--version"],{stdio:"pipe"}),!0}catch{return!1}}async function j(t,r,e=!1){let o=await Y();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(t,r=!1){console.log(`
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(`
3
3
  Setting up your Cloudflare D1 Database and KV Store...
4
- `);let e=C(t),o=await B(e,r),n=await J(e,r);return{d1DatabaseId:o,kvNamespaceId:n,resourceName:e}}async function B(t,r){r&&(console.log(c.bold(`Processing D1 database...
5
- `)),console.log(` Checking D1 database: ${t}`));let e=await I(t);return r?e.wasCreated?console.log(c.green(` Created D1 database: ${t} (${e.id})
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...
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
- `)):console.log(" D1 already set up."),e.id}async function J(t,r){r&&(console.log(c.bold(`Processing KV namespace...
9
- `)),console.log(` Checking KV namespace: ${t}`));let e=await v(t);return r?e.wasCreated?console.log(c.green(` Created KV namespace: ${t} (${e.id})
8
+ `)):console.log(" D1 already set up."),e.id}async function B(t,r){r&&(console.log(c.bold(`Processing KV namespace...
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
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(`
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 H from"chalk";async function L(t,r,e,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...
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...
17
17
 
18
- This could take up to a minute.`,env:n,verbose:o})}catch(i){throw console.error(H.red(`
19
- Failed to build or deploy`)),i}}import w from"chalk";var Z="every-app-gateway";async function U(){let t=await R(),e=(await x()).find(o=>o.name===Z);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(`
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(`
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
- 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 X}from"node:crypto";async function z(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 z(t,r.id,e.appId))return{created:!1};let n=Math.floor(Date.now()/1e3),i=X(),p=`
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 W(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 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.
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 M(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 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!
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 b("every-app-gateway");console.log(),await j(r,"Installing dependencies for Cloudflare deployment...",o),await V(r,o),await L(r,a,s,o),await M(a,r,o);let l=await b(s),d=await D(r);return await W({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(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};
@@ -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.23";import{buildCommand as t,buildRouteMap as m}from"@stricli/core";var c=t({loader:async()=>import("./create-UNNKB6HT.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-SL2JAB5S.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
- `)}}),y=t({loader:async()=>{let{remoteD1Shell:e}=await import("./remoteD1Shell-HKNBYVAD.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-ADO5FMV4.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(`
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(`
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(`
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};
@@ -1,4 +1,4 @@
1
- import{f as g,g as p,h as b}from"./chunk-6P7AGKFE.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...
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
2
  `);try{let{stdout:n}=await y("npx",["wrangler","whoami"],{reject:!1}),r=n.split(`
3
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
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(`
@@ -1,2 +1,2 @@
1
- import v from"node:fs/promises";import f from"node:path";import b from"node:os";import*as D from"smol-toml";function C(){let e=b.homedir(),t=b.platform(),r;return t==="win32"?r=f.join(process.env.LOCALAPPDATA||f.join(e,"AppData","Local"),".wrangler"):t==="darwin"?r=f.join(e,"Library","Preferences",".wrangler"):r=f.join(e,".wrangler"),f.join(r,"config","default.toml")}async function O(){let e=C();try{let t=await v.readFile(e,"utf-8"),r=D.parse(t);if(!r.oauth_token||!r.refresh_token)throw new Error("OAuth tokens not found in wrangler config");return r}catch(t){throw t.code==="ENOENT"?new Error("Wrangler config not found. Please run 'npx wrangler login' first."):t}}function P(e){let t=new Date(e).getTime(),r=Date.now(),a=1*60*1e3;return t-r<a}async function j(e){let t=await fetch("https://dash.cloudflare.com/oauth2/token",{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"refresh_token",refresh_token:e})});if(!t.ok)throw new Error(`Failed to refresh OAuth token: ${t.status} ${t.statusText}`);let r=await t.json();return{oauth_token:r.access_token,expiration_time:new Date(Date.now()+r.expires_in*1e3).toISOString(),refresh_token:r.refresh_token||e,scopes:r.scope?r.scope.split(" "):[]}}async function g(){let e=await O();return P(e.expiration_time)?(await j(e.refresh_token)).oauth_token:e.oauth_token}async function w(e,t={}){let r=await g(),a=await fetch(`https://api.cloudflare.com/client/v4${e}`,{...t,headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json",...t.headers}}),n=await a.json();if(!a.ok){let o=n.errors?n.errors.map(i=>`[${i.code}] ${i.message}`).join(", "):a.statusText;throw new Error(`Cloudflare API request failed: ${a.status} ${o}`)}if(!n.success){let o=n.errors.map(i=>`[${i.code}] ${i.message}`).join(", ");throw new Error(`Cloudflare API error: ${o}`)}return n.result}async function m(){let e=await w("/accounts");if(!e||e.length===0)throw new Error("No Cloudflare accounts found");let t=e[0];if(!t)throw new Error("No Cloudflare accounts found");return t.id}async function y(e){try{let t=await w(`/accounts/${e}/workers/subdomain`);if(!t||!t.subdomain)throw new Error("No workers.dev subdomain found for this account");return t.subdomain}catch(t){throw new Error(`Failed to get workers.dev subdomain: ${t instanceof Error?t.message:"Unknown error"}`)}}async function I(e,t){let r=t||await m(),a=await y(r);return`https://${e}.${a}.workers.dev`}import{z as d}from"zod";var h="every-";function T(e){return e.startsWith(h)?e:`${h}${e}`}var R=d.object({uuid:d.string(),name:d.string(),created_at:d.string().optional(),version:d.string().optional()}),k=d.array(R);import{execa as E}from"execa";async function p(){let{stdout:e}=await E("npx",["wrangler","d1","list","--json"]),t=JSON.parse(e);return k.parse(t)}async function N(e){let{stdout:t}=await E("npx",["wrangler","d1","create",e]),r=t.match(/"database_id":\s*"([^"]+)"/);if(!r||!r[1])throw new Error("Failed to parse database ID from wrangler output");return r[1]}async function W(e){let r=(await p()).find(n=>n.name===e);return r?{id:r.uuid,name:e,wasCreated:!1}:{id:await N(e),name:e,wasCreated:!0}}import{execa as _}from"execa";async function L(){let{stdout:e}=await _("npx",["wrangler","kv","namespace","list"]);return JSON.parse(e)}async function F(e){let{stdout:t}=await _("npx",["wrangler","kv","namespace","create",e]);return V(t)}function V(e){let t=e.match(/"id":\s*"([a-f0-9]+)"/);if(!t||!t[1])throw new Error("Failed to parse namespace ID from wrangler output");return t[1]}async function $(e){let r=(await L()).find(n=>n.title===e);return r?{id:r.id,name:e,wasCreated:!1}:{id:await F(e),name:e,wasCreated:!0}}import u from"node:fs/promises";import x from"node:path";import*as s from"jsonc-parser";import S from"chalk";async function ce(e){e.verbose&&console.log("Updating wrangler.jsonc with resource IDs and configuration...");let t=e.configPath;(await u.stat(t)).isDirectory()&&(t=x.join(t,"wrangler.jsonc"));let a=await u.readFile(t,"utf-8"),n=s.parse(a),o=[];if(n.d1_databases){if(n.d1_databases.length===0)throw new Error("No D1 databases found in wrangler.jsonc. Every app must have exactly one D1 database.");if(n.d1_databases.length>1)throw new Error(`Found ${n.d1_databases.length} D1 databases in wrangler.jsonc. Every app must have exactly one D1 database.`)}if(n.kv_namespaces){if(n.kv_namespaces.length===0)throw new Error("No KV namespaces found in wrangler.jsonc. Every app must have exactly one KV namespace.");if(n.kv_namespaces.length>1)throw new Error(`Found ${n.kv_namespaces.length} KV namespaces in wrangler.jsonc. Every app must have exactly one KV namespace.`)}if(e.name&&o.push(...s.modify(a,["name"],e.name,{})),e.d1DatabaseId&&o.push(...s.modify(a,["d1_databases",0,"database_id"],e.d1DatabaseId,{})),e.d1DatabaseName&&o.push(...s.modify(a,["d1_databases",0,"database_name"],e.d1DatabaseName,{})),e.kvNamespaceId&&o.push(...s.modify(a,["kv_namespaces",0,"id"],e.kvNamespaceId,{})),e.vars)for(let[c,l]of Object.entries(e.vars))o.push(...s.modify(a,["vars",c],l,{}));let i=s.applyEdits(a,o);await u.writeFile(t,i),e.verbose&&console.log(S.dim(` wrangler.jsonc updated successfully
2
- `))}async function de(e){let t=await u.readFile(e,"utf-8"),r=s.parse(t);if(!r.name||typeof r.name!="string")throw new Error("Worker name not found in wrangler.jsonc");return r.name}async function A(e){let t=x.join(e,"wrangler.jsonc");try{let r=await u.readFile(t,"utf-8");return s.parse(r)}catch(r){throw r instanceof Error&&"code"in r&&r.code==="ENOENT"?new Error("wrangler.jsonc not found in current directory. Make sure you're running this command from your app's root directory."):r}}import{execa as K}from"execa";async function U(e){let t=await A(e);if(!t.d1_databases||t.d1_databases.length===0)throw new Error("No D1 databases found in wrangler.jsonc. Please add a D1 database configuration.");let r=t.d1_databases[0];if(!r)throw new Error("No D1 database configuration found in wrangler.jsonc.");let a=r.database_name;if(!a)throw new Error("No database_name found in D1 database configuration in wrangler.jsonc.");let[n,o,i]=await Promise.all([m(),p(),g()]),c=o.find(l=>l.name===a);if(!c)throw new Error(`Database "${a}" not found in your Cloudflare account. Have you run deployment to create the database?`);return{CLOUDFLARE_ACCOUNT_ID:n,CLOUDFLARE_DATABASE_ID:c.uuid,CLOUDFLARE_API_TOKEN:i}}async function pe(e,t,r){let{cwd:a,env:n={},verbose:o=!1}=r,i=await U(a),c={cwd:a,stdio:o?"inherit":"pipe",env:{...process.env,...n,...i}};await K(e,t,c)}export{T as a,p as b,W as c,$ as d,g as e,w as f,m as g,y as h,I as i,ce as j,de as k,A as l,U as m,pe as n};
1
+ import v from"node:fs/promises";import f from"node:path";import h from"node:os";import*as b from"smol-toml";function C(){let e=h.homedir(),t=h.platform(),r;return t==="win32"?r=f.join(process.env.LOCALAPPDATA||f.join(e,"AppData","Local"),".wrangler"):t==="darwin"?r=f.join(e,"Library","Preferences",".wrangler"):r=f.join(e,".wrangler"),f.join(r,"config","default.toml")}async function O(){let e=C();try{let t=await v.readFile(e,"utf-8"),r=b.parse(t);if(!r.oauth_token||!r.refresh_token)throw new Error("OAuth tokens not found in wrangler config");return r}catch(t){throw t.code==="ENOENT"?new Error("Wrangler config not found. Please run 'npx wrangler login' first."):t}}function P(e){let t=new Date(e).getTime(),r=Date.now(),a=1*60*1e3;return t-r<a}async function j(e){let t=await fetch("https://dash.cloudflare.com/oauth2/token",{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"refresh_token",refresh_token:e})});if(!t.ok)throw new Error(`Failed to refresh OAuth token: ${t.status} ${t.statusText}`);let r=await t.json();return{oauth_token:r.access_token,expiration_time:new Date(Date.now()+r.expires_in*1e3).toISOString(),refresh_token:r.refresh_token||e,scopes:r.scope?r.scope.split(" "):[]}}async function g(){let e=await O();return P(e.expiration_time)?(await j(e.refresh_token)).oauth_token:e.oauth_token}async function w(e,t={}){let r=await g(),a=await fetch(`https://api.cloudflare.com/client/v4${e}`,{...t,headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json",...t.headers}}),n=await a.json();if(!a.ok){let o=n.errors?n.errors.map(i=>`[${i.code}] ${i.message}`).join(", "):a.statusText;throw new Error(`Cloudflare API request failed: ${a.status} ${o}`)}if(!n.success){let o=n.errors.map(i=>`[${i.code}] ${i.message}`).join(", ");throw new Error(`Cloudflare API error: ${o}`)}return n.result}async function m(){let e=await w("/accounts");if(!e||e.length===0)throw new Error("No Cloudflare accounts found");let t=e[0];if(!t)throw new Error("No Cloudflare accounts found");return t.id}async function D(e){try{let t=await w(`/accounts/${e}/workers/subdomain`);if(!t||!t.subdomain)throw new Error("No workers.dev subdomain found for this account");return t.subdomain}catch(t){throw new Error(`Failed to get workers.dev subdomain: ${t instanceof Error?t.message:"Unknown error"}`)}}async function T(e,t){let r=t||await m(),a=await D(r);return`https://${e}.${a}.workers.dev`}import{z as d}from"zod";var y="every-";function I(e){return e.startsWith(y)?e:`${y}${e}`}var N=d.object({uuid:d.string(),name:d.string(),created_at:d.string().optional(),version:d.string().optional()}),k=d.array(N);import{execa as _}from"execa";async function p(){let{stdout:e}=await _("npx",["wrangler","d1","list","--json"]),t=JSON.parse(e);return k.parse(t)}async function R(e){let{stdout:t}=await _("npx",["wrangler","d1","create",e]),r=t.match(/"database_id":\s*"([^"]+)"/);if(!r||!r[1])throw new Error("Failed to parse database ID from wrangler output");return r[1]}async function W(e){let r=(await p()).find(n=>n.name===e);return r?{id:r.uuid,name:e,wasCreated:!1}:{id:await R(e),name:e,wasCreated:!0}}import{execa as E}from"execa";async function L(){let{stdout:e}=await E("npx",["wrangler","kv","namespace","list"]);return JSON.parse(e)}async function V(e){let{stdout:t}=await E("npx",["wrangler","kv","namespace","create",e]);return $(t)}function $(e){let t=e.match(/"id":\s*"([a-f0-9]+)"/);if(!t||!t[1])throw new Error("Failed to parse namespace ID from wrangler output");return t[1]}async function F(e){let r=(await L()).find(n=>n.title===e);return r?{id:r.id,name:e,wasCreated:!1}:{id:await V(e),name:e,wasCreated:!0}}import u from"node:fs/promises";import x from"node:path";import*as s from"jsonc-parser";import S from"chalk";async function ce(e){e.verbose&&console.log("Updating wrangler.jsonc with resource IDs and configuration...");let t=e.configPath;(await u.stat(t)).isDirectory()&&(t=x.join(t,"wrangler.jsonc"));let a=await u.readFile(t,"utf-8"),n=s.parse(a),o=[];if(n.d1_databases){if(n.d1_databases.length===0)throw new Error("No D1 databases found in wrangler.jsonc. Every app must have exactly one D1 database.");if(n.d1_databases.length>1)throw new Error(`Found ${n.d1_databases.length} D1 databases in wrangler.jsonc. Every app must have exactly one D1 database.`)}if(n.kv_namespaces){if(n.kv_namespaces.length===0)throw new Error("No KV namespaces found in wrangler.jsonc. Every app must have exactly one KV namespace.");if(n.kv_namespaces.length>1)throw new Error(`Found ${n.kv_namespaces.length} KV namespaces in wrangler.jsonc. Every app must have exactly one KV namespace.`)}if(e.name&&o.push(...s.modify(a,["name"],e.name,{})),e.d1DatabaseId&&o.push(...s.modify(a,["d1_databases",0,"database_id"],e.d1DatabaseId,{})),e.d1DatabaseName&&o.push(...s.modify(a,["d1_databases",0,"database_name"],e.d1DatabaseName,{})),e.kvNamespaceId&&o.push(...s.modify(a,["kv_namespaces",0,"id"],e.kvNamespaceId,{})),e.vars)for(let[c,l]of Object.entries(e.vars))o.push(...s.modify(a,["vars",c],l,{}));let i=s.applyEdits(a,o);await u.writeFile(t,i),e.verbose&&console.log(S.dim(` wrangler.jsonc updated successfully
2
+ `))}async function de(e){let t=await u.readFile(e,"utf-8"),r=s.parse(t);if(!r.name||typeof r.name!="string")throw new Error("Worker name not found in wrangler.jsonc");return r.name}async function A(e){let t=x.join(e,"wrangler.jsonc");try{let r=await u.readFile(t,"utf-8");return s.parse(r)}catch(r){throw r instanceof Error&&"code"in r&&r.code==="ENOENT"?new Error("wrangler.jsonc not found in current directory. Make sure you're running this command from your app's root directory."):r}}import{execa as K}from"execa";async function U(e){let t=await A(e);if(!t.d1_databases||t.d1_databases.length===0)throw new Error("No D1 databases found in wrangler.jsonc. Please add a D1 database configuration.");let r=t.d1_databases[0];if(!r)throw new Error("No D1 database configuration found in wrangler.jsonc.");let a=r.database_name;if(!a)throw new Error("No database_name found in D1 database configuration in wrangler.jsonc.");let[n,o,i]=await Promise.all([m(),p(),g()]),c=o.find(l=>l.name===a);if(!c)throw new Error(`Database "${a}" not found in your Cloudflare account. Have you run deployment to create the database?`);return{CLOUDFLARE_ACCOUNT_ID:n,CLOUDFLARE_DATABASE_ID:c.uuid,CLOUDFLARE_API_TOKEN:i}}async function pe(e,t,r){let{cwd:a,env:n={},verbose:o=!1}=r,i=await U(a),c={cwd:a,stdio:o?"inherit":"pipe",env:{...process.env,...n,...i}};await K(e,t,c)}export{I as a,p as b,W as c,F as d,g as e,w as f,m as g,D as h,T as i,ce as j,de as k,A as l,U as m,pe as n};
@@ -1,4 +1,4 @@
1
- import{i as l}from"./chunk-6P7AGKFE.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
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
2
  VITE_APP_ID=${t}
3
3
  VITE_GATEWAY_URL=${o}
4
4
  # Set Cloudflare secrets locally
@@ -1,4 +1,4 @@
1
- import{a as h,c as b}from"./chunk-6XTEOGWY.js";import{a as d,b as g,c as f,d as u,e as y}from"./chunk-2FK6FGTW.js";import{a as w,c as i}from"./chunk-F3TYA4CA.js";import"./chunk-6P7AGKFE.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(`
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
2
  Error: pnpm is required but not installed. Please install it first:`)),console.error(x.cyan(` npm i -g pnpm
3
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
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...
@@ -1,4 +1,4 @@
1
- import{b as l,c as r}from"./chunk-6XTEOGWY.js";import{a as t}from"./chunk-F3TYA4CA.js";import"./chunk-6P7AGKFE.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-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(`
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
@@ -1,4 +1,4 @@
1
- import{d as C,e as T}from"./chunk-2FK6FGTW.js";import{a as k,b as h,c as A,d as c,e as p}from"./chunk-F3TYA4CA.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-6P7AGKFE.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(`
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
2
  Setting up your Cloudflare D1 Database and KV Store...
3
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
4
  `)):console.log(l.dim(` Linking to existing D1 database: ${t} (${e.id})
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-EVUGQ5V6.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-BAI6ILH4.js";import{run as i}from"@stricli/core";await i(o,process.argv.slice(2),r(process));
@@ -1,4 +1,4 @@
1
- import{m as c}from"./chunk-6P7AGKFE.js";import r from"chalk";import{execa as l}from"execa";async function p(a,...o){let n=process.cwd();try{if(!o||o.length===0)throw new Error(`No command provided. Usage: npx @every-app/cli app remote-d1-shell -- <command>
1
+ import{m as c}from"./chunk-OFG6XV6S.js";import r from"chalk";import{execa as l}from"execa";async function p(a,...o){let n=process.cwd();try{if(!o||o.length===0)throw new Error(`No command provided. Usage: npx @every-app/cli app remote-d1-shell -- <command>
2
2
  Example: npx @every-app/cli app remote-d1-shell -- npx drizzle-kit migrate`);let[e,...t]=o;if(!e)throw new Error("Invalid command");console.log("Retrieving shell info from Cloudflare...");let i=await c(n);console.log(r.bold(`
3
3
  Running: ${r.cyan([e,...t].join(" "))}
4
4
  `)),await l(e,t,{cwd:n,stdio:"inherit",env:{...process.env,...i}}),console.log(`
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.23",
7
+ "version": "0.0.24",
8
8
  "files": [
9
9
  "dist"
10
10
  ],