@every-app/cli 0.0.15 → 0.0.17

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-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}
2
+ import{a as o,b as s}from"./chunk-TECQINNU.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,4 +1,4 @@
1
- import{b as l,c as d,d as u}from"./chunk-65T2UMWS.js";import s from"chalk";import m from"enquirer";import{execa as g}from"execa";async function x(e="Do you want to deploy to Cloudflare?"){console.log(`Checking Cloudflare account...
1
+ import{b as l,c as d,d as u}from"./chunk-L2OIOFLM.js";import s from"chalk";import m from"enquirer";import{execa as g}from"execa";async function x(e="Do you want to deploy to Cloudflare?"){console.log(`Checking Cloudflare account...
2
2
  `);try{let{stdout:n}=await g("npx",["wrangler","whoami"],{reject:!1}),t=n.split(`
3
3
  `),r=[],o=!1;for(let a of t)if(r.push(a),a.includes("\u2514\u2500")&&a.includes("\u2534\u2500")&&a.includes("\u2518")){o=!0;break}let i=o?r.join(`
4
4
  `):n;return console.log(s.dim(i)),console.log(),(await m.prompt({type:"confirm",name:"confirm",message:e,initial:!1})).confirm}catch(n){throw console.error(s.red(`
@@ -1,4 +1,4 @@
1
- import{a as l}from"./chunk-5PTHALCD.js";import{e as m}from"./chunk-65T2UMWS.js";import o from"node:fs/promises";import a from"node:path";import d from"node:os";import p from"chalk";async function u(e,r,t={}){let i=t.exclude||[];await o.mkdir(r,{recursive:!0});let y=await o.readdir(e,{withFileTypes:!0});for(let n of y){let s=a.join(e,n.name),c=a.join(r,n.name);i.some(f=>n.name===f)||(n.isDirectory()?await u(s,c,t):await o.copyFile(s,c))}}async function h(e){try{return(await o.stat(e)).isDirectory()}catch{return!1}}async function E(e,r){let t=await m("every-app-gateway"),i=`# Vite client-side secrets
1
+ import{a as l}from"./chunk-5PTHALCD.js";import{e as m}from"./chunk-L2OIOFLM.js";import o from"node:fs/promises";import a from"node:path";import d from"node:os";import p from"chalk";async function u(e,r,t={}){let i=t.exclude||[];await o.mkdir(r,{recursive:!0});let y=await o.readdir(e,{withFileTypes:!0});for(let n of y){let s=a.join(e,n.name),c=a.join(r,n.name);i.some(f=>n.name===f)||(n.isDirectory()?await u(s,c,t):await o.copyFile(s,c))}}async function h(e){try{return(await o.stat(e)).isDirectory()}catch{return!1}}async function E(e,r){let t=await m("every-app-gateway"),i=`# Vite client-side secrets
2
2
  VITE_APP_ID=${r}
3
3
  VITE_GATEWAY_URL=${t}
4
4
  # Set Cloudflare secrets locally
@@ -0,0 +1,6 @@
1
+ import k from"node:fs/promises";import y from"node:fs";import s from"node:path";import d from"node:os";import*as u from"smol-toml";function b(){let e=d.homedir(),n=d.platform(),r,t;if(n==="win32"){let o=process.env.APPDATA||s.join(e,"AppData","Roaming");r=process.env.XDG_CONFIG_HOME?s.join(process.env.XDG_CONFIG_HOME,".wrangler"):s.join(o,"xdg.config",".wrangler"),t=s.join(e,".wrangler")}else n==="darwin"?(r=process.env.XDG_CONFIG_HOME?s.join(process.env.XDG_CONFIG_HOME,".wrangler"):s.join(e,"Library","Preferences",".wrangler"),t=s.join(e,".wrangler")):(r=process.env.XDG_CONFIG_HOME?s.join(process.env.XDG_CONFIG_HOME,".wrangler"):s.join(e,".config",".wrangler"),t=s.join(e,".wrangler"));try{if(y.statSync(t).isDirectory())return s.join(t,"config","default.toml")}catch{}return s.join(r,"config","default.toml")}async function _(){let e=b();try{let n=await k.readFile(e,"utf-8"),r=u.parse(n);if(!r.oauth_token||!r.refresh_token)throw new Error("OAuth tokens not found in wrangler config");return r}catch(n){throw n.code==="ENOENT"?new Error("Wrangler config not found. Please run 'npx wrangler login' first."):n}}function D(e){let n=new Date(e).getTime(),r=Date.now(),t=1*60*1e3;return n-r<t}async function j(e){let n=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(!n.ok)throw new Error(`Failed to refresh OAuth token: ${n.status} ${n.statusText}`);let r=await n.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 E(){let e=await _();return D(e.expiration_time)?(await j(e.refresh_token)).oauth_token:e.oauth_token}async function l(e,n={}){let r=await E(),t=await fetch(`https://api.cloudflare.com/client/v4${e}`,{...n,headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json",...n.headers}}),o=await t.json();if(!t.ok){let a=o.errors?o.errors.map(c=>`[${c.code}] ${c.message}`).join(", "):t.statusText;throw new Error(`Cloudflare API request failed: ${t.status} ${a}`)}if(!o.success){let a=o.errors.map(c=>`[${c.code}] ${c.message}`).join(", ");throw new Error(`Cloudflare API error: ${a}`)}return o.result}async function v(){let e=await l("/accounts");if(!e||e.length===0)throw new Error("No Cloudflare accounts found");let n=e[0];if(!n)throw new Error("No Cloudflare accounts found");return n.id}async function C(e){try{let n=await l(`/accounts/${e}/workers/subdomain`);if(!n||!n.subdomain)throw new Error("No workers.dev subdomain found for this account");return n.subdomain}catch(n){throw new Error(`Failed to get workers.dev subdomain: ${n instanceof Error?n.message:"Unknown error"}`)}}async function F(e,n){let r=n||await v(),t=await C(r);return`https://${e}.${t}.workers.dev`}import{execa as m}from"execa";import f from"chalk";async function O(){let{stdout:e}=await m("npx",["wrangler","d1","list","--json"]);return JSON.parse(e)}async function x(e){let{stdout:n}=await m("npx",["wrangler","d1","create",e]),r=n.match(/"database_id":\s*"([^"]+)"/);if(!r||!r[1])throw new Error("Failed to parse database ID from wrangler output");return r[1]}async function G(e,n=!1){n&&console.log(` Checking D1 database: ${e}`);try{let t=(await O()).find(a=>a.name===e);if(t)return console.log(n?f.dim(` Linking to existing D1 database: ${e} (${t.uuid})
2
+ `):" D1 already set up."),t.uuid;n&&console.log(f.dim(` Creating new D1 database: ${e}`));let o=await x(e);return console.log(n?f.green(` Created D1 database: ${e} (${o})
3
+ `):f.green(` D1 successfully created.
4
+ `)),o}catch(r){throw console.error(f.red(`Failed to get or create D1 database: ${e}`),r instanceof Error?f.dim(`
5
+ ${r.message}`):""),r}}import g from"node:fs/promises";import p from"node:path";import*as i from"jsonc-parser";import A from"chalk";async function X(e){e.verbose&&console.log("Updating wrangler.jsonc with resource IDs and configuration...");let n=e.configPath;(await g.stat(n)).isDirectory()&&(n=p.join(n,"wrangler.jsonc"));let t=await g.readFile(n,"utf-8"),o=i.parse(t),a=[];if(o.d1_databases){if(o.d1_databases.length===0)throw new Error("No D1 databases found in wrangler.jsonc. Every app must have exactly one D1 database.");if(o.d1_databases.length>1)throw new Error(`Found ${o.d1_databases.length} D1 databases in wrangler.jsonc. Every app must have exactly one D1 database.`)}if(o.kv_namespaces){if(o.kv_namespaces.length===0)throw new Error("No KV namespaces found in wrangler.jsonc. Every app must have exactly one KV namespace.");if(o.kv_namespaces.length>1)throw new Error(`Found ${o.kv_namespaces.length} KV namespaces in wrangler.jsonc. Every app must have exactly one KV namespace.`)}if(e.name&&a.push(...i.modify(t,["name"],e.name,{})),e.d1DatabaseId&&a.push(...i.modify(t,["d1_databases",0,"database_id"],e.d1DatabaseId,{})),e.d1DatabaseName&&a.push(...i.modify(t,["d1_databases",0,"database_name"],e.d1DatabaseName,{})),e.kvNamespaceId&&a.push(...i.modify(t,["kv_namespaces",0,"id"],e.kvNamespaceId,{})),e.vars)for(let[w,h]of Object.entries(e.vars))a.push(...i.modify(t,["vars",w],h,{}));let c=i.applyEdits(t,a);await g.writeFile(n,c),e.verbose&&console.log(A.dim(` wrangler.jsonc updated successfully
6
+ `))}async function L(e){let n=await g.readFile(e,"utf-8"),r=i.parse(n);if(!r.name||typeof r.name!="string")throw new Error("Worker name not found in wrangler.jsonc");return r.name}async function V(e){let n=p.join(e,"wrangler.jsonc");try{let r=await g.readFile(n,"utf-8");return i.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}}export{E as a,l as b,v as c,C as d,F as e,O as f,G as g,X as h,L as i,V as j};
@@ -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.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
- `)}}),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-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(`
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.17";import{buildCommand as o,buildRouteMap as m}from"@stricli/core";var c=o({loader:async()=>import("./create-FNUN6W4F.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-TSFGQYNN.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=o({loader:async()=>{let{remoteD1Shell:e}=await import("./remoteD1Shell-5IXOYOBP.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-TTPUUE5V.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,8 +1,8 @@
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(`
1
+ import{a as m,b as d,c as g,d as f,e as u,f as y}from"./chunk-KNDAMQHW.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-L2OIOFLM.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
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
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...
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 _="https://github.com/every-app/every-app.git",V="templates/simple-todo";async function x(e,o){o&&console.log(`Cloning template repository...
6
6
  `);let n=await f("every-app-create-");await y(_,n,o),o&&console.log(`Extracting template...
7
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
8
  `)),{tempDir:n,targetDir:r}}import A from"chalk";async function E(e,o){console.log(`Creating Cloudflare resources...
@@ -1,4 +1,4 @@
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(`
1
+ import{a as T,c as v,d as x}from"./chunk-J4VNT4W4.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-L2OIOFLM.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...
@@ -1,6 +1,6 @@
1
- import{d as g,e as w,f as E}from"./chunk-MOGNJRIZ.js";import{a as D,b as R,c,d as l}from"./chunk-FQY6RMLS.js";import{a as y,b as d,c as A}from"./chunk-5PTHALCD.js";import{c as f,e as u,g as T,h as C,i as _}from"./chunk-65T2UMWS.js";import m from"chalk";import N from"node:path";var P="every-app-gateway",U="every-app-gateway";async function k(o=!1){console.log(`
1
+ import{d as g,e as w,f as E}from"./chunk-KNDAMQHW.js";import{a as D,b as R,c,d as l}from"./chunk-J4VNT4W4.js";import{a as y,b as d,c as A}from"./chunk-5PTHALCD.js";import{c as f,e as u,g as T,h as C,i as _}from"./chunk-L2OIOFLM.js";import m from"chalk";import N from"node:path";var P="every-app-gateway",U="every-app-gateway";async function k(o=!1){console.log(`
2
2
  Setting up Cloudflare your D1 Database and KV Store...
3
- `);let e=await f(),t=await T(P,o),r=await A(U,o);return{d1DatabaseId:t,kvNamespaceId:r,accountId:e}}import h from"node:path";var J="git@github.com:every-app/every-app.git",Y="apps/every-app-gateway";async function K(o,e=!1){await E(J,o,e);let t=h.join(o,Y);return console.log(),await d(t,"Installing dependencies for Cloudflare Deployment...",e),t}import G from"node:crypto";import S from"node:crypto";import p from"chalk";function B(){return S.randomBytes(32).toString("base64")}function L(){let{privateKey:o,publicKey:e}=S.generateKeyPairSync("rsa",{modulusLength:2048,publicKeyEncoding:{type:"spki",format:"pem"},privateKeyEncoding:{type:"pkcs8",format:"pem"}});return{privateKey:o,publicKey:e}}async function W(o,e,t=!1){console.log("Configuring Secrets...");try{if(await c("GATEWAY_URL",e,t)||await l("GATEWAY_URL",o,e,t,`Setting GATEWAY_URL to: ${o}`),!await c("BETTER_AUTH_SECRET",e,t)){let s=B();await l("BETTER_AUTH_SECRET",s,e,t,"Generating new Better Auth secret...")}let n=await c("JWT_PRIVATE_KEY",e,t),a=await c("JWT_PUBLIC_KEY",e,t);if(n&&a)t&&console.log(p.dim(` JWT key pair already exists
3
+ `);let e=await f(),t=await T(P,o),r=await A(U,o);return{d1DatabaseId:t,kvNamespaceId:r,accountId:e}}import h from"node:path";var J="https://github.com/every-app/every-app.git",Y="apps/every-app-gateway";async function K(o,e=!1){await E(J,o,e);let t=h.join(o,Y);return console.log(),await d(t,"Installing dependencies for Cloudflare Deployment...",e),t}import G from"node:crypto";import S from"node:crypto";import p from"chalk";function B(){return S.randomBytes(32).toString("base64")}function L(){let{privateKey:o,publicKey:e}=S.generateKeyPairSync("rsa",{modulusLength:2048,publicKeyEncoding:{type:"spki",format:"pem"},privateKeyEncoding:{type:"pkcs8",format:"pem"}});return{privateKey:o,publicKey:e}}async function W(o,e,t=!1){console.log("Configuring Secrets...");try{if(await c("GATEWAY_URL",e,t)||await l("GATEWAY_URL",o,e,t,`Setting GATEWAY_URL to: ${o}`),!await c("BETTER_AUTH_SECRET",e,t)){let s=B();await l("BETTER_AUTH_SECRET",s,e,t,"Generating new Better Auth secret...")}let n=await c("JWT_PRIVATE_KEY",e,t),a=await c("JWT_PUBLIC_KEY",e,t);if(n&&a)t&&console.log(p.dim(` JWT key pair already exists
4
4
  `));else if(!n&&!a){t&&console.log(p.dim(` Generating new JWT key pair...
5
5
  `));let s=L();await l("JWT_PRIVATE_KEY",s.privateKey,e,t),await l("JWT_PUBLIC_KEY",s.publicKey,e,t),t&&console.log(p.green(`Created JWT key pair secrets
6
6
  `))}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(t?`Secret setup complete!
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-VCCHKIQU.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-TECQINNU.js";import{run as i}from"@stricli/core";await i(o,process.argv.slice(2),r(process));
@@ -1,4 +1,4 @@
1
- import{a as d,c,f as l,j as g}from"./chunk-65T2UMWS.js";import t from"chalk";import{execa as h}from"execa";async function A(w,...e){let r=process.cwd();try{if(!e||e.length===0)throw new Error(`No command provided. Usage: every app remote-d1-shell -- <command>
1
+ import{a as d,c,f as l,j as g}from"./chunk-L2OIOFLM.js";import t from"chalk";import{execa as h}from"execa";async function A(w,...e){let r=process.cwd();try{if(!e||e.length===0)throw new Error(`No command provided. Usage: every app remote-d1-shell -- <command>
2
2
  Example: every app remote-d1-shell -- npx drizzle-kit migrate`);let[a,...s]=e;if(!a)throw new Error("Invalid command");let o=await g(r);if(!o.d1_databases||o.d1_databases.length===0)throw new Error("No D1 databases found in wrangler.jsonc. Please add a D1 database configuration.");let n=o.d1_databases[0].database_name;if(!n)throw new Error("No database_name found in D1 database configuration in wrangler.jsonc.");console.log("Retrieving shell info from Cloudflare...");let[f,m,b]=await Promise.all([c(),l(),d()]),i=m.find(p=>p.name===n);if(!i)throw new Error(`Database "${n}" not found in your Cloudflare account. Have you run \`every app deploy\` to create the database?`);let u=i.uuid;console.log(t.bold(`
3
3
  Running: ${t.cyan([a,...s].join(" "))}
4
4
  `)),await h(a,s,{cwd:r,stdio:"inherit",env:{...process.env,CLOUDFLARE_ACCOUNT_ID:f,CLOUDFLARE_DATABASE_ID:u,CLOUDFLARE_API_TOKEN:b}}),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.15",
7
+ "version": "0.0.17",
8
8
  "files": [
9
9
  "dist"
10
10
  ],
@@ -1,6 +0,0 @@
1
- import k from"node:fs/promises";import d from"node:path";import g from"node:os";import*as u from"smol-toml";function y(){let e=g.homedir(),n=g.platform(),r;return n==="win32"?r=d.join(process.env.LOCALAPPDATA||d.join(e,"AppData","Local"),".wrangler"):n==="darwin"?r=d.join(e,"Library","Preferences",".wrangler"):r=d.join(e,".wrangler"),d.join(r,"config","default.toml")}async function b(){let e=y();try{let n=await k.readFile(e,"utf-8"),r=u.parse(n);if(!r.oauth_token||!r.refresh_token)throw new Error("OAuth tokens not found in wrangler config");return r}catch(n){throw n.code==="ENOENT"?new Error("Wrangler config not found. Please run 'npx wrangler login' first."):n}}function D(e){let n=new Date(e).getTime(),r=Date.now(),t=1*60*1e3;return n-r<t}async function _(e){let n=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(!n.ok)throw new Error(`Failed to refresh OAuth token: ${n.status} ${n.statusText}`);let r=await n.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 j(){let e=await b();return D(e.expiration_time)?(await _(e.refresh_token)).oauth_token:e.oauth_token}async function l(e,n={}){let r=await j(),t=await fetch(`https://api.cloudflare.com/client/v4${e}`,{...n,headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json",...n.headers}}),o=await t.json();if(!t.ok){let a=o.errors?o.errors.map(i=>`[${i.code}] ${i.message}`).join(", "):t.statusText;throw new Error(`Cloudflare API request failed: ${t.status} ${a}`)}if(!o.success){let a=o.errors.map(i=>`[${i.code}] ${i.message}`).join(", ");throw new Error(`Cloudflare API error: ${a}`)}return o.result}async function E(){let e=await l("/accounts");if(!e||e.length===0)throw new Error("No Cloudflare accounts found");let n=e[0];if(!n)throw new Error("No Cloudflare accounts found");return n.id}async function v(e){try{let n=await l(`/accounts/${e}/workers/subdomain`);if(!n||!n.subdomain)throw new Error("No workers.dev subdomain found for this account");return n.subdomain}catch(n){throw new Error(`Failed to get workers.dev subdomain: ${n instanceof Error?n.message:"Unknown error"}`)}}async function O(e,n){let r=n||await E(),t=await v(r);return`https://${e}.${t}.workers.dev`}import{execa as m}from"execa";import c from"chalk";async function x(){let{stdout:e}=await m("npx",["wrangler","d1","list","--json"]);return JSON.parse(e)}async function A(e){let{stdout:n}=await m("npx",["wrangler","d1","create",e]),r=n.match(/"database_id":\s*"([^"]+)"/);if(!r||!r[1])throw new Error("Failed to parse database ID from wrangler output");return r[1]}async function N(e,n=!1){n&&console.log(` Checking D1 database: ${e}`);try{let t=(await x()).find(a=>a.name===e);if(t)return console.log(n?c.dim(` Linking to existing D1 database: ${e} (${t.uuid})
2
- `):" D1 already set up."),t.uuid;n&&console.log(c.dim(` Creating new D1 database: ${e}`));let o=await A(e);return console.log(n?c.green(` Created D1 database: ${e} (${o})
3
- `):c.green(` D1 successfully created.
4
- `)),o}catch(r){throw console.error(c.red(`Failed to get or create D1 database: ${e}`),r instanceof Error?c.dim(`
5
- ${r.message}`):""),r}}import f from"node:fs/promises";import w from"node:path";import*as s from"jsonc-parser";import P from"chalk";async function M(e){e.verbose&&console.log("Updating wrangler.jsonc with resource IDs and configuration...");let n=e.configPath;(await f.stat(n)).isDirectory()&&(n=w.join(n,"wrangler.jsonc"));let t=await f.readFile(n,"utf-8"),o=s.parse(t),a=[];if(o.d1_databases){if(o.d1_databases.length===0)throw new Error("No D1 databases found in wrangler.jsonc. Every app must have exactly one D1 database.");if(o.d1_databases.length>1)throw new Error(`Found ${o.d1_databases.length} D1 databases in wrangler.jsonc. Every app must have exactly one D1 database.`)}if(o.kv_namespaces){if(o.kv_namespaces.length===0)throw new Error("No KV namespaces found in wrangler.jsonc. Every app must have exactly one KV namespace.");if(o.kv_namespaces.length>1)throw new Error(`Found ${o.kv_namespaces.length} KV namespaces in wrangler.jsonc. Every app must have exactly one KV namespace.`)}if(e.name&&a.push(...s.modify(t,["name"],e.name,{})),e.d1DatabaseId&&a.push(...s.modify(t,["d1_databases",0,"database_id"],e.d1DatabaseId,{})),e.d1DatabaseName&&a.push(...s.modify(t,["d1_databases",0,"database_name"],e.d1DatabaseName,{})),e.kvNamespaceId&&a.push(...s.modify(t,["kv_namespaces",0,"id"],e.kvNamespaceId,{})),e.vars)for(let[h,p]of Object.entries(e.vars))a.push(...s.modify(t,["vars",h],p,{}));let i=s.applyEdits(t,a);await f.writeFile(n,i),e.verbose&&console.log(P.dim(` wrangler.jsonc updated successfully
6
- `))}async function V(e){let n=await f.readFile(e,"utf-8"),r=s.parse(n);if(!r.name||typeof r.name!="string")throw new Error("Worker name not found in wrangler.jsonc");return r.name}async function K(e){let n=w.join(e,"wrangler.jsonc");try{let r=await f.readFile(n,"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}}export{j as a,l as b,E as c,v as d,O as e,x as f,N as g,M as h,V as i,K as j};