@every-app/cli 0.0.7 → 0.0.9
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.
- package/dist/bash-complete.js +1 -1
- package/dist/{chunk-LCSNH5IG.js → chunk-CQBCTFZE.js} +4 -4
- package/dist/chunk-HFR3IFIX.js +13 -0
- package/dist/{chunk-LN5JWSQH.js → chunk-KRQD7ZWZ.js} +4 -4
- package/dist/{chunk-W5YMWENN.js → chunk-MLX4WISN.js} +1 -1
- package/dist/create-NSFBGITH.js +32 -0
- package/dist/deploy-EVIZXTLI.js +44 -0
- package/dist/{deploy-CJAEI25G.js → deploy-OU5FTS67.js} +6 -6
- package/dist/index.js +1 -1
- package/dist/{remoteD1Shell-AJ3S325G.js → remoteD1Shell-KTDD4RTN.js} +1 -1
- package/package.json +5 -3
- package/dist/chunk-SWDH4UHI.js +0 -13
- package/dist/create-HZ2EZA27.js +0 -33
- package/dist/deploy-OFAXTS72.js +0 -46
package/dist/bash-complete.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as o,b as s}from"./chunk-
|
|
2
|
+
import{a as o,b as s}from"./chunk-KRQD7ZWZ.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,7 +1,7 @@
|
|
|
1
|
-
import p from"node:fs/promises";import d from"node:path";import f from"node:os";import*as g from"smol-toml";function w(){let r=f.homedir(),n=f.platform(),e;return n==="win32"?e=d.join(process.env.LOCALAPPDATA||d.join(r,"AppData","Local"),".wrangler"):n==="darwin"?e=d.join(r,"Library","Preferences",".wrangler"):e=d.join(r,".wrangler"),d.join(e,"config","default.toml")}async function h(){let r=w();try{let n=await p.readFile(r,"utf-8"),e=g.parse(n);if(!e.oauth_token||!e.refresh_token)throw new Error("OAuth tokens not found in wrangler config");return e}catch(n){throw n.code==="ENOENT"?new Error("Wrangler config not found. Please run 'npx wrangler login' first."):n}}function k(r){let n=new Date(r).getTime(),e=Date.now(),t=1*60*1e3;return n-e<t}async function b(r){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:r})});if(!n.ok)throw new Error(`Failed to refresh OAuth token: ${n.status} ${n.statusText}`);let e=await n.json();return{oauth_token:e.access_token,expiration_time:new Date(Date.now()+e.expires_in*1e3).toISOString(),refresh_token:e.refresh_token||r,scopes:e.scope?e.scope.split(" "):[]}}async function y(){let r=await h();return k(r.expiration_time)?(await b(r.refresh_token)).oauth_token:r.oauth_token}async function l(r,n={}){let e=await y(),t=await fetch(`https://api.cloudflare.com/client/v4${r}`,{...n,headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json",...n.headers}}),o=await t.json();if(!t.ok){let s=o.errors?o.errors.map(c=>`[${c.code}] ${c.message}`).join(", "):t.statusText;throw new Error(`Cloudflare API request failed: ${t.status} ${s}`)}if(!o.success){let s=o.errors.map(c=>`[${c.code}] ${c.message}`).join(", ");throw new Error(`Cloudflare API error: ${s}`)}return o.result}async function _(){let r=await l("/accounts");if(!r||r.length===0)throw new Error("No Cloudflare accounts found");let n=r[0];if(!n)throw new Error("No Cloudflare accounts found");return n.id}async function A(r){try{let n=await l(`/accounts/${r}/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 $(r,n){let e=n||await _(),t=await A(e);return`https://${r}.${t}.workers.dev`}import u from"node:fs/promises";import D from"node:path";import*as a from"jsonc-parser";function T(r,n,e){let t=[];return e.name&&t.push(...a.modify(r,["name"],e.name,{})),n.d1_databases&&e.d1DatabaseId&&n.d1_databases.forEach((o,s)=>{t.push(...a.modify(r,["d1_databases",s,"database_id"],e.d1DatabaseId,{})),e.d1DatabaseName&&t.push(...a.modify(r,["d1_databases",s,"database_name"],e.d1DatabaseName,{}))}),n.kv_namespaces&&e.kvNamespaceId&&n.kv_namespaces.forEach((o,s)=>{t.push(...a.modify(r,["kv_namespaces",s,"id"],e.kvNamespaceId,{}))}),t}async function v(r,n){let e=await u.readFile(r,"utf-8"),t=a.parse(e),o=T(e,t,n),s=a.applyEdits(e,o);await u.writeFile(r,s)}async function N(r){let n=await u.readFile(r,"utf-8"),e=a.parse(n);if(!e.name||typeof e.name!="string")throw new Error("Worker name not found in wrangler.jsonc");return e.name}async function F(r){let n=D.join(r,"wrangler.jsonc");try{let e=await u.readFile(n,"utf-8");return a.parse(e)}catch(e){throw e instanceof Error&&"code"in e&&e.code==="ENOENT"?new Error("wrangler.jsonc not found in current directory. Make sure you're running this command from your app's root directory."):e}}import{execa as m}from"execa";import i from"chalk";async function
|
|
2
|
-
`));try{let e=(await
|
|
1
|
+
import p from"node:fs/promises";import d from"node:path";import f from"node:os";import*as g from"smol-toml";function w(){let r=f.homedir(),n=f.platform(),e;return n==="win32"?e=d.join(process.env.LOCALAPPDATA||d.join(r,"AppData","Local"),".wrangler"):n==="darwin"?e=d.join(r,"Library","Preferences",".wrangler"):e=d.join(r,".wrangler"),d.join(e,"config","default.toml")}async function h(){let r=w();try{let n=await p.readFile(r,"utf-8"),e=g.parse(n);if(!e.oauth_token||!e.refresh_token)throw new Error("OAuth tokens not found in wrangler config");return e}catch(n){throw n.code==="ENOENT"?new Error("Wrangler config not found. Please run 'npx wrangler login' first."):n}}function k(r){let n=new Date(r).getTime(),e=Date.now(),t=1*60*1e3;return n-e<t}async function b(r){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:r})});if(!n.ok)throw new Error(`Failed to refresh OAuth token: ${n.status} ${n.statusText}`);let e=await n.json();return{oauth_token:e.access_token,expiration_time:new Date(Date.now()+e.expires_in*1e3).toISOString(),refresh_token:e.refresh_token||r,scopes:e.scope?e.scope.split(" "):[]}}async function y(){let r=await h();return k(r.expiration_time)?(await b(r.refresh_token)).oauth_token:r.oauth_token}async function l(r,n={}){let e=await y(),t=await fetch(`https://api.cloudflare.com/client/v4${r}`,{...n,headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json",...n.headers}}),o=await t.json();if(!t.ok){let s=o.errors?o.errors.map(c=>`[${c.code}] ${c.message}`).join(", "):t.statusText;throw new Error(`Cloudflare API request failed: ${t.status} ${s}`)}if(!o.success){let s=o.errors.map(c=>`[${c.code}] ${c.message}`).join(", ");throw new Error(`Cloudflare API error: ${s}`)}return o.result}async function _(){let r=await l("/accounts");if(!r||r.length===0)throw new Error("No Cloudflare accounts found");let n=r[0];if(!n)throw new Error("No Cloudflare accounts found");return n.id}async function A(r){try{let n=await l(`/accounts/${r}/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 $(r,n){let e=n||await _(),t=await A(e);return`https://${r}.${t}.workers.dev`}import u from"node:fs/promises";import D from"node:path";import*as a from"jsonc-parser";function T(r,n,e){let t=[];return e.name&&t.push(...a.modify(r,["name"],e.name,{})),n.d1_databases&&e.d1DatabaseId&&n.d1_databases.forEach((o,s)=>{t.push(...a.modify(r,["d1_databases",s,"database_id"],e.d1DatabaseId,{})),e.d1DatabaseName&&t.push(...a.modify(r,["d1_databases",s,"database_name"],e.d1DatabaseName,{}))}),n.kv_namespaces&&e.kvNamespaceId&&n.kv_namespaces.forEach((o,s)=>{t.push(...a.modify(r,["kv_namespaces",s,"id"],e.kvNamespaceId,{}))}),t}async function v(r,n){let e=await u.readFile(r,"utf-8"),t=a.parse(e),o=T(e,t,n),s=a.applyEdits(e,o);await u.writeFile(r,s)}async function N(r){let n=await u.readFile(r,"utf-8"),e=a.parse(n);if(!e.name||typeof e.name!="string")throw new Error("Worker name not found in wrangler.jsonc");return e.name}async function F(r){let n=D.join(r,"wrangler.jsonc");try{let e=await u.readFile(n,"utf-8");return a.parse(e)}catch(e){throw e instanceof Error&&"code"in e&&e.code==="ENOENT"?new Error("wrangler.jsonc not found in current directory. Make sure you're running this command from your app's root directory."):e}}import{execa as m}from"execa";import i from"chalk";async function C(){let{stdout:r}=await m("npx",["wrangler","d1","list","--json"]);return JSON.parse(r)}async function E(r){let{stdout:n}=await m("npx",["wrangler","d1","create",r]),e=n.match(/"database_id":\s*"([^"]+)"/);if(!e||!e[1])throw new Error("Failed to parse database ID from wrangler output");return e[1]}async function M(r){console.log(i.bold(`Checking D1 database: ${r}
|
|
2
|
+
`));try{let e=(await C()).find(o=>o.name===r);if(e)return console.log(i.green(`Linking to existing D1 database: ${r} (${e.uuid})
|
|
3
3
|
`)),e.uuid;console.log(i.bold(`Creating new D1 database: ${r}
|
|
4
|
-
`));let t=await
|
|
4
|
+
`));let t=await E(r);return console.log(i.green(`Created D1 database: ${r} (${t})
|
|
5
5
|
`)),t}catch(n){throw console.error(i.red(`
|
|
6
6
|
Failed to get or create D1 database: ${r}`),n instanceof Error?i.dim(`
|
|
7
|
-
${n.message}`):""),n}}export{y as a,_ as b,$ as c,v as d,N as e,F as f,
|
|
7
|
+
${n.message}`):""),n}}export{y as a,_ as b,$ as c,v as d,N as e,F as f,C as g,M as h};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import{execa as f}from"execa";import c from"chalk";async function p(e,n,o={}){let{env:t,cwd:r,verbose:m=!1}=o;if(m){console.log(c.dim(` \u250C\u2500 Running: ${e} ${n.join(" ")}`));let s=f(e,n,{cwd:r,env:t,stdio:void 0,all:!0});s.stdout&&s.stdout.on("data",l=>{l.toString().split(`
|
|
2
|
+
`).forEach(a=>{a.trim()&&console.log(c.dim(` \u2502 ${a}`))})}),s.stderr&&s.stderr.on("data",l=>{l.toString().split(`
|
|
3
|
+
`).forEach(a=>{a.trim()&&console.error(c.dim(` \u2502 ${a}`))})});let w=await s;return console.log(c.dim(` \u2514\u2500 Complete
|
|
4
|
+
`)),w}else return console.log(`Running: ${e} ${n.join(" ")}`),await f(e,n,{cwd:r,env:t,stdio:"pipe"})}import u from"node:fs/promises";import g from"node:path";import d from"chalk";async function y(e,n,o=!1){try{if(e==="pnpm"){await p("npx",["pnpm","install"],{cwd:n,stdio:"inherit",verbose:o});return}await p(e,["install"],{cwd:n,stdio:"inherit",verbose:o})}catch(t){throw new Error(`Failed to install dependencies with ${e}: ${t instanceof Error?t.message:"Unknown error"}`)}}async function $(e){try{return(await u.stat(g.join(e,"node_modules"))).isDirectory()}catch{return!1}}async function C(e,n=!1){if(!await $(e)){console.log(d.bold(`Installing dependencies...
|
|
5
|
+
`));try{let t=await u.access(g.join(e,"pnpm-lock.yaml")).then(()=>!0).catch(()=>!1),r=await u.access(g.join(e,"package-lock.json")).then(()=>!0).catch(()=>!1);await y(t?"pnpm":r?"npm":"pnpm",e,n),console.log(d.green(`Dependencies installed
|
|
6
|
+
`))}catch(t){throw console.error(d.red(`
|
|
7
|
+
Failed to install dependencies`)),t}}}import{execa as h}from"execa";import i from"chalk";async function x(){let{stdout:e}=await h("npx",["wrangler","kv","namespace","list"]);return JSON.parse(e)}async function P(e){let{stdout:n}=await h("npx",["wrangler","kv","namespace","create",e]);return b(n)}function b(e){let n=e.match(/"id":\s*"([a-f0-9]+)"/);if(!n||!n[1])throw new Error("Failed to parse namespace ID from wrangler output");return n[1]}async function S(e){console.log(i.bold(`Checking KV namespace: ${e}
|
|
8
|
+
`));try{let o=(await x()).find(r=>r.title===e);if(o)return console.log(i.green(`Linking to existing KV namespace: ${e} (${o.id})
|
|
9
|
+
`)),o.id;console.log(i.bold(`Creating new KV namespace: ${e}
|
|
10
|
+
`));let t=await P(e);return console.log(i.green(`Created KV namespace: ${e} (${t})
|
|
11
|
+
`)),t}catch(n){throw console.error(i.red(`
|
|
12
|
+
Failed to get or create KV namespace: ${e}`),n instanceof Error?i.dim(`
|
|
13
|
+
${n.message}`):""),n}}export{p as a,y as b,C as c,S as d};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
`)}}),u=o({loader:async()=>{let{deploy:e}=await import("./deploy-
|
|
3
|
-
`)}}),y=o({loader:async()=>{let{remoteD1Shell:e}=await import("./remoteD1Shell-
|
|
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-
|
|
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.9";import{buildCommand as o,buildRouteMap as m}from"@stricli/core";var c=o({loader:async()=>import("./create-NSFBGITH.js"),parameters:{positional:{kind:"tuple",parameters:[]}},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-EVIZXTLI.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-KTDD4RTN.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-OU5FTS67.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,4 +1,4 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as m}from"./chunk-HFR3IFIX.js";import{c as p}from"./chunk-CQBCTFZE.js";async function g(t,e,r=!1){try{await m("git",["clone",t,e],{stdio:"inherit",verbose:r})}catch(i){throw new Error(`Failed to clone repository from ${t}: ${i instanceof Error?i.message:"Unknown error"}`)}}import o from"node:fs/promises";import n from"node:path";import f from"node:os";import y from"chalk";async function u(t,e,r={}){let i=r.exclude||[];await o.mkdir(e,{recursive:!0});let s=await o.readdir(t,{withFileTypes:!0});for(let a of s){let c=n.join(t,a.name),l=n.join(e,a.name);i.some(d=>a.name===d)||(a.isDirectory()?await u(c,l,r):await o.copyFile(c,l))}}async function O(t){try{return(await o.stat(t)).isDirectory()}catch{return!1}}async function R(t,e){let r=await p("every-app-gateway"),i=`CORE_APP_URL=${r}
|
|
2
2
|
`,s=`VITE_APP_ID=${e}
|
|
3
3
|
VITE_PARENT_ORIGIN=${r}
|
|
4
4
|
`;await Promise.all([o.writeFile(n.join(t,".dev.vars"),i),o.writeFile(n.join(t,".env.local"),s)])}async function j(t){return await o.mkdtemp(n.join(f.tmpdir(),t))}async function I(t,e=!1){try{await o.rm(t,{recursive:!0,force:!0}),e&&console.log(y.dim(` Removed: ${t}`))}catch{console.warn(y.yellow("\u26A0\uFE0F Warning: Failed to clean up temporary directory:"),t)}}export{g as a,u as b,O as c,R as d,j as e,I as f};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import{a as c,b as g,c as m,d,e as u,f as y}from"./chunk-MLX4WISN.js";import{b as p,d as b}from"./chunk-HFR3IFIX.js";import{d as f,h as w}from"./chunk-CQBCTFZE.js";import h from"node:fs/promises";import l from"node:path";import k from"enquirer";import{execa as D}from"execa";import e from"chalk";var v="git@github.com:every-app/every-app.git",E="templates/simple-todo";function I(a){return!a||a.trim().length===0?"App ID cannot be empty":a.length>64?"App ID must be 64 characters or less":/^[a-z][a-z0-9-]*$/.test(a)?!0:"App ID must be in kebab-case format (lowercase letters, numbers, and hyphens only, starting with a letter)"}async function $(){return(await k.prompt({type:"input",name:"appId",message:"Enter your app ID (kebab-case format)",initial:"my-cool-app",validate:I})).appId}async function j(){return(await k.prompt({type:"select",name:"packageManager",message:"Select your package manager",choices:[{name:"pnpm",message:"pnpm (recommended)"},{name:"npm",message:"npm"}],initial:0})).packageManager}async function x(a,n){let o=l.join(a,"package.json"),r=JSON.parse(await h.readFile(o,"utf-8"));r.name=n,await h.writeFile(o,JSON.stringify(r,null,2)+`
|
|
2
|
+
`,"utf-8")}async function A(a){try{await D("npm",["run","db:migrate:local"],{cwd:a,stdio:["inherit","inherit","inherit"]}),console.log(e.green(`
|
|
3
|
+
Local database migrations completed successfully
|
|
4
|
+
`))}catch{console.warn(e.yellow(`
|
|
5
|
+
Failed to run local migrations. You can run them manually with:`)),console.warn(e.dim(` npm run db:migrate:local
|
|
6
|
+
`))}}async function z(a){console.log(e.bold(`
|
|
7
|
+
Create a new Every App project
|
|
8
|
+
`));let n=null;try{console.log(e.bold(`Project Configuration
|
|
9
|
+
`));let o=await $(),r=await j();console.log(e.dim(`
|
|
10
|
+
Creating project: ${o}`)),console.log(e.dim(`Package manager: ${r}
|
|
11
|
+
`)),console.log(e.bold(`Cloning template repository...
|
|
12
|
+
`)),n=await u("every-app-create-"),await c(v,n),console.log(e.bold(`
|
|
13
|
+
Extracting template...
|
|
14
|
+
`));let P=l.join(n,E),t=l.join(process.cwd(),o);if(await m(t))throw new Error(`Directory "${o}" already exists in the current location`);await g(P,t,{exclude:["node_modules",".git","pnpm-lock.yaml","package-lock.json",".env.local",".env.production",".dev.vars","manual-steps.md"]}),console.log(e.green(`Template copied to ${t}
|
|
15
|
+
`)),console.log(e.bold(`Creating Cloudflare resources...
|
|
16
|
+
`));let s=await w(o),i=await b(o);console.log(e.green(`Cloudflare resources ready:
|
|
17
|
+
`)),console.log(e.dim(` D1 Database: ${o} (${s})`)),console.log(e.dim(` KV Namespace: ${o} (${i})
|
|
18
|
+
`)),console.log(e.bold(`Updating configuration files...
|
|
19
|
+
`));let C=l.join(t,"wrangler.jsonc");await f(C,{name:o,d1DatabaseId:s,d1DatabaseName:o,kvNamespaceId:i}),await x(t,o),await d(t,o),console.log(e.green(`Configuration updated
|
|
20
|
+
`)),console.log(e.bold(`Installing dependencies with ${r}...
|
|
21
|
+
`)),await p(r,t),console.log(e.green(`
|
|
22
|
+
Dependencies installed
|
|
23
|
+
`)),console.log(e.bold(`Running database migrations locally...
|
|
24
|
+
`)),await A(t),console.log(e.bold.green(`
|
|
25
|
+
Project created successfully!
|
|
26
|
+
`)),console.log(e.dim(`Location: ${t}
|
|
27
|
+
`)),console.log(e.bold(`Next steps:
|
|
28
|
+
`)),console.log(e.cyan(` 1. cd ${o}`)),console.log(e.cyan(` 2. ${r} run dev`)),console.log(e.cyan(` 3. Open your browser and start building!
|
|
29
|
+
`)),console.log(e.bold(`Deploy to production:
|
|
30
|
+
`)),console.log(e.dim(` ${r} run db:migrate:prod # Run remote migrations`)),console.log(e.dim(` npm run deploy # Deploy to Cloudflare
|
|
31
|
+
`))}catch(o){throw console.error(e.red(`
|
|
32
|
+
Failed to create project:`),o instanceof Error?o.message:"Unknown error"),o}finally{n&&await y(n)}}export{z as default};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import{a as C}from"./chunk-B6LAGOID.js";import{a as y,c as D,d as R}from"./chunk-HFR3IFIX.js";import{a as _,b as $,c as b,f as E,g as v,h as k}from"./chunk-CQBCTFZE.js";import n from"chalk";import U from"node:path";import h from"node:fs/promises";import{execa as N}from"execa";import*as g from"jsonc-parser";import{randomUUID as A}from"node:crypto";async function T(o,t){console.log(n.bold(`
|
|
2
|
+
Setting up Cloudflare resources...
|
|
3
|
+
`));let a=new Map,r=new Map;if(o.d1_databases&&o.d1_databases.length>0){console.log(n.bold(`Processing D1 databases...
|
|
4
|
+
`));for(let e=0;e<o.d1_databases.length;e++){let s=o.d1_databases[e].database_name;if(!s){console.warn(n.yellow(`Skipping D1 database at index ${e}: no database_name specified
|
|
5
|
+
`));continue}let c=await k(s);a.set(e,c)}}if(o.kv_namespaces&&o.kv_namespaces.length>0){console.log(n.bold(`Processing KV namespaces...
|
|
6
|
+
`));for(let e=0;e<o.kv_namespaces.length;e++){if(!o.kv_namespaces[e].binding){console.warn(n.yellow(`Skipping KV namespace at index ${e}: no binding specified
|
|
7
|
+
`));continue}let s=await R(t);r.set(e,s)}}return{d1Updates:a,kvUpdates:r}}async function S(o,t,a,r){console.log(n.bold(`Updating wrangler.jsonc with resource IDs...
|
|
8
|
+
`));let e=U.join(o,"wrangler.jsonc"),i=await h.readFile(e,"utf-8"),s=[];for(let[d,p]of t.entries())s.push(...g.modify(i,["d1_databases",d,"database_id"],p,{}));for(let[d,p]of a.entries())s.push(...g.modify(i,["kv_namespaces",d,"id"],p,{}));s.push(...g.modify(i,["vars","CORE_APP_URL"],r,{}));let c=g.applyEdits(i,s);await h.writeFile(e,c),console.log(n.green(`wrangler.jsonc updated successfully
|
|
9
|
+
`))}async function j(o,t){if(!t.d1_databases||t.d1_databases.length===0){console.log(n.dim(`No D1 databases configured, skipping migrations
|
|
10
|
+
`));return}console.log(n.bold(`Running database migrations...
|
|
11
|
+
`));try{console.log(n.dim(` Running production migrations...
|
|
12
|
+
`)),await N("npm",["run","db:migrate:prod"],{cwd:o,stdio:["inherit","inherit","inherit"]}),console.log(n.green(`Migrations completed
|
|
13
|
+
`))}catch{console.warn(n.yellow(`Failed to run migrations. You may need to run them manually with: npm run db:migrate:prod
|
|
14
|
+
`))}}async function x(o,t,a,r){console.log(n.bold(`Building and deploying to Cloudflare...
|
|
15
|
+
`));try{let e=U.join(o,"package.json"),i=JSON.parse(await h.readFile(e,"utf-8")),s={...process.env,VITE_PARENT_ORIGIN:t,VITE_APP_ID:a};i.scripts?.deploy?await y("npm",["run","deploy"],{cwd:o,stdio:"inherit",env:s,verbose:r}):(await y("npm",["run","build"],{cwd:o,stdio:"inherit",env:s,verbose:r}),await y("npx",["wrangler","deploy"],{cwd:o,stdio:"inherit",env:s,verbose:r})),console.log(n.green(`
|
|
16
|
+
Deployment completed successfully!
|
|
17
|
+
`))}catch(e){throw console.error(n.red(`
|
|
18
|
+
Failed to build or deploy`)),e}}async function f(o,t,a){try{let r=await _(),e=await fetch(`https://api.cloudflare.com/client/v4/accounts/${o}/d1/database/${t}/query`,{method:"POST",headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json"},body:JSON.stringify({sql:a})}),i=await e.json();if(!e.ok||!i.success){let d=i.errors?i.errors.map(p=>`[${p.code}] ${p.message}`).join(", "):e.statusText;throw console.error(n.red(`
|
|
19
|
+
D1 Query Error:`)),console.error(n.dim(`SQL: ${a}`)),console.error(n.dim(`Error: ${d}`)),new Error(`D1 query failed: ${d}`)}let s=i.result;if(!s||s.length===0)throw new Error("No results returned from D1 query");let c=s[0];if(!c)throw new Error("First result is undefined");return c.results}catch(r){throw r instanceof Error&&!r.message.includes("D1 query failed")&&(console.error(n.red(`
|
|
20
|
+
D1 Query Error:`)),console.error(n.dim(`SQL: ${a}`))),r}}async function M(o,t,a,r){console.log(n.bold(`
|
|
21
|
+
Setting up UserApp records...
|
|
22
|
+
`));try{let e=await $(),s=(await v()).find(l=>l.name==="every-app-gateway");if(!s){console.warn(n.yellow(`every-app-gateway database not found. Skipping UserApp record creation.
|
|
23
|
+
`));return}let c=s.uuid,d=await f(e,c,"SELECT id, name, email FROM users");if(d.length===0)throw new Error("No users found in the database. Please create a user first before deploying apps.");let p=a||o,u=r||o;if(d.length===1){let l=d[0],m=Math.floor(Date.now()/1e3);if((await f(e,c,`SELECT id FROM user_apps WHERE user_id = '${l.id}' AND app_id = '${o}'`)).length>0)console.log(n.yellow(`UserApp record already exists for user ${l.name} (${l.email}), skipping...
|
|
24
|
+
`));else{let w=`
|
|
25
|
+
INSERT INTO user_apps (id, user_id, app_id, name, description, app_url, status, created_at, updated_at)
|
|
26
|
+
VALUES ('${A()}', '${l.id}', '${o}', '${p}', '${u}', '${t}', 'installed', ${m}, ${m})
|
|
27
|
+
`;await f(e,c,w),console.log(n.green(`UserApp record created for user ${l.name} (${l.email})
|
|
28
|
+
`))}}else{console.log(n.yellow(`Multiple users found (${d.length}). Adding app to all users...
|
|
29
|
+
`));for(let l of d){let m=Math.floor(Date.now()/1e3);if((await f(e,c,`SELECT id FROM user_apps WHERE user_id = '${l.id}' AND app_id = '${o}'`)).length>0)console.log(n.dim(` App already exists for user ${l.name} (${l.email}), skipping...
|
|
30
|
+
`));else{let w=`
|
|
31
|
+
INSERT INTO user_apps (id, user_id, app_id, name, description, app_url, status, created_at, updated_at)
|
|
32
|
+
VALUES ('${A()}', '${l.id}', '${o}', '${p}', '${u}', '${t}', 'installed', ${m}, ${m})
|
|
33
|
+
`;await f(e,c,w),console.log(n.dim(` Added app for user ${l.name} (${l.email})
|
|
34
|
+
`))}}console.log(n.green(`UserApp records processed for ${d.length} users
|
|
35
|
+
`))}}catch(e){throw console.error(n.red("Failed to insert UserApp records:"),e instanceof Error?e.message:e),e}}async function O(o,t=!1,a=!1){try{console.log(n.bold(`
|
|
36
|
+
Reading project configuration...
|
|
37
|
+
`));let r=await E(o);if(!r.name)throw new Error("Worker name not found in wrangler.jsonc. Please add a 'name' field.");let e=r.name;if(console.log(n.dim(`Project name: ${e}
|
|
38
|
+
`)),!t&&!await C("Do you want to deploy this app to Cloudflare?")){console.log(n.red(`
|
|
39
|
+
Deployment cancelled by user
|
|
40
|
+
`));return}let{d1Updates:i,kvUpdates:s}=await T(r,e),c=await b("every-app-gateway");await S(o,i,s,c),await D(o,a),await j(o,r),await x(o,c,e,a);let d=await b(r.name),p,u;r.name==="every-todo-app"&&(p="Todos",u="Minimal todo list"),await M(r.name,d,p,u),console.log(n.bold.green(`\u{1F389} Deployment successful!
|
|
41
|
+
`)),console.log(n.bold(`Your app is now live at: ${n.cyan(d)}
|
|
42
|
+
`)),console.log(n.dim(`Try it out by visiting the URL above in your browser.
|
|
43
|
+
`))}catch(r){throw console.error(n.red(`
|
|
44
|
+
Deployment failed:`),r instanceof Error?r.message:r),r}}async function G(o){let t=process.cwd(),a=o.verbose||!1;await O(t,!1,a)}export{G as deploy};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as y,e as w,f as T}from"./chunk-
|
|
1
|
+
import{a as y,e as w,f as T}from"./chunk-MLX4WISN.js";import{a as b}from"./chunk-B6LAGOID.js";import{a as m,b as u,d as C}from"./chunk-HFR3IFIX.js";import{b as f,c as E,d as _,e as R,h as A}from"./chunk-CQBCTFZE.js";import c from"chalk";import O from"node:path";import k from"node:path";import W from"node:crypto";import l from"chalk";import{execa as U}from"execa";import S from"node:crypto";import t from"chalk";function K(){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 B(o){try{let{stdout:e}=await U("npx",["wrangler","secret","list","--format","json"],{cwd:o});return JSON.parse(e)}catch{return[]}}async function d(o,e){return(await B(e)).some(n=>n.name===o)}async function g(o,e,r){let n=U("npx",["wrangler","secret","put",o],{cwd:r});n.stdin&&(n.stdin.write(e),n.stdin.end()),await n}async function P(o,e){console.log(t.bold(`
|
|
2
2
|
Setting up secrets...
|
|
3
3
|
`));try{if(console.log(t.bold(`Checking secret: CORE_APP_URL
|
|
4
4
|
`)),await d("CORE_APP_URL",e)?console.log(t.dim(` Secret already exists
|
|
@@ -19,17 +19,17 @@ Setting up secrets...
|
|
|
19
19
|
`))}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.green(`Secret setup complete!
|
|
20
20
|
`))}catch(r){throw console.error(t.red(`
|
|
21
21
|
Failed to setup secrets`),r instanceof Error?t.dim(`
|
|
22
|
-
${r.message}`):""),r}}var
|
|
22
|
+
${r.message}`):""),r}}var x="git@github.com:every-app/every-app.git",J="every-app-gateway",H="every-app-gateway",N="apps/every-app-gateway";async function v(){console.log(l.bold(`
|
|
23
23
|
Setting up Cloudflare resources...
|
|
24
|
-
`));let o=await f(),e=await A(J),r=await C(H);return{d1DatabaseId:e,kvNamespaceId:r,accountId:o}}async function I(o,e=!1){console.log(l.bold("Cloning gateway repository...")),console.log(l.dim(` Repository: ${
|
|
25
|
-
`));try{await y(
|
|
24
|
+
`));let o=await f(),e=await A(J),r=await C(H);return{d1DatabaseId:e,kvNamespaceId:r,accountId:o}}async function I(o,e=!1){console.log(l.bold("Cloning gateway repository...")),console.log(l.dim(` Repository: ${x}
|
|
25
|
+
`));try{await y(x,o,e);let r=k.join(o,N);return console.log(l.bold(`Installing dependencies in apps/every-app-gateway...
|
|
26
26
|
`)),await u("pnpm",r,e),console.log(l.green(`Installation complete!
|
|
27
27
|
`)),r}catch(r){throw console.error(l.red(`
|
|
28
28
|
Failed to clone repository or install dependencies`),r instanceof Error?l.dim(`
|
|
29
|
-
${r.message}`):""),r}}async function h(o,e,r,n=!1){try{let s=k.join(o,"wrangler.jsonc");await _(s,{d1DatabaseId:e.d1DatabaseId,kvNamespaceId:e.kvNamespaceId}),await
|
|
29
|
+
${r.message}`):""),r}}async function h(o,e,r,n=!1){try{let s=k.join(o,"wrangler.jsonc");await _(s,{d1DatabaseId:e.d1DatabaseId,kvNamespaceId:e.kvNamespaceId}),await P(r,o),console.log(l.bold(`Deploying to Cloudflare...
|
|
30
30
|
`));let i=W.randomUUID();await m("npm",["run","deploy"],{cwd:o,stdio:"inherit",env:{...process.env,BETTER_AUTH_SECRET:i},verbose:n})}catch(s){throw console.error(l.red(`
|
|
31
31
|
Failed to update config or deploy`),s instanceof Error?l.dim(`
|
|
32
|
-
${s.message}`):""),s}}async function de(o){let e=o.verbose||!1;if(!await
|
|
32
|
+
${s.message}`):""),s}}async function de(o){let e=o.verbose||!1;if(!await b("Do you want to deploy EveryApp Gateway into this Cloudflare account?")){console.log(c.red(`
|
|
33
33
|
Deployment cancelled by user
|
|
34
34
|
`));return}let n=await v(),s=await w("gateway-deploy-");console.log(c.dim(`
|
|
35
35
|
Working directory: ${s}
|
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-
|
|
2
|
+
import{a as r,b as o}from"./chunk-KRQD7ZWZ.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,b as c,f as l,g}from"./chunk-
|
|
1
|
+
import{a as d,b as c,f as l,g}from"./chunk-CQBCTFZE.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 l(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(),g(),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
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@every-app/cli",
|
|
3
3
|
"author": "",
|
|
4
|
-
"description": "Every CLI -
|
|
4
|
+
"description": "Every App CLI - Deploy and manage apps.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"version": "0.0.
|
|
7
|
+
"version": "0.0.9",
|
|
8
8
|
"files": [
|
|
9
9
|
"dist"
|
|
10
10
|
],
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
"build": "tsup --silent",
|
|
23
23
|
"build:prepublish": "pnpm install --ignore-scripts && npm run types:check && npm run build",
|
|
24
24
|
"prepublishOnly": "npm run build:prepublish",
|
|
25
|
-
"postinstall": "every install"
|
|
25
|
+
"postinstall": "every install",
|
|
26
|
+
"knip": "knip"
|
|
26
27
|
},
|
|
27
28
|
"tsup": {
|
|
28
29
|
"entry": {
|
|
@@ -48,6 +49,7 @@
|
|
|
48
49
|
},
|
|
49
50
|
"devDependencies": {
|
|
50
51
|
"@types/node": "^22.18.13",
|
|
52
|
+
"knip": "^5.66.4",
|
|
51
53
|
"tsup": "^6.7.0",
|
|
52
54
|
"typescript": "5.9.3"
|
|
53
55
|
}
|
package/dist/chunk-SWDH4UHI.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import{execa as g}from"execa";import c from"chalk";async function p(e,n,o={}){let{env:t,cwd:r,verbose:f=!1}=o;if(f){console.log(c.dim(` \u250C\u2500 Running: ${e} ${n.join(" ")}`));let s=g(e,n,{cwd:r,env:t,stdio:void 0,all:!0});s.stdout&&s.stdout.on("data",l=>{l.toString().split(`
|
|
2
|
-
`).forEach(i=>{i.trim()&&console.log(c.dim(` \u2502 ${i}`))})}),s.stderr&&s.stderr.on("data",l=>{l.toString().split(`
|
|
3
|
-
`).forEach(i=>{i.trim()&&console.error(c.dim(` \u2502 ${i}`))})});let w=await s;return console.log(c.dim(` \u2514\u2500 Complete
|
|
4
|
-
`)),w}else return console.log(`Running: ${e} ${n.join(" ")}`),await g(e,n,{cwd:r,env:t,stdio:"pipe"})}import u from"node:fs/promises";import m from"node:path";import d from"chalk";import{execa as k}from"execa";async function x(e){try{return await k("which",[e]),!0}catch{return!1}}async function P(e,n,o=!1){try{if(e==="pnpm"&&!await x("pnpm")){await p("npx",["pnpm","install"],{cwd:n,stdio:"inherit",verbose:o});return}await p(e,["install"],{cwd:n,stdio:"inherit",verbose:o})}catch(t){throw new Error(`Failed to install dependencies with ${e}: ${t instanceof Error?t.message:"Unknown error"}`)}}async function $(e){try{return(await u.stat(m.join(e,"node_modules"))).isDirectory()}catch{return!1}}async function O(e,n=!1){if(!await $(e)){console.log(d.bold(`Installing dependencies...
|
|
5
|
-
`));try{let t=await u.access(m.join(e,"pnpm-lock.yaml")).then(()=>!0).catch(()=>!1),r=await u.access(m.join(e,"package-lock.json")).then(()=>!0).catch(()=>!1);await P(t?"pnpm":r?"npm":"pnpm",e,n),console.log(d.green(`Dependencies installed
|
|
6
|
-
`))}catch(t){throw console.error(d.red(`
|
|
7
|
-
Failed to install dependencies`)),t}}}import{execa as h}from"execa";import a from"chalk";async function b(){let{stdout:e}=await h("npx",["wrangler","kv","namespace","list"]);return JSON.parse(e)}async function v(e){let{stdout:n}=await h("npx",["wrangler","kv","namespace","create",e]);return K(n)}function K(e){let n=e.match(/"id":\s*"([a-f0-9]+)"/);if(!n||!n[1])throw new Error("Failed to parse namespace ID from wrangler output");return n[1]}async function N(e){console.log(a.bold(`Checking KV namespace: ${e}
|
|
8
|
-
`));try{let o=(await b()).find(r=>r.title===e);if(o)return console.log(a.green(`Linking to existing KV namespace: ${e} (${o.id})
|
|
9
|
-
`)),o.id;console.log(a.bold(`Creating new KV namespace: ${e}
|
|
10
|
-
`));let t=await v(e);return console.log(a.green(`Created KV namespace: ${e} (${t})
|
|
11
|
-
`)),t}catch(n){throw console.error(a.red(`
|
|
12
|
-
Failed to get or create KV namespace: ${e}`),n instanceof Error?a.dim(`
|
|
13
|
-
${n.message}`):""),n}}export{p as a,P as b,O as c,N as d};
|
package/dist/create-HZ2EZA27.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import{a as c,b as g,c as m,d,e as u,f as y}from"./chunk-W5YMWENN.js";import{b as p,d as b}from"./chunk-SWDH4UHI.js";import{d as f,h as w}from"./chunk-LCSNH5IG.js";import h from"node:fs/promises";import i from"node:path";import k from"enquirer";import{execa as D}from"execa";import e from"chalk";var v="git@github.com:every-app/every-app.git",$="templates/simple-todo";function E(n){return!n||n.trim().length===0?"App ID cannot be empty":n.length>64?"App ID must be 64 characters or less":/^[a-z][a-z0-9-]*$/.test(n)?!0:"App ID must be in kebab-case format (lowercase letters, numbers, and hyphens only, starting with a letter)"}async function x(){return(await k.prompt({type:"input",name:"appId",message:"Enter your app ID (kebab-case format)",initial:"my-cool-app",validate:E})).appId}async function j(){return(await k.prompt({type:"select",name:"packageManager",message:"Select your package manager",choices:[{name:"pnpm",message:"pnpm (recommended)"},{name:"npm",message:"npm"}],initial:0})).packageManager}async function I(n,a){let o=i.join(n,"package.json"),t=JSON.parse(await h.readFile(o,"utf-8"));t.name=a,t.scripts["db:migrate:dev"]=`wrangler d1 migrations apply ${a} --local`,t.scripts["db:migrate:prod"]=`wrangler d1 migrations apply ${a} --remote`,await h.writeFile(o,JSON.stringify(t,null,2)+`
|
|
2
|
-
`,"utf-8")}async function A(n,a){try{await D("npx",["wrangler","d1","migrations","apply",a,"--local"],{cwd:n,input:`y
|
|
3
|
-
`,stdio:["pipe","inherit","inherit"]}),console.log(e.green(`
|
|
4
|
-
Local database migrations completed successfully
|
|
5
|
-
`))}catch{console.warn(e.yellow(`
|
|
6
|
-
Failed to run local migrations. You can run them manually with:`)),console.warn(e.dim(` npm run db:migrate:dev
|
|
7
|
-
`))}}async function z(n){console.log(e.bold(`
|
|
8
|
-
Create a new Every App project
|
|
9
|
-
`));let a=null;try{console.log(e.bold(`Project Configuration
|
|
10
|
-
`));let o=await x(),t=await j();console.log(e.dim(`
|
|
11
|
-
Creating project: ${o}`)),console.log(e.dim(`Package manager: ${t}
|
|
12
|
-
`)),console.log(e.bold(`Cloning template repository...
|
|
13
|
-
`)),a=await u("every-app-create-"),await c(v,a),console.log(e.bold(`
|
|
14
|
-
Extracting template...
|
|
15
|
-
`));let P=i.join(a,$),r=i.join(process.cwd(),o);if(await m(r))throw new Error(`Directory "${o}" already exists in the current location`);await g(P,r,{exclude:["node_modules",".git","pnpm-lock.yaml","package-lock.json",".env.local",".env.production",".dev.vars","manual-steps.md"]}),console.log(e.green(`Template copied to ${r}
|
|
16
|
-
`)),console.log(e.bold(`Creating Cloudflare resources...
|
|
17
|
-
`));let s=await w(o),l=await b(o);console.log(e.green(`Cloudflare resources ready:
|
|
18
|
-
`)),console.log(e.dim(` D1 Database: ${o} (${s})`)),console.log(e.dim(` KV Namespace: ${o} (${l})
|
|
19
|
-
`)),console.log(e.bold(`Updating configuration files...
|
|
20
|
-
`));let C=i.join(r,"wrangler.jsonc");await f(C,{name:o,d1DatabaseId:s,d1DatabaseName:o,kvNamespaceId:l}),await I(r,o),await d(r,o),console.log(e.green(`Configuration updated
|
|
21
|
-
`)),console.log(e.bold(`Installing dependencies with ${t}...
|
|
22
|
-
`)),await p(t,r),console.log(e.green(`
|
|
23
|
-
Dependencies installed
|
|
24
|
-
`)),console.log(e.bold(`Running database migrations locally...
|
|
25
|
-
`)),await A(r,o),console.log(e.bold.green(`
|
|
26
|
-
Project created successfully!
|
|
27
|
-
`)),console.log(e.dim(`Location: ${r}
|
|
28
|
-
`)),console.log(e.bold(`Next steps:
|
|
29
|
-
`)),console.log(e.cyan(` 1. cd ${o}`)),console.log(e.cyan(` 2. ${t} run dev`)),console.log(e.cyan(` 3. Open your browser and start building!
|
|
30
|
-
`)),console.log(e.bold(`Deploy to production:
|
|
31
|
-
`)),console.log(e.dim(` ${t} run db:migrate:prod # Run remote migrations`)),console.log(e.dim(` npm run deploy # Deploy to Cloudflare
|
|
32
|
-
`))}catch(o){throw console.error(e.red(`
|
|
33
|
-
Failed to create project:`),o instanceof Error?o.message:"Unknown error"),o}finally{a&&await y(a)}}export{z as default};
|
package/dist/deploy-OFAXTS72.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import{a as R}from"./chunk-B6LAGOID.js";import{a as y,c as D,d as C}from"./chunk-SWDH4UHI.js";import{a as $,b as _,c as b,f as E,g as v,h as k}from"./chunk-LCSNH5IG.js";import n from"chalk";import U from"node:path";import h from"node:fs/promises";import{execa as I}from"execa";import*as g from"jsonc-parser";import{randomUUID as A}from"node:crypto";async function N(s,t){console.log(n.bold(`
|
|
2
|
-
Setting up Cloudflare resources...
|
|
3
|
-
`));let a=new Map,o=new Map;if(s.d1_databases&&s.d1_databases.length>0){console.log(n.bold(`Processing D1 databases...
|
|
4
|
-
`));for(let e=0;e<s.d1_databases.length;e++){let r=s.d1_databases[e].database_name;if(!r){console.warn(n.yellow(`Skipping D1 database at index ${e}: no database_name specified
|
|
5
|
-
`));continue}let c=await k(r);a.set(e,c)}}if(s.kv_namespaces&&s.kv_namespaces.length>0){console.log(n.bold(`Processing KV namespaces...
|
|
6
|
-
`));for(let e=0;e<s.kv_namespaces.length;e++){if(!s.kv_namespaces[e].binding){console.warn(n.yellow(`Skipping KV namespace at index ${e}: no binding specified
|
|
7
|
-
`));continue}let r=await C(t);o.set(e,r)}}return{d1Updates:a,kvUpdates:o}}async function S(s,t,a,o){console.log(n.bold(`Updating wrangler.jsonc with resource IDs...
|
|
8
|
-
`));let e=U.join(s,"wrangler.jsonc"),i=await h.readFile(e,"utf-8"),r=[];for(let[d,p]of t.entries())r.push(...g.modify(i,["d1_databases",d,"database_id"],p,{}));for(let[d,p]of a.entries())r.push(...g.modify(i,["kv_namespaces",d,"id"],p,{}));r.push(...g.modify(i,["vars","CORE_APP_URL"],o,{}));let c=g.applyEdits(i,r);await h.writeFile(e,c),console.log(n.green(`wrangler.jsonc updated successfully
|
|
9
|
-
`))}async function T(s,t){if(!t.d1_databases||t.d1_databases.length===0){console.log(n.dim(`No D1 databases configured, skipping migrations
|
|
10
|
-
`));return}console.log(n.bold(`Running database migrations...
|
|
11
|
-
`));for(let a of t.d1_databases){let o=a.binding;if(!o){console.warn(n.yellow(`Skipping migration: no binding specified
|
|
12
|
-
`));continue}try{console.log(n.dim(` Running migrations for ${o}...
|
|
13
|
-
`)),await I("npx",["wrangler","d1","migrations","apply",o,"--remote"],{cwd:s,input:`y
|
|
14
|
-
`,stdio:["pipe","inherit","inherit"]}),console.log(n.green(`Migrations completed for ${o}
|
|
15
|
-
`))}catch{console.warn(n.yellow(`Failed to run migrations for ${o}. You may need to run them manually.
|
|
16
|
-
`))}}}async function j(s,t,a,o){console.log(n.bold(`Building and deploying to Cloudflare...
|
|
17
|
-
`));try{let e=U.join(s,"package.json"),i=JSON.parse(await h.readFile(e,"utf-8")),r={...process.env,VITE_PARENT_ORIGIN:t,VITE_APP_ID:a};i.scripts?.deploy?await y("npm",["run","deploy"],{cwd:s,stdio:"inherit",env:r,verbose:o}):(await y("npm",["run","build"],{cwd:s,stdio:"inherit",env:r,verbose:o}),await y("npx",["wrangler","deploy"],{cwd:s,stdio:"inherit",env:r,verbose:o})),console.log(n.green(`
|
|
18
|
-
Deployment completed successfully!
|
|
19
|
-
`))}catch(e){throw console.error(n.red(`
|
|
20
|
-
Failed to build or deploy`)),e}}async function f(s,t,a){try{let o=await $(),e=await fetch(`https://api.cloudflare.com/client/v4/accounts/${s}/d1/database/${t}/query`,{method:"POST",headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json"},body:JSON.stringify({sql:a})}),i=await e.json();if(!e.ok||!i.success){let d=i.errors?i.errors.map(p=>`[${p.code}] ${p.message}`).join(", "):e.statusText;throw console.error(n.red(`
|
|
21
|
-
D1 Query Error:`)),console.error(n.dim(`SQL: ${a}`)),console.error(n.dim(`Error: ${d}`)),new Error(`D1 query failed: ${d}`)}let r=i.result;if(!r||r.length===0)throw new Error("No results returned from D1 query");let c=r[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(n.red(`
|
|
22
|
-
D1 Query Error:`)),console.error(n.dim(`SQL: ${a}`))),o}}async function M(s,t,a,o){console.log(n.bold(`
|
|
23
|
-
Setting up UserApp records...
|
|
24
|
-
`));try{let e=await _(),r=(await v()).find(l=>l.name==="every-app-gateway");if(!r){console.warn(n.yellow(`every-app-gateway database not found. Skipping UserApp record creation.
|
|
25
|
-
`));return}let c=r.uuid,d=await f(e,c,"SELECT id, name, email FROM users");if(d.length===0)throw new Error("No users found in the database. Please create a user first before deploying apps.");let p=a||s,u=o||s;if(d.length===1){let l=d[0],m=Math.floor(Date.now()/1e3);if((await f(e,c,`SELECT id FROM user_apps WHERE user_id = '${l.id}' AND app_id = '${s}'`)).length>0)console.log(n.yellow(`UserApp record already exists for user ${l.name} (${l.email}), skipping...
|
|
26
|
-
`));else{let w=`
|
|
27
|
-
INSERT INTO user_apps (id, user_id, app_id, name, description, app_url, status, created_at, updated_at)
|
|
28
|
-
VALUES ('${A()}', '${l.id}', '${s}', '${p}', '${u}', '${t}', 'installed', ${m}, ${m})
|
|
29
|
-
`;await f(e,c,w),console.log(n.green(`UserApp record created for user ${l.name} (${l.email})
|
|
30
|
-
`))}}else{console.log(n.yellow(`Multiple users found (${d.length}). Adding app to all users...
|
|
31
|
-
`));for(let l of d){let m=Math.floor(Date.now()/1e3);if((await f(e,c,`SELECT id FROM user_apps WHERE user_id = '${l.id}' AND app_id = '${s}'`)).length>0)console.log(n.dim(` App already exists for user ${l.name} (${l.email}), skipping...
|
|
32
|
-
`));else{let w=`
|
|
33
|
-
INSERT INTO user_apps (id, user_id, app_id, name, description, app_url, status, created_at, updated_at)
|
|
34
|
-
VALUES ('${A()}', '${l.id}', '${s}', '${p}', '${u}', '${t}', 'installed', ${m}, ${m})
|
|
35
|
-
`;await f(e,c,w),console.log(n.dim(` Added app for user ${l.name} (${l.email})
|
|
36
|
-
`))}}console.log(n.green(`UserApp records processed for ${d.length} users
|
|
37
|
-
`))}}catch(e){throw console.error(n.red("Failed to insert UserApp records:"),e instanceof Error?e.message:e),e}}async function O(s,t=!1,a=!1){try{console.log(n.bold(`
|
|
38
|
-
Reading project configuration...
|
|
39
|
-
`));let o=await E(s);if(!o.name)throw new Error("Worker name not found in wrangler.jsonc. Please add a 'name' field.");let e=o.name;if(console.log(n.dim(`Project name: ${e}
|
|
40
|
-
`)),!t&&!await R("Do you want to deploy this app to Cloudflare?")){console.log(n.red(`
|
|
41
|
-
Deployment cancelled by user
|
|
42
|
-
`));return}let{d1Updates:i,kvUpdates:r}=await N(o,e),c=await b("every-app-gateway");await S(s,i,r,c),await D(s,a),await T(s,o),await j(s,c,e,a);let d=await b(o.name),p,u;o.name==="every-todo-app"&&(p="Todos",u="Minimal todo list"),await M(o.name,d,p,u),console.log(n.bold.green(`\u{1F389} Deployment successful!
|
|
43
|
-
`)),console.log(n.bold(`Your app is now live at: ${n.cyan(d)}
|
|
44
|
-
`)),console.log(n.dim(`Try it out by visiting the URL above in your browser.
|
|
45
|
-
`))}catch(o){throw console.error(n.red(`
|
|
46
|
-
Deployment failed:`),o instanceof Error?o.message:o),o}}async function G(s){let t=process.cwd(),a=s.verbose||!1;await O(t,!1,a)}export{G as deploy,O as deployAppFromDirectory};
|