create-better-t-stack 1.9.2 → 1.10.1

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,7 +1,7 @@
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 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
- ${p[0]}`):i=`import { VitePWA } from "vite-plugin-pwa";
4
- ${i}`}let o=`VitePWA({
2
+ import{cancel as j,intro as rn,log as D,outro as nn,spinner as sn}from"@clack/prompts";import{Command as on}from"commander";import h from"picocolors";import we from"node:path";import{fileURLToPath as Ot}from"node:url";var K=()=>{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=we.dirname(Bt),v=we.join(Lt,"../"),P={projectName:"my-better-t-app",frontend:["tanstack-router"],database:"sqlite",orm:"drizzle",auth:!0,addons:[],examples:[],git:!0,packageManager:K(),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",mysql2:"^3.14.0","@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 Xa from"node:path";import{cancel as Ya,spinner as Za}from"@clack/prompts";import er from"fs-extra";import nt from"picocolors";import I from"node:path";import k from"fs-extra";import Mt from"node:path";import Pe from"fs-extra";var g=e=>{let{dependencies:a=[],devDependencies:t=[],projectDir:r}=e,n=Mt.join(r,"package.json"),s=Pe.readJSONSync(n);s.dependencies||(s.dependencies={}),s.devDependencies||(s.devDependencies={});for(let o of a){let i=se[o];s.dependencies[o]=i}for(let o of t){let i=se[o];s.devDependencies[o]=i}Pe.writeJSONSync(n,s,{spaces:2})};import X from"node:path";import{log as zt,spinner as Nt}from"@clack/prompts";import{execa as Ut}from"execa";import Y from"fs-extra";import ye from"picocolors";async function je(e,a,t){let r=Nt(),n=X.join(e,"apps/web");if(await Y.pathExists(n))try{r.start("Setting up Tauri desktop app support..."),g({devDependencies:["@tauri-apps/cli"],projectDir:n});let s=X.join(n,"package.json");if(await Y.pathExists(s)){let d=await Y.readJson(s);d.scripts={...d.scripts,tauri:"tauri","desktop:dev":"tauri dev","desktop:build":"tauri build"},await Y.writeJson(s,d,{spaces:2})}let o,i;switch(a){case"npm":o="npx",i=["@tauri-apps/cli@latest"];break;case"pnpm":o="pnpm",i=["dlx","@tauri-apps/cli@latest"];break;case"bun":o="bunx",i=["@tauri-apps/cli@latest"];break;default:o="npx",i=["@tauri-apps/cli@latest"]}let c=t.includes("react-router")?"http://localhost:5173":"http://localhost:3001";i=[...i,"init",`--app-name=${X.basename(e)}`,`--window-title=${X.basename(e)}`,"--frontend-dist=dist",`--dev-url=${c}`,`--before-dev-command=${a} run dev`,`--before-build-command=${a} run build`],await Ut(o,i,{cwd:n,env:{CI:"true"}}),r.stop("Tauri desktop app support configured successfully!")}catch(s){throw r.stop(ye.red("Failed to set up Tauri")),s instanceof Error&&zt.error(ye.red(s.message)),s}}async function ve(e,a,t,r){let n=r.includes("react-router")||r.includes("tanstack-router");a.includes("pwa")&&n&&await Gt(e,r),a.includes("tauri")&&n&&await je(e,t,r),a.includes("biome")&&await qt(e),a.includes("husky")&&await Vt(e)}function _t(e,a){return I.join(e,"apps/web")}async function qt(e){let a=I.join(v,"template/with-biome");await k.pathExists(a)&&await k.copy(a,e,{overwrite:!0}),g({devDependencies:["@biomejs/biome"],projectDir:e});let t=I.join(e,"package.json");if(await k.pathExists(t)){let r=await k.readJson(t);r.scripts={...r.scripts,check:"biome check --write ."},await k.writeJson(t,r,{spaces:2})}}async function Vt(e){let a=I.join(v,"template/with-husky");await k.pathExists(a)&&await k.copy(a,e,{overwrite:!0}),g({devDependencies:["husky","lint-staged"],projectDir:e});let t=I.join(e,"package.json");if(await k.pathExists(t)){let r=await k.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 k.writeJson(t,r,{spaces:2})}}async function Gt(e,a){let t=I.join(v,"template/with-pwa");await k.pathExists(t)&&await k.copy(t,e,{overwrite:!0});let r=_t(e,a);if(!await k.pathExists(r))return;g({dependencies:["vite-plugin-pwa"],devDependencies:["@vite-pwa/assets-generator"],projectDir:r});let n=I.join(r,"vite.config.ts");if(await k.pathExists(n)){let o=await k.readFile(n,"utf8");if(!o.includes("vite-plugin-pwa")){let p=o.match(/^import .* from ['"](.*)['"]/m);p?o=o.replace(p[0],`import { VitePWA } from "vite-plugin-pwa";
3
+ ${p[0]}`):o=`import { VitePWA } from "vite-plugin-pwa";
4
+ ${o}`}let i=`VitePWA({
5
5
  registerType: "autoUpdate",
6
6
  manifest: {
7
7
  name: "My App",
@@ -16,18 +16,18 @@ ${i}`}let o=`VitePWA({
16
16
  devOptions: {
17
17
  enabled: true,
18
18
  },
19
- })`;i.includes("VitePWA(")||(a.includes("react-router")?i=i.replace(/plugins: \[\s*tailwindcss\(\)/,`plugins: [
19
+ })`;o.includes("VitePWA(")||(a.includes("react-router")?o=o.replace(/plugins: \[\s*tailwindcss\(\)/,`plugins: [
20
20
  tailwindcss(),
21
- ${o}`):a.includes("tanstack-router")?i=i.replace(/plugins: \[\s*tailwindcss\(\)/,`plugins: [
21
+ ${i}`):a.includes("tanstack-router")?o=o.replace(/plugins: \[\s*tailwindcss\(\)/,`plugins: [
22
22
  tailwindcss(),
23
- ${o}`):i=i.replace(/plugins: \[/,`plugins: [
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}
23
+ ${i}`):o=o.replace(/plugins: \[/,`plugins: [
24
+ ${i},`)),await k.writeFile(n,o)}let s=I.join(r,"package.json");if(await k.pathExists(s)){let o=await k.readJson(s);o.scripts={...o.scripts,"generate-pwa-assets":"pwa-assets-generator"},await k.writeJson(s,o,{spaces:2})}}import oe from"node:path";import{log as ke}from"@clack/prompts";import xe from"picocolors";function $e(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=oe.join(e,"apps/server"),n=oe.join(e,"apps/web"),s=oe.join(e,"apps/native");try{g({dependencies:["better-auth"],projectDir:r}),(t.includes("react-router")||t.includes("tanstack-router")||t.includes("tanstack-start"))&&g({dependencies:["better-auth"],projectDir:n}),t.includes("native")&&(g({dependencies:["better-auth","@better-auth/expo"],projectDir:s}),g({dependencies:["@better-auth/expo"],projectDir:r}))}catch(o){throw ke.error(xe.red("Failed to configure authentication")),o instanceof Error&&ke.error(xe.red(o.message)),o}}import Wt from"node:path";async function Se(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"),g({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:o="drizzle",runtime:i="bun",frontend:p=["tanstack-router"]}=e,c=p.includes("react-router"),d=p.includes("tanstack-router"),w=p.includes("native"),$=t==="npm"?"npm run":t,A=c?"5173":"3001";return`# ${a}
25
25
 
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.
26
+ This project was created with [Better-T-Stack](https://github.com/AmanVarshney01/create-better-t-stack), a modern TypeScript stack that combines React, ${d?"TanStack Router":"React Router"}, Hono, tRPC, and more.
27
27
 
28
28
  ## Features
29
29
 
30
- ${Kt(r,n,s,i,o,p)}
30
+ ${Kt(r,n,s,o,i,p)}
31
31
 
32
32
  ## Getting Started
33
33
 
@@ -37,16 +37,16 @@ First, install the dependencies:
37
37
  ${t} install
38
38
  \`\`\`
39
39
 
40
- ${Xt(r,n,b,i)}
40
+ ${Xt(r,n,$,o)}
41
41
 
42
42
  Then, run the development server:
43
43
 
44
44
  \`\`\`bash
45
- ${b} dev
45
+ ${$} dev
46
46
  \`\`\`
47
47
 
48
- ${l||c?`Open [http://localhost:${k}](http://localhost:${k}) in your browser to see the web application.`:""}
49
- ${m?`Use the Expo Go app to run the mobile application.
48
+ ${d||c?`Open [http://localhost:${A}](http://localhost:${A}) in your browser to see the web application.`:""}
49
+ ${w?`Use the Expo Go app to run the mobile application.
50
50
  `:""}
51
51
  The API is running at [http://localhost:3000](http://localhost:3000).
52
52
 
@@ -62,15 +62,15 @@ See: https://github.com/vite-pwa/vite-plugin-pwa/issues/809
62
62
  \`\`\`
63
63
  ${a}/
64
64
  \u251C\u2500\u2500 apps/
65
- ${l||c?`\u2502 \u251C\u2500\u2500 web/ # Frontend application (React, ${l?"TanStack Router":"React Router"})
66
- `:""}${m?`\u2502 \u251C\u2500\u2500 native/ # Mobile application (React Native, Expo)
65
+ ${d||c?`\u2502 \u251C\u2500\u2500 web/ # Frontend application (React, ${d?"TanStack Router":"React Router"})
66
+ `:""}${w?`\u2502 \u251C\u2500\u2500 native/ # Mobile application (React Native, Expo)
67
67
  `:""}\u2502 \u2514\u2500\u2500 server/ # Backend API (Hono, tRPC)
68
68
  \`\`\`
69
69
 
70
70
  ## Available Scripts
71
71
 
72
- ${Yt(b,r,i,n,m)}
73
- `}function Kt(e,a,t,r,n,s){let i=s.includes("tanstack-router"),o=s.includes("react-router"),p=s.includes("native"),c=["- **TypeScript** - For type safety and improved developer experience"];i?c.push("- **TanStack Router** - File-based routing with full type safety"):o&&c.push("- **React Router** - Declarative routing for React"),p&&(c.push("- **React Native** - Build mobile apps using React"),c.push("- **Expo** - Tools for React Native development")),c.push("- **TailwindCSS** - Utility-first CSS for rapid UI development","- **shadcn/ui** - Reusable UI components","- **Hono** - Lightweight, performant server framework","- **tRPC** - End-to-end type-safe APIs",`- **${n==="bun"?"Bun":"Node.js"}** - Runtime environment`),e!=="none"&&c.push(`- **${r==="drizzle"?"Drizzle":"Prisma"}** - TypeScript-first ORM`,`- **${e==="sqlite"?"SQLite/Turso":"PostgreSQL"}** - Database engine`),a&&c.push("- **Authentication** - Email & password authentication with Better Auth");for(let l of t)l==="pwa"?c.push("- **PWA** - Progressive Web App support"):l==="tauri"?c.push("- **Tauri** - Build native desktop applications"):l==="biome"?c.push("- **Biome** - Linting and formatting"):l==="husky"&&c.push("- **Husky** - Git hooks for code quality");return c.join(`
72
+ ${Yt($,r,o,n,w)}
73
+ `}function Kt(e,a,t,r,n,s){let o=s.includes("tanstack-router"),i=s.includes("react-router"),p=s.includes("native"),c=["- **TypeScript** - For type safety and improved developer experience"];o?c.push("- **TanStack Router** - File-based routing with full type safety"):i&&c.push("- **React Router** - Declarative routing for React"),p&&(c.push("- **React Native** - Build mobile apps using React"),c.push("- **Expo** - Tools for React Native development")),c.push("- **TailwindCSS** - Utility-first CSS for rapid UI development","- **shadcn/ui** - Reusable UI components","- **Hono** - Lightweight, performant server framework","- **tRPC** - End-to-end type-safe APIs",`- **${n==="bun"?"Bun":"Node.js"}** - Runtime environment`),e!=="none"&&c.push(`- **${r==="drizzle"?"Drizzle":"Prisma"}** - TypeScript-first ORM`,`- **${e==="sqlite"?"SQLite/Turso":"PostgreSQL"}** - Database engine`),a&&c.push("- **Authentication** - Email & password authentication with Better Auth");for(let d of t)d==="pwa"?c.push("- **PWA** - Progressive Web App support"):d==="tauri"?c.push("- **Tauri** - Build native desktop applications"):d==="biome"?c.push("- **Biome** - Linting and formatting"):d==="husky"&&c.push("- **Husky** - Git hooks for code quality");return c.join(`
74
74
  `)}function Xt(e,a,t,r){if(e==="none")return"";let n=`## Database Setup
75
75
 
76
76
  `;return e==="sqlite"?n+=`This project uses SQLite${r==="drizzle"?" with Drizzle ORM":" with Prisma"}.
@@ -101,34 +101,34 @@ ${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 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
- ${n}`,await oe.writeFile(t,r.trim())}function Te(){M.info(`MongoDB Atlas Setup:
104
+ - \`cd apps/server && ${e} db:local\`: Start the local SQLite database`)),s}import Le from"node:path";import{log as ka,spinner as xa}from"@clack/prompts";import $a from"fs-extra";import Me from"picocolors";import Ce from"node:path";import{cancel as Zt,isCancel as ea,log as O,text as ta}from"@clack/prompts";import{execa as aa}from"execa";import ie from"fs-extra";import N from"picocolors";import{execa as Te}from"execa";async function Z(e){try{return process.platform==="win32"?(await Te("where",[e])).exitCode===0:(await Te("which",[e])).exitCode===0}catch{return!1}}async function ra(){return Z("atlas")}async function na(e){try{if(!await ra())return O.error(N.red("MongoDB Atlas CLI not found.")),O.info(N.yellow("Please install it from: https://www.mongodb.com/docs/atlas/cli/current/install-atlas-cli/")),null;O.info(N.yellow("Setting up MongoDB Atlas...")),await aa("atlas",["deployments","setup"],{cwd:e,stdio:"inherit"}),O.info(N.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&&O.error(N.red(a.message)),null}}async function ce(e,a){let t=Ce.join(e,"apps/server",".env"),r="";await ie.pathExists(t)&&(r=await ie.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
+ ${n}`,await ie.writeFile(t,r.trim())}function De(){O.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 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:
111
+ 5. Add to .env as DATABASE_URL="your_connection_string"`)}async function Re(e){let a=Ce.join(e,"apps/server");try{let t=await na(a);t?(await ce(e,t),O.success(N.green("MongoDB Atlas connection string saved to .env file!"))):(await ce(e),De())}catch(t){O.error(N.red(`Error during MongoDB Atlas setup: ${t}`)),await ce(e),De()}}import W from"node:path";import{cancel as sa,isCancel as oa,log as L,password as ia}from"@clack/prompts";import{execa as ca}from"execa";import B from"fs-extra";import V from"picocolors";async function pa(e,a){try{L.info(V.blue("Initializing Prisma PostgreSQL"));let t=W.join(e,"prisma");await B.ensureDir(t),await ca(a==="npm"?"npx":a==="pnpm"?"pnpm dlx":"bunx",["prisma","init","--db"],{cwd:e,stdio:"inherit"}),L.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 ia({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 oa(n)?(sa("Database setup cancelled"),null):{databaseUrl:n}}catch(t){return t instanceof Error&&L.error(V.red(t.message)),null}}async function pe(e,a){let t=W.join(e,"apps/server",".env"),r="";await B.pathExists(t)&&(r=await B.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 B.writeFile(t,r.trim())}function Fe(){L.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),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,`
120
+ DATABASE_URL="your_database_url"`)}async function Ie(e,a="npm"){let t=W.join(e,"apps/server");try{let r=await pa(t,a);r?(await pe(e,r),await la(t),L.success(V.green("Prisma PostgreSQL database configured successfully!"))):(await pe(e),Fe())}catch(r){L.error(V.red(`Error during Prisma PostgreSQL setup: ${r}`)),await pe(e),Fe(),L.info("Setup completed with manual configuration required.")}}async function la(e){try{g({dependencies:["@prisma/extension-accelerate"],projectDir:e});let a=W.join(e,"prisma/index.ts");await B.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 _.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}"
127
+ `.trim());let r=W.join(e,"src/db/index.ts");if(await B.pathExists(r)){let n=await B.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 B.writeFile(r,n))}}catch{L.warn(V.yellow("Could not add Prisma Accelerate extension automatically"))}}import da from"node:os";import Oe from"node:path";import{cancel as le,confirm as ua,isCancel as de,log as G,select as ma,spinner as ue,text as fa}from"@clack/prompts";import{$ as R}from"execa";import ha from"fs-extra";import T from"picocolors";async function ga(){return Z("turso")}async function ba(){try{return!(await R`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 R`turso auth login`,e.stop("Logged in to Turso successfully!"),!0}catch(a){throw e.stop(T.red("Failed to log in to Turso")),a}}async function Pa(e){let a=ue();try{if(a.start("Installing Turso CLI..."),e)await R`brew install tursodatabase/tap/turso`;else{let{stdout:t}=await R`curl -sSfL https://get.tur.so/install.sh`;await R`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(),G.warn(T.yellow("Turso CLI installation cancelled by user")),new Error("Installation cancelled")):(a.stop(T.red("Failed to install Turso CLI")),t)}}async function ya(){try{let{stdout:e}=await R`turso group list`,a=e.trim().split(`
129
+ `);return a.length<=1?[]:a.slice(1).map(r=>{let[n,s,o,i]=r.trim().split(/\s{2,}/);return{name:n,locations:s,version:o,status:i}})}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(T.red("Operation cancelled")),process.exit(0)),t}async function va(e,a){try{a?await R`turso db create ${e} --group ${a}`:await R`turso db create ${e}`}catch(n){throw n instanceof Error&&n.message.includes("already exists")?new Error("DATABASE_EXISTS"):n}let{stdout:t}=await R`turso db show ${e} --url`,{stdout:r}=await R`turso db tokens create ${e}`;return{dbUrl:t.trim(),authToken:r.trim()}}async function J(e,a){let t=Oe.join(e,"apps/server",".env"),r=a?`DATABASE_URL="${a.dbUrl}"
130
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:
131
+ DATABASE_AUTH_TOKEN=`;await ha.writeFile(t,r)}function ee(){G.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
@@ -136,18 +136,10 @@ DATABASE_AUTH_TOKEN=`;await ha.writeFile(t,r)}function te(){W.info(`Manual Turso
136
136
  4. Add these credentials to the .env file in apps/server/.env
137
137
 
138
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
- CORS_ORIGIN=${b}`}if(a.auth&&(n.includes("BETTER_AUTH_SECRET")||(n+=`
141
- BETTER_AUTH_SECRET=${ke()}`),n.includes("BETTER_AUTH_URL")||(n+=`
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
- 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("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";
139
+ DATABASE_AUTH_TOKEN=your_auth_token`)}async function Be(e,a){if(!a){await J(e),G.info(T.blue("Skipping Turso setup. Setting up empty configuration.")),ee();return}let t=da.platform(),r=t==="darwin";if(!(t!=="win32")){G.warn(T.yellow("Automatic Turso setup is not supported on Windows.")),await J(e),ee();return}try{if(!await ga()){let w=await ua({message:"Would you like to install Turso CLI?",initialValue:!0});if(de(w)&&(le(T.red("Operation cancelled")),process.exit(0)),!w){await J(e),ee();return}await Pa(r)}await ba()||await wa();let i=await ja(),p=!1,c="",d=Oe.basename(e);for(;!p;){let w=await fa({message:"Enter a name for your database:",defaultValue:d,initialValue:d,placeholder:d});de(w)&&(le(T.red("Operation cancelled")),process.exit(0)),c=w;let $=ue();try{$.start(`Creating Turso database "${c}"${i?` in group "${i}"`:""}...`);let A=await va(c,i);await J(e,A),$.stop("Turso database configured successfully!"),p=!0}catch(A){if(A instanceof Error&&A.message==="DATABASE_EXISTS")$.stop(T.yellow(`Database "${T.red(c)}" already exists`)),d=`${c}-${Math.floor(Math.random()*1e3)}`;else throw $.stop(T.red("Failed to create Turso database")),A}}}catch(s){G.error(T.red(`Error during Turso setup: ${s}`)),await J(e),ee(),G.success("Setup completed with manual configuration required.")}}async function ze(e,a,t,r,n,s,o){let i=xa(),p=Le.join(e,"apps/server");if(a==="none"){await $a.remove(Le.join(p,"src/db"));return}try{t==="prisma"?g({dependencies:["@prisma/client"],devDependencies:["prisma"],projectDir:p}):t==="drizzle"&&(a==="sqlite"?g({dependencies:["drizzle-orm","@libsql/client"],devDependencies:["drizzle-kit"],projectDir:p}):a==="postgres"?g({dependencies:["drizzle-orm","postgres"],devDependencies:["drizzle-kit"],projectDir:p}):a==="mysql"&&g({dependencies:["drizzle-orm","mysql2"],devDependencies:["drizzle-kit"],projectDir:p})),a==="sqlite"&&n?await Be(e,t==="drizzle"):a==="postgres"&&t==="prisma"&&s?await Ie(e,r):a==="mongodb"&&o&&await Re(e)}catch(c){throw i.stop(Me.red("Failed to set up database")),c instanceof Error&&ka.error(Me.red(c.message)),c}}import U from"node:path";import te from"fs-extra";async function me(e,a){await te.ensureDir(U.dirname(e));let t="";await te.pathExists(e)&&(t=await te.readFile(e,"utf8"));let r=!1;for(let{key:n,value:s,condition:o}of a)if(o){let i=new RegExp(`^${n}=.*$`,"m");i.test(t)?s&&(t=t.replace(i,`${n}=${s}`),r=!0):(t+=`
140
+ ${n}=${s}`,r=!0)}r&&await te.writeFile(e,t.trim())}async function Ne(e,a){let t=U.join(e,"apps/server"),r=U.join(t,".env"),n=a.frontend.includes("react-router"),s=a.frontend.includes("tanstack-router"),o=a.frontend.includes("tanstack-start"),i=n||s||o,p="http://localhost:3000";n?p="http://localhost:5173":(s||o)&&(p="http://localhost:3001");let c="",d=a.dbSetup==="turso"||a.dbSetup==="prisma-postgres"||a.dbSetup==="mongodb-atlas";d||(a.database==="postgres"?c="postgresql://postgres:postgres@localhost:5432/mydb?schema=public":a.database==="mysql"?c="mysql://root:password@localhost:3306/mydb":a.database==="mongodb"?c="mongodb://localhost:27017/mydatabase":a.database==="sqlite"&&(c="file:./local.db"));let w=[{key:"CORS_ORIGIN",value:p,condition:!0},{key:"BETTER_AUTH_SECRET",value:$e(),condition:!!a.auth},{key:"BETTER_AUTH_URL",value:"http://localhost:3000",condition:!!a.auth},{key:"DATABASE_URL",value:c,condition:a.database!=="none"&&c!==""&&!d},{key:"GOOGLE_GENERATIVE_AI_API_KEY",value:"",condition:a.examples?.includes("ai")||!1}];if(await me(r,w),i){let $=U.join(e,"apps/web"),A=[{key:"VITE_SERVER_URL",value:"http://localhost:3000",condition:!0}];await me(U.join($,".env"),A)}if(a.frontend.includes("native")){let $=U.join(e,"apps/native"),A=[{key:"EXPO_PUBLIC_SERVER_URL",value:"http://localhost:3000",condition:!0}];await me(U.join($,".env"),A)}}import x from"node:path";import b from"fs-extra";async function Ue(e,a,t,r,n,s=["tanstack-router"]){let o=s.includes("tanstack-router"),i=s.includes("tanstack-start"),p=s.includes("react-router"),c=o||p||i,d;o?d="web-tanstack-router":i?d="web-tanstack-start":d="web-react-router";let w=await b.pathExists(x.join(e,"apps/web"));a.includes("todo")&&c&&w?await Ta(e,t,r,d):await Ra(e,t),a.includes("ai")&&(n==="hono"||n==="express")&&c&&w&&await Aa(e,d)}async function Aa(e,a){let t=x.join(v,"template/examples/ai");if(await b.pathExists(t)){let r=x.join(t,`apps/${a}/src/routes/ai.tsx`),n=x.join(e,"apps/web/src/routes/ai.tsx");await b.pathExists(r)&&await b.copy(r,n,{overwrite:!0}),await Ea(e,a);let s=x.join(e,"apps/web");g({dependencies:["ai"],projectDir:s});let o=x.join(e,"apps/server");g({dependencies:["ai","@ai-sdk/google"],projectDir:o}),await Sa(e)}}async function Sa(e){let a=x.join(e,"apps/server/src/index.ts");if(await b.pathExists(a)){let t=await b.readFile(a,"utf8"),r=t.includes("hono"),n=t.includes("express");if(r){let s=`import { streamText } from "ai";
149
141
  import { google } from "@ai-sdk/google";
150
- import { stream } from "hono/streaming";`,i=`
142
+ import { stream } from "hono/streaming";`,o=`
151
143
  // AI chat endpoint
152
144
  app.post("/ai", async (c) => {
153
145
  const body = await c.req.json();
@@ -167,14 +159,14 @@ app.post("/ai", async (c) => {
167
159
  ${s}
168
160
  ${t.substring(c+1)}`}else t=`${s}
169
161
 
170
- ${t}`;let o=t.indexOf('app.use("/trpc"')||t.indexOf("app.use(trpc(");if(o!==-1)t=`${t.substring(0,o)}${i}
162
+ ${t}`;let i=t.indexOf('app.use("/trpc"')||t.indexOf("app.use(trpc(");if(i!==-1)t=`${t.substring(0,i)}${o}
171
163
 
172
- ${t.substring(o)}`;else{let p=t.indexOf("export default");p!==-1?t=`${t.substring(0,p)}${i}
164
+ ${t.substring(i)}`;else{let p=t.indexOf("export default");p!==-1?t=`${t.substring(0,p)}${o}
173
165
 
174
166
  ${t.substring(p)}`:t=`${t}
175
167
 
176
- ${i}`}}else if(n){let s=`import { streamText } from "ai";
177
- import { google } from "@ai-sdk/google";`,i=`
168
+ ${o}`}}else if(n){let s=`import { streamText } from "ai";
169
+ import { google } from "@ai-sdk/google";`,o=`
178
170
  // AI chat endpoint
179
171
  app.post("/ai", async (req, res) => {
180
172
  const { messages = [] } = req.body;
@@ -190,66 +182,66 @@ app.post("/ai", async (req, res) => {
190
182
  ${s}
191
183
  ${t.substring(c+1)}`}else t=`${s}
192
184
 
193
- ${t}`;let o=t.indexOf('app.use("/trpc"');if(o!==-1)t=`${t.substring(0,o)}${i}
185
+ ${t}`;let i=t.indexOf('app.use("/trpc"');if(i!==-1)t=`${t.substring(0,i)}${o}
194
186
 
195
- ${t.substring(o)}`;else{let p=t.indexOf("app.listen(");if(p!==-1){let c=t.lastIndexOf(`
196
- `,p);t=`${t.substring(0,c)}${i}
187
+ ${t.substring(i)}`;else{let p=t.indexOf("app.listen(");if(p!==-1){let c=t.lastIndexOf(`
188
+ `,p);t=`${t.substring(0,c)}${o}
197
189
 
198
190
  ${t.substring(c)}`}else t=`${t}
199
191
 
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
- ${i}${i.trim().endsWith(",")?"":","}
192
+ ${o}`}}await b.writeFile(a,t)}}async function Ea(e,a){let t=x.join(e,"apps/web/src/components/header.tsx");if(await b.pathExists(t)){let r=await b.readFile(t,"utf8"),n=/const links = \[\s*([^;]*?)\s*\];/s,s=r.match(n);if(s){let o=s[1];if(!o.includes('"/ai"')){let i=`const links = [
193
+ ${o}${o.trim().endsWith(",")?"":","}
202
194
  { to: "/ai", label: "AI Chat" },
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(`
195
+ ];`;r=r.replace(n,i),await b.writeFile(t,r)}}}}async function Ta(e,a,t,r){let n=x.join(v,"template/examples/todo");if(await b.pathExists(n)){let s=x.join(n,`apps/${r}/src/routes/todos.tsx`),o=x.join(e,"apps/web/src/routes/todos.tsx");if(await b.pathExists(s)&&await b.copy(s,o,{overwrite:!0}),a!=="none"){let i=x.join(n,`apps/server/src/routers/with-${a}-todo.ts`),p=x.join(e,"apps/server/src/routers/todo.ts");await b.pathExists(i)&&await b.copy(i,p,{overwrite:!0}),await Da(e)}await Ca(e,r)}}async function Da(e){let a=x.join(e,"apps/server/src/routers/index.ts");if(await b.pathExists(a)){let t=await b.readFile(a,"utf8");if(!t.includes("import { todoRouter }")){let r=t.lastIndexOf("import"),n=t.indexOf(`
204
196
 
205
197
  `,r);n!==-1?t=`${t.slice(0,n)}
206
198
  import { todoRouter } from "./todo";${t.slice(n)}`:t=`import { todoRouter } from "./todo";
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 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
- ${i}${i.trim().endsWith(",")?"":","}
199
+ ${t}`;let s=t.indexOf("export const appRouter = router({");if(s!==-1){let o=t.indexOf("{",s)+1;t=`${t.slice(0,o)}
200
+ todo: todoRouter,${t.slice(o)}`}await b.writeFile(a,t)}}}async function Ca(e,a){let t=x.join(e,"apps/web/src/components/header.tsx");if(await b.pathExists(t)){let r=await b.readFile(t,"utf8"),n=/const links = \[\s*([^;]*?)\s*\];/s,s=r.match(n);if(s){let o=s[1];if(!o.includes('"/todos"')){let i=`const links = [
201
+ ${o}${o.trim().endsWith(",")?"":","}
210
202
  { 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=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
- ${b.trim()}`:""}${k?`
222
- ${k.trim()}`:""}${j?`
223
- ${j.trim()}`:""}${T?`
224
- ${T.trim()}`:""}
225
-
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
203
+ ];`;r=r.replace(n,i),await b.writeFile(t,r)}}}}async function Ra(e,a){if(a==="drizzle"){let r=x.join(e,"apps/server/src/db/schema/todo.ts");await b.pathExists(r)&&await b.remove(r)}else if(a==="prisma"){let r=x.join(e,"apps/server/prisma/schema/todo.prisma");await b.pathExists(r)&&await b.remove(r)}let t=x.join(e,"apps/server/src/routers/todo.ts");await b.pathExists(t)&&await b.remove(t),await Fa(e)}async function Fa(e){let a=x.join(e,"apps/server/src/routers/index.ts");if(await b.pathExists(a)){let t=await b.readFile(a,"utf8");t=t.replace(/import { todoRouter } from ".\/todo";/,""),t=t.replace(/todo: todoRouter,/,""),await b.writeFile(a,t)}}import{log as _e,spinner as qe}from"@clack/prompts";import{$ as Ve}from"execa";import ae from"picocolors";async function Ge({projectDir:e,packageManager:a,addons:t=[]}){let r=qe();try{r.start(`Running ${a} install...`),await Ve({cwd:e,stderr:"inherit"})`${a} install`,r.stop("Dependencies installed successfully"),(t.includes("biome")||t.includes("husky"))&&await Ia(e,a)}catch(n){throw r.stop(ae.red("Failed to install dependencies")),n instanceof Error&&_e.error(ae.red(`Installation error: ${n.message}`)),n}}async function Ia(e,a){let t=qe();try{t.start("Running Biome format check..."),await Ve({cwd:e,stderr:"inherit"})`${a} biome check --write .`,t.stop("Biome check completed successfully")}catch{t.stop(ae.yellow("Biome check encountered issues")),_e.warn(ae.yellow("Some files may need manual formatting"))}}import{note as Oa}from"@clack/prompts";import y from"picocolors";function We(e,a,t,r,n,s,o,i,p){let c=t==="npm"?"npm run":t,d=`cd ${a}`,w=s?.includes("husky")||s?.includes("biome"),$=e!=="none"?Ma(e,n,c,o):"",A=s?.includes("tauri")?za(c):"",Q=w?La(c):"",q=i?.includes("native")?Ba():"",E=s?.includes("pwa")&&i?.includes("react-router")?Na():"",F=i?.includes("tanstack-router"),C=i?.includes("tanstack-start"),ge=i?.includes("react-router"),be=F||ge||C,Rt=i?.includes("native"),Ft=be||Rt,It=ge?"5173":"3001";Oa(`${y.cyan("1.")} ${d}
204
+ ${r?"":`${y.cyan("2.")} ${t} install
205
+ `}${y.cyan(r?"2.":"3.")} ${c} dev
206
+
207
+ ${y.bold("Your project will be available at:")}
208
+ ${Ft?`${be?`${y.cyan("\u2022")} Frontend: http://localhost:${It}
209
+ `:""}`:`${y.yellow("NOTE:")} You are creating a backend-only app (no frontend selected)
210
+ `}${y.cyan("\u2022")} API: http://localhost:3000
211
+ ${q?`
212
+ ${q.trim()}`:""}${$?`
213
+ ${$.trim()}`:""}${A?`
214
+ ${A.trim()}`:""}${Q?`
215
+ ${Q.trim()}`:""}${E?`
216
+ ${E.trim()}`:""}
217
+
218
+ ${y.bold("Like Better-T Stack?")} Please consider giving us a star on GitHub:
219
+ ${y.cyan("https://github.com/AmanVarshney01/create-better-t-stack")}`,"Next steps")}function Ba(){return`${y.yellow("NOTE:")} For Expo connectivity issues, update apps/native/.env
228
220
  with your local IP:
229
221
  EXPO_PUBLIC_SERVER_URL=http://192.168.0.103:3000
230
- `}function Ma(e){return`${x.bold("Linting and formatting:")}
231
- ${x.cyan("\u2022")} Format and lint fix: ${`${e} check`}
222
+ `}function La(e){return`${y.bold("Linting and formatting:")}
223
+ ${y.cyan("\u2022")} Format and lint fix: ${`${e} check`}
232
224
 
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:")}
225
+ `}function Ma(e,a,t,r){let n=[];return a==="prisma"?(e==="sqlite"&&n.push(`${y.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(`${y.yellow("NOTE:")} Prisma with Bun may require additional configuration. If you encounter errors,
226
+ follow the guidance provided in the error messages`),n.push(`${y.cyan("\u2022")} Apply schema: ${`${t} db:push`}`),n.push(`${y.cyan("\u2022")} Database UI: ${`${t} db:studio`}`)):a==="drizzle"&&(n.push(`${y.cyan("\u2022")} Apply schema: ${`${t} db:push`}`),n.push(`${y.cyan("\u2022")} Database UI: ${`${t} db:studio`}`)),n.length?`${y.bold("Database commands:")}
235
227
  ${n.join(`
236
228
  `)}
237
229
 
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.
230
+ `:""}function za(e){return`
231
+ ${y.bold("Desktop app with Tauri:")}
232
+ ${y.cyan("\u2022")} Start desktop app: ${`cd apps/web && ${e} desktop:dev`}
233
+ ${y.cyan("\u2022")} Build desktop app: ${`cd apps/web && ${e} desktop:build`}
234
+ ${y.yellow("NOTE:")} Tauri requires Rust and platform-specific dependencies.
243
235
  See: https://v2.tauri.app/start/prerequisites/
244
236
 
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.
237
+ `}function Na(){return`${y.bold("PWA with React Router v7:")}
238
+ ${y.yellow("NOTE:")} There is a known compatibility issue between VitePWA and React Router v7.
247
239
  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 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}
240
+ `}import re from"node:path";import{log as Ua}from"@clack/prompts";import{$ as Je,execa as _a}from"execa";import M from"fs-extra";import qa from"picocolors";async function He(e,a){await Va(e,a),await Ga(e,a)}async function Va(e,a){let t=re.join(e,"package.json");if(await M.pathExists(t)){let r=await M.readJson(t);r.name=a.projectName;let{stdout:n}=await _a(a.packageManager,["-v"],{cwd:e});if(r.packageManager=`${a.packageManager}@${n.trim()}`,await M.writeJson(t,r,{spaces:2}),a.packageManager==="pnpm"){let s=re.join(v,"template/with-pnpm/pnpm-workspace.yaml"),o=re.join(e,"pnpm-workspace.yaml");await M.pathExists(s)&&await M.copy(s,o)}}}async function Ga(e,a){let t=re.join(e,"apps/server/package.json");if(await M.pathExists(t)){let r=await M.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 M.writeJson(t,r,{spaces:2})}}async function Qe(e,a){if(!a)return;if((await Je({cwd:e,reject:!1,stderr:"pipe"})`git --version`).exitCode!==0){Ua.warn(qa.yellow("Git is not installed"));return}let r=await Je({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 Ke(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 Wa(r,n,s,t):a==="node"&&await Ja(r,n,s,t)}async function Wa(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}),g({devDependencies:["@types/bun"],projectDir:e}),r==="hono"){let o=`${t}
249
241
 
250
242
  export default app;
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";
252
- `,o=`
243
+ `;await z.writeFile(a,o)}}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:"tsx watch src/index.ts",start:"node dist/src/index.js"},await z.writeJson(n,s,{spaces:2}),g({devDependencies:["tsx","@types/node"],projectDir:e}),r==="hono"){g({dependencies:["@hono/node-server"],projectDir:e});let o=`import { serve } from "@hono/node-server";
244
+ `,i=`
253
245
  serve(
254
246
  {
255
247
  fetch: app.fetch,
@@ -259,14 +251,14 @@ serve(
259
251
  console.log(\`Server is running on http://localhost:\${info.port}\`);
260
252
  },
261
253
  );
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
- `,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(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
- `,o=s.lastIndexOf("import"),p=s.indexOf(`
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 $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=`
254
+ `;if(!t.includes("@hono/node-server")){let p=t.lastIndexOf("import"),c=t.substring(0,p),d=t.substring(p),w=c+o+d+i;await z.writeFile(a,w)}}else if(r==="elysia"&&(g({dependencies:["@elysiajs/node"],projectDir:e}),!t.includes("@elysiajs/node"))){let o=`import { node } from "@elysiajs/node";
255
+ `,i=t.indexOf(`
256
+ `,t.indexOf("import")),p=t.substring(0,i+1),c=t.substring(i+1),d=p+o+c;d=d.replace(/const app = new Elysia\([^)]*\)/,"const app = new Elysia({ adapter: node() })"),await z.writeFile(a,d)}}import u from"node:path";import l from"fs-extra";async function Xe(e){let a=u.join(v,"template/base");if(!await l.pathExists(a))throw new Error(`Template directory not found: ${a}`);await l.ensureDir(e);let t=await l.readdir(a);for(let s of t){let o=u.join(a,s),i=u.join(e,s);s!=="apps"&&(await l.stat(o).then(p=>p.isDirectory())?await l.copy(o,i):await l.copy(o,i))}await l.ensureDir(u.join(e,"apps"));let r=u.join(a,"apps/server"),n=u.join(e,"apps/server");await l.pathExists(r)&&await l.copy(r,n)}async function Ye(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 o=u.join(e,"apps/web");await l.ensureDir(o);let i=u.join(v,"template/base/apps/web-base");await l.pathExists(i)&&await l.copy(i,o);let p="web-react-router";t?p="web-tanstack-router":r&&(p="web-tanstack-start");let c=u.join(v,`template/base/apps/${p}`);await l.pathExists(c)&&await l.copy(c,o,{overwrite:!0});let d=u.join(o,"package.json");if(await l.pathExists(d)){let w=await l.readJson(d);w.name="web",await l.writeJson(d,w,{spaces:2})}}if(s){let o=u.join(v,"template/base/apps/native"),i=u.join(e,"apps/native");await l.pathExists(o)&&await l.copy(o,i),await l.writeFile(u.join(e,".npmrc"),`node-linker=hoisted
257
+ `)}}async function Ze(e,a){let t=u.join(v,`template/with-${a}`);await l.pathExists(t)&&await l.copy(t,e,{overwrite:!0})}async function et(e,a,t,r){if(a==="none"||t==="none")return;let n=u.join(v,Qa(a,t));if(await l.pathExists(n)&&(await l.copy(n,e,{overwrite:!0}),!r)){if(a==="prisma"){let s=u.join(e,"apps/server/prisma/schema/auth.prisma");await l.pathExists(s)&&await l.remove(s)}else if(a==="drizzle"){let s=u.join(e,"apps/server/src/db/schema/auth.ts");await l.pathExists(s)&&await l.remove(s)}}}async function tt(e,a,t,r,n,s){if(!a)return;let o=u.join(v,"template/with-auth");if(await l.pathExists(o)){let i=s.includes("react-router"),p=s.includes("tanstack-router"),c=s.includes("tanstack-start");if(i||p||c){let E=u.join(e,"apps/web"),F=u.join(o,"apps/web-base");if(await l.pathExists(F)&&await l.copy(F,E,{overwrite:!0}),i){let C=u.join(o,"apps/web-react-router");await l.pathExists(C)&&await l.copy(C,E,{overwrite:!0})}if(p){let C=u.join(o,"apps/web-tanstack-router");await l.pathExists(C)&&await l.copy(C,E,{overwrite:!0})}if(c){let C=u.join(o,"apps/web-tanstack-start");await l.pathExists(C)&&await l.copy(C,E,{overwrite:!0})}}let d=u.join(o,"apps/server/src"),w=u.join(e,"apps/server/src");await l.copy(u.join(d,"lib/trpc.ts"),u.join(w,"lib/trpc.ts"),{overwrite:!0}),await l.copy(u.join(d,"routers/index.ts"),u.join(w,"routers/index.ts"),{overwrite:!0});let $=`with-${t}-context.ts`;await l.copy(u.join(d,"lib",$),u.join(w,"lib/context.ts"),{overwrite:!0});let A=`with-${t}-index.ts`;await l.copy(u.join(d,A),u.join(w,"index.ts"),{overwrite:!0});let Q=Ka(r,n),q=u.join(d,Q);if(await l.pathExists(q)){let E=await l.readdir(q);for(let F of E)await l.copy(u.join(q,F),u.join(w,"lib",F),{overwrite:!0})}if(s.includes("native")){let E=u.join(o,"apps/native"),F=u.join(e,"apps/native");await l.pathExists(E)&&await l.copy(E,F,{overwrite:!0}),g({dependencies:["@better-auth/expo"],projectDir:u.join(e,"apps/server")}),await Ha(e,r,n)}}}async function Ha(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 l.pathExists(n)){let s=await l.readFile(n,"utf8");if(!s.includes("@better-auth/expo")){let o=`import { expo } from "@better-auth/expo";
258
+ `,i=s.lastIndexOf("import"),p=s.indexOf(`
259
+ `,i)+1;s=s.substring(0,p)+o+s.substring(p)}s.includes("plugins:")?s.includes("expo()")||(s=s.replace(/plugins: \[(.*?)\]/s,(o,i)=>`plugins: [${i}${i.trim()?", ":""}expo()]`)):s=s.replace(/}\);/,` plugins: [expo()],
260
+ });`),s.includes("my-better-t-app://")||(s=s.replace(/trustedOrigins: \[(.*?)\]/s,(o,i)=>`trustedOrigins: [${i}${i.trim()?", ":""}"my-better-t-app://"]`)),await l.writeFile(n,s)}}async function at(e){let a=await rt(e);for(let t of a)if(await l.pathExists(t)){let r=u.join(u.dirname(t),".gitignore");await l.move(t,r,{overwrite:!0})}}async function rt(e){let a=[],t=u.join(e,"_gitignore");await l.pathExists(t)&&a.push(t);try{let r=await l.readdir(e,{withFileTypes:!0});for(let n of r)if(n.isDirectory()&&n.name!=="node_modules"){let s=u.join(e,n.name),o=await rt(s);a.push(...o)}}catch{}return a}function Qa(e,a){if(e==="drizzle"){if(a==="sqlite")return"template/with-drizzle-sqlite";if(a==="postgres")return"template/with-drizzle-postgres";if(a==="mysql")return"template/with-drizzle-mysql"}if(e==="prisma"){if(a==="sqlite")return"template/with-prisma-sqlite";if(a==="postgres")return"template/with-prisma-postgres";if(a==="mysql")return"template/with-prisma-mysql";if(a==="mongodb")return"template/with-prisma-mongodb"}return"template/base"}function Ka(e,a){if(e==="drizzle"){if(a==="sqlite")return"with-drizzle-sqlite-lib";if(a==="postgres")return"with-drizzle-postgres-lib";if(a==="mysql")return"with-drizzle-mysql-lib"}if(e==="prisma"){if(a==="sqlite")return"with-prisma-sqlite-lib";if(a==="postgres")return"with-prisma-postgres-lib";if(a==="mysql")return"with-prisma-mysql-lib";if(a==="mongodb")return"with-prisma-mongodb-lib"}throw new Error("Invalid ORM or database configuration for auth setup")}async function st(e){let a=Za(),t=Xa.resolve(process.cwd(),e.projectName);try{return await er.ensureDir(t),await Xe(t),await Ye(t,e.frontend),await at(t),await Ze(t,e.backend),await Se(t,e.backend,e.runtime),await et(t,e.orm,e.database,e.auth),await ze(t,e.database,e.orm,e.packageManager,e.dbSetup==="turso",e.dbSetup==="prisma-postgres",e.dbSetup==="mongodb-atlas"),await tt(t,e.auth,e.backend,e.orm,e.database,e.frontend),await Ae(t,e.auth,e.frontend),await Ke(t,e.runtime,e.backend),await Ue(t,e.examples,e.orm,e.auth,e.backend,e.frontend),await Ne(t,e),await Qe(t,e.git),e.addons.length>0&&await ve(t,e.addons,e.packageManager,e.frontend),await He(t,e),await Ee(t,e),e.noInstall||await Ge({projectDir:t,packageManager:e.packageManager,addons:e.addons}),We(e.database,e.projectName,e.packageManager,!e.noInstall,e.orm,e.addons,e.runtime,e.frontend),t}catch(r){throw a.message(nt.red("Failed")),r instanceof Error&&(Ya(nt.red(`Error during project creation: ${r.message}`)),process.exit(1)),r}}import{cancel as Yr,group as Zr}from"@clack/prompts";import en from"picocolors";import{cancel as tr,isCancel as ar,multiselect as rr}from"@clack/prompts";import nr from"picocolors";async function ot(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,o=P.addons.filter(p=>t||p!=="pwa"&&p!=="tauri"),i=await rr({message:"Select addons",options:s,initialValues:o,required:!1});return ar(i)&&(tr(nr.red("Operation cancelled")),process.exit(0)),i.includes("husky")&&!i.includes("biome")&&i.push("biome"),i}import{cancel as sr,confirm as or,isCancel as ir}from"@clack/prompts";import cr 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:P.auth});return ir(r)&&(sr(cr.red("Operation cancelled")),process.exit(0)),r}import{cancel as pr,isCancel as lr,select as dr}from"@clack/prompts";import ur from"picocolors";async function ct(e){if(e!==void 0)return e;let a=await dr({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:P.backend});return lr(a)&&(pr(ur.red("Operation cancelled")),process.exit(0)),a}import{cancel as mr,isCancel as fr,select as hr}from"@clack/prompts";import gr from"picocolors";async function pt(e){if(e!==void 0)return e;let a=await hr({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:"mysql",label:"MySQL",hint:"popular open-source relational database system"},{value:"mongodb",label:"MongoDB",hint:"open-source NoSQL database that stores data in JSON-like documents called BSON"}],initialValue:P.database});return fr(a)&&(mr(gr.red("Operation cancelled")),process.exit(0)),a}import{cancel as br,isCancel as wr,select as Pr}from"@clack/prompts";import yr from"picocolors";async function lt(e,a,t){if(a!==void 0)return a;if(e==="sqlite"&&t==="prisma")return"none";let r=[];if(e==="sqlite")r=[{value:"turso",label:"Turso",hint:"SQLite for Production. Powered by libSQL"},{value:"none",label:"None",hint:"Manual setup"}];else if(e==="postgres")r=[{value:"prisma-postgres",label:"Prisma Postgres",hint:"Instant Postgres for Global Applications"},{value:"none",label:"None",hint:"Manual setup"}];else if(e==="mongodb")r=[{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 n=await Pr({message:`Select ${e} setup option`,options:r,initialValue:"none"});return wr(n)&&(br(yr.red("Operation cancelled")),process.exit(0)),n}import{cancel as jr,isCancel as vr,multiselect as dt}from"@clack/prompts";import kr from"picocolors";async function ut(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 dt({message:"Include examples",options:[{value:"todo",label:"Todo App",hint:"A simple CRUD example app"}],required:!1,initialValues:P.examples})),(r==="hono"||r==="express")&&(s=await dt({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:P.examples})),vr(s)&&(jr(kr.red("Operation cancelled")),process.exit(0)),s}import{cancel as mt,isCancel as ft,multiselect as xr,select as $r}from"@clack/prompts";import ht from"picocolors";async function gt(e){if(e!==void 0)return e;let a=await xr({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:P.frontend.some(r=>r==="tanstack-router"||r==="react-router"||r==="tanstack-start")?["web"]:[]});ft(a)&&(mt(ht.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:P.frontend.find(n=>n==="tanstack-router"||n==="react-router"||n==="tanstack-start")||"tanstack-router"});ft(r)&&(mt(ht.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 Er}from"@clack/prompts";import Tr from"picocolors";async function bt(e){if(e!==void 0)return e;let a=await Sr({message:"Initialize git repository?",initialValue:P.git});return Er(a)&&(Ar(Tr.red("Operation cancelled")),process.exit(0)),a}import{cancel as Dr,confirm as Cr,isCancel as Rr}from"@clack/prompts";import Fr from"picocolors";async function wt(e){if(e!==void 0)return e;let a=await Cr({message:"Install dependencies?",initialValue:!P.noInstall});return Rr(a)&&(Dr(Fr.red("Operation cancelled")),process.exit(0)),!a}import{cancel as Ir,isCancel as Or,log as Br,select as Lr}from"@clack/prompts";import Mr from"picocolors";async function Pt(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 Lr({message:"Select ORM",options:[{value:"drizzle",label:"Drizzle",hint:"lightweight and performant TypeScript ORM"},{value:"prisma",label:"Prisma",hint:"Powerful, feature-rich ORM"}],initialValue:P.orm});return Or(r)&&(Ir(Mr.red("Operation cancelled")),process.exit(0)),r}import{cancel as zr,isCancel as Nr,select as Ur}from"@clack/prompts";import _r from"picocolors";async function yt(e){if(e!==void 0)return e;let a=K(),t=await Ur({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)&&(zr(_r.red("Operation cancelled")),process.exit(0)),t}import H from"node:path";import{cancel as qr,isCancel as Vr,text as Gr}from"@clack/prompts";import _ from"fs-extra";import Wr from"picocolors";var Jr=["<",">",":",'"',"|","?","*"],jt=255;function vt(e){if(e!=="."){if(!e)return"Project name cannot be empty";if(e.length>jt)return`Project name must be less than ${jt} characters`;if(Jr.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 kt(e){if(e)if(e==="."){let s=process.cwd();if(_.readdirSync(s).length===0)return e}else{let s=H.basename(e);if(!vt(s)){let i=H.resolve(process.cwd(),e);if(!_.pathExistsSync(i)||_.readdirSync(i).length===0)return e}}let a=!1,t="",r=P.projectName,n=1;for(;_.pathExistsSync(H.resolve(process.cwd(),r));)r=`${P.projectName}-${n}`,n++;for(;!a;){let s=await Gr({message:"Enter your project name or path (relative to current directory)",placeholder:r,initialValue:e,defaultValue:r,validate:o=>{let i=o.trim()||r;if(i==="."){if(_.readdirSync(process.cwd()).length>0)return"Current directory is not empty. Please choose a different directory.";a=!0;return}let p=H.resolve(process.cwd(),i),c=H.basename(p),d=vt(c);if(d)return d;if(!p.startsWith(process.cwd()))return"Project path must be within current directory";if(_.pathExistsSync(p)&&_.readdirSync(p).length>0)return`Directory "${i}" already exists and is not empty. Please choose a different name or path.`;a=!0}});Vr(s)&&(qr(Wr.red("Operation cancelled.")),process.exit(0)),t=s||r}return t}import{cancel as Hr,isCancel as Qr,select as Kr}from"@clack/prompts";import Xr from"picocolors";async function xt(e){if(e!==void 0)return e;let a=await Kr({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:P.runtime});return Qr(a)&&(Hr(Xr.red("Operation cancelled")),process.exit(0)),a}async function $t(e){let a=await Zr({projectName:async()=>kt(e.projectName),frontend:()=>gt(e.frontend),backend:()=>ct(e.backend),runtime:()=>xt(e.runtime),database:()=>pt(e.database),orm:({results:t})=>Pt(e.orm,t.database!=="none",t.database),auth:({results:t})=>it(e.auth,t.database!=="none",t.frontend),dbSetup:({results:t})=>lt(t.database??"none",e.dbSetup,t.orm),addons:({results:t})=>ot(e.addons,t.frontend),examples:({results:t})=>ut(e.examples,t.database,t.frontend,t.backend),git:()=>bt(e.git),packageManager:()=>yt(e.packageManager),noInstall:()=>wt(e.noInstall)},{onCancel:()=>{Yr(en.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 S from"picocolors";function fe(e){let a=[];if(e.projectName&&a.push(`${S.blue("Project Name:")} ${e.projectName}`),e.frontend!==void 0){let t=e.frontend.length>0?e.frontend.join(", "):"none";a.push(`${S.blue("Frontend:")} ${t}`)}if(e.backend!==void 0&&a.push(`${S.blue("Backend Framework:")} ${e.backend}`),e.runtime!==void 0&&a.push(`${S.blue("Runtime:")} ${e.runtime}`),e.database!==void 0&&a.push(`${S.blue("Database:")} ${e.database}`),e.orm!==void 0&&a.push(`${S.blue("ORM:")} ${e.orm}`),e.auth!==void 0&&a.push(`${S.blue("Authentication:")} ${e.auth}`),e.addons!==void 0){let t=e.addons.length>0?e.addons.join(", "):"none";a.push(`${S.blue("Addons:")} ${t}`)}if(e.examples!==void 0){let t=e.examples.length>0?e.examples.join(", "):"none";a.push(`${S.blue("Examples:")} ${t}`)}return e.git!==void 0&&a.push(`${S.blue("Git Init:")} ${e.git}`),e.packageManager!==void 0&&a.push(`${S.blue("Package Manager:")} ${e.packageManager}`),e.noInstall!==void 0&&a.push(`${S.blue("Skip Install:")} ${e.noInstall}`),e.dbSetup!==void 0&&a.push(`${S.blue("Database Setup:")} ${e.dbSetup}`),a.join(`
261
+ `)}function At(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 tn from"node:path";import an from"fs-extra";var St=()=>{let e=tn.join(v,"package.json");return an.readJSONSync(e).version??"1.0.0"};import Et from"gradient-string";var Tt=`
270
262
  \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
263
  \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
264
  \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 +272,10 @@ serve(
280
272
  \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
273
  \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
274
  \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
- `,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(`
275
+ `,Dt={pink:"#F5C2E7",mauve:"#CBA6F7",red:"#F38BA8",maroon:"#E78284",peach:"#FAB387",yellow:"#F9E2AF",green:"#A6E3A1",teal:"#94E2D5",sky:"#89DCEB",sapphire:"#74C7EC",lavender:"#B4BEFE"},Ct=()=>{let e=process.stdout.columns||80,a=Tt.split(`
276
+ `),t=Math.max(...a.map(r=>r.length));e<t?console.log(Et(Object.values(Dt)).multiline(`
285
277
  \u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557
286
278
  \u2551 Better T-Stack \u2551
287
279
  \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(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)});
280
+ `)):console.log(Et(Object.values(Dt)).multiline(Tt))};process.on("SIGINT",()=>{D.error(h.red("Operation cancelled")),process.exit(0)});var he=new on;async function cn(){let e=Date.now();he.name("create-better-t-stack").description("Create a new Better-T Stack project").version(St()).argument("[project-directory]","Project name/directory").option("-y, --yes","Use default configuration").option("--database <type>","Database type (none, sqlite, postgres, mysql, 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=sn();try{Ct(),rn(h.magenta("Creating a new Better-T-Stack project"));let t=he.opts(),r=he.args[0],n=pn(t,r);!t.yes&&Object.keys(n).length>0&&(D.info(h.yellow("Using these pre-selected options:")),D.message(fe(n)),D.message(""));let s=t.yes?{...P,projectName:r??P.projectName,...n}:await $t(n);t.yes&&(D.info(h.yellow("Using these default options:")),D.message(fe(s)),D.message("")),await st(s),D.success(h.blue(`You can reproduce this setup with the following command:
281
+ ${h.white(At(s))}`));let o=((Date.now()-e)/1e3).toFixed(2);nn(h.magenta(`Project created successfully in ${h.bold(o)} seconds!`))}catch(t){a.stop(h.red("Failed")),t instanceof Error&&(j(h.red(`An unexpected error occurred: ${t.message}`)),process.exit(1))}}function pn(e,a){let t={};if(e.database&&(["none","sqlite","postgres","mysql","mongodb"].includes(e.database)||(j(h.red(`Invalid database type: ${e.database}. Must be none, sqlite, postgres, mysql, or mongodb.`)),process.exit(1)),t.database=e.database),e.orm&&(["drizzle","prisma"].includes(e.orm)||(j(h.red(`Invalid ORM type: ${e.orm}. Must be drizzle or prisma.`)),process.exit(1)),t.orm=e.orm),t.database==="mongodb"&&t.orm==="drizzle"&&(j(h.red("MongoDB is only available with Prisma. Cannot use --database mongodb with --orm drizzle")),process.exit(1)),e.dbSetup&&(["turso","prisma-postgres","mongodb-atlas","none"].includes(e.dbSetup)||(j(h.red(`Invalid database setup: ${e.dbSetup}. Must be turso, prisma-postgres, mongodb-atlas, or none.`)),process.exit(1)),e.dbSetup!=="none"?(t.dbSetup=e.dbSetup,e.dbSetup==="turso"?(e.database&&e.database!=="sqlite"&&(j(h.red(`Turso setup requires a SQLite database. Cannot use --db-setup turso with --database ${e.database}`)),process.exit(1)),t.database="sqlite",e.orm==="prisma"&&(j(h.red("Turso setup is not compatible with Prisma. Cannot use --db-setup turso with --orm prisma")),process.exit(1)),t.orm="drizzle"):e.dbSetup==="prisma-postgres"?(e.database&&e.database!=="postgres"&&(j(h.red("Prisma PostgreSQL setup requires PostgreSQL database. Cannot use --db-setup prisma-postgres with a different database type.")),process.exit(1)),t.database="postgres",e.orm&&e.orm!=="prisma"&&(j(h.red("Prisma PostgreSQL setup requires Prisma ORM. Cannot use --db-setup prisma-postgres with a different ORM.")),process.exit(1)),t.orm="prisma"):e.dbSetup==="mongodb-atlas"&&(e.database&&e.database!=="mongodb"&&(j(h.red("MongoDB Atlas setup requires MongoDB database. Cannot use --db-setup mongodb-atlas with a different database type.")),process.exit(1)),t.database="mongodb",t.orm="prisma")):t.dbSetup="none"),t.database==="none"&&(e.auth===!0&&(j(h.red("Authentication requires a database. Cannot use --auth with --database none.")),process.exit(1)),e.orm&&e.orm!=="none"&&(j(h.red(`Cannot use ORM with no database. Cannot use --orm ${e.orm} with --database none.`)),process.exit(1)),e.dbSetup&&e.dbSetup!=="none"&&(j(h.red(`Database setup requires a database. Cannot use --db-setup ${e.dbSetup} with --database none.`)),process.exit(1))),"auth"in e&&(t.auth=e.auth),e.backend&&(["hono","elysia","express"].includes(e.backend)||(j(h.red(`Invalid backend framework: ${e.backend}. Must be hono, elysia, or express.`)),process.exit(1)),t.backend=e.backend),e.runtime&&(["bun","node"].includes(e.runtime)||(j(h.red(`Invalid runtime: ${e.runtime}. Must be bun or node.`)),process.exit(1)),t.runtime=e.runtime),e.frontend&&e.frontend.length>0){let r=["tanstack-router","react-router","tanstack-start","native","none"],n=e.frontend.filter(s=>!r.includes(s));if(n.length>0&&(j(h.red(`Invalid frontend(s): ${n.join(", ")}. Valid options are: ${r.join(", ")}.`)),process.exit(1)),e.frontend.includes("none"))e.frontend.length>1&&(j(h.red("Cannot combine 'none' with other frontend options.")),process.exit(1)),t.frontend=[];else{let s=e.frontend.filter(i=>i==="tanstack-router"||i==="react-router"||i==="tanstack-start"||i==="native");s.filter(i=>i==="tanstack-router"||i==="react-router"||i==="tanstack-start").length>1&&(j(h.red("Cannot select multiple web frameworks. Choose only one of: tanstack-router, tanstack-start, react-router")),process.exit(1)),t.frontend=s}}if(e.addons&&e.addons.length>0){let r=["pwa","tauri","biome","husky","none"],n=e.addons.filter(s=>!r.includes(s));if(n.length>0&&(j(h.red(`Invalid addon(s): ${n.join(", ")}. Valid options are: ${r.join(", ")}.`)),process.exit(1)),e.addons.includes("none"))e.addons.length>1&&(j(h.red("Cannot combine 'none' with other addons.")),process.exit(1)),t.addons=[];else{let s=e.addons.filter(c=>c==="pwa"||c==="tauri"||c==="biome"||c==="husky"),o=["pwa","tauri"],i=s.some(c=>o.includes(c)),p=t.frontend?.some(c=>c==="tanstack-router"||c==="react-router");i&&!p&&(j(h.red("PWA and Tauri addons require tanstack-router or react-router. Cannot use these addons with your frontend selection.")),process.exit(1)),s.includes("husky")&&!s.includes("biome")&&s.push("biome"),t.addons=s}}if("examples"in e){if(e.examples===!1)t.examples=[];else if(Array.isArray(e.examples)){let r=["todo","ai"],n=e.examples.filter(o=>!r.includes(o));n.length>0&&(j(h.red(`Invalid example(s): ${n.join(", ")}. Valid options are: ${r.join(", ")}.`)),process.exit(1)),e.examples.includes("ai")&&(e.backend==="elysia"||t.backend==="elysia")&&(j(h.red("AI example is only compatible with Hono backend. Cannot use --examples ai with --backend elysia")),process.exit(1));let s=t.frontend?.some(o=>["tanstack-router","react-router","tanstack-start"].includes(o));e.examples.length>0&&!s&&(!e.frontend||!e.frontend.some(o=>["tanstack-router","react-router","tanstack-start"].includes(o)))&&(j(h.red("Examples require a web frontend (tanstack-router, react-router, or tanstack-start). Cannot use --examples without a compatible frontend.")),process.exit(1)),t.examples=e.examples.filter(o=>o==="todo"||o==="ai")}}return e.packageManager&&(["npm","pnpm","bun"].includes(e.packageManager)||(j(h.red(`Invalid package manager: ${e.packageManager}. Must be npm, pnpm, or bun.`)),process.exit(1)),t.packageManager=e.packageManager),"git"in e&&(t.git=e.git),"install"in e&&(t.noInstall=!e.install),a&&(t.projectName=a),t}cn().catch(e=>{D.error("Aborting installation..."),e instanceof Error?D.error(e.message):(D.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-better-t-stack",
3
- "version": "1.9.2",
3
+ "version": "1.10.1",
4
4
  "description": "A modern CLI tool for scaffolding end-to-end type-safe TypeScript projects with best practices and customizable configurations",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -18,10 +18,12 @@
18
18
  "persistent": true
19
19
  },
20
20
  "db:push": {
21
- "cache": false
21
+ "cache": false,
22
+ "persistent": true
22
23
  },
23
24
  "db:studio": {
24
- "cache": false
25
+ "cache": false,
26
+ "persistent": true
25
27
  }
26
28
  }
27
29
  }
@@ -12,12 +12,9 @@ export const todoRouter = router({
12
12
  create: publicProcedure
13
13
  .input(z.object({ text: z.string().min(1) }))
14
14
  .mutation(async ({ input }) => {
15
- return await db
16
- .insert(todo)
17
- .values({
18
- text: input.text,
19
- })
20
- .returning();
15
+ return await db.insert(todo).values({
16
+ text: input.text,
17
+ });
21
18
  }),
22
19
 
23
20
  toggle: publicProcedure
@@ -26,16 +23,12 @@ export const todoRouter = router({
26
23
  return await db
27
24
  .update(todo)
28
25
  .set({ completed: input.completed })
29
- .where(eq(todo.id, input.id))
30
- .returning();
26
+ .where(eq(todo.id, input.id));
31
27
  }),
32
28
 
33
29
  delete: publicProcedure
34
30
  .input(z.object({ id: z.number() }))
35
31
  .mutation(async ({ input }) => {
36
- return await db
37
- .delete(todo)
38
- .where(eq(todo.id, input.id))
39
- .returning();
32
+ return await db.delete(todo).where(eq(todo.id, input.id));
40
33
  }),
41
34
  });
@@ -0,0 +1,15 @@
1
+ import { betterAuth } from "better-auth";
2
+ import { drizzleAdapter } from "better-auth/adapters/drizzle";
3
+ import { db } from "../db";
4
+ import * as schema from "../db/schema/auth";
5
+
6
+ export const auth = betterAuth({
7
+ database: drizzleAdapter(db, {
8
+ provider: "mysql",
9
+ schema: schema,
10
+ }),
11
+ trustedOrigins: [process.env.CORS_ORIGIN || ""],
12
+ emailAndPassword: {
13
+ enabled: true,
14
+ },
15
+ });
@@ -8,10 +8,4 @@ export const auth = betterAuth({
8
8
  }),
9
9
  trustedOrigins: [process.env.CORS_ORIGIN || ""],
10
10
  emailAndPassword: { enabled: true },
11
- advanced: {
12
- defaultCookieAttributes: {
13
- sameSite: "none",
14
- secure: true,
15
- },
16
- },
17
11
  });
@@ -0,0 +1,11 @@
1
+ import { betterAuth } from "better-auth";
2
+ import { prismaAdapter } from "better-auth/adapters/prisma";
3
+ import prisma from "../../prisma";
4
+
5
+ export const auth = betterAuth({
6
+ database: prismaAdapter(prisma, {
7
+ provider: "mysql",
8
+ }),
9
+ trustedOrigins: [process.env.CORS_ORIGIN || ""],
10
+ emailAndPassword: { enabled: true },
11
+ });
@@ -8,10 +8,4 @@ export const auth = betterAuth({
8
8
  }),
9
9
  trustedOrigins: [process.env.CORS_ORIGIN || ""],
10
10
  emailAndPassword: { enabled: true },
11
- advanced: {
12
- defaultCookieAttributes: {
13
- sameSite: "none",
14
- secure: true,
15
- },
16
- },
17
11
  });
@@ -8,10 +8,4 @@ export const auth = betterAuth({
8
8
  }),
9
9
  trustedOrigins: [process.env.CORS_ORIGIN || ""],
10
10
  emailAndPassword: { enabled: true },
11
- advanced: {
12
- defaultCookieAttributes: {
13
- sameSite: "none",
14
- secure: true,
15
- },
16
- },
17
11
  });
@@ -0,0 +1,10 @@
1
+ import { defineConfig } from "drizzle-kit";
2
+
3
+ export default defineConfig({
4
+ schema: "./src/db/schema",
5
+ out: "./src/db/migrations",
6
+ dialect: "mysql",
7
+ dbCredentials: {
8
+ url: process.env.DATABASE_URL || "",
9
+ },
10
+ });
@@ -0,0 +1,3 @@
1
+ import { drizzle } from "drizzle-orm/mysql2";
2
+
3
+ export const db = drizzle({ connection: { uri: process.env.DATABASE_URL } });
@@ -0,0 +1,58 @@
1
+ import {
2
+ mysqlTable,
3
+ varchar,
4
+ text,
5
+ timestamp,
6
+ boolean,
7
+ } from "drizzle-orm/mysql-core";
8
+
9
+ export const user = mysqlTable("user", {
10
+ id: varchar("id", { length: 36 }).primaryKey(),
11
+ name: text("name").notNull(),
12
+ email: varchar("email", { length: 255 }).notNull().unique(),
13
+ emailVerified: boolean("email_verified").notNull(),
14
+ image: text("image"),
15
+ createdAt: timestamp("created_at").notNull(),
16
+ updatedAt: timestamp("updated_at").notNull(),
17
+ });
18
+
19
+ export const session = mysqlTable("session", {
20
+ id: varchar("id", { length: 36 }).primaryKey(),
21
+ expiresAt: timestamp("expires_at").notNull(),
22
+ token: varchar("token", { length: 255 }).notNull().unique(),
23
+ createdAt: timestamp("created_at").notNull(),
24
+ updatedAt: timestamp("updated_at").notNull(),
25
+ ipAddress: text("ip_address"),
26
+ userAgent: text("user_agent"),
27
+ userId: varchar("user_id", { length: 36 })
28
+ .notNull()
29
+ .references(() => user.id, { onDelete: "cascade" }),
30
+ });
31
+
32
+ export const account = mysqlTable("account", {
33
+ id: varchar("id", { length: 36 }).primaryKey(),
34
+ accountId: text("account_id").notNull(),
35
+ providerId: text("provider_id").notNull(),
36
+ userId: varchar("user_id", { length: 36 })
37
+ .notNull()
38
+ .references(() => user.id, { onDelete: "cascade" }),
39
+ accessToken: text("access_token"),
40
+ refreshToken: text("refresh_token"),
41
+ idToken: text("id_token"),
42
+
43
+ accessTokenExpiresAt: timestamp("access_token_expires_at"),
44
+ refreshTokenExpiresAt: timestamp("refresh_token_expires_at"),
45
+ scope: text("scope"),
46
+ password: text("password"),
47
+ createdAt: timestamp("created_at").notNull(),
48
+ updatedAt: timestamp("updated_at").notNull(),
49
+ });
50
+
51
+ export const verification = mysqlTable("verification", {
52
+ id: varchar("id", { length: 36 }).primaryKey(),
53
+ identifier: text("identifier").notNull(),
54
+ value: text("value").notNull(),
55
+ expiresAt: timestamp("expires_at").notNull(),
56
+ createdAt: timestamp("created_at"),
57
+ updatedAt: timestamp("updated_at"),
58
+ });
@@ -0,0 +1,7 @@
1
+ import { mysqlTable, varchar, int, boolean } from "drizzle-orm/mysql-core";
2
+
3
+ export const todo = mysqlTable("todo", {
4
+ id: int("id").primaryKey().autoincrement(),
5
+ text: varchar("text", { length: 255 }).notNull(),
6
+ completed: boolean("completed").default(false).notNull(),
7
+ });
@@ -1,5 +1,5 @@
1
1
  import { PrismaClient } from "@prisma/client";
2
2
 
3
- let prisma = new PrismaClient();
3
+ const prisma = new PrismaClient();
4
4
 
5
5
  export default prisma;
@@ -0,0 +1,5 @@
1
+ import { PrismaClient } from "@prisma/client";
2
+
3
+ const prisma = new PrismaClient();
4
+
5
+ export default prisma;
@@ -0,0 +1,59 @@
1
+ model User {
2
+ id String @id
3
+ name String @db.Text
4
+ email String
5
+ emailVerified Boolean
6
+ image String? @db.Text
7
+ createdAt DateTime
8
+ updatedAt DateTime
9
+ sessions Session[]
10
+ accounts Account[]
11
+
12
+ @@unique([email])
13
+ @@map("user")
14
+ }
15
+
16
+ model Session {
17
+ id String @id
18
+ expiresAt DateTime
19
+ token String
20
+ createdAt DateTime
21
+ updatedAt DateTime
22
+ ipAddress String? @db.Text
23
+ userAgent String? @db.Text
24
+ userId String
25
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
26
+
27
+ @@unique([token])
28
+ @@map("session")
29
+ }
30
+
31
+ model Account {
32
+ id String @id
33
+ accountId String @db.Text
34
+ providerId String @db.Text
35
+ userId String
36
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
37
+ accessToken String? @db.Text
38
+ refreshToken String? @db.Text
39
+ idToken String? @db.Text
40
+ accessTokenExpiresAt DateTime?
41
+ refreshTokenExpiresAt DateTime?
42
+ scope String? @db.Text
43
+ password String? @db.Text
44
+ createdAt DateTime
45
+ updatedAt DateTime
46
+
47
+ @@map("account")
48
+ }
49
+
50
+ model Verification {
51
+ id String @id
52
+ identifier String @db.Text
53
+ value String @db.Text
54
+ expiresAt DateTime
55
+ createdAt DateTime?
56
+ updatedAt DateTime?
57
+
58
+ @@map("verification")
59
+ }
@@ -0,0 +1,9 @@
1
+ generator client {
2
+ provider = "prisma-client-js"
3
+ previewFeatures = ["prismaSchemaFolder"]
4
+ }
5
+
6
+ datasource db {
7
+ provider = "mysql"
8
+ url = env("DATABASE_URL")
9
+ }
@@ -0,0 +1,7 @@
1
+ model Todo {
2
+ id Int @id @default(autoincrement())
3
+ text String
4
+ completed Boolean @default(false)
5
+
6
+ @@map("todo")
7
+ }
@@ -1,5 +1,5 @@
1
1
  import { PrismaClient } from "@prisma/client";
2
2
 
3
- let prisma = new PrismaClient();
3
+ const prisma = new PrismaClient();
4
4
 
5
5
  export default prisma;
@@ -1,5 +1,5 @@
1
1
  import { PrismaClient } from "@prisma/client";
2
2
 
3
- let prisma = new PrismaClient();
3
+ const prisma = new PrismaClient();
4
4
 
5
5
  export default prisma;