create-better-t-stack 1.9.1 → 1.9.2
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/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{cancel as v,intro as nn,log as S,outro as sn,spinner as on}from"@clack/prompts";import{Command as cn}from"commander";import g from"picocolors";import be from"node:path";import{fileURLToPath as Ot}from"node:url";var X=()=>{let e=process.env.npm_config_user_agent;return e?.startsWith("pnpm")?"pnpm":e?.startsWith("bun")?"bun":"npm"};var
|
|
2
|
+
import{cancel as v,intro as nn,log as S,outro as sn,spinner as on}from"@clack/prompts";import{Command as cn}from"commander";import g from"picocolors";import be from"node:path";import{fileURLToPath as Ot}from"node:url";var X=()=>{let e=process.env.npm_config_user_agent;return e?.startsWith("pnpm")?"pnpm":e?.startsWith("bun")?"bun":"npm"};var Bt=Ot(import.meta.url),Lt=be.dirname(Bt),A=be.join(Lt,"../"),y={projectName:"my-better-t-app",frontend:["tanstack-router"],database:"sqlite",orm:"drizzle",auth:!0,addons:[],examples:[],git:!0,packageManager:X(),noInstall:!1,dbSetup:"none",backend:"hono",runtime:"bun"},se={"better-auth":"^1.2.4","@better-auth/expo":"^1.2.5","drizzle-orm":"^0.38.4","drizzle-kit":"^0.30.5","@libsql/client":"^0.14.0",postgres:"^3.4.5","@prisma/client":"^6.5.0",prisma:"^6.5.0","vite-plugin-pwa":"^0.21.2","@vite-pwa/assets-generator":"^0.2.6","@tauri-apps/cli":"^2.4.0","@biomejs/biome":"1.9.4",husky:"^9.1.7","lint-staged":"^15.5.0","@hono/node-server":"^1.14.0",tsx:"^4.19.2","@types/node":"^22.13.11","@types/bun":"^1.2.6","@elysiajs/node":"^1.2.6","@elysiajs/cors":"^1.2.0","@elysiajs/trpc":"^1.1.0",elysia:"^1.2.25","@hono/trpc-server":"^0.3.4",hono:"^4.7.5",cors:"^2.8.5",express:"^5.1.0","@types/express":"^5.0.1","@types/cors":"^2.8.17",ai:"^4.2.8","@ai-sdk/google":"^1.2.3","@prisma/extension-accelerate":"^1.3.0"};import Ya from"node:path";import{cancel as Za,spinner as er}from"@clack/prompts";import tr from"fs-extra";import rt from"picocolors";import L from"node:path";import $ from"fs-extra";import Mt from"node:path";import we from"fs-extra";var w=e=>{let{dependencies:a=[],devDependencies:t=[],projectDir:r}=e,n=Mt.join(r,"package.json"),s=we.readJSONSync(n);s.dependencies||(s.dependencies={}),s.devDependencies||(s.devDependencies={});for(let i of a){let o=se[i];s.dependencies[i]=o}for(let i of t){let o=se[i];s.devDependencies[i]=o}we.writeJSONSync(n,s,{spaces:2})};import Y from"node:path";import{log as _t,spinner as Ut}from"@clack/prompts";import{execa as Nt}from"execa";import Z from"fs-extra";import Pe from"picocolors";async function ye(e,a,t){let r=Ut(),n=Y.join(e,"apps/web");if(await Z.pathExists(n))try{r.start("Setting up Tauri desktop app support..."),w({devDependencies:["@tauri-apps/cli"],projectDir:n});let s=Y.join(n,"package.json");if(await Z.pathExists(s)){let l=await Z.readJson(s);l.scripts={...l.scripts,tauri:"tauri","desktop:dev":"tauri dev","desktop:build":"tauri build"},await Z.writeJson(s,l,{spaces:2})}let i,o;switch(a){case"npm":i="npx",o=["@tauri-apps/cli@latest"];break;case"pnpm":i="pnpm",o=["dlx","@tauri-apps/cli@latest"];break;case"bun":i="bunx",o=["@tauri-apps/cli@latest"];break;default:i="npx",o=["@tauri-apps/cli@latest"]}let c=t.includes("react-router")?"http://localhost:5173":"http://localhost:3001";o=[...o,"init",`--app-name=${Y.basename(e)}`,`--window-title=${Y.basename(e)}`,"--frontend-dist=dist",`--dev-url=${c}`,`--before-dev-command=${a} run dev`,`--before-build-command=${a} run build`],await Nt(i,o,{cwd:n,env:{CI:"true"}}),r.stop("Tauri desktop app support configured successfully!")}catch(s){throw r.stop(Pe.red("Failed to set up Tauri")),s instanceof Error&&_t.error(Pe.red(s.message)),s}}async function je(e,a,t,r){let n=r.includes("react-router")||r.includes("tanstack-router");a.includes("pwa")&&n&&await Vt(e,r),a.includes("tauri")&&n&&await ye(e,t,r),a.includes("biome")&&await Gt(e),a.includes("husky")&&await qt(e)}function zt(e,a){return L.join(e,"apps/web")}async function Gt(e){let a=L.join(A,"template/with-biome");await $.pathExists(a)&&await $.copy(a,e,{overwrite:!0}),w({devDependencies:["@biomejs/biome"],projectDir:e});let t=L.join(e,"package.json");if(await $.pathExists(t)){let r=await $.readJson(t);r.scripts={...r.scripts,check:"biome check --write ."},await $.writeJson(t,r,{spaces:2})}}async function qt(e){let a=L.join(A,"template/with-husky");await $.pathExists(a)&&await $.copy(a,e,{overwrite:!0}),w({devDependencies:["husky","lint-staged"],projectDir:e});let t=L.join(e,"package.json");if(await $.pathExists(t)){let r=await $.readJson(t);r.scripts={...r.scripts,prepare:"husky"},r["lint-staged"]={"*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json,jsonc}":["biome check --write ."]},await $.writeJson(t,r,{spaces:2})}}async function Vt(e,a){let t=L.join(A,"template/with-pwa");await $.pathExists(t)&&await $.copy(t,e,{overwrite:!0});let r=zt(e,a);if(!await $.pathExists(r))return;w({dependencies:["vite-plugin-pwa"],devDependencies:["@vite-pwa/assets-generator"],projectDir:r});let n=L.join(r,"vite.config.ts");if(await $.pathExists(n)){let i=await $.readFile(n,"utf8");if(!i.includes("vite-plugin-pwa")){let p=i.match(/^import .* from ['"](.*)['"]/m);p?i=i.replace(p[0],`import { VitePWA } from "vite-plugin-pwa";
|
|
3
3
|
${p[0]}`):i=`import { VitePWA } from "vite-plugin-pwa";
|
|
4
4
|
${i}`}let o=`VitePWA({
|
|
5
5
|
registerType: "autoUpdate",
|
|
@@ -21,7 +21,7 @@ ${i}`}let o=`VitePWA({
|
|
|
21
21
|
${o}`):a.includes("tanstack-router")?i=i.replace(/plugins: \[\s*tailwindcss\(\)/,`plugins: [
|
|
22
22
|
tailwindcss(),
|
|
23
23
|
${o}`):i=i.replace(/plugins: \[/,`plugins: [
|
|
24
|
-
${o},`)),await
|
|
24
|
+
${o},`)),await $.writeFile(n,i)}let s=L.join(r,"package.json");if(await $.pathExists(s)){let i=await $.readJson(s);i.scripts={...i.scripts,"generate-pwa-assets":"pwa-assets-generator"},await $.writeJson(s,i,{spaces:2})}}import ie from"node:path";import{log as xe}from"@clack/prompts";import ve from"picocolors";function ke(e=32){let a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",t="",r=a.length;for(let n=0;n<e;n++)t+=a.charAt(Math.floor(Math.random()*r));return t}async function Ae(e,a,t=[]){if(!a)return;let r=ie.join(e,"apps/server"),n=ie.join(e,"apps/web"),s=ie.join(e,"apps/native");try{w({dependencies:["better-auth"],projectDir:r}),(t.includes("react-router")||t.includes("tanstack-router")||t.includes("tanstack-start"))&&w({dependencies:["better-auth"],projectDir:n}),t.includes("native")&&(w({dependencies:["better-auth","@better-auth/expo"],projectDir:s}),w({dependencies:["@better-auth/expo"],projectDir:r}))}catch(i){throw xe.error(ve.red("Failed to configure authentication")),i instanceof Error&&xe.error(ve.red(i.message)),i}}import Wt from"node:path";async function $e(e,a,t){let r=Wt.join(e,"apps/server"),n=[],s=[];a==="hono"?(n.push("hono","@hono/trpc-server"),t==="node"&&(n.push("@hono/node-server"),s.push("tsx","@types/node"))):a==="elysia"?(n.push("elysia","@elysiajs/cors","@elysiajs/trpc"),t==="node"&&(n.push("@elysiajs/node"),s.push("tsx","@types/node"))):a==="express"&&(n.push("express","cors"),s.push("@types/express","@types/cors"),t==="node"&&s.push("tsx","@types/node")),t==="bun"&&s.push("@types/bun"),w({dependencies:n,devDependencies:s,projectDir:r})}import Jt from"node:path";import Ht from"fs-extra";async function Ee(e,a){let t=Jt.join(e,"README.md"),r=Qt(a);try{await Ht.writeFile(t,r)}catch(n){console.error("Failed to create README.md file:",n)}}function Qt(e){let{projectName:a,packageManager:t,database:r,auth:n,addons:s=[],orm:i="drizzle",runtime:o="bun",frontend:p=["tanstack-router"]}=e,c=p.includes("react-router"),l=p.includes("tanstack-router"),m=p.includes("native"),b=t==="npm"?"npm run":t,k=c?"5173":"3001";return`# ${a}
|
|
25
25
|
|
|
26
26
|
This project was created with [Better-T-Stack](https://github.com/AmanVarshney01/create-better-t-stack), a modern TypeScript stack that combines React, ${l?"TanStack Router":"React Router"}, Hono, tRPC, and more.
|
|
27
27
|
|
|
@@ -101,51 +101,51 @@ ${t} db:push
|
|
|
101
101
|
- \`${e} dev:native\`: Start the React Native/Expo development server`),a!=="none"&&(s+=`
|
|
102
102
|
- \`${e} db:push\`: Push schema changes to database
|
|
103
103
|
- \`${e} db:studio\`: Open database studio UI`,a==="sqlite"&&t==="drizzle"&&(s+=`
|
|
104
|
-
- \`cd apps/server && ${e} db:local\`: Start the local SQLite database`)),s}import
|
|
104
|
+
- \`cd apps/server && ${e} db:local\`: Start the local SQLite database`)),s}import Be from"node:path";import{log as va,spinner as ka}from"@clack/prompts";import Aa from"fs-extra";import Le from"picocolors";import De from"node:path";import{cancel as Zt,isCancel as ea,log as M,text as ta}from"@clack/prompts";import{execa as aa}from"execa";import oe from"fs-extra";import G from"picocolors";import{execa as Se}from"execa";async function ee(e){try{return process.platform==="win32"?(await Se("where",[e])).exitCode===0:(await Se("which",[e])).exitCode===0}catch{return!1}}async function ra(){return ee("atlas")}async function na(e){try{if(!await ra())return M.error(G.red("MongoDB Atlas CLI not found.")),M.info(G.yellow("Please install it from: https://www.mongodb.com/docs/atlas/cli/current/install-atlas-cli/")),null;M.info(G.yellow("Setting up MongoDB Atlas...")),await aa("atlas",["deployments","setup"],{cwd:e,stdio:"inherit"}),M.info(G.yellow("Please enter your connection string"));let t=await ta({message:"Paste your complete MongoDB connection string:",validate(r){if(!r)return"Please enter a connection string";if(!r.startsWith("mongodb"))return"URL should start with mongodb"}});return ea(t)?(Zt("MongoDB setup cancelled"),null):{connectionString:t}}catch(a){return a instanceof Error&&M.error(G.red(a.message)),null}}async function ce(e,a){let t=De.join(e,"apps/server",".env"),r="";await oe.pathExists(t)&&(r=await oe.readFile(t,"utf8"));let n=a?`DATABASE_URL="${a.connectionString}"`:'DATABASE_URL="mongodb://localhost:27017/mydb"';r.includes("DATABASE_URL=")?r=r.replace(/DATABASE_URL=.*(\r?\n|$)/,`${n}$1`):r+=`
|
|
105
105
|
${n}`,await oe.writeFile(t,r.trim())}function Te(){M.info(`MongoDB Atlas Setup:
|
|
106
106
|
|
|
107
107
|
1. Install Atlas CLI: https://www.mongodb.com/docs/atlas/cli/stable/install-atlas-cli/
|
|
108
108
|
2. Run 'atlas deployments setup' and follow prompts
|
|
109
109
|
3. Get your connection string from the output
|
|
110
110
|
4. Format: mongodb+srv://USERNAME:PASSWORD@CLUSTER.mongodb.net/DATABASE_NAME
|
|
111
|
-
5. Add to .env as DATABASE_URL="your_connection_string"`)}async function
|
|
112
|
-
It looks like: prisma+postgres://accelerate.prisma-data.net/?api_key=...`));let n=await oa({message:"Paste your Prisma Postgres database URL:",validate(s){if(!s)return"Please enter a database URL";if(!s.startsWith("prisma+postgres://"))return"URL should start with prisma+postgres://"}});return ia(n)?(sa("Database setup cancelled"),null):{databaseUrl:n}}catch(t){return t instanceof Error&&
|
|
113
|
-
${n}`,await
|
|
111
|
+
5. Add to .env as DATABASE_URL="your_connection_string"`)}async function Re(e){let a=De.join(e,"apps/server");try{let t=await na(a);t?(await ce(e,t),M.success(G.green("MongoDB Atlas connection string saved to .env file!"))):(await ce(e),Te())}catch(t){M.error(G.red(`Error during MongoDB Atlas setup: ${t}`)),await ce(e),Te()}}import H from"node:path";import{cancel as sa,isCancel as ia,log as U,password as oa}from"@clack/prompts";import{execa as ca}from"execa";import _ from"fs-extra";import V from"picocolors";async function pa(e,a){try{U.info(V.blue("Initializing Prisma PostgreSQL"));let t=H.join(e,"prisma");await _.ensureDir(t),await ca(a==="npm"?"npx":a==="pnpm"?"pnpm dlx":"bunx",["prisma","init","--db"],{cwd:e,stdio:"inherit"}),U.info(V.yellow(`Please copy the Prisma Postgres URL from the output above.
|
|
112
|
+
It looks like: prisma+postgres://accelerate.prisma-data.net/?api_key=...`));let n=await oa({message:"Paste your Prisma Postgres database URL:",validate(s){if(!s)return"Please enter a database URL";if(!s.startsWith("prisma+postgres://"))return"URL should start with prisma+postgres://"}});return ia(n)?(sa("Database setup cancelled"),null):{databaseUrl:n}}catch(t){return t instanceof Error&&U.error(V.red(t.message)),null}}async function pe(e,a){let t=H.join(e,"apps/server",".env"),r="";await _.pathExists(t)&&(r=await _.readFile(t,"utf8"));let n=a?`DATABASE_URL="${a.databaseUrl}"`:'DATABASE_URL="postgresql://postgres:postgres@localhost:5432/mydb?schema=public"';r.includes("DATABASE_URL=")?r=r.replace(/DATABASE_URL=.*(\r?\n|$)/,`${n}$1`):r+=`
|
|
113
|
+
${n}`,await _.writeFile(t,r.trim())}function Ce(){U.info(`Manual Prisma PostgreSQL Setup Instructions:
|
|
114
114
|
|
|
115
115
|
1. Visit https://console.prisma.io and create an account
|
|
116
116
|
2. Create a new PostgreSQL database from the dashboard
|
|
117
117
|
3. Get your database URL
|
|
118
118
|
4. Add the database URL to the .env file in apps/server/.env
|
|
119
119
|
|
|
120
|
-
DATABASE_URL="your_database_url"`)}async function Ie(e,a="npm"){let t=H.join(e,"apps/server");try{let r=await pa(t,a);r?(await pe(e,r),await la(t),
|
|
120
|
+
DATABASE_URL="your_database_url"`)}async function Ie(e,a="npm"){let t=H.join(e,"apps/server");try{let r=await pa(t,a);r?(await pe(e,r),await la(t),U.success(V.green("Prisma PostgreSQL database configured successfully!"))):(await pe(e),Ce())}catch(r){U.error(V.red(`Error during Prisma PostgreSQL setup: ${r}`)),await pe(e),Ce(),U.info("Setup completed with manual configuration required.")}}async function la(e){try{w({dependencies:["@prisma/extension-accelerate"],projectDir:e});let a=H.join(e,"prisma/index.ts");await _.writeFile(a,`
|
|
121
121
|
import { PrismaClient } from '@prisma/client';
|
|
122
122
|
import { withAccelerate } from "@prisma/extension-accelerate";
|
|
123
123
|
|
|
124
124
|
const prisma = new PrismaClient().$extends(withAccelerate());
|
|
125
125
|
|
|
126
126
|
export default prisma;
|
|
127
|
-
`.trim());let r=H.join(e,"src/db/index.ts");if(await
|
|
128
|
-
${n}`,n=n.replace("export const db = new PrismaClient();","export const db = new PrismaClient().$extends(withAccelerate());"),await
|
|
129
|
-
`);return a.length<=1?[]:a.slice(1).map(r=>{let[n,s,i,o]=r.trim().split(/\s{2,}/);return{name:n,locations:s,version:i,status:o}})}catch(e){return console.error("Error fetching Turso groups:",e),[]}}async function ja(){let e=await ya();if(e.length===0)return null;if(e.length===1)return e[0].name;let a=e.map(r=>({value:r.name,label:`${r.name} (${r.locations})`})),t=await ma({message:"Select a Turso database group:",options:a});return de(t)&&(le(
|
|
130
|
-
|
|
131
|
-
|
|
127
|
+
`.trim());let r=H.join(e,"src/db/index.ts");if(await _.pathExists(r)){let n=await _.readFile(r,"utf8");n.includes("@prisma/extension-accelerate")||(n=`import { withAccelerate } from "@prisma/extension-accelerate";
|
|
128
|
+
${n}`,n=n.replace("export const db = new PrismaClient();","export const db = new PrismaClient().$extends(withAccelerate());"),await _.writeFile(r,n))}}catch{U.warn(V.yellow("Could not add Prisma Accelerate extension automatically"))}}import da from"node:os";import Fe from"node:path";import{cancel as le,confirm as ua,isCancel as de,log as W,select as ma,spinner as ue,text as fa}from"@clack/prompts";import{$ as F}from"execa";import ha from"fs-extra";import C from"picocolors";async function ga(){return ee("turso")}async function ba(){try{return!(await F`turso auth whoami`).stdout.includes("You are not logged in")}catch{return!1}}async function wa(){let e=ue();try{return e.start("Logging in to Turso..."),await F`turso auth login`,e.stop("Logged in to Turso successfully!"),!0}catch(a){throw e.stop(C.red("Failed to log in to Turso")),a}}async function Pa(e){let a=ue();try{if(a.start("Installing Turso CLI..."),e)await F`brew install tursodatabase/tap/turso`;else{let{stdout:t}=await F`curl -sSfL https://get.tur.so/install.sh`;await F`bash -c '${t}'`}return a.stop("Turso CLI installed successfully!"),!0}catch(t){throw t instanceof Error&&t.message.includes("User force closed")?(a.stop(),W.warn(C.yellow("Turso CLI installation cancelled by user")),new Error("Installation cancelled")):(a.stop(C.red("Failed to install Turso CLI")),t)}}async function ya(){try{let{stdout:e}=await F`turso group list`,a=e.trim().split(`
|
|
129
|
+
`);return a.length<=1?[]:a.slice(1).map(r=>{let[n,s,i,o]=r.trim().split(/\s{2,}/);return{name:n,locations:s,version:i,status:o}})}catch(e){return console.error("Error fetching Turso groups:",e),[]}}async function ja(){let e=await ya();if(e.length===0)return null;if(e.length===1)return e[0].name;let a=e.map(r=>({value:r.name,label:`${r.name} (${r.locations})`})),t=await ma({message:"Select a Turso database group:",options:a});return de(t)&&(le(C.red("Operation cancelled")),process.exit(0)),t}async function xa(e,a){try{a?await F`turso db create ${e} --group ${a}`:await F`turso db create ${e}`}catch(n){throw n instanceof Error&&n.message.includes("already exists")?new Error("DATABASE_EXISTS"):n}let{stdout:t}=await F`turso db show ${e} --url`,{stdout:r}=await F`turso db tokens create ${e}`;return{dbUrl:t.trim(),authToken:r.trim()}}async function Q(e,a){let t=Fe.join(e,"apps/server",".env"),r=a?`DATABASE_URL="${a.dbUrl}"
|
|
130
|
+
DATABASE_AUTH_TOKEN="${a.authToken}"`:`DATABASE_URL=
|
|
131
|
+
DATABASE_AUTH_TOKEN=`;await ha.writeFile(t,r)}function te(){W.info(`Manual Turso Setup Instructions:
|
|
132
132
|
|
|
133
133
|
1. Visit https://turso.tech and create an account
|
|
134
134
|
2. Create a new database from the dashboard
|
|
135
135
|
3. Get your database URL and authentication token
|
|
136
136
|
4. Add these credentials to the .env file in apps/server/.env
|
|
137
137
|
|
|
138
|
-
|
|
139
|
-
|
|
138
|
+
DATABASE_URL=your_database_url
|
|
139
|
+
DATABASE_AUTH_TOKEN=your_auth_token`)}async function Oe(e,a){if(!a){await Q(e),W.info(C.blue("Skipping Turso setup. Setting up empty configuration.")),te();return}let t=da.platform(),r=t==="darwin";if(!(t!=="win32")){W.warn(C.yellow("Automatic Turso setup is not supported on Windows.")),await Q(e),te();return}try{if(!await ga()){let m=await ua({message:"Would you like to install Turso CLI?",initialValue:!0});if(de(m)&&(le(C.red("Operation cancelled")),process.exit(0)),!m){await Q(e),te();return}await Pa(r)}await ba()||await wa();let o=await ja(),p=!1,c="",l=Fe.basename(e);for(;!p;){let m=await fa({message:"Enter a name for your database:",defaultValue:l,initialValue:l,placeholder:l});de(m)&&(le(C.red("Operation cancelled")),process.exit(0)),c=m;let b=ue();try{b.start(`Creating Turso database "${c}"${o?` in group "${o}"`:""}...`);let k=await xa(c,o);await Q(e,k),b.stop("Turso database configured successfully!"),p=!0}catch(k){if(k instanceof Error&&k.message==="DATABASE_EXISTS")b.stop(C.yellow(`Database "${C.red(c)}" already exists`)),l=`${c}-${Math.floor(Math.random()*1e3)}`;else throw b.stop(C.red("Failed to create Turso database")),k}}}catch(s){W.error(C.red(`Error during Turso setup: ${s}`)),await Q(e),te(),W.success("Setup completed with manual configuration required.")}}async function Me(e,a,t,r,n,s,i){let o=ka(),p=Be.join(e,"apps/server");if(a==="none"){await Aa.remove(Be.join(p,"src/db"));return}try{a==="sqlite"?(t==="drizzle"?w({dependencies:["drizzle-orm","@libsql/client"],devDependencies:["drizzle-kit"],projectDir:p}):t==="prisma"&&w({dependencies:["@prisma/client"],devDependencies:["prisma"],projectDir:p}),n&&await Oe(e,!0)):a==="postgres"?t==="drizzle"?w({dependencies:["drizzle-orm","postgres"],devDependencies:["drizzle-kit"],projectDir:p}):t==="prisma"&&(w({dependencies:["@prisma/client"],devDependencies:["prisma"],projectDir:p}),a==="postgres"&&t==="prisma"&&s&&await Ie(e,r)):a==="mongodb"&&(t==="prisma"&&w({dependencies:["@prisma/client"],devDependencies:["prisma"],projectDir:p}),i&&await Re(e))}catch(c){throw o.stop(Le.red("Failed to set up database")),c instanceof Error&&va.error(Le.red(c.message)),c}}import J from"node:path";import B from"fs-extra";async function _e(e,a){let t=J.join(e,"apps/server"),r=J.join(t,".env"),n="";if(await B.pathExists(r)&&(n=await B.readFile(r,"utf8")),!n.includes("CORS_ORIGIN")){let c=a.frontend.includes("react-router"),l=a.frontend.includes("tanstack-router"),m=a.frontend.includes("tanstack-start"),b="http://localhost:3000";c?b="http://localhost:5173":(l||m)&&(b="http://localhost:3001"),n+=`
|
|
140
140
|
CORS_ORIGIN=${b}`}if(a.auth&&(n.includes("BETTER_AUTH_SECRET")||(n+=`
|
|
141
141
|
BETTER_AUTH_SECRET=${ke()}`),n.includes("BETTER_AUTH_URL")||(n+=`
|
|
142
142
|
BETTER_AUTH_URL=http://localhost:3000`)),a.database!=="none"){if(a.orm==="prisma"&&!n.includes("DATABASE_URL")){let c="";a.database==="sqlite"?c="":a.database==="postgres"?c=`
|
|
143
143
|
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/mydb?schema=public"`:a.database==="mongodb"&&(c=`
|
|
144
|
-
DATABASE_URL="mongodb://localhost:27017/mydatabase"`),n+=c}a.database==="sqlite"&&a.dbSetup!=="turso"&&(n.includes("
|
|
145
|
-
|
|
146
|
-
GOOGLE_GENERATIVE_AI_API_KEY=`),await
|
|
147
|
-
`),await
|
|
148
|
-
`),await
|
|
144
|
+
DATABASE_URL="mongodb://localhost:27017/mydatabase"`),n+=c}a.database==="sqlite"&&a.dbSetup!=="turso"&&(n.includes("DATABASE_URL")||(n+=`
|
|
145
|
+
DATABASE_URL=file:./local.db`))}a.examples?.includes("ai")&&!n.includes("GOOGLE_GENERATIVE_AI_API_KEY")&&(n+=`
|
|
146
|
+
GOOGLE_GENERATIVE_AI_API_KEY=`),await B.writeFile(r,n.trim());let s=a.frontend.includes("react-router"),i=a.frontend.includes("tanstack-router"),o=a.frontend.includes("tanstack-start");if(s||i||o){let c=J.join(e,"apps/web");await $a(c)}if(a.frontend.includes("native")){let c=J.join(e,"apps/native"),l=J.join(c,".env"),m="";await B.pathExists(l)&&(m=await B.readFile(l,"utf8")),m.includes("EXPO_PUBLIC_SERVER_URL")||(m+=`EXPO_PUBLIC_SERVER_URL=http://localhost:3000
|
|
147
|
+
`),await B.writeFile(l,m.trim())}}async function $a(e){let a=J.join(e,".env"),t="";await B.pathExists(a)&&(t=await B.readFile(a,"utf8")),t.includes("VITE_SERVER_URL")||(t+=`VITE_SERVER_URL=http://localhost:3000
|
|
148
|
+
`),await B.writeFile(a,t.trim())}import E from"node:path";import P from"fs-extra";async function Ue(e,a,t,r,n,s=["tanstack-router"]){let i=s.includes("tanstack-router"),o=s.includes("tanstack-start"),p=s.includes("react-router"),c=i||p||o,l;i?l="web-tanstack-router":o?l="web-tanstack-start":l="web-react-router";let m=await P.pathExists(E.join(e,"apps/web"));a.includes("todo")&&c&&m?await Da(e,t,r,l):await Ia(e,t),a.includes("ai")&&(n==="hono"||n==="express")&&c&&m&&await Ea(e,l)}async function Ea(e,a){let t=E.join(A,"template/examples/ai");if(await P.pathExists(t)){let r=E.join(t,`apps/${a}/src/routes/ai.tsx`),n=E.join(e,"apps/web/src/routes/ai.tsx");await P.pathExists(r)&&await P.copy(r,n,{overwrite:!0}),await Ta(e,a);let s=E.join(e,"apps/web");w({dependencies:["ai"],projectDir:s});let i=E.join(e,"apps/server");w({dependencies:["ai","@ai-sdk/google"],projectDir:i}),await Sa(e)}}async function Sa(e){let a=E.join(e,"apps/server/src/index.ts");if(await P.pathExists(a)){let t=await P.readFile(a,"utf8"),r=t.includes("hono"),n=t.includes("express");if(r){let s=`import { streamText } from "ai";
|
|
149
149
|
import { google } from "@ai-sdk/google";
|
|
150
150
|
import { stream } from "hono/streaming";`,i=`
|
|
151
151
|
// AI chat endpoint
|
|
@@ -197,55 +197,55 @@ ${t.substring(o)}`;else{let p=t.indexOf("app.listen(");if(p!==-1){let c=t.lastIn
|
|
|
197
197
|
|
|
198
198
|
${t.substring(c)}`}else t=`${t}
|
|
199
199
|
|
|
200
|
-
${i}`}}await P.writeFile(a,t)}}async function Ta(e,a){let t=
|
|
200
|
+
${i}`}}await P.writeFile(a,t)}}async function Ta(e,a){let t=E.join(e,"apps/web/src/components/header.tsx");if(await P.pathExists(t)){let r=await P.readFile(t,"utf8"),n=/const links = \[\s*([^;]*?)\s*\];/s,s=r.match(n);if(s){let i=s[1];if(!i.includes('"/ai"')){let o=`const links = [
|
|
201
201
|
${i}${i.trim().endsWith(",")?"":","}
|
|
202
202
|
{ to: "/ai", label: "AI Chat" },
|
|
203
|
-
];`;r=r.replace(n,o),await P.writeFile(t,r)}}}}async function
|
|
203
|
+
];`;r=r.replace(n,o),await P.writeFile(t,r)}}}}async function Da(e,a,t,r){let n=E.join(A,"template/examples/todo");if(await P.pathExists(n)){let s=E.join(n,`apps/${r}/src/routes/todos.tsx`),i=E.join(e,"apps/web/src/routes/todos.tsx");if(await P.pathExists(s)&&await P.copy(s,i,{overwrite:!0}),a!=="none"){let o=E.join(n,`apps/server/src/routers/with-${a}-todo.ts`),p=E.join(e,"apps/server/src/routers/todo.ts");await P.pathExists(o)&&await P.copy(o,p,{overwrite:!0}),await Ra(e)}await Ca(e,r)}}async function Ra(e){let a=E.join(e,"apps/server/src/routers/index.ts");if(await P.pathExists(a)){let t=await P.readFile(a,"utf8");if(!t.includes("import { todoRouter }")){let r=t.lastIndexOf("import"),n=t.indexOf(`
|
|
204
204
|
|
|
205
205
|
`,r);n!==-1?t=`${t.slice(0,n)}
|
|
206
206
|
import { todoRouter } from "./todo";${t.slice(n)}`:t=`import { todoRouter } from "./todo";
|
|
207
207
|
${t}`;let s=t.indexOf("export const appRouter = router({");if(s!==-1){let i=t.indexOf("{",s)+1;t=`${t.slice(0,i)}
|
|
208
|
-
todo: todoRouter,${t.slice(i)}`}await P.writeFile(a,t)}}}async function
|
|
208
|
+
todo: todoRouter,${t.slice(i)}`}await P.writeFile(a,t)}}}async function Ca(e,a){let t=E.join(e,"apps/web/src/components/header.tsx");if(await P.pathExists(t)){let r=await P.readFile(t,"utf8"),n=/const links = \[\s*([^;]*?)\s*\];/s,s=r.match(n);if(s){let i=s[1];if(!i.includes('"/todos"')){let o=`const links = [
|
|
209
209
|
${i}${i.trim().endsWith(",")?"":","}
|
|
210
210
|
{ to: "/todos", label: "Todos" },
|
|
211
|
-
];`;r=r.replace(n,o),await P.writeFile(t,r)}}}}async function Ia(e,a){if(a==="drizzle"){let r=
|
|
212
|
-
${r?"":`${
|
|
213
|
-
`}${
|
|
214
|
-
|
|
215
|
-
${
|
|
216
|
-
${It?`${ge?`${
|
|
217
|
-
`:""}`:`${
|
|
218
|
-
`}${
|
|
219
|
-
${
|
|
220
|
-
${
|
|
211
|
+
];`;r=r.replace(n,o),await P.writeFile(t,r)}}}}async function Ia(e,a){if(a==="drizzle"){let r=E.join(e,"apps/server/src/db/schema/todo.ts");await P.pathExists(r)&&await P.remove(r)}else if(a==="prisma"){let r=E.join(e,"apps/server/prisma/schema/todo.prisma");await P.pathExists(r)&&await P.remove(r)}let t=E.join(e,"apps/server/src/routers/todo.ts");await P.pathExists(t)&&await P.remove(t),await Fa(e)}async function Fa(e){let a=E.join(e,"apps/server/src/routers/index.ts");if(await P.pathExists(a)){let t=await P.readFile(a,"utf8");t=t.replace(/import { todoRouter } from ".\/todo";/,""),t=t.replace(/todo: todoRouter,/,""),await P.writeFile(a,t)}}import{log as Ne,spinner as ze}from"@clack/prompts";import{$ as Ge}from"execa";import ae from"picocolors";async function qe({projectDir:e,packageManager:a,addons:t=[]}){let r=ze();try{r.start(`Running ${a} install...`),await Ge({cwd:e,stderr:"inherit"})`${a} install`,r.stop("Dependencies installed successfully"),(t.includes("biome")||t.includes("husky"))&&await Oa(e,a)}catch(n){throw r.stop(ae.red("Failed to install dependencies")),n instanceof Error&&Ne.error(ae.red(`Installation error: ${n.message}`)),n}}async function Oa(e,a){let t=ze();try{t.start("Running Biome format check..."),await Ge({cwd:e,stderr:"inherit"})`${a} biome check --write .`,t.stop("Biome check completed successfully")}catch{t.stop(ae.yellow("Biome check encountered issues")),Ne.warn(ae.yellow("Some files may need manual formatting"))}}import{note as Ba}from"@clack/prompts";import x from"picocolors";function Ve(e,a,t,r,n,s,i,o,p){let c=t==="npm"?"npm run":t,l=`cd ${a}`,m=s?.includes("husky")||s?.includes("biome"),b=e!=="none"?_a(e,n,c,i):"",k=s?.includes("tauri")?Ua(c):"",j=m?Ma(c):"",R=o?.includes("native")?La():"",T=s?.includes("pwa")&&o?.includes("react-router")?Na():"",O=o?.includes("tanstack-router"),I=o?.includes("tanstack-start"),he=o?.includes("react-router"),ge=O||he||I,Ct=o?.includes("native"),It=ge||Ct,Ft=he?"5173":"3001";Ba(`${x.cyan("1.")} ${l}
|
|
212
|
+
${r?"":`${x.cyan("2.")} ${t} install
|
|
213
|
+
`}${x.cyan(r?"2.":"3.")} ${c} dev
|
|
214
|
+
|
|
215
|
+
${x.bold("Your project will be available at:")}
|
|
216
|
+
${It?`${ge?`${x.cyan("\u2022")} Frontend: http://localhost:${Ft}
|
|
217
|
+
`:""}`:`${x.yellow("NOTE:")} You are creating a backend-only app (no frontend selected)
|
|
218
|
+
`}${x.cyan("\u2022")} API: http://localhost:3000
|
|
219
|
+
${R?`
|
|
220
|
+
${R.trim()}`:""}${b?`
|
|
221
221
|
${b.trim()}`:""}${k?`
|
|
222
|
-
${k.trim()}`:""}${
|
|
223
|
-
${
|
|
222
|
+
${k.trim()}`:""}${j?`
|
|
223
|
+
${j.trim()}`:""}${T?`
|
|
224
224
|
${T.trim()}`:""}
|
|
225
225
|
|
|
226
|
-
${
|
|
227
|
-
${
|
|
226
|
+
${x.bold("Like Better-T Stack?")} Please consider giving us a star on GitHub:
|
|
227
|
+
${x.cyan("https://github.com/AmanVarshney01/create-better-t-stack")}`,"Next steps")}function La(){return`${x.yellow("NOTE:")} For Expo connectivity issues, update apps/native/.env
|
|
228
228
|
with your local IP:
|
|
229
229
|
EXPO_PUBLIC_SERVER_URL=http://192.168.0.103:3000
|
|
230
|
-
`}function Ma(e){return`${
|
|
231
|
-
${
|
|
230
|
+
`}function Ma(e){return`${x.bold("Linting and formatting:")}
|
|
231
|
+
${x.cyan("\u2022")} Format and lint fix: ${`${e} check`}
|
|
232
232
|
|
|
233
|
-
`}function
|
|
234
|
-
follow the guidance provided in the error messages`),n.push(`${
|
|
233
|
+
`}function _a(e,a,t,r){let n=[];return a==="prisma"?(e==="sqlite"&&n.push(`${x.yellow("NOTE:")} Turso support with Prisma is in Early Access and requires additional setup.`,"Learn more at: https://www.prisma.io/docs/orm/overview/databases/turso"),r==="bun"&&n.push(`${x.yellow("NOTE:")} Prisma with Bun may require additional configuration. If you encounter errors,
|
|
234
|
+
follow the guidance provided in the error messages`),n.push(`${x.cyan("\u2022")} Apply schema: ${`${t} db:push`}`),n.push(`${x.cyan("\u2022")} Database UI: ${`${t} db:studio`}`)):a==="drizzle"&&(n.push(`${x.cyan("\u2022")} Apply schema: ${`${t} db:push`}`),n.push(`${x.cyan("\u2022")} Database UI: ${`${t} db:studio`}`)),n.length?`${x.bold("Database commands:")}
|
|
235
235
|
${n.join(`
|
|
236
236
|
`)}
|
|
237
237
|
|
|
238
|
-
`:""}function
|
|
239
|
-
${
|
|
240
|
-
${
|
|
241
|
-
${
|
|
242
|
-
${
|
|
238
|
+
`:""}function Ua(e){return`
|
|
239
|
+
${x.bold("Desktop app with Tauri:")}
|
|
240
|
+
${x.cyan("\u2022")} Start desktop app: ${`cd apps/web && ${e} desktop:dev`}
|
|
241
|
+
${x.cyan("\u2022")} Build desktop app: ${`cd apps/web && ${e} desktop:build`}
|
|
242
|
+
${x.yellow("NOTE:")} Tauri requires Rust and platform-specific dependencies.
|
|
243
243
|
See: https://v2.tauri.app/start/prerequisites/
|
|
244
244
|
|
|
245
|
-
`}function
|
|
246
|
-
${
|
|
245
|
+
`}function Na(){return`${x.bold("PWA with React Router v7:")}
|
|
246
|
+
${x.yellow("NOTE:")} There is a known compatibility issue between VitePWA and React Router v7.
|
|
247
247
|
See: https://github.com/vite-pwa/vite-plugin-pwa/issues/809
|
|
248
|
-
`}import re from"node:path";import{log as za}from"@clack/prompts";import{$ as We,execa as Ga}from"execa";import
|
|
248
|
+
`}import re from"node:path";import{log as za}from"@clack/prompts";import{$ as We,execa as Ga}from"execa";import N from"fs-extra";import qa from"picocolors";async function Je(e,a){await Va(e,a),await Wa(e,a)}async function Va(e,a){let t=re.join(e,"package.json");if(await N.pathExists(t)){let r=await N.readJson(t);r.name=a.projectName;let{stdout:n}=await Ga(a.packageManager,["-v"],{cwd:e});if(r.packageManager=`${a.packageManager}@${n.trim()}`,await N.writeJson(t,r,{spaces:2}),a.packageManager==="pnpm"){let s=re.join(A,"template/with-pnpm/pnpm-workspace.yaml"),i=re.join(e,"pnpm-workspace.yaml");await N.pathExists(s)&&await N.copy(s,i)}}}async function Wa(e,a){let t=re.join(e,"apps/server/package.json");if(await N.pathExists(t)){let r=await N.readJson(t);a.database!=="none"&&(a.database==="sqlite"&&(r.scripts["db:local"]="turso dev --db-file local.db"),a.orm==="prisma"?(r.scripts["db:push"]="prisma db push --schema ./prisma/schema",r.scripts["db:studio"]="prisma studio"):a.orm==="drizzle"&&(r.scripts["db:push"]="drizzle-kit push",r.scripts["db:studio"]="drizzle-kit studio")),await N.writeJson(t,r,{spaces:2})}}async function He(e,a){if(!a)return;if((await We({cwd:e,reject:!1,stderr:"pipe"})`git --version`).exitCode!==0){za.warn(qa.yellow("Git is not installed"));return}let r=await We({cwd:e,reject:!1,stderr:"pipe"})`git init`;if(r.exitCode!==0)throw new Error(`Git initialization failed: ${r.stderr}`)}import ne from"node:path";import z from"fs-extra";async function Qe(e,a,t){let r=ne.join(e,"apps/server"),n=ne.join(r,"src/index.ts"),s=await z.readFile(n,"utf-8");a==="bun"?await Ja(r,n,s,t):a==="node"&&await Ha(r,n,s,t)}async function Ja(e,a,t,r){let n=ne.join(e,"package.json"),s=await z.readJson(n);if(s.scripts={...s.scripts,dev:"bun run --hot src/index.ts",start:"bun run dist/src/index.js"},await z.writeJson(n,s,{spaces:2}),w({devDependencies:["@types/bun"],projectDir:e}),r==="hono"){let i=`${t}
|
|
249
249
|
|
|
250
250
|
export default app;
|
|
251
251
|
`;await z.writeFile(a,i)}}async function Ha(e,a,t,r){let n=ne.join(e,"package.json"),s=await z.readJson(n);if(s.scripts={...s.scripts,dev:"tsx watch src/index.ts",start:"node dist/src/index.js"},await z.writeJson(n,s,{spaces:2}),w({devDependencies:["tsx","@types/node"],projectDir:e}),r==="hono"){w({dependencies:["@hono/node-server"],projectDir:e});let i=`import { serve } from "@hono/node-server";
|
|
@@ -261,12 +261,12 @@ serve(
|
|
|
261
261
|
);
|
|
262
262
|
`;if(!t.includes("@hono/node-server")){let p=t.lastIndexOf("import"),c=t.substring(0,p),l=t.substring(p),m=c+i+l+o;await z.writeFile(a,m)}}else if(r==="elysia"&&(w({dependencies:["@elysiajs/node"],projectDir:e}),!t.includes("@elysiajs/node"))){let i=`import { node } from "@elysiajs/node";
|
|
263
263
|
`,o=t.indexOf(`
|
|
264
|
-
`,t.indexOf("import")),p=t.substring(0,o+1),c=t.substring(o+1),l=p+i+c;l=l.replace(/const app = new Elysia\([^)]*\)/,"const app = new Elysia({ adapter: node() })"),await z.writeFile(a,l)}}import u from"node:path";import d from"fs-extra";async function Ke(e){let a=u.join(
|
|
265
|
-
`)}}async function Ye(e,a){let t=u.join(
|
|
264
|
+
`,t.indexOf("import")),p=t.substring(0,o+1),c=t.substring(o+1),l=p+i+c;l=l.replace(/const app = new Elysia\([^)]*\)/,"const app = new Elysia({ adapter: node() })"),await z.writeFile(a,l)}}import u from"node:path";import d from"fs-extra";async function Ke(e){let a=u.join(A,"template/base");if(!await d.pathExists(a))throw new Error(`Template directory not found: ${a}`);await d.ensureDir(e);let t=await d.readdir(a);for(let s of t){let i=u.join(a,s),o=u.join(e,s);s!=="apps"&&(await d.stat(i).then(p=>p.isDirectory())?await d.copy(i,o):await d.copy(i,o))}await d.ensureDir(u.join(e,"apps"));let r=u.join(a,"apps/server"),n=u.join(e,"apps/server");await d.pathExists(r)&&await d.copy(r,n)}async function Xe(e,a){let t=a.includes("tanstack-router"),r=a.includes("tanstack-start"),n=a.includes("react-router"),s=a.includes("native");if(t||n||r){let i=u.join(e,"apps/web");await d.ensureDir(i);let o=u.join(A,"template/base/apps/web-base");await d.pathExists(o)&&await d.copy(o,i);let p="web-react-router";t?p="web-tanstack-router":r&&(p="web-tanstack-start");let c=u.join(A,`template/base/apps/${p}`);await d.pathExists(c)&&await d.copy(c,i,{overwrite:!0});let l=u.join(i,"package.json");if(await d.pathExists(l)){let m=await d.readJson(l);m.name="web",await d.writeJson(l,m,{spaces:2})}}if(s){let i=u.join(A,"template/base/apps/native"),o=u.join(e,"apps/native");await d.pathExists(i)&&await d.copy(i,o),await d.writeFile(u.join(e,".npmrc"),`node-linker=hoisted
|
|
265
|
+
`)}}async function Ye(e,a){let t=u.join(A,`template/with-${a}`);await d.pathExists(t)&&await d.copy(t,e,{overwrite:!0})}async function Ze(e,a,t,r){if(a==="none"||t==="none")return;let n=u.join(A,Ka(a,t));if(await d.pathExists(n)&&(await d.copy(n,e,{overwrite:!0}),!r)){if(a==="prisma"){let s=u.join(e,"apps/server/prisma/schema/auth.prisma");await d.pathExists(s)&&await d.remove(s)}else if(a==="drizzle"){let s=u.join(e,"apps/server/src/db/schema/auth.ts");await d.pathExists(s)&&await d.remove(s)}}}async function et(e,a,t,r,n,s){if(!a)return;let i=u.join(A,"template/with-auth");if(await d.pathExists(i)){let o=s.includes("react-router"),p=s.includes("tanstack-router"),c=s.includes("tanstack-start");if(o||p||c){let T=u.join(e,"apps/web"),O=u.join(i,"apps/web-base");if(await d.pathExists(O)&&await d.copy(O,T,{overwrite:!0}),o){let I=u.join(i,"apps/web-react-router");await d.pathExists(I)&&await d.copy(I,T,{overwrite:!0})}if(p){let I=u.join(i,"apps/web-tanstack-router");await d.pathExists(I)&&await d.copy(I,T,{overwrite:!0})}if(c){let I=u.join(i,"apps/web-tanstack-start");await d.pathExists(I)&&await d.copy(I,T,{overwrite:!0})}}let l=u.join(i,"apps/server/src"),m=u.join(e,"apps/server/src");await d.copy(u.join(l,"lib/trpc.ts"),u.join(m,"lib/trpc.ts"),{overwrite:!0}),await d.copy(u.join(l,"routers/index.ts"),u.join(m,"routers/index.ts"),{overwrite:!0});let b=`with-${t}-context.ts`;await d.copy(u.join(l,"lib",b),u.join(m,"lib/context.ts"),{overwrite:!0});let k=`with-${t}-index.ts`;await d.copy(u.join(l,k),u.join(m,"index.ts"),{overwrite:!0});let j=Xa(r,n),R=u.join(l,j);if(await d.pathExists(R)){let T=await d.readdir(R);for(let O of T)await d.copy(u.join(R,O),u.join(m,"lib",O),{overwrite:!0})}if(s.includes("native")){let T=u.join(i,"apps/native"),O=u.join(e,"apps/native");await d.pathExists(T)&&await d.copy(T,O,{overwrite:!0}),w({dependencies:["@better-auth/expo"],projectDir:u.join(e,"apps/server")}),await Qa(e,r,n)}}}async function Qa(e,a,t){let r=u.join(e,"apps/server"),n;if(a==="drizzle"?t==="sqlite"?n=u.join(r,"src/lib/auth.ts"):t==="postgres"&&(n=u.join(r,"src/lib/auth.ts")):a==="prisma"&&(t==="sqlite"?n=u.join(r,"src/lib/auth.ts"):t==="postgres"&&(n=u.join(r,"src/lib/auth.ts"))),n&&await d.pathExists(n)){let s=await d.readFile(n,"utf8");if(!s.includes("@better-auth/expo")){let i=`import { expo } from "@better-auth/expo";
|
|
266
266
|
`,o=s.lastIndexOf("import"),p=s.indexOf(`
|
|
267
267
|
`,o)+1;s=s.substring(0,p)+i+s.substring(p)}s.includes("plugins:")?s.includes("expo()")||(s=s.replace(/plugins: \[(.*?)\]/s,(i,o)=>`plugins: [${o}${o.trim()?", ":""}expo()]`)):s=s.replace(/}\);/,` plugins: [expo()],
|
|
268
|
-
});`),s.includes("my-better-t-app://")||(s=s.replace(/trustedOrigins: \[(.*?)\]/s,(i,o)=>`trustedOrigins: [${o}${o.trim()?", ":""}"my-better-t-app://"]`)),await d.writeFile(n,s)}}async function tt(e){let a=await at(e);for(let t of a)if(await d.pathExists(t)){let r=u.join(u.dirname(t),".gitignore");await d.move(t,r,{overwrite:!0})}}async function at(e){let a=[],t=u.join(e,"_gitignore");await d.pathExists(t)&&a.push(t);try{let r=await d.readdir(e,{withFileTypes:!0});for(let n of r)if(n.isDirectory()&&n.name!=="node_modules"){let s=u.join(e,n.name),i=await at(s);a.push(...i)}}catch{}return a}function Ka(e,a){if(e==="drizzle")return a==="sqlite"?"template/with-drizzle-sqlite":"template/with-drizzle-postgres";if(e==="prisma"){if(a==="sqlite")return"template/with-prisma-sqlite";if(a==="postgres")return"template/with-prisma-postgres";if(a==="mongodb")return"template/with-prisma-mongodb"}return"template/base"}function Xa(e,a){if(e==="drizzle")return a==="sqlite"?"with-drizzle-sqlite-lib":"with-drizzle-postgres-lib";if(e==="prisma"){if(a==="sqlite")return"with-prisma-sqlite-lib";if(a==="postgres")return"with-prisma-postgres-lib";if(a==="mongodb")return"with-prisma-mongodb-lib"}throw new Error("Invalid ORM or database configuration for auth setup")}async function nt(e){let a=er(),t=Ya.resolve(process.cwd(),e.projectName);try{return await tr.ensureDir(t),await Ke(t),await Xe(t,e.frontend),await tt(t),await Ye(t,e.backend),await Ee(t,e.backend,e.runtime),await Ze(t,e.orm,e.database,e.auth),await Me(t,e.database,e.orm,e.packageManager,e.dbSetup==="turso",e.dbSetup==="prisma-postgres",e.dbSetup==="mongodb-atlas"),await et(t,e.auth,e.backend,e.orm,e.database,e.frontend),await $e(t,e.auth,e.frontend),await Qe(t,e.runtime,e.backend),await _e(t,e.examples,e.orm,e.auth,e.backend,e.frontend),await Ne(t,e),await He(t,e.git),e.addons.length>0&&await je(t,e.addons,e.packageManager,e.frontend),await Je(t,e),await Ae(t,e),e.noInstall||await qe({projectDir:t,packageManager:e.packageManager,addons:e.addons}),Ve(e.database,e.projectName,e.packageManager,!e.noInstall,e.orm,e.addons,e.runtime,e.frontend),t}catch(r){throw a.message(rt.red("Failed")),r instanceof Error&&(Za(rt.red(`Error during project creation: ${r.message}`)),process.exit(1)),r}}import{cancel as Zr,group as en,log as tn}from"@clack/prompts";import kt from"picocolors";import{cancel as ar,isCancel as rr,multiselect as nr}from"@clack/prompts";import sr from"picocolors";async function st(e,a){if(e!==void 0)return e;let t=a?.includes("react-router")||a?.includes("tanstack-router"),r=[{value:"biome",label:"Biome",hint:"Add Biome for linting and formatting"},{value:"husky",label:"Husky",hint:"Add Git hooks with Husky, lint-staged (requires Biome)"}],s=t?[...[{value:"pwa",label:"PWA (Progressive Web App)",hint:"Make your app installable and work offline"},{value:"tauri",label:"Tauri Desktop App",hint:"Build native desktop apps from your web frontend"}],...r]:r,i=y.addons.filter(p=>t||p!=="pwa"&&p!=="tauri"),o=await nr({message:"Select addons",options:s,initialValues:i,required:!1});return rr(o)&&(ar(sr.red("Operation cancelled")),process.exit(0)),o.includes("husky")&&!o.includes("biome")&&o.push("biome"),o}import{cancel as ir,confirm as or,isCancel as cr}from"@clack/prompts";import pr from"picocolors";async function it(e,a,t){if(!a)return!1;if(e!==void 0)return e;let r=await or({message:"Add authentication with Better-Auth?",initialValue:y.auth});return cr(r)&&(ir(pr.red("Operation cancelled")),process.exit(0)),r}import{cancel as lr,isCancel as dr,select as ur}from"@clack/prompts";import mr from"picocolors";async function ot(e){if(e!==void 0)return e;let a=await ur({message:"Select backend framework",options:[{value:"hono",label:"Hono",hint:"Lightweight, ultrafast web framework"},{value:"express",label:"Express",hint:"Fast, unopinionated, minimalist web framework for Node.js"},{value:"elysia",label:"Elysia",hint:"Ergonomic web framework for building backend servers"}],initialValue:y.backend});return dr(a)&&(lr(mr.red("Operation cancelled")),process.exit(0)),a}import{cancel as fr,isCancel as hr,select as gr}from"@clack/prompts";import br from"picocolors";async function ct(e){if(e!==void 0)return e;let a=await gr({message:"Select database",options:[{value:"none",label:"None",hint:"No database setup"},{value:"sqlite",label:"SQLite",hint:"by Turso"},{value:"postgres",label:"PostgreSQL",hint:"Traditional relational database"},{value:"mongodb",label:"MongoDB",hint:"NoSQL document-oriented database"}],initialValue:y.database});return hr(a)&&(fr(br.red("Operation cancelled")),process.exit(0)),a}import{cancel as wr,isCancel as Pr,select as yr}from"@clack/prompts";import jr from"picocolors";async function pt(e,a){if(a!==void 0)return a;let t=[];if(e==="sqlite")t=[{value:"turso",label:"Turso",hint:"SQLite for Production. Powered by libSQL."},{value:"none",label:"None",hint:"Manual setup"}];else if(e==="postgres")t=[{value:"prisma-postgres",label:"Prisma Postgres",hint:"Instant Postgres for Global Applications"},{value:"none",label:"None",hint:"Manual setup"}];else if(e==="mongodb")t=[{value:"mongodb-atlas",label:"MongoDB Atlas",hint:"The most effective way to deploy MongoDB"},{value:"none",label:"None",hint:"Manual setup"}];else return"none";let r=await yr({message:`Select ${e} setup option`,options:t,initialValue:"none"});return Pr(r)&&(wr(jr.red("Operation cancelled")),process.exit(0)),r}import{cancel as xr,isCancel as vr,multiselect as lt}from"@clack/prompts";import kr from"picocolors";async function dt(e,a,t,r){if(e!==void 0)return e;if(a==="none")return[];if(!(t?.includes("react-router")||t?.includes("tanstack-router")||t?.includes("tanstack-start")))return[];let s=[];return r==="elysia"&&(s=await lt({message:"Include examples",options:[{value:"todo",label:"Todo App",hint:"A simple CRUD example app"}],required:!1,initialValues:y.examples})),(r==="hono"||r==="express")&&(s=await lt({message:"Include examples",options:[{value:"todo",label:"Todo App",hint:"A simple CRUD example app"},{value:"ai",label:"AI Chat",hint:"A simple AI chat interface using AI SDK"}],required:!1,initialValues:y.examples})),vr(s)&&(xr(kr.red("Operation cancelled")),process.exit(0)),s}import{cancel as ut,isCancel as mt,multiselect as $r,select as Er}from"@clack/prompts";import ft from"picocolors";async function ht(e){if(e!==void 0)return e;let a=await $r({message:"Select platforms to develop for",options:[{value:"web",label:"Web",hint:"React Web Application"},{value:"native",label:"Native",hint:"Create a React Native/Expo app"}],required:!1,initialValues:y.frontend.some(r=>r==="tanstack-router"||r==="react-router"||r==="tanstack-start")?["web"]:[]});mt(a)&&(ut(ft.red("Operation cancelled")),process.exit(0));let t=[];if(a.includes("web")){let r=await Er({message:"Choose frontend framework",options:[{value:"tanstack-router",label:"TanStack Router",hint:"Modern and scalable routing for React Applications"},{value:"react-router",label:"React Router",hint:"A user\u2011obsessed, standards\u2011focused, multi\u2011strategy router you can deploy anywhere."},{value:"tanstack-start",label:"TanStack Start (beta)",hint:"SSR, Streaming, Server Functions, API Routes, bundling and more powered by TanStack Router and Vite."}],initialValue:y.frontend.find(n=>n==="tanstack-router"||n==="react-router"||n==="tanstack-start")||"tanstack-router"});mt(r)&&(ut(ft.red("Operation cancelled")),process.exit(0)),t.push(r)}return a.includes("native")&&t.push("native"),t}import{cancel as Ar,confirm as Sr,isCancel as Tr}from"@clack/prompts";import Rr from"picocolors";async function gt(e){if(e!==void 0)return e;let a=await Sr({message:"Initialize git repository?",initialValue:y.git});return Tr(a)&&(Ar(Rr.red("Operation cancelled")),process.exit(0)),a}import{cancel as Cr,confirm as Dr,isCancel as Ir}from"@clack/prompts";import Fr from"picocolors";async function bt(e){if(e!==void 0)return e;let a=await Dr({message:"Install dependencies?",initialValue:!y.noInstall});return Ir(a)&&(Cr(Fr.red("Operation cancelled")),process.exit(0)),!a}import{cancel as Or,isCancel as Lr,log as Br,select as Mr}from"@clack/prompts";import Nr from"picocolors";async function wt(e,a,t){if(!a)return"none";if(e!==void 0)return e;if(t==="mongodb")return Br.info("Only Prisma is supported with MongoDB."),"prisma";let r=await Mr({message:"Select ORM",options:[{value:"drizzle",label:"Drizzle",hint:"Type-safe, lightweight ORM"},{value:"prisma",label:"Prisma",hint:"Powerful, feature-rich ORM"}],initialValue:y.orm});return Lr(r)&&(Or(Nr.red("Operation cancelled")),process.exit(0)),r}import{cancel as _r,isCancel as Ur,select as zr}from"@clack/prompts";import Gr from"picocolors";async function Pt(e){if(e!==void 0)return e;let a=X(),t=await zr({message:"Choose package manager",options:[{value:"npm",label:"npm",hint:"Node Package Manager"},{value:"pnpm",label:"pnpm",hint:"Fast, disk space efficient package manager"},{value:"bun",label:"bun",hint:"All-in-one JavaScript runtime & toolkit"}],initialValue:a});return Ur(t)&&(_r(Gr.red("Operation cancelled")),process.exit(0)),t}import K from"node:path";import{cancel as qr,isCancel as Vr,text as Wr}from"@clack/prompts";import q from"fs-extra";import Jr from"picocolors";var Hr=["<",">",":",'"',"|","?","*"],yt=255;function jt(e){if(e!=="."){if(!e)return"Project name cannot be empty";if(e.length>yt)return`Project name must be less than ${yt} characters`;if(Hr.some(a=>e.includes(a)))return"Project name contains invalid characters";if(e.startsWith(".")||e.startsWith("-"))return"Project name cannot start with a dot or dash";if(e.toLowerCase()==="node_modules"||e.toLowerCase()==="favicon.ico")return"Project name is reserved"}}async function xt(e){if(e)if(e==="."){let s=process.cwd();if(q.readdirSync(s).length===0)return e}else{let s=K.basename(e);if(!jt(s)){let o=K.resolve(process.cwd(),e);if(!q.pathExistsSync(o)||q.readdirSync(o).length===0)return e}}let a=!1,t="",r=y.projectName,n=1;for(;q.pathExistsSync(K.resolve(process.cwd(),r));)r=`${y.projectName}-${n}`,n++;for(;!a;){let s=await Wr({message:"Enter your project name or path (relative to current directory)",placeholder:r,initialValue:e,defaultValue:r,validate:i=>{let o=i.trim()||r;if(o==="."){if(q.readdirSync(process.cwd()).length>0)return"Current directory is not empty. Please choose a different directory.";a=!0;return}let p=K.resolve(process.cwd(),o),c=K.basename(p),l=jt(c);if(l)return l;if(!p.startsWith(process.cwd()))return"Project path must be within current directory";if(q.pathExistsSync(p)&&q.readdirSync(p).length>0)return`Directory "${o}" already exists and is not empty. Please choose a different name or path.`;a=!0}});Vr(s)&&(qr(Jr.red("Operation cancelled.")),process.exit(0)),t=s||r}return t}import{cancel as Qr,isCancel as Kr,select as Xr}from"@clack/prompts";import Yr from"picocolors";async function vt(e){if(e!==void 0)return e;let a=await Xr({message:"Select runtime",options:[{value:"bun",label:"Bun",hint:"Fast all-in-one JavaScript runtime"},{value:"node",label:"Node.js",hint:"Traditional Node.js runtime"}],initialValue:y.runtime});return Kr(a)&&(Qr(Yr.red("Operation cancelled")),process.exit(0)),a}async function $t(e){e.dbSetup&&(e.dbSetup==="turso"?(e.database="sqlite",e.orm==="prisma"&&(tn.warn(kt.yellow("Turso is not compatible with Prisma - switching to Drizzle")),e.orm="drizzle")):e.dbSetup==="prisma-postgres"?(e.database="postgres",e.orm="prisma"):e.dbSetup==="mongodb-atlas"&&(e.database="mongodb",e.orm="prisma"));let a=await en({projectName:async()=>xt(e.projectName),frontend:()=>ht(e.frontend),backend:()=>ot(e.backend),runtime:()=>vt(e.runtime),database:()=>ct(e.database),orm:({results:t})=>wt(e.orm,t.database!=="none",t.database),auth:({results:t})=>it(e.auth,t.database!=="none",t.frontend),dbSetup:({results:t})=>pt(t.database??"none",e.dbSetup),addons:({results:t})=>st(e.addons,t.frontend),examples:({results:t})=>dt(e.examples,t.database,t.frontend,t.backend),git:()=>gt(e.git),packageManager:()=>Pt(e.packageManager),noInstall:()=>bt(e.noInstall)},{onCancel:()=>{Zr(kt.red("Operation cancelled")),process.exit(0)}});return{projectName:a.projectName,frontend:a.frontend,database:a.database,orm:a.orm,auth:a.auth,addons:a.addons,examples:a.examples,git:a.git,packageManager:a.packageManager,noInstall:a.noInstall,dbSetup:a.dbSetup,backend:a.backend,runtime:a.runtime}}import R from"picocolors";function me(e){let a=[];if(e.projectName&&a.push(`${R.blue("Project Name:")} ${e.projectName}`),e.frontend!==void 0){let t=e.frontend.length>0?e.frontend.join(", "):"none";a.push(`${R.blue("Frontend:")} ${t}`)}if(e.backend!==void 0&&a.push(`${R.blue("Backend Framework:")} ${e.backend}`),e.runtime!==void 0&&a.push(`${R.blue("Runtime:")} ${e.runtime}`),e.database!==void 0&&a.push(`${R.blue("Database:")} ${e.database}`),e.orm!==void 0&&a.push(`${R.blue("ORM:")} ${e.orm}`),e.auth!==void 0&&a.push(`${R.blue("Authentication:")} ${e.auth}`),e.addons!==void 0){let t=e.addons.length>0?e.addons.join(", "):"none";a.push(`${R.blue("Addons:")} ${t}`)}if(e.examples!==void 0){let t=e.examples.length>0?e.examples.join(", "):"none";a.push(`${R.blue("Examples:")} ${t}`)}return e.git!==void 0&&a.push(`${R.blue("Git Init:")} ${e.git}`),e.packageManager!==void 0&&a.push(`${R.blue("Package Manager:")} ${e.packageManager}`),e.noInstall!==void 0&&a.push(`${R.blue("Skip Install:")} ${e.noInstall}`),e.dbSetup!==void 0&&a.push(`${R.blue("Database Setup:")} ${e.dbSetup}`),a.join(`
|
|
269
|
-
`)}function
|
|
268
|
+
});`),s.includes("my-better-t-app://")||(s=s.replace(/trustedOrigins: \[(.*?)\]/s,(i,o)=>`trustedOrigins: [${o}${o.trim()?", ":""}"my-better-t-app://"]`)),await d.writeFile(n,s)}}async function tt(e){let a=await at(e);for(let t of a)if(await d.pathExists(t)){let r=u.join(u.dirname(t),".gitignore");await d.move(t,r,{overwrite:!0})}}async function at(e){let a=[],t=u.join(e,"_gitignore");await d.pathExists(t)&&a.push(t);try{let r=await d.readdir(e,{withFileTypes:!0});for(let n of r)if(n.isDirectory()&&n.name!=="node_modules"){let s=u.join(e,n.name),i=await at(s);a.push(...i)}}catch{}return a}function Ka(e,a){if(e==="drizzle")return a==="sqlite"?"template/with-drizzle-sqlite":"template/with-drizzle-postgres";if(e==="prisma"){if(a==="sqlite")return"template/with-prisma-sqlite";if(a==="postgres")return"template/with-prisma-postgres";if(a==="mongodb")return"template/with-prisma-mongodb"}return"template/base"}function Xa(e,a){if(e==="drizzle")return a==="sqlite"?"with-drizzle-sqlite-lib":"with-drizzle-postgres-lib";if(e==="prisma"){if(a==="sqlite")return"with-prisma-sqlite-lib";if(a==="postgres")return"with-prisma-postgres-lib";if(a==="mongodb")return"with-prisma-mongodb-lib"}throw new Error("Invalid ORM or database configuration for auth setup")}async function nt(e){let a=er(),t=Ya.resolve(process.cwd(),e.projectName);try{return await tr.ensureDir(t),await Ke(t),await Xe(t,e.frontend),await tt(t),await Ye(t,e.backend),await $e(t,e.backend,e.runtime),await Ze(t,e.orm,e.database,e.auth),await Me(t,e.database,e.orm,e.packageManager,e.dbSetup==="turso",e.dbSetup==="prisma-postgres",e.dbSetup==="mongodb-atlas"),await et(t,e.auth,e.backend,e.orm,e.database,e.frontend),await Ae(t,e.auth,e.frontend),await Qe(t,e.runtime,e.backend),await Ue(t,e.examples,e.orm,e.auth,e.backend,e.frontend),await _e(t,e),await He(t,e.git),e.addons.length>0&&await je(t,e.addons,e.packageManager,e.frontend),await Je(t,e),await Ee(t,e),e.noInstall||await qe({projectDir:t,packageManager:e.packageManager,addons:e.addons}),Ve(e.database,e.projectName,e.packageManager,!e.noInstall,e.orm,e.addons,e.runtime,e.frontend),t}catch(r){throw a.message(rt.red("Failed")),r instanceof Error&&(Za(rt.red(`Error during project creation: ${r.message}`)),process.exit(1)),r}}import{cancel as Zr,group as en,log as tn}from"@clack/prompts";import kt from"picocolors";import{cancel as ar,isCancel as rr,multiselect as nr}from"@clack/prompts";import sr from"picocolors";async function st(e,a){if(e!==void 0)return e;let t=a?.includes("react-router")||a?.includes("tanstack-router"),r=[{value:"biome",label:"Biome",hint:"Add Biome for linting and formatting"},{value:"husky",label:"Husky",hint:"Add Git hooks with Husky, lint-staged (requires Biome)"}],s=t?[...[{value:"pwa",label:"PWA (Progressive Web App)",hint:"Make your app installable and work offline"},{value:"tauri",label:"Tauri Desktop App",hint:"Build native desktop apps from your web frontend"}],...r]:r,i=y.addons.filter(p=>t||p!=="pwa"&&p!=="tauri"),o=await nr({message:"Select addons",options:s,initialValues:i,required:!1});return rr(o)&&(ar(sr.red("Operation cancelled")),process.exit(0)),o.includes("husky")&&!o.includes("biome")&&o.push("biome"),o}import{cancel as ir,confirm as or,isCancel as cr}from"@clack/prompts";import pr from"picocolors";async function it(e,a,t){if(!a)return!1;if(e!==void 0)return e;let r=await or({message:"Add authentication with Better-Auth?",initialValue:y.auth});return cr(r)&&(ir(pr.red("Operation cancelled")),process.exit(0)),r}import{cancel as lr,isCancel as dr,select as ur}from"@clack/prompts";import mr from"picocolors";async function ot(e){if(e!==void 0)return e;let a=await ur({message:"Select backend framework",options:[{value:"hono",label:"Hono",hint:"Lightweight, ultrafast web framework"},{value:"express",label:"Express",hint:"Fast, unopinionated, minimalist web framework for Node.js"},{value:"elysia",label:"Elysia",hint:"Ergonomic web framework for building backend servers"}],initialValue:y.backend});return dr(a)&&(lr(mr.red("Operation cancelled")),process.exit(0)),a}import{cancel as fr,isCancel as hr,select as gr}from"@clack/prompts";import br from"picocolors";async function ct(e){if(e!==void 0)return e;let a=await gr({message:"Select database",options:[{value:"none",label:"None",hint:"No database setup"},{value:"sqlite",label:"SQLite",hint:"lightweight, server-less, embedded relational database management system"},{value:"postgres",label:"PostgreSQL",hint:"powerful, open source object-relational database system"},{value:"mongodb",label:"MongoDB",hint:"open-source NoSQL database that stores data in JSON-like documents called BSON"}],initialValue:y.database});return hr(a)&&(fr(br.red("Operation cancelled")),process.exit(0)),a}import{cancel as wr,isCancel as Pr,select as yr}from"@clack/prompts";import jr from"picocolors";async function pt(e,a){if(a!==void 0)return a;let t=[];if(e==="sqlite")t=[{value:"turso",label:"Turso",hint:"SQLite for Production. Powered by libSQL."},{value:"none",label:"None",hint:"Manual setup"}];else if(e==="postgres")t=[{value:"prisma-postgres",label:"Prisma Postgres",hint:"Instant Postgres for Global Applications"},{value:"none",label:"None",hint:"Manual setup"}];else if(e==="mongodb")t=[{value:"mongodb-atlas",label:"MongoDB Atlas",hint:"The most effective way to deploy MongoDB"},{value:"none",label:"None",hint:"Manual setup"}];else return"none";let r=await yr({message:`Select ${e} setup option`,options:t,initialValue:"none"});return Pr(r)&&(wr(jr.red("Operation cancelled")),process.exit(0)),r}import{cancel as xr,isCancel as vr,multiselect as lt}from"@clack/prompts";import kr from"picocolors";async function dt(e,a,t,r){if(e!==void 0)return e;if(a==="none")return[];if(!(t?.includes("react-router")||t?.includes("tanstack-router")||t?.includes("tanstack-start")))return[];let s=[];return r==="elysia"&&(s=await lt({message:"Include examples",options:[{value:"todo",label:"Todo App",hint:"A simple CRUD example app"}],required:!1,initialValues:y.examples})),(r==="hono"||r==="express")&&(s=await lt({message:"Include examples",options:[{value:"todo",label:"Todo App",hint:"A simple CRUD example app"},{value:"ai",label:"AI Chat",hint:"A simple AI chat interface using AI SDK"}],required:!1,initialValues:y.examples})),vr(s)&&(xr(kr.red("Operation cancelled")),process.exit(0)),s}import{cancel as ut,isCancel as mt,multiselect as Ar,select as $r}from"@clack/prompts";import ft from"picocolors";async function ht(e){if(e!==void 0)return e;let a=await Ar({message:"Select platforms to develop for",options:[{value:"web",label:"Web",hint:"React Web Application"},{value:"native",label:"Native",hint:"Create a React Native/Expo app"}],required:!1,initialValues:y.frontend.some(r=>r==="tanstack-router"||r==="react-router"||r==="tanstack-start")?["web"]:[]});mt(a)&&(ut(ft.red("Operation cancelled")),process.exit(0));let t=[];if(a.includes("web")){let r=await $r({message:"Choose frontend framework",options:[{value:"tanstack-router",label:"TanStack Router",hint:"Modern and scalable routing for React Applications"},{value:"react-router",label:"React Router",hint:"A user\u2011obsessed, standards\u2011focused, multi\u2011strategy router you can deploy anywhere."},{value:"tanstack-start",label:"TanStack Start (beta)",hint:"SSR, Streaming, Server Functions, API Routes, bundling and more powered by TanStack Router and Vite."}],initialValue:y.frontend.find(n=>n==="tanstack-router"||n==="react-router"||n==="tanstack-start")||"tanstack-router"});mt(r)&&(ut(ft.red("Operation cancelled")),process.exit(0)),t.push(r)}return a.includes("native")&&t.push("native"),t}import{cancel as Er,confirm as Sr,isCancel as Tr}from"@clack/prompts";import Dr from"picocolors";async function gt(e){if(e!==void 0)return e;let a=await Sr({message:"Initialize git repository?",initialValue:y.git});return Tr(a)&&(Er(Dr.red("Operation cancelled")),process.exit(0)),a}import{cancel as Rr,confirm as Cr,isCancel as Ir}from"@clack/prompts";import Fr from"picocolors";async function bt(e){if(e!==void 0)return e;let a=await Cr({message:"Install dependencies?",initialValue:!y.noInstall});return Ir(a)&&(Rr(Fr.red("Operation cancelled")),process.exit(0)),!a}import{cancel as Or,isCancel as Br,log as Lr,select as Mr}from"@clack/prompts";import _r from"picocolors";async function wt(e,a,t){if(!a)return"none";if(e!==void 0)return e;if(t==="mongodb")return Lr.info("Only Prisma is supported with MongoDB."),"prisma";let r=await Mr({message:"Select ORM",options:[{value:"drizzle",label:"Drizzle",hint:"lightweight and performant TypeScript ORM"},{value:"prisma",label:"Prisma",hint:"Powerful, feature-rich ORM"}],initialValue:y.orm});return Br(r)&&(Or(_r.red("Operation cancelled")),process.exit(0)),r}import{cancel as Ur,isCancel as Nr,select as zr}from"@clack/prompts";import Gr from"picocolors";async function Pt(e){if(e!==void 0)return e;let a=X(),t=await zr({message:"Choose package manager",options:[{value:"npm",label:"npm",hint:"Node Package Manager"},{value:"pnpm",label:"pnpm",hint:"Fast, disk space efficient package manager"},{value:"bun",label:"bun",hint:"All-in-one JavaScript runtime & toolkit"}],initialValue:a});return Nr(t)&&(Ur(Gr.red("Operation cancelled")),process.exit(0)),t}import K from"node:path";import{cancel as qr,isCancel as Vr,text as Wr}from"@clack/prompts";import q from"fs-extra";import Jr from"picocolors";var Hr=["<",">",":",'"',"|","?","*"],yt=255;function jt(e){if(e!=="."){if(!e)return"Project name cannot be empty";if(e.length>yt)return`Project name must be less than ${yt} characters`;if(Hr.some(a=>e.includes(a)))return"Project name contains invalid characters";if(e.startsWith(".")||e.startsWith("-"))return"Project name cannot start with a dot or dash";if(e.toLowerCase()==="node_modules")return"Project name is reserved"}}async function xt(e){if(e)if(e==="."){let s=process.cwd();if(q.readdirSync(s).length===0)return e}else{let s=K.basename(e);if(!jt(s)){let o=K.resolve(process.cwd(),e);if(!q.pathExistsSync(o)||q.readdirSync(o).length===0)return e}}let a=!1,t="",r=y.projectName,n=1;for(;q.pathExistsSync(K.resolve(process.cwd(),r));)r=`${y.projectName}-${n}`,n++;for(;!a;){let s=await Wr({message:"Enter your project name or path (relative to current directory)",placeholder:r,initialValue:e,defaultValue:r,validate:i=>{let o=i.trim()||r;if(o==="."){if(q.readdirSync(process.cwd()).length>0)return"Current directory is not empty. Please choose a different directory.";a=!0;return}let p=K.resolve(process.cwd(),o),c=K.basename(p),l=jt(c);if(l)return l;if(!p.startsWith(process.cwd()))return"Project path must be within current directory";if(q.pathExistsSync(p)&&q.readdirSync(p).length>0)return`Directory "${o}" already exists and is not empty. Please choose a different name or path.`;a=!0}});Vr(s)&&(qr(Jr.red("Operation cancelled.")),process.exit(0)),t=s||r}return t}import{cancel as Qr,isCancel as Kr,select as Xr}from"@clack/prompts";import Yr from"picocolors";async function vt(e){if(e!==void 0)return e;let a=await Xr({message:"Select runtime",options:[{value:"bun",label:"Bun",hint:"Fast all-in-one JavaScript runtime"},{value:"node",label:"Node.js",hint:"Traditional Node.js runtime"}],initialValue:y.runtime});return Kr(a)&&(Qr(Yr.red("Operation cancelled")),process.exit(0)),a}async function At(e){e.dbSetup&&(e.dbSetup==="turso"?(e.database="sqlite",e.orm==="prisma"&&(tn.warn(kt.yellow("Turso is not compatible with Prisma - switching to Drizzle")),e.orm="drizzle")):e.dbSetup==="prisma-postgres"?(e.database="postgres",e.orm="prisma"):e.dbSetup==="mongodb-atlas"&&(e.database="mongodb",e.orm="prisma"));let a=await en({projectName:async()=>xt(e.projectName),frontend:()=>ht(e.frontend),backend:()=>ot(e.backend),runtime:()=>vt(e.runtime),database:()=>ct(e.database),orm:({results:t})=>wt(e.orm,t.database!=="none",t.database),auth:({results:t})=>it(e.auth,t.database!=="none",t.frontend),dbSetup:({results:t})=>pt(t.database??"none",e.dbSetup),addons:({results:t})=>st(e.addons,t.frontend),examples:({results:t})=>dt(e.examples,t.database,t.frontend,t.backend),git:()=>gt(e.git),packageManager:()=>Pt(e.packageManager),noInstall:()=>bt(e.noInstall)},{onCancel:()=>{Zr(kt.red("Operation cancelled")),process.exit(0)}});return{projectName:a.projectName,frontend:a.frontend,database:a.database,orm:a.orm,auth:a.auth,addons:a.addons,examples:a.examples,git:a.git,packageManager:a.packageManager,noInstall:a.noInstall,dbSetup:a.dbSetup,backend:a.backend,runtime:a.runtime}}import D from"picocolors";function me(e){let a=[];if(e.projectName&&a.push(`${D.blue("Project Name:")} ${e.projectName}`),e.frontend!==void 0){let t=e.frontend.length>0?e.frontend.join(", "):"none";a.push(`${D.blue("Frontend:")} ${t}`)}if(e.backend!==void 0&&a.push(`${D.blue("Backend Framework:")} ${e.backend}`),e.runtime!==void 0&&a.push(`${D.blue("Runtime:")} ${e.runtime}`),e.database!==void 0&&a.push(`${D.blue("Database:")} ${e.database}`),e.orm!==void 0&&a.push(`${D.blue("ORM:")} ${e.orm}`),e.auth!==void 0&&a.push(`${D.blue("Authentication:")} ${e.auth}`),e.addons!==void 0){let t=e.addons.length>0?e.addons.join(", "):"none";a.push(`${D.blue("Addons:")} ${t}`)}if(e.examples!==void 0){let t=e.examples.length>0?e.examples.join(", "):"none";a.push(`${D.blue("Examples:")} ${t}`)}return e.git!==void 0&&a.push(`${D.blue("Git Init:")} ${e.git}`),e.packageManager!==void 0&&a.push(`${D.blue("Package Manager:")} ${e.packageManager}`),e.noInstall!==void 0&&a.push(`${D.blue("Skip Install:")} ${e.noInstall}`),e.dbSetup!==void 0&&a.push(`${D.blue("Database Setup:")} ${e.dbSetup}`),a.join(`
|
|
269
|
+
`)}function $t(e){let a=[];e.database==="none"?a.push("--database none"):(a.push(`--database ${e.database}`),e.orm&&a.push(`--orm ${e.orm}`),e.dbSetup&&a.push(`--db-setup ${e.dbSetup}`)),a.push(e.auth?"--auth":"--no-auth"),a.push(e.git?"--git":"--no-git"),a.push(e.noInstall?"--no-install":"--install"),e.runtime&&a.push(`--runtime ${e.runtime}`),e.backend&&a.push(`--backend ${e.backend}`),e.frontend&&e.frontend.length>0&&a.push(`--frontend ${e.frontend.join(" ")}`),e.addons&&e.addons.length>0?a.push(`--addons ${e.addons.join(" ")}`):a.push("--addons none"),e.examples&&e.examples.length>0?a.push(`--examples ${e.examples.join(" ")}`):a.push("--no-examples"),e.packageManager&&a.push(`--package-manager ${e.packageManager}`);let t="",r=e.packageManager;r==="npm"?t="npx create-better-t-stack@latest":r==="pnpm"?t="pnpm create better-t-stack@latest":r==="bun"&&(t="bun create better-t-stack@latest");let n=e.projectName?` ${e.projectName}`:"";return`${t}${n} ${a.join(" ")}`}import an from"node:path";import rn from"fs-extra";var Et=()=>{let e=an.join(A,"package.json");return rn.readJSONSync(e).version??"1.0.0"};import St from"gradient-string";var Tt=`
|
|
270
270
|
\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2557
|
|
271
271
|
\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u2550\u2588\u2588\u2554\u2550\u2550\u255D\u255A\u2550\u2550\u2588\u2588\u2554\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557
|
|
272
272
|
\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D
|
|
@@ -280,10 +280,10 @@ serve(
|
|
|
280
280
|
\u2588\u2588\u2551 \u255A\u2550\u2550\u2550\u2550\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2588\u2588\u2557
|
|
281
281
|
\u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2557
|
|
282
282
|
\u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D
|
|
283
|
-
`,
|
|
284
|
-
`),t=Math.max(...a.map(r=>r.length));e<t?console.log(St(Object.values(
|
|
283
|
+
`,Dt={pink:"#F5C2E7",mauve:"#CBA6F7",red:"#F38BA8",maroon:"#E78284",peach:"#FAB387",yellow:"#F9E2AF",green:"#A6E3A1",teal:"#94E2D5",sky:"#89DCEB",sapphire:"#74C7EC",lavender:"#B4BEFE"},Rt=()=>{let e=process.stdout.columns||80,a=Tt.split(`
|
|
284
|
+
`),t=Math.max(...a.map(r=>r.length));e<t?console.log(St(Object.values(Dt)).multiline(`
|
|
285
285
|
\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557
|
|
286
286
|
\u2551 Better T-Stack \u2551
|
|
287
287
|
\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D
|
|
288
|
-
`)):console.log(St(Object.values(
|
|
289
|
-
${g.white(
|
|
288
|
+
`)):console.log(St(Object.values(Dt)).multiline(Tt))};process.on("SIGINT",()=>{S.error(g.red("Operation cancelled")),process.exit(0)});var fe=new cn;async function pn(){let e=Date.now();fe.name("create-better-t-stack").description("Create a new Better-T Stack project").version(Et()).argument("[project-directory]","Project name/directory").option("-y, --yes","Use default configuration").option("--database <type>","Database type (none, sqlite, postgres, mongodb)").option("--orm <type>","ORM type (drizzle, prisma)").option("--auth","Include authentication").option("--no-auth","Exclude authentication").option("--frontend <types...>","Frontend types (tanstack-router, react-router, tanstack-start, native, none)").option("--addons <types...>","Additional addons (pwa, tauri, biome, husky, none)").option("--examples <types...>","Examples to include (todo, ai)").option("--no-examples","Skip all examples").option("--git","Initialize git repository").option("--no-git","Skip git initialization").option("--package-manager <pm>","Package manager (npm, pnpm, bun)").option("--install","Install dependencies").option("--no-install","Skip installing dependencies").option("--db-setup <setup>","Database setup (turso, prisma-postgres, mongodb-atlas, none)").option("--backend <framework>","Backend framework (hono, express, elysia)").option("--runtime <runtime>","Runtime (bun, node)").parse();let a=on();try{Rt(),nn(g.magenta("Creating a new Better-T-Stack project"));let t=fe.opts(),r=fe.args[0];ln(t);let n=dn(t,r);!t.yes&&Object.keys(n).length>0&&(S.info(g.yellow("Using these pre-selected options:")),S.message(me(n)),S.message(""));let s=t.yes?{...y,projectName:r??y.projectName,...n}:await At(n);t.yes&&(S.info(g.yellow("Using these default options:")),S.message(me(s)),S.message("")),await nt(s),S.success(g.blue(`You can reproduce this setup with the following command:
|
|
289
|
+
${g.white($t(s))}`));let i=((Date.now()-e)/1e3).toFixed(2);sn(g.magenta(`Project created successfully in ${g.bold(i)} seconds!`))}catch(t){a.stop(g.red("Failed")),t instanceof Error&&(v(g.red(`An unexpected error occurred: ${t.message}`)),process.exit(1))}}function ln(e){if(e.database&&!["none","sqlite","postgres","mongodb"].includes(e.database)&&(v(g.red(`Invalid database type: ${e.database}. Must be none, sqlite, postgres, or mongodb.`)),process.exit(1)),e.orm&&!["drizzle","prisma"].includes(e.orm)&&(v(g.red(`Invalid ORM type: ${e.orm}. Must be drizzle or prisma.`)),process.exit(1)),e.dbSetup&&!["turso","prisma-postgres","mongodb-atlas","none"].includes(e.dbSetup)&&(v(g.red(`Invalid database setup: ${e.dbSetup}. Must be turso, prisma-postgres, mongodb-atlas, or none.`)),process.exit(1)),e.database==="mongodb"&&e.orm==="drizzle"&&(v(g.red("MongoDB is only available with Prisma. Cannot use --database mongodb with --orm drizzle")),process.exit(1)),e.database==="none"&&(e.auth===!0&&(v(g.red("Authentication requires a database. Cannot use --auth with --database none.")),process.exit(1)),e.orm&&e.orm!=="none"&&(v(g.red(`Cannot use ORM with no database. Cannot use --orm ${e.orm} with --database none.`)),process.exit(1)),e.dbSetup&&e.dbSetup!=="none"&&(v(g.red(`Database setup requires a database. Cannot use --db-setup ${e.dbSetup} with --database none.`)),process.exit(1))),e.dbSetup==="turso"&&(e.database&&e.database!=="sqlite"&&(v(g.red(`Turso setup requires a SQLite database. Cannot use --db-setup turso with --database ${e.database}`)),process.exit(1)),e.orm==="prisma"&&(v(g.red("Turso setup is not compatible with Prisma. Cannot use --db-setup turso with --orm prisma")),process.exit(1))),e.dbSetup==="prisma-postgres"&&(e.database&&e.database!=="postgres"&&(v(g.red("Prisma PostgreSQL setup requires PostgreSQL database. Cannot use --db-setup prisma-postgres with a different database type.")),process.exit(1)),e.orm&&e.orm!=="prisma"&&(v(g.red("Prisma PostgreSQL setup requires Prisma ORM. Cannot use --db-setup prisma-postgres with a different ORM.")),process.exit(1))),e.dbSetup==="mongodb-atlas"&&e.database&&e.database!=="mongodb"&&(v(g.red("MongoDB Atlas setup requires MongoDB database. Cannot use --db-setup mongodb-atlas with a different database type.")),process.exit(1)),e.packageManager&&!["npm","pnpm","bun"].includes(e.packageManager)&&(v(g.red(`Invalid package manager: ${e.packageManager}. Must be npm, pnpm, or bun.`)),process.exit(1)),e.backend&&!["hono","elysia","express"].includes(e.backend)&&(v(g.red(`Invalid backend framework: ${e.backend}. Must be hono, elysia, or express.`)),process.exit(1)),e.runtime&&!["bun","node"].includes(e.runtime)&&(v(g.red(`Invalid runtime: ${e.runtime}. Must be bun or node.`)),process.exit(1)),e.examples&&Array.isArray(e.examples)&&e.examples.length>0){let a=["todo","ai"],t=e.examples.filter(r=>!a.includes(r));t.length>0&&(v(g.red(`Invalid example(s): ${t.join(", ")}. Valid options are: ${a.join(", ")}.`)),process.exit(1)),e.examples.includes("ai")&&e.backend==="elysia"&&(v(g.red("AI example is only compatible with Hono backend. Cannot use --examples ai with --backend elysia")),process.exit(1)),e.frontend&&!e.frontend.some(r=>["tanstack-router","react-router","tanstack-start"].includes(r))&&!e.frontend.includes("none")&&(v(g.red("Examples require a web frontend. Cannot use --examples with --frontend native only")),process.exit(1))}if(e.frontend&&e.frontend.length>0){let a=["tanstack-router","react-router","tanstack-start","native","none"],t=e.frontend.filter(n=>!a.includes(n));t.length>0&&(v(g.red(`Invalid frontend(s): ${t.join(", ")}. Valid options are: ${a.join(", ")}.`)),process.exit(1)),e.frontend.filter(n=>n==="tanstack-router"||n==="react-router"||n==="tanstack-start").length>1&&(v(g.red("Cannot select multiple web frameworks. Choose only one of: tanstack-router, tanstack-start, react-router")),process.exit(1)),e.frontend.includes("none")&&e.frontend.length>1&&(v(g.red("Cannot combine 'none' with other frontend options.")),process.exit(1))}if(e.addons&&Array.isArray(e.addons)&&e.addons.length>0){let a=["pwa","tauri","biome","husky","none"],t=e.addons.filter(s=>!a.includes(s));t.length>0&&(v(g.red(`Invalid addon(s): ${t.join(", ")}. Valid options are: ${a.join(", ")}.`)),process.exit(1)),e.addons.includes("none")&&e.addons.length>1&&(v(g.red("Cannot combine 'none' with other addons.")),process.exit(1));let r=["pwa","tauri"];e.addons.some(s=>r.includes(s))&&e.frontend&&!e.frontend.some(s=>["tanstack-router","react-router"].includes(s))&&(v(g.red(`PWA and Tauri addons require tanstack-router or react-router. Cannot use --addons ${e.addons.filter(s=>r.includes(s)).join(", ")} with incompatible frontend options.`)),process.exit(1))}}function dn(e,a){let t;if(e.frontend)if(e.frontend.includes("none"))t=[];else{t=e.frontend.filter(j=>j==="tanstack-router"||j==="react-router"||j==="tanstack-start"||j==="native");let k=t.filter(j=>j==="tanstack-router"||j==="react-router"||j==="tanstack-start");if(k.length>1){let j=k[0];t=t.filter(R=>R==="native"||R===j)}}let r;"examples"in e&&(e.examples===!1?r=[]:Array.isArray(e.examples)&&(r=e.examples.filter(k=>k==="todo"||k==="ai"),t&&t.length>0&&!t.some(k=>["tanstack-router","react-router","tanstack-start"].includes(k))&&(r=[],S.warn(g.yellow("Examples require web frontend - ignoring examples flag"))),r.includes("ai")&&e.backend==="elysia"&&(r=r.filter(k=>k!=="ai"),S.warn(g.yellow("AI example is not compatible with Elysia - removing AI example")))));let n;if(e.addons&&Array.isArray(e.addons))if(e.addons.includes("none"))n=[];else{if(n=e.addons.filter(j=>j==="pwa"||j==="tauri"||j==="biome"||j==="husky"),!t?.some(j=>j==="tanstack-router"||j==="react-router")){let j=["pwa","tauri"],R=n.filter(T=>!j.includes(T));R.length!==n.length&&(S.warn(g.yellow("PWA and Tauri addons require tanstack-router or react-router - removing these addons")),n=R)}n.includes("husky")&&!n.includes("biome")&&n.push("biome")}let s=e.database,i=e.orm,o="auth"in e?e.auth:void 0,p=e.backend,c=e.runtime,l=e.packageManager,m;e.dbSetup&&(e.dbSetup==="none"?m="none":(m=e.dbSetup,m==="turso"?(s="sqlite",i==="prisma"&&(S.warn(g.yellow("Turso is not compatible with Prisma - switching to Drizzle")),i="drizzle")):m==="prisma-postgres"?(s="postgres",i="prisma"):m==="mongodb-atlas"&&(s="mongodb",i="prisma")));let b={};return a&&(b.projectName=a),s!==void 0&&(b.database=s),i!==void 0&&(b.orm=i),o!==void 0&&(b.auth=o),l&&(b.packageManager=l),"git"in e&&(b.git=e.git),"install"in e&&(b.noInstall=!e.install),m!==void 0&&(b.dbSetup=m),p&&(b.backend=p),c&&(b.runtime=c),t!==void 0&&(b.frontend=t),n!==void 0&&(b.addons=n),r!==void 0&&(b.examples=r),b}pn().catch(e=>{S.error("Aborting installation..."),e instanceof Error?S.error(e.message):(S.error("An unknown error has occurred. Please open an issue on GitHub with the below:"),console.log(e)),process.exit(1)});
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@ export default defineConfig({
|
|
|
5
5
|
out: "./src/db/migrations",
|
|
6
6
|
dialect: "turso",
|
|
7
7
|
dbCredentials: {
|
|
8
|
-
url: process.env.
|
|
9
|
-
authToken: process.env.
|
|
8
|
+
url: process.env.DATABASE_URL || "",
|
|
9
|
+
authToken: process.env.DATABASE_AUTH_TOKEN,
|
|
10
10
|
},
|
|
11
11
|
});
|
|
@@ -2,8 +2,8 @@ import { drizzle } from "drizzle-orm/libsql";
|
|
|
2
2
|
import { createClient } from "@libsql/client";
|
|
3
3
|
|
|
4
4
|
const client = createClient({
|
|
5
|
-
url: process.env.
|
|
6
|
-
authToken: process.env.
|
|
5
|
+
url: process.env.DATABASE_URL || "",
|
|
6
|
+
authToken: process.env.DATABASE_AUTH_TOKEN ,
|
|
7
7
|
});
|
|
8
8
|
|
|
9
9
|
export const db = drizzle({ client });
|