@every-app/cli 0.0.1 → 0.0.3
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-KHVRTG63.js +4 -0
- package/dist/chunk-R3ED3ZGI.js +4 -0
- package/dist/chunk-XWM5KXMK.js +19 -0
- package/dist/{create-X6J53SEW.js → create-A6ESZFI6.js} +2 -2
- package/dist/deploy-7BBFD45Y.js +46 -0
- package/dist/deploy-VWOTU23U.js +43 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-CCUZOASZ.js +0 -4
- package/dist/chunk-HER6JKW3.js +0 -19
- package/dist/chunk-TZI4RSSA.js +0 -3
- package/dist/deploy-PTSGJKAA.js +0 -29
- package/dist/deploy-VQGIFHQL.js +0 -43
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-KHVRTG63.js";import{proposeCompletions as r}from"@stricli/core";var t=process.argv.slice(3);process.env.COMP_LINE?.endsWith(" ")&&t.push("");await r(s,t,o(process));try{for(let{completion:p}of await r(s,t,o(process)))process.stdout.write(`${p}
|
|
3
3
|
`)}catch{}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import p from"node:fs";import l from"node:os";import d from"node:path";function R(e){return{process:e,os:l,fs:p,path:d}}import{buildApplication as g,buildRouteMap as C}from"@stricli/core";import{buildInstallCommand as h,buildUninstallCommand as v}from"@stricli/auto-complete";var o="@every-app/cli";var r="Every CLI - Command line tool for deploying and managing Every applications";var n="0.0.3";import{buildCommand as a,buildRouteMap as m}from"@stricli/core";var c=a({loader:async()=>import("./create-A6ESZFI6.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=a({loader:async()=>{let{deploy:e}=await import("./deploy-7BBFD45Y.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
|
+
`)}}),s=m({routes:{create:c,deploy:u},docs:{brief:"App management commands"}});import{buildCommand as y,buildRouteMap as f}from"@stricli/core";var b=y({loader:async()=>{let{deploy:e}=await import("./deploy-VWOTU23U.js");return e},parameters:{positional:{kind:"tuple",parameters:[]},flags:{repo:{kind:"parsed",parse:String,brief:"Git repository URL to deploy",optional:!0},verbose:{kind:"boolean",brief:"Show detailed output during deployment",optional:!0}}},docs:{brief:"Deploy the gateway application to Cloudflare",fullDescription:["Clones the gateway repository, installs dependencies, runs migrations, and deploys to Cloudflare Workers.","The deployment process:"," 1. Clones the repository to a temporary directory"," 2. Installs npm dependencies"," 3. Runs database migrations against production D1"," 4. Runs wrangler deploy"," 5. Cleans up temporary files"].join(`
|
|
4
|
+
`)}}),i=f({routes:{deploy:b},docs:{brief:"Gateway management commands"}});var x=C({routes:{app:s,gateway:i,install:h("every",{bash:"__every_bash_complete"}),uninstall:v("every",{bash:!0})},docs:{brief:r,hideRoute:{install:!0,uninstall:!0}}}),V=g(x,{name:o,versionInfo:{currentVersion:n}});export{R as a,V as b};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{a as p,f as m}from"./chunk-XWM5KXMK.js";async function g(t,e,r=!1){try{await p("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 m("every-app-gateway"),i=`CORE_APP_URL=${r}
|
|
2
|
+
`,s=`VITE_APP_ID=${e}
|
|
3
|
+
VITE_PARENT_ORIGIN=${r}
|
|
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,19 @@
|
|
|
1
|
+
import{execa as y}from"execa";import f from"chalk";async function m(e,n,r={}){let{env:t,cwd:o,verbose:a=!1}=r;if(a){console.log(f.dim(` \u250C\u2500 Running: ${e} ${n.join(" ")}`));let s=y(e,n,{cwd:o,env:t,stdio:void 0,all:!0});s.stdout&&s.stdout.on("data",p=>{p.toString().split(`
|
|
2
|
+
`).forEach(l=>{l.trim()&&console.log(f.dim(` \u2502 ${l}`))})}),s.stderr&&s.stderr.on("data",p=>{p.toString().split(`
|
|
3
|
+
`).forEach(l=>{l.trim()&&console.error(f.dim(` \u2502 ${l}`))})});let D=await s;return console.log(f.dim(` \u2514\u2500 Complete
|
|
4
|
+
`)),D}else return console.log(`Running: ${e} ${n.join(" ")}`),await y(e,n,{cwd:o,env:t,stdio:"pipe"})}import w from"node:fs/promises";import k from"node:path";import h from"chalk";import{execa as C}from"execa";async function j(e){try{return await C("which",[e]),!0}catch{return!1}}async function A(e,n,r=!1){try{if(e==="pnpm"&&!await j("pnpm")){await m("npx",["pnpm","install"],{cwd:n,stdio:"inherit",verbose:r});return}await m(e,["install"],{cwd:n,stdio:"inherit",verbose:r})}catch(t){throw new Error(`Failed to install dependencies with ${e}: ${t instanceof Error?t.message:"Unknown error"}`)}}async function T(e){try{return(await w.stat(k.join(e,"node_modules"))).isDirectory()}catch{return!1}}async function ee(e,n=!1){if(!await T(e)){console.log(h.bold(`Installing dependencies...
|
|
5
|
+
`));try{let t=await w.access(k.join(e,"pnpm-lock.yaml")).then(()=>!0).catch(()=>!1),o=await w.access(k.join(e,"package-lock.json")).then(()=>!0).catch(()=>!1);await A(t?"pnpm":o?"npm":"pnpm",e,n),console.log(h.green(`Dependencies installed
|
|
6
|
+
`))}catch(t){throw console.error(h.red(`
|
|
7
|
+
Failed to install dependencies`)),t}}}import v from"node:fs/promises";import u from"node:path";import b from"node:os";import*as x from"smol-toml";function O(){let e=b.homedir(),n=b.platform(),r;return n==="win32"?r=u.join(process.env.LOCALAPPDATA||u.join(e,"AppData","Local"),".wrangler"):n==="darwin"?r=u.join(e,"Library","Preferences",".wrangler"):r=u.join(e,".wrangler"),u.join(r,"config","default.toml")}async function I(){let e=O();try{let n=await v.readFile(e,"utf-8"),r=x.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 W(e){let n=new Date(e).getTime(),r=Date.now(),t=1*60*1e3;return n-r<t}async function F(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 M(){let e=await I();return W(e.expiration_time)?(await F(e.refresh_token)).oauth_token:e.oauth_token}async function P(e,n={}){let r=await M(),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(s=>`[${s.code}] ${s.message}`).join(", "):t.statusText;throw new Error(`Cloudflare API request failed: ${t.status} ${a}`)}if(!o.success){let a=o.errors.map(s=>`[${s.code}] ${s.message}`).join(", ");throw new Error(`Cloudflare API error: ${a}`)}return o.result}async function N(){let e=await P("/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 S(e){try{let n=await P(`/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 ae(e,n){let r=n||await N(),t=await S(r);return`https://${e}.${t}.workers.dev`}import g from"node:fs/promises";import L from"node:path";import*as i from"jsonc-parser";function V(e,n,r){let t=[];return r.name&&t.push(...i.modify(e,["name"],r.name,{})),n.d1_databases&&r.d1DatabaseId&&n.d1_databases.forEach((o,a)=>{t.push(...i.modify(e,["d1_databases",a,"database_id"],r.d1DatabaseId,{})),r.d1DatabaseName&&t.push(...i.modify(e,["d1_databases",a,"database_name"],r.d1DatabaseName,{}))}),n.kv_namespaces&&r.kvNamespaceId&&n.kv_namespaces.forEach((o,a)=>{t.push(...i.modify(e,["kv_namespaces",a,"id"],r.kvNamespaceId,{}))}),t}async function de(e,n){let r=await g.readFile(e,"utf-8"),t=i.parse(r),o=V(r,t,n),a=i.applyEdits(r,o);await g.writeFile(e,a)}async function le(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 ue(e){let n=L.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}}import{execa as $}from"execa";import c from"chalk";async function K(){let{stdout:e}=await $("npx",["wrangler","d1","list","--json"]);return JSON.parse(e)}async function R(e){let{stdout:n}=await $("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 me(e){console.log(c.bold(`Checking D1 database: ${e}
|
|
8
|
+
`));try{let r=(await K()).find(o=>o.name===e);if(r)return console.log(c.green(`Linking to existing D1 database: ${e} (${r.uuid})
|
|
9
|
+
`)),r.uuid;console.log(c.bold(`Creating new D1 database: ${e}
|
|
10
|
+
`));let t=await R(e);return console.log(c.green(`Created D1 database: ${e} (${t})
|
|
11
|
+
`)),t}catch(n){throw console.error(c.red(`
|
|
12
|
+
Failed to get or create D1 database: ${e}`),n instanceof Error?c.dim(`
|
|
13
|
+
${n.message}`):""),n}}import{execa as _}from"execa";import d from"chalk";async function U(){let{stdout:e}=await _("npx",["wrangler","kv","namespace","list"]);return JSON.parse(e)}async function J(e){let{stdout:n}=await _("npx",["wrangler","kv","namespace","create",e]);return q(n)}function q(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 ye(e){console.log(d.bold(`Checking KV namespace: ${e}
|
|
14
|
+
`));try{let r=(await U()).find(o=>o.title===e);if(r)return console.log(d.green(`Linking to existing KV namespace: ${e} (${r.id})
|
|
15
|
+
`)),r.id;console.log(d.bold(`Creating new KV namespace: ${e}
|
|
16
|
+
`));let t=await J(e);return console.log(d.green(`Created KV namespace: ${e} (${t})
|
|
17
|
+
`)),t}catch(n){throw console.error(d.red(`
|
|
18
|
+
Failed to get or create KV namespace: ${e}`),n instanceof Error?d.dim(`
|
|
19
|
+
${n.message}`):""),n}}export{m as a,A as b,ee as c,M as d,N as e,ae as f,de as g,le as h,ue as i,K as j,me as k,ye as l};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as c,b as g,c as m,d,e as u,f as y}from"./chunk-
|
|
1
|
+
import{a as c,b as g,c as m,d,e as u,f as y}from"./chunk-R3ED3ZGI.js";import{b as p,g as f,k as w,l as b}from"./chunk-XWM5KXMK.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:coolapps-xyz/openeverything-packages.git",$="templates/simple-todo";function x(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 E(){return(await k.prompt({type:"input",name:"appId",message:"Enter your app ID (kebab-case format)",initial:"my-cool-app",validate:x})).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
2
|
`,"utf-8")}async function A(n,a){try{await D("npx",["wrangler","d1","migrations","apply",a,"--local"],{cwd:n,input:`y
|
|
3
3
|
`,stdio:["pipe","inherit","inherit"]}),console.log(e.green(`
|
|
4
4
|
Local database migrations completed successfully
|
|
@@ -28,6 +28,6 @@ Project created successfully!
|
|
|
28
28
|
`)),console.log(e.bold(`Next steps:
|
|
29
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
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(`
|
|
31
|
+
`)),console.log(e.dim(` ${t} run db:migrate:prod # Run remote migrations`)),console.log(e.dim(` npm run deploy # Deploy to Cloudflare
|
|
32
32
|
`))}catch(o){throw console.error(e.red(`
|
|
33
33
|
Failed to create project:`),o instanceof Error?o.message:"Unknown error"),o}finally{a&&await y(a)}}export{S as default};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import{a as R}from"./chunk-B6LAGOID.js";import{a as y,c as D,d as $,e as _,f as b,i as E,j as v,k,l as C}from"./chunk-XWM5KXMK.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};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import{a as y,e as w,f as T}from"./chunk-R3ED3ZGI.js";import{a as x}from"./chunk-B6LAGOID.js";import{a as m,b as u,e as f,f as E,g as _,h as R,k as A,l as C}from"./chunk-XWM5KXMK.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 b}from"execa";import U from"node:crypto";import t from"chalk";function K(){return U.randomBytes(32).toString("base64")}function L(){let{privateKey:o,publicKey:e}=U.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 b("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=b("npx",["wrangler","secret","put",o],{cwd:r});n.stdin&&(n.stdin.write(e),n.stdin.end()),await n}async function S(o,e){console.log(t.bold(`
|
|
2
|
+
Setting up secrets...
|
|
3
|
+
`));try{if(console.log(t.bold(`Checking secret: CORE_APP_URL
|
|
4
|
+
`)),await d("CORE_APP_URL",e)?console.log(t.dim(` Secret already exists
|
|
5
|
+
`)):(console.log(t.dim(` Setting CORE_APP_URL to: ${o}
|
|
6
|
+
`)),await g("CORE_APP_URL",o,e),console.log(t.green(`Created secret: CORE_APP_URL
|
|
7
|
+
`))),console.log(t.bold(`Checking secret: BETTER_AUTH_URL
|
|
8
|
+
`)),await d("BETTER_AUTH_URL",e)?console.log(t.dim(` Secret already exists
|
|
9
|
+
`)):(console.log(t.dim(` Setting BETTER_AUTH_URL to: ${o}
|
|
10
|
+
`)),await g("BETTER_AUTH_URL",o,e),console.log(t.green(`Created secret: BETTER_AUTH_URL
|
|
11
|
+
`))),console.log(t.bold(`Checking secret: BETTER_AUTH_SECRET
|
|
12
|
+
`)),await d("BETTER_AUTH_SECRET",e))console.log(t.dim(` Secret already exists
|
|
13
|
+
`));else{console.log(t.dim(` Generating new Better Auth secret...
|
|
14
|
+
`));let p=K();await g("BETTER_AUTH_SECRET",p,e),console.log(t.green(`Created secret: BETTER_AUTH_SECRET
|
|
15
|
+
`))}console.log(t.bold(`Checking secret: JWT_PRIVATE_KEY
|
|
16
|
+
`));let i=await d("JWT_PRIVATE_KEY",e),a=await d("JWT_PUBLIC_KEY",e);if(i&&a)console.log(t.dim(` JWT key pair already exists
|
|
17
|
+
`));else if(!i&&!a){console.log(t.dim(` Generating new JWT key pair...
|
|
18
|
+
`));let p=L();await g("JWT_PRIVATE_KEY",p.privateKey,e),await g("JWT_PUBLIC_KEY",p.publicKey,e),console.log(t.green(`Created JWT key pair secrets
|
|
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
|
+
`))}catch(r){throw console.error(t.red(`
|
|
21
|
+
Failed to setup secrets`),r instanceof Error?t.dim(`
|
|
22
|
+
${r.message}`):""),r}}var P="git@github.com:coolapps-xyz/openeverything-packages.git",J="every-app-gateway",H="every-app-gateway",N="apps/every-app-gateway";async function v(){console.log(l.bold(`
|
|
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: ${P}
|
|
25
|
+
`));try{await y(P,o,e);let r=k.join(o,N);return console.log(l.bold(`Installing dependencies in apps/every-app-gateway...
|
|
26
|
+
`)),await u("pnpm",r,e),console.log(l.green(`Installation complete!
|
|
27
|
+
`)),r}catch(r){throw console.error(l.red(`
|
|
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 S(r,o),console.log(l.bold(`Deploying to Cloudflare...
|
|
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
|
+
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 x("Do you want to deploy EveryApp Gateway into this Cloudflare account?")){console.log(c.red(`
|
|
33
|
+
Deployment cancelled by user
|
|
34
|
+
`));return}let n=await v(),s=await w("gateway-deploy-");console.log(c.dim(`
|
|
35
|
+
Working directory: ${s}
|
|
36
|
+
`));let i=null;try{let a=await I(s,e);console.log(c.bold(`Determining worker URL...
|
|
37
|
+
`));let p=O.join(a,"wrangler.jsonc"),D=await R(p);i=await E(D),console.log(c.green(`Worker will be deployed to: ${i}
|
|
38
|
+
`)),await h(a,n,i,e)}catch(a){throw console.error(c.red(`
|
|
39
|
+
Deployment failed:`),a instanceof Error?a.message:a),a}finally{await T(s,e)}if(!i)throw new Error("Worker URL not net properly during deployment");console.log(c.bold.green(`\u{1F389} Gateway deployment successful!
|
|
40
|
+
`)),console.log(c.bold(`Your gateway is now live at: ${c.cyan(i)}
|
|
41
|
+
`)),console.log(c.dim(`Try it out by visiting the URL above in your browser.
|
|
42
|
+
`)),console.log(c.yellow(`Note: if you see an error in the browser, cloudflare may still be setting up your domain. Wait ~1 minute to see if resolves itself.
|
|
43
|
+
`))}export{de as deploy};
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as r,b as o}from"./chunk-
|
|
2
|
+
import{a as r,b as o}from"./chunk-KHVRTG63.js";import{run as i}from"@stricli/core";await i(o,process.argv.slice(2),r(process));
|
package/package.json
CHANGED
package/dist/chunk-CCUZOASZ.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import{a as m,e as l}from"./chunk-HER6JKW3.js";async function g(t,r){try{await m("git",["clone",t,r],{stdio:"inherit"})}catch(e){throw new Error(`Failed to clone repository from ${t}: ${e instanceof Error?e.message:"Unknown error"}`)}}import o from"node:fs/promises";import i from"node:path";import f from"node:os";import y from"chalk";async function u(t,r,e={}){let s=e.exclude||[];await o.mkdir(r,{recursive:!0});let a=await o.readdir(t,{withFileTypes:!0});for(let n of a){let c=i.join(t,n.name),p=i.join(r,n.name);s.some(d=>n.name===d)||(n.isDirectory()?await u(c,p,e):await o.copyFile(c,p))}}async function O(t){try{return(await o.stat(t)).isDirectory()}catch{return!1}}async function R(t,r){let e=await l("every-app-gateway"),s=`CORE_APP_URL=${e}
|
|
2
|
-
`,a=`VITE_APP_ID=${r}
|
|
3
|
-
VITE_PARENT_ORIGIN=${e}
|
|
4
|
-
`;await Promise.all([o.writeFile(i.join(t,".dev.vars"),s),o.writeFile(i.join(t,".env.local"),a)])}async function j(t){return await o.mkdtemp(i.join(f.tmpdir(),t))}async function I(t,r=!1){try{await o.rm(t,{recursive:!0,force:!0}),r&&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};
|
package/dist/chunk-HER6JKW3.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import{execa as $}from"execa";import f from"chalk";async function m(e,n,r={}){console.log(f.dim(` \u250C\u2500 Running: ${e} ${n.join(" ")}`));let{env:t,cwd:o}=r,a=$(e,n,{cwd:o,env:t,stdio:void 0,all:!0});a.stdout&&a.stdout.on("data",p=>{p.toString().split(`
|
|
2
|
-
`).forEach(d=>{d.trim()&&console.log(f.dim(` \u2502 ${d}`))})}),a.stderr&&a.stderr.on("data",p=>{p.toString().split(`
|
|
3
|
-
`).forEach(d=>{d.trim()&&console.error(f.dim(` \u2502 ${d}`))})});let l=await a;return console.log(f.dim(` \u2514\u2500 Complete
|
|
4
|
-
`)),l}import w from"node:fs/promises";import k from"node:path";import h from"chalk";import{execa as C}from"execa";async function D(e){try{return await C("which",[e]),!0}catch{return!1}}async function A(e,n){try{if(e==="pnpm"&&!await D("pnpm")){await m("npx",["pnpm","install"],{cwd:n,stdio:"inherit"});return}await m(e,["install"],{cwd:n,stdio:"inherit"})}catch(r){throw new Error(`Failed to install dependencies with ${e}: ${r instanceof Error?r.message:"Unknown error"}`)}}async function j(e){try{return(await w.stat(k.join(e,"node_modules"))).isDirectory()}catch{return!1}}async function Z(e){if(!await j(e)){console.log(h.bold(`Installing dependencies...
|
|
5
|
-
`));try{let r=await w.access(k.join(e,"pnpm-lock.yaml")).then(()=>!0).catch(()=>!1),t=await w.access(k.join(e,"package-lock.json")).then(()=>!0).catch(()=>!1);await A(r?"pnpm":t?"npm":"pnpm",e),console.log(h.green(`Dependencies installed
|
|
6
|
-
`))}catch(r){throw console.error(h.red(`
|
|
7
|
-
Failed to install dependencies`)),r}}}import T from"node:fs/promises";import u from"node:path";import y from"node:os";import*as b from"smol-toml";function v(){let e=y.homedir(),n=y.platform(),r;return n==="win32"?r=u.join(process.env.LOCALAPPDATA||u.join(e,"AppData","Local"),".wrangler"):n==="darwin"?r=u.join(e,"Library","Preferences",".wrangler"):r=u.join(e,".wrangler"),u.join(r,"config","default.toml")}async function O(){let e=v();try{let n=await T.readFile(e,"utf-8"),r=b.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 I(e){let n=new Date(e).getTime(),r=Date.now(),t=1*60*1e3;return n-r<t}async function W(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 F(){let e=await O();return I(e.expiration_time)?(await W(e.refresh_token)).oauth_token:e.oauth_token}async function x(e,n={}){let r=await F(),t=await fetch(`https://api.cloudflare.com/client/v4${e}`,{...n,headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json",...n.headers}});if(!t.ok)throw new Error(`Cloudflare API request failed: ${t.status} ${t.statusText}`);let o=await t.json();if(!o.success){let a=o.errors.map(l=>`[${l.code}] ${l.message}`).join(", ");throw new Error(`Cloudflare API error: ${a}`)}return o.result}async function M(){let e=await x("/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 N(e){try{let n=await x(`/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 oe(e,n){let r=n||await M(),t=await N(r);return`https://${e}.${t}.workers.dev`}import g from"node:fs/promises";import S from"node:path";import*as s from"jsonc-parser";function L(e,n,r){let t=[];return r.name&&t.push(...s.modify(e,["name"],r.name,{})),n.d1_databases&&r.d1DatabaseId&&n.d1_databases.forEach((o,a)=>{t.push(...s.modify(e,["d1_databases",a,"database_id"],r.d1DatabaseId,{})),r.d1DatabaseName&&t.push(...s.modify(e,["d1_databases",a,"database_name"],r.d1DatabaseName,{}))}),n.kv_namespaces&&r.kvNamespaceId&&n.kv_namespaces.forEach((o,a)=>{t.push(...s.modify(e,["kv_namespaces",a,"id"],r.kvNamespaceId,{}))}),t}async function ce(e,n){let r=await g.readFile(e,"utf-8"),t=s.parse(r),o=L(r,t,n),a=s.applyEdits(r,o);await g.writeFile(e,a)}async function de(e){let n=await g.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 ue(e){let n=S.join(e,"wrangler.jsonc");try{let r=await g.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}}import{execa as P}from"execa";import i from"chalk";async function V(){let{stdout:e}=await P("npx",["wrangler","d1","list","--json"]);return JSON.parse(e)}async function K(e){let{stdout:n}=await P("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 pe(e){console.log(i.bold(`Checking D1 database: ${e}
|
|
8
|
-
`));try{let r=(await V()).find(o=>o.name===e);if(r)return console.log(i.green(`Linking to existing D1 database: ${e} (${r.uuid})
|
|
9
|
-
`)),r.uuid;console.log(i.bold(`Creating new D1 database: ${e}
|
|
10
|
-
`));let t=await K(e);return console.log(i.green(`Created D1 database: ${e} (${t})
|
|
11
|
-
`)),t}catch(n){throw console.error(i.red(`
|
|
12
|
-
Failed to get or create D1 database: ${e}`),n instanceof Error?i.dim(`
|
|
13
|
-
${n.message}`):""),n}}import{execa as _}from"execa";import c from"chalk";async function U(){let{stdout:e}=await _("npx",["wrangler","kv","namespace","list"]);return JSON.parse(e)}async function R(e){let{stdout:n}=await _("npx",["wrangler","kv","namespace","create",e]);return J(n)}function J(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 ke(e){console.log(c.bold(`Checking KV namespace: ${e}
|
|
14
|
-
`));try{let r=(await U()).find(o=>o.title===e);if(r)return console.log(c.green(`Linking to existing KV namespace: ${e} (${r.id})
|
|
15
|
-
`)),r.id;console.log(c.bold(`Creating new KV namespace: ${e}
|
|
16
|
-
`));let t=await R(e);return console.log(c.green(`Created KV namespace: ${e} (${t})
|
|
17
|
-
`)),t}catch(n){throw console.error(c.red(`
|
|
18
|
-
Failed to get or create KV namespace: ${e}`),n instanceof Error?c.dim(`
|
|
19
|
-
${n.message}`):""),n}}export{m as a,A as b,Z as c,M as d,oe as e,ce as f,de as g,ue as h,pe as i,ke as j};
|
package/dist/chunk-TZI4RSSA.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import p from"node:fs";import l from"node:os";import d from"node:path";function D(e){return{process:e,os:l,fs:p,path:d}}import{buildApplication as g,buildRouteMap as C}from"@stricli/core";import{buildInstallCommand as h,buildUninstallCommand as x}from"@stricli/auto-complete";var t="@every-app/cli";var r="Every CLI - Command line tool for deploying and managing Every applications";var n="0.0.1";import{buildCommand as s,buildRouteMap as m}from"@stricli/core";var c=s({loader:async()=>import("./create-X6J53SEW.js"),parameters:{positional:{kind:"tuple",parameters:[]}},docs:{brief:"Create a new EveryApp app"}}),u=s({loader:async()=>{let{deploy:e}=await import("./deploy-PTSGJKAA.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(`
|
|
2
|
-
`)}}),i=m({routes:{create:c,deploy:u},docs:{brief:"App management commands"}});import{buildCommand as y,buildRouteMap as b}from"@stricli/core";var f=y({loader:async()=>{let{deploy:e}=await import("./deploy-VQGIFHQL.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(`
|
|
3
|
-
`)}}),a=b({routes:{deploy:f},docs:{brief:"Gateway management commands"}});var v=C({routes:{app:i,gateway:a,install:h("every",{bash:"__every_bash_complete"}),uninstall:x("every",{bash:!0})},docs:{brief:r,hideRoute:{install:!0,uninstall:!0}}}),G=g(v,{name:t,versionInfo:{currentVersion:n}});export{D as a,G as b};
|
package/dist/deploy-PTSGJKAA.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import{a as k}from"./chunk-B6LAGOID.js";import{a as c,c as b,e as f,h as y,i as w,j as h}from"./chunk-HER6JKW3.js";import n from"chalk";import u from"node:path";import p from"node:fs/promises";import{execa as v}from"execa";import*as l from"jsonc-parser";async function _(e,o){console.log(n.bold(`
|
|
2
|
-
Setting up Cloudflare resources...
|
|
3
|
-
`));let s=new Map,t=new Map;if(e.d1_databases&&e.d1_databases.length>0){console.log(n.bold(`Processing D1 databases...
|
|
4
|
-
`));for(let a=0;a<e.d1_databases.length;a++){let i=e.d1_databases[a].database_name;if(!i){console.warn(n.yellow(`Skipping D1 database at index ${a}: no database_name specified
|
|
5
|
-
`));continue}let d=await w(i);s.set(a,d)}}if(e.kv_namespaces&&e.kv_namespaces.length>0){console.log(n.bold(`Processing KV namespaces...
|
|
6
|
-
`));for(let a=0;a<e.kv_namespaces.length;a++){if(!e.kv_namespaces[a].binding){console.warn(n.yellow(`Skipping KV namespace at index ${a}: no binding specified
|
|
7
|
-
`));continue}let i=await h(o);t.set(a,i)}}return{d1Updates:s,kvUpdates:t}}async function C(e,o,s,t){console.log(n.bold(`Updating wrangler.jsonc with resource IDs...
|
|
8
|
-
`));let a=u.join(e,"wrangler.jsonc"),r=await p.readFile(a,"utf-8"),i=[];for(let[g,m]of o.entries())i.push(...l.modify(r,["d1_databases",g,"database_id"],m,{}));for(let[g,m]of s.entries())i.push(...l.modify(r,["kv_namespaces",g,"id"],m,{}));i.push(...l.modify(r,["vars","CORE_APP_URL"],t,{}));let d=l.applyEdits(r,i);await p.writeFile(a,d),console.log(n.green(`wrangler.jsonc updated successfully
|
|
9
|
-
`))}async function D(e,o){if(!o.d1_databases||o.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 s of o.d1_databases){let t=s.binding;if(!t){console.warn(n.yellow(`Skipping migration: no binding specified
|
|
12
|
-
`));continue}try{console.log(n.dim(` Running migrations for ${t}...
|
|
13
|
-
`)),await v("npx",["wrangler","d1","migrations","apply",t,"--remote"],{cwd:e,input:`y
|
|
14
|
-
`,stdio:["pipe","inherit","inherit"]}),console.log(n.green(`Migrations completed for ${t}
|
|
15
|
-
`))}catch{console.warn(n.yellow(`Failed to run migrations for ${t}. You may need to run them manually.
|
|
16
|
-
`))}}}async function P(e,o,s){console.log(n.bold(`Building and deploying to Cloudflare...
|
|
17
|
-
`));try{let t=u.join(e,"package.json"),a=JSON.parse(await p.readFile(t,"utf-8")),r={...process.env,VITE_PARENT_ORIGIN:o,VITE_APP_ID:s};if(a.scripts?.deploy){let d=await p.access(u.join(e,"pnpm-lock.yaml")).then(()=>!0).catch(()=>!1)?"pnpm":"npm";await c(d,["run","deploy"],{cwd:e,stdio:"inherit",env:r})}else await c("npm",["run","build"],{cwd:e,stdio:"inherit",env:r}),await c("npx",["wrangler","deploy"],{cwd:e,stdio:"inherit",env:r});console.log(n.green(`
|
|
18
|
-
Deployment completed successfully!
|
|
19
|
-
`))}catch(t){throw console.error(n.red(`
|
|
20
|
-
Failed to build or deploy`)),t}}async function F(){let e=process.cwd();try{console.log(n.bold(`
|
|
21
|
-
Reading project configuration...
|
|
22
|
-
`));let o=await y(e);if(!o.name)throw new Error("Worker name not found in wrangler.jsonc. Please add a 'name' field.");let s=o.name;if(console.log(n.dim(`Project name: ${s}
|
|
23
|
-
`)),!await k("Do you want to deploy this app to Cloudflare?")){console.log(n.red(`
|
|
24
|
-
Deployment cancelled by user
|
|
25
|
-
`));return}let{d1Updates:a,kvUpdates:r}=await _(o,s),i=await f("every-app-gateway");await C(e,a,r,i),await b(e),await D(e,o),await P(e,i,s);let d=await f(s);console.log(n.bold.green(`\u{1F389} Deployment successful!
|
|
26
|
-
`)),console.log(n.bold(`Your app is now live at: ${n.cyan(d)}
|
|
27
|
-
`)),console.log(n.dim(`Try it out by visiting the URL above in your browser.
|
|
28
|
-
`))}catch(o){throw console.error(n.red(`
|
|
29
|
-
Deployment failed:`),o instanceof Error?o.message:o),o}}export{F as deploy};
|
package/dist/deploy-VQGIFHQL.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import{a as y,e as w,f as T}from"./chunk-CCUZOASZ.js";import{a as x}from"./chunk-B6LAGOID.js";import{a as m,b as u,d as f,e as E,f as _,g as R,i as A,j as C}from"./chunk-HER6JKW3.js";import a from"chalk";import O from"node:path";import k from"node:path";import W from"node:crypto";import i from"chalk";import{execa as U}from"execa";import b from"node:crypto";import t from"chalk";function K(){return b.randomBytes(32).toString("base64")}function L(){let{privateKey:o,publicKey:e}=b.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(r=>r.name===o)}async function g(o,e,n){let r=U("npx",["wrangler","secret","put",o],{cwd:n});r.stdin&&(r.stdin.write(e),r.stdin.end()),await r}async function S(o,e){console.log(t.bold(`
|
|
2
|
-
Setting up secrets...
|
|
3
|
-
`));try{if(console.log(t.bold(`Checking secret: CORE_APP_URL
|
|
4
|
-
`)),await d("CORE_APP_URL",e)?console.log(t.dim(` Secret already exists
|
|
5
|
-
`)):(console.log(t.dim(` Setting CORE_APP_URL to: ${o}
|
|
6
|
-
`)),await g("CORE_APP_URL",o,e),console.log(t.green(`Created secret: CORE_APP_URL
|
|
7
|
-
`))),console.log(t.bold(`Checking secret: BETTER_AUTH_URL
|
|
8
|
-
`)),await d("BETTER_AUTH_URL",e)?console.log(t.dim(` Secret already exists
|
|
9
|
-
`)):(console.log(t.dim(` Setting BETTER_AUTH_URL to: ${o}
|
|
10
|
-
`)),await g("BETTER_AUTH_URL",o,e),console.log(t.green(`Created secret: BETTER_AUTH_URL
|
|
11
|
-
`))),console.log(t.bold(`Checking secret: BETTER_AUTH_SECRET
|
|
12
|
-
`)),await d("BETTER_AUTH_SECRET",e))console.log(t.dim(` Secret already exists
|
|
13
|
-
`));else{console.log(t.dim(` Generating new Better Auth secret...
|
|
14
|
-
`));let p=K();await g("BETTER_AUTH_SECRET",p,e),console.log(t.green(`Created secret: BETTER_AUTH_SECRET
|
|
15
|
-
`))}console.log(t.bold(`Checking secret: JWT_PRIVATE_KEY
|
|
16
|
-
`));let l=await d("JWT_PRIVATE_KEY",e),s=await d("JWT_PUBLIC_KEY",e);if(l&&s)console.log(t.dim(` JWT key pair already exists
|
|
17
|
-
`));else if(!l&&!s){console.log(t.dim(` Generating new JWT key pair...
|
|
18
|
-
`));let p=L();await g("JWT_PRIVATE_KEY",p.privateKey,e),await g("JWT_PUBLIC_KEY",p.publicKey,e),console.log(t.green(`Created JWT key pair secrets
|
|
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
|
-
`))}catch(n){throw console.error(t.red(`
|
|
21
|
-
Failed to setup secrets`),n instanceof Error?t.dim(`
|
|
22
|
-
${n.message}`):""),n}}var P="git@github.com:coolapps-xyz/openeverything-packages.git",J="every-app-gateway",H="every-app-gateway",N="apps/every-app-gateway";async function v(){console.log(i.bold(`
|
|
23
|
-
Setting up Cloudflare resources...
|
|
24
|
-
`));let o=await f(),e=await A(J),n=await C(H);return{d1DatabaseId:e,kvNamespaceId:n,accountId:o}}async function I(o){console.log(i.bold("Cloning gateway repository...")),console.log(i.dim(` Repository: ${P}
|
|
25
|
-
`));try{await y(P,o);let e=k.join(o,N);return console.log(i.bold(`Installing dependencies in apps/every-app-gateway...
|
|
26
|
-
`)),await u("pnpm",e),console.log(i.green(`Installation complete!
|
|
27
|
-
`)),e}catch(e){throw console.error(i.red(`
|
|
28
|
-
Failed to clone repository or install dependencies`),e instanceof Error?i.dim(`
|
|
29
|
-
${e.message}`):""),e}}async function h(o,e,n){try{let r=k.join(o,"wrangler.jsonc");await _(r,{d1DatabaseId:e.d1DatabaseId,kvNamespaceId:e.kvNamespaceId}),await S(n,o),console.log(i.bold(`Deploying to Cloudflare...
|
|
30
|
-
`));let c=W.randomUUID();await m("npm",["run","deploy"],{cwd:o,stdio:"inherit",env:{...process.env,BETTER_AUTH_SECRET:c}})}catch(r){throw console.error(i.red(`
|
|
31
|
-
Failed to update config or deploy`),r instanceof Error?i.dim(`
|
|
32
|
-
${r.message}`):""),r}}async function de(o){let e=o.verbose||!1;if(!await x("Do you want to deploy EveryApp Gateway into this Cloudflare account?")){console.log(a.red(`
|
|
33
|
-
Deployment cancelled by user
|
|
34
|
-
`));return}let r=await v(),c=await w("gateway-deploy-");console.log(a.dim(`
|
|
35
|
-
Working directory: ${c}
|
|
36
|
-
`));let l=null;try{let s=await I(c);console.log(a.bold(`Determining worker URL...
|
|
37
|
-
`));let p=O.join(s,"wrangler.jsonc"),D=await R(p);l=await E(D),console.log(a.green(`Worker will be deployed to: ${l}
|
|
38
|
-
`)),await h(s,r,l)}catch(s){throw console.error(a.red(`
|
|
39
|
-
Deployment failed:`),s instanceof Error?s.message:s),s}finally{await T(c,e)}if(!l)throw new Error("Worker URL not net properly during deployment");console.log(a.bold.green(`\u{1F389} Deployment successful!
|
|
40
|
-
`)),console.log(a.bold(`Your gateway is now live at: ${a.cyan(l)}
|
|
41
|
-
`)),console.log(a.dim(`Try it out by visiting the URL above in your browser.
|
|
42
|
-
`)),console.log(a.yellow(`Note: if you see an error in the browser, cloudflare may still be setting up your domain. Wait ~1 minute to see if resolves itself.
|
|
43
|
-
`))}export{de as deploy};
|