create-better-t-stack 1.9.1 → 1.10.0
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 +88 -96
- package/package.json +1 -1
- package/template/base/turbo.json +4 -2
- package/template/examples/todo/apps/server/src/routers/with-drizzle-todo.ts +5 -12
- package/template/with-auth/apps/server/src/with-drizzle-mysql-lib/auth.ts +15 -0
- package/template/with-auth/apps/server/src/with-prisma-mongodb-lib/auth.ts +0 -6
- package/template/with-auth/apps/server/src/with-prisma-mysql-lib/auth.ts +11 -0
- package/template/with-auth/apps/server/src/with-prisma-postgres-lib/auth.ts +0 -6
- package/template/with-auth/apps/server/src/with-prisma-sqlite-lib/auth.ts +0 -6
- package/template/with-drizzle-mysql/apps/server/drizzle.config.ts +10 -0
- package/template/with-drizzle-mysql/apps/server/src/db/index.ts +3 -0
- package/template/with-drizzle-mysql/apps/server/src/db/schema/auth.ts +58 -0
- package/template/with-drizzle-mysql/apps/server/src/db/schema/todo.ts +7 -0
- package/template/with-drizzle-sqlite/apps/server/drizzle.config.ts +2 -2
- package/template/with-drizzle-sqlite/apps/server/src/db/index.ts +2 -2
- package/template/with-prisma-mysql/apps/server/prisma/index.ts +5 -0
- package/template/with-prisma-mysql/apps/server/prisma/schema/auth.prisma +59 -0
- package/template/with-prisma-mysql/apps/server/prisma/schema/schema.prisma +9 -0
- package/template/with-prisma-mysql/apps/server/prisma/schema/todo.prisma +7 -0
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{cancel as
|
|
3
|
-
${p[0]}`):
|
|
4
|
-
${
|
|
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
|
-
})`;
|
|
19
|
+
})`;o.includes("VitePWA(")||(a.includes("react-router")?o=o.replace(/plugins: \[\s*tailwindcss\(\)/,`plugins: [
|
|
20
20
|
tailwindcss(),
|
|
21
|
-
${
|
|
21
|
+
${i}`):a.includes("tanstack-router")?o=o.replace(/plugins: \[\s*tailwindcss\(\)/,`plugins: [
|
|
22
22
|
tailwindcss(),
|
|
23
|
-
${
|
|
24
|
-
${
|
|
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, ${
|
|
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,
|
|
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
|
|
40
|
+
${Xt(r,n,$,o)}
|
|
41
41
|
|
|
42
42
|
Then, run the development server:
|
|
43
43
|
|
|
44
44
|
\`\`\`bash
|
|
45
|
-
${
|
|
45
|
+
${$} dev
|
|
46
46
|
\`\`\`
|
|
47
47
|
|
|
48
|
-
${
|
|
49
|
-
${
|
|
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
|
-
${
|
|
66
|
-
`:""}${
|
|
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(
|
|
73
|
-
`}function Kt(e,a,t,r,n,s){let
|
|
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,53 +101,45 @@ ${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 Le from"node:path";import{log as
|
|
105
|
-
${n}`,await
|
|
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
|
|
112
|
-
It looks like: prisma+postgres://accelerate.prisma-data.net/?api_key=...`));let n=await
|
|
113
|
-
${n}`,await
|
|
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=
|
|
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=
|
|
128
|
-
${n}`,n=n.replace("export const db = new PrismaClient();","export const db = new PrismaClient().$extends(withAccelerate());"),await
|
|
129
|
-
`);return a.length<=1?[]:a.slice(1).map(r=>{let[n,s,i
|
|
130
|
-
|
|
131
|
-
|
|
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
|
+
DATABASE_AUTH_TOKEN="${a.authToken}"`:`DATABASE_URL=
|
|
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
|
|
135
135
|
3. Get your database URL and authentication token
|
|
136
136
|
4. Add these credentials to the .env file in apps/server/.env
|
|
137
137
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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("TURSO_CONNECTION_URL")||(n+=`
|
|
145
|
-
TURSO_CONNECTION_URL=http://127.0.0.1:8080`))}a.examples?.includes("ai")&&!n.includes("GOOGLE_GENERATIVE_AI_API_KEY")&&(n+=`
|
|
146
|
-
GOOGLE_GENERATIVE_AI_API_KEY=`),await L.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 Ea(c)}if(a.frontend.includes("native")){let c=J.join(e,"apps/native"),l=J.join(c,".env"),m="";await L.pathExists(l)&&(m=await L.readFile(l,"utf8")),m.includes("EXPO_PUBLIC_SERVER_URL")||(m+=`EXPO_PUBLIC_SERVER_URL=http://localhost:3000
|
|
147
|
-
`),await L.writeFile(l,m.trim())}}async function Ea(e){let a=J.join(e,".env"),t="";await L.pathExists(a)&&(t=await L.readFile(a,"utf8")),t.includes("VITE_SERVER_URL")||(t+=`VITE_SERVER_URL=http://localhost:3000
|
|
148
|
-
`),await L.writeFile(a,t.trim())}import A from"node:path";import P from"fs-extra";async function _e(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(A.join(e,"apps/web"));a.includes("todo")&&c&&m?await Ra(e,t,r,l):await Ia(e,t),a.includes("ai")&&(n==="hono"||n==="express")&&c&&m&&await Aa(e,l)}async function Aa(e,a){let t=A.join($,"template/examples/ai");if(await P.pathExists(t)){let r=A.join(t,`apps/${a}/src/routes/ai.tsx`),n=A.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=A.join(e,"apps/web");w({dependencies:["ai"],projectDir:s});let i=A.join(e,"apps/server");w({dependencies:["ai","@ai-sdk/google"],projectDir:i}),await Sa(e)}}async function Sa(e){let a=A.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";
|
|
138
|
+
DATABASE_URL=your_database_url
|
|
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";`,
|
|
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
|
|
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(
|
|
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
|
-
${
|
|
177
|
-
import { google } from "@ai-sdk/google";`,
|
|
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
|
|
185
|
+
${t}`;let i=t.indexOf('app.use("/trpc"');if(i!==-1)t=`${t.substring(0,i)}${o}
|
|
194
186
|
|
|
195
|
-
${t.substring(
|
|
196
|
-
`,p);t=`${t.substring(0,c)}${
|
|
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
|
-
${
|
|
201
|
-
${
|
|
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,
|
|
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
|
|
208
|
-
todo: todoRouter,${t.slice(
|
|
209
|
-
${
|
|
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,
|
|
212
|
-
${r?"":`${
|
|
213
|
-
`}${
|
|
214
|
-
|
|
215
|
-
${
|
|
216
|
-
${
|
|
217
|
-
`:""}`:`${
|
|
218
|
-
`}${
|
|
219
|
-
${
|
|
220
|
-
${
|
|
221
|
-
${
|
|
222
|
-
${
|
|
223
|
-
${
|
|
224
|
-
${
|
|
225
|
-
|
|
226
|
-
${
|
|
227
|
-
${
|
|
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
|
|
231
|
-
${
|
|
222
|
+
`}function La(e){return`${y.bold("Linting and formatting:")}
|
|
223
|
+
${y.cyan("\u2022")} Format and lint fix: ${`${e} check`}
|
|
232
224
|
|
|
233
|
-
`}function
|
|
234
|
-
follow the guidance provided in the error messages`),n.push(`${
|
|
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
|
|
239
|
-
${
|
|
240
|
-
${
|
|
241
|
-
${
|
|
242
|
-
${
|
|
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
|
|
246
|
-
${
|
|
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
|
|
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,
|
|
252
|
-
`,
|
|
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),
|
|
263
|
-
`,
|
|
264
|
-
`,t.indexOf("import")),p=t.substring(0,
|
|
265
|
-
`)}}async function
|
|
266
|
-
`,
|
|
267
|
-
`,
|
|
268
|
-
});`),s.includes("my-better-t-app://")||(s=s.replace(/trustedOrigins: \[(.*?)\]/s,(i,o)=>`trustedOrigins: [${o}${o.trim()?", ":""}"my-better-t-app://"]`)),await d.writeFile(n,s)}}async function tt(e){let a=await at(e);for(let t of a)if(await d.pathExists(t)){let r=u.join(u.dirname(t),".gitignore");await d.move(t,r,{overwrite:!0})}}async function at(e){let a=[],t=u.join(e,"_gitignore");await d.pathExists(t)&&a.push(t);try{let r=await d.readdir(e,{withFileTypes:!0});for(let n of r)if(n.isDirectory()&&n.name!=="node_modules"){let s=u.join(e,n.name),i=await at(s);a.push(...i)}}catch{}return a}function Ka(e,a){if(e==="drizzle")return a==="sqlite"?"template/with-drizzle-sqlite":"template/with-drizzle-postgres";if(e==="prisma"){if(a==="sqlite")return"template/with-prisma-sqlite";if(a==="postgres")return"template/with-prisma-postgres";if(a==="mongodb")return"template/with-prisma-mongodb"}return"template/base"}function Xa(e,a){if(e==="drizzle")return a==="sqlite"?"with-drizzle-sqlite-lib":"with-drizzle-postgres-lib";if(e==="prisma"){if(a==="sqlite")return"with-prisma-sqlite-lib";if(a==="postgres")return"with-prisma-postgres-lib";if(a==="mongodb")return"with-prisma-mongodb-lib"}throw new Error("Invalid ORM or database configuration for auth setup")}async function nt(e){let a=er(),t=Ya.resolve(process.cwd(),e.projectName);try{return await tr.ensureDir(t),await Ke(t),await Xe(t,e.frontend),await tt(t),await Ye(t,e.backend),await Ee(t,e.backend,e.runtime),await Ze(t,e.orm,e.database,e.auth),await Me(t,e.database,e.orm,e.packageManager,e.dbSetup==="turso",e.dbSetup==="prisma-postgres",e.dbSetup==="mongodb-atlas"),await et(t,e.auth,e.backend,e.orm,e.database,e.frontend),await $e(t,e.auth,e.frontend),await Qe(t,e.runtime,e.backend),await _e(t,e.examples,e.orm,e.auth,e.backend,e.frontend),await Ne(t,e),await He(t,e.git),e.addons.length>0&&await je(t,e.addons,e.packageManager,e.frontend),await Je(t,e),await Ae(t,e),e.noInstall||await qe({projectDir:t,packageManager:e.packageManager,addons:e.addons}),Ve(e.database,e.projectName,e.packageManager,!e.noInstall,e.orm,e.addons,e.runtime,e.frontend),t}catch(r){throw a.message(rt.red("Failed")),r instanceof Error&&(Za(rt.red(`Error during project creation: ${r.message}`)),process.exit(1)),r}}import{cancel as Zr,group as en,log as tn}from"@clack/prompts";import kt from"picocolors";import{cancel as ar,isCancel as rr,multiselect as nr}from"@clack/prompts";import sr from"picocolors";async function st(e,a){if(e!==void 0)return e;let t=a?.includes("react-router")||a?.includes("tanstack-router"),r=[{value:"biome",label:"Biome",hint:"Add Biome for linting and formatting"},{value:"husky",label:"Husky",hint:"Add Git hooks with Husky, lint-staged (requires Biome)"}],s=t?[...[{value:"pwa",label:"PWA (Progressive Web App)",hint:"Make your app installable and work offline"},{value:"tauri",label:"Tauri Desktop App",hint:"Build native desktop apps from your web frontend"}],...r]:r,i=y.addons.filter(p=>t||p!=="pwa"&&p!=="tauri"),o=await nr({message:"Select addons",options:s,initialValues:i,required:!1});return rr(o)&&(ar(sr.red("Operation cancelled")),process.exit(0)),o.includes("husky")&&!o.includes("biome")&&o.push("biome"),o}import{cancel as ir,confirm as or,isCancel as cr}from"@clack/prompts";import pr from"picocolors";async function it(e,a,t){if(!a)return!1;if(e!==void 0)return e;let r=await or({message:"Add authentication with Better-Auth?",initialValue:y.auth});return cr(r)&&(ir(pr.red("Operation cancelled")),process.exit(0)),r}import{cancel as lr,isCancel as dr,select as ur}from"@clack/prompts";import mr from"picocolors";async function ot(e){if(e!==void 0)return e;let a=await ur({message:"Select backend framework",options:[{value:"hono",label:"Hono",hint:"Lightweight, ultrafast web framework"},{value:"express",label:"Express",hint:"Fast, unopinionated, minimalist web framework for Node.js"},{value:"elysia",label:"Elysia",hint:"Ergonomic web framework for building backend servers"}],initialValue:y.backend});return dr(a)&&(lr(mr.red("Operation cancelled")),process.exit(0)),a}import{cancel as fr,isCancel as hr,select as gr}from"@clack/prompts";import br from"picocolors";async function ct(e){if(e!==void 0)return e;let a=await gr({message:"Select database",options:[{value:"none",label:"None",hint:"No database setup"},{value:"sqlite",label:"SQLite",hint:"by Turso"},{value:"postgres",label:"PostgreSQL",hint:"Traditional relational database"},{value:"mongodb",label:"MongoDB",hint:"NoSQL document-oriented database"}],initialValue:y.database});return hr(a)&&(fr(br.red("Operation cancelled")),process.exit(0)),a}import{cancel as wr,isCancel as Pr,select as yr}from"@clack/prompts";import jr from"picocolors";async function pt(e,a){if(a!==void 0)return a;let t=[];if(e==="sqlite")t=[{value:"turso",label:"Turso",hint:"SQLite for Production. Powered by libSQL."},{value:"none",label:"None",hint:"Manual setup"}];else if(e==="postgres")t=[{value:"prisma-postgres",label:"Prisma Postgres",hint:"Instant Postgres for Global Applications"},{value:"none",label:"None",hint:"Manual setup"}];else if(e==="mongodb")t=[{value:"mongodb-atlas",label:"MongoDB Atlas",hint:"The most effective way to deploy MongoDB"},{value:"none",label:"None",hint:"Manual setup"}];else return"none";let r=await yr({message:`Select ${e} setup option`,options:t,initialValue:"none"});return Pr(r)&&(wr(jr.red("Operation cancelled")),process.exit(0)),r}import{cancel as xr,isCancel as vr,multiselect as lt}from"@clack/prompts";import kr from"picocolors";async function dt(e,a,t,r){if(e!==void 0)return e;if(a==="none")return[];if(!(t?.includes("react-router")||t?.includes("tanstack-router")||t?.includes("tanstack-start")))return[];let s=[];return r==="elysia"&&(s=await lt({message:"Include examples",options:[{value:"todo",label:"Todo App",hint:"A simple CRUD example app"}],required:!1,initialValues:y.examples})),(r==="hono"||r==="express")&&(s=await lt({message:"Include examples",options:[{value:"todo",label:"Todo App",hint:"A simple CRUD example app"},{value:"ai",label:"AI Chat",hint:"A simple AI chat interface using AI SDK"}],required:!1,initialValues:y.examples})),vr(s)&&(xr(kr.red("Operation cancelled")),process.exit(0)),s}import{cancel as ut,isCancel as mt,multiselect as $r,select as Er}from"@clack/prompts";import ft from"picocolors";async function ht(e){if(e!==void 0)return e;let a=await $r({message:"Select platforms to develop for",options:[{value:"web",label:"Web",hint:"React Web Application"},{value:"native",label:"Native",hint:"Create a React Native/Expo app"}],required:!1,initialValues:y.frontend.some(r=>r==="tanstack-router"||r==="react-router"||r==="tanstack-start")?["web"]:[]});mt(a)&&(ut(ft.red("Operation cancelled")),process.exit(0));let t=[];if(a.includes("web")){let r=await Er({message:"Choose frontend framework",options:[{value:"tanstack-router",label:"TanStack Router",hint:"Modern and scalable routing for React Applications"},{value:"react-router",label:"React Router",hint:"A user\u2011obsessed, standards\u2011focused, multi\u2011strategy router you can deploy anywhere."},{value:"tanstack-start",label:"TanStack Start (beta)",hint:"SSR, Streaming, Server Functions, API Routes, bundling and more powered by TanStack Router and Vite."}],initialValue:y.frontend.find(n=>n==="tanstack-router"||n==="react-router"||n==="tanstack-start")||"tanstack-router"});mt(r)&&(ut(ft.red("Operation cancelled")),process.exit(0)),t.push(r)}return a.includes("native")&&t.push("native"),t}import{cancel as Ar,confirm as Sr,isCancel as Tr}from"@clack/prompts";import Rr from"picocolors";async function gt(e){if(e!==void 0)return e;let a=await Sr({message:"Initialize git repository?",initialValue:y.git});return Tr(a)&&(Ar(Rr.red("Operation cancelled")),process.exit(0)),a}import{cancel as Cr,confirm as Dr,isCancel as Ir}from"@clack/prompts";import Fr from"picocolors";async function bt(e){if(e!==void 0)return e;let a=await Dr({message:"Install dependencies?",initialValue:!y.noInstall});return Ir(a)&&(Cr(Fr.red("Operation cancelled")),process.exit(0)),!a}import{cancel as Or,isCancel as Lr,log as Br,select as Mr}from"@clack/prompts";import Nr from"picocolors";async function wt(e,a,t){if(!a)return"none";if(e!==void 0)return e;if(t==="mongodb")return Br.info("Only Prisma is supported with MongoDB."),"prisma";let r=await Mr({message:"Select ORM",options:[{value:"drizzle",label:"Drizzle",hint:"Type-safe, lightweight ORM"},{value:"prisma",label:"Prisma",hint:"Powerful, feature-rich ORM"}],initialValue:y.orm});return Lr(r)&&(Or(Nr.red("Operation cancelled")),process.exit(0)),r}import{cancel as _r,isCancel as Ur,select as zr}from"@clack/prompts";import Gr from"picocolors";async function Pt(e){if(e!==void 0)return e;let a=X(),t=await zr({message:"Choose package manager",options:[{value:"npm",label:"npm",hint:"Node Package Manager"},{value:"pnpm",label:"pnpm",hint:"Fast, disk space efficient package manager"},{value:"bun",label:"bun",hint:"All-in-one JavaScript runtime & toolkit"}],initialValue:a});return Ur(t)&&(_r(Gr.red("Operation cancelled")),process.exit(0)),t}import K from"node:path";import{cancel as qr,isCancel as Vr,text as Wr}from"@clack/prompts";import q from"fs-extra";import Jr from"picocolors";var Hr=["<",">",":",'"',"|","?","*"],yt=255;function jt(e){if(e!=="."){if(!e)return"Project name cannot be empty";if(e.length>yt)return`Project name must be less than ${yt} characters`;if(Hr.some(a=>e.includes(a)))return"Project name contains invalid characters";if(e.startsWith(".")||e.startsWith("-"))return"Project name cannot start with a dot or dash";if(e.toLowerCase()==="node_modules"||e.toLowerCase()==="favicon.ico")return"Project name is reserved"}}async function xt(e){if(e)if(e==="."){let s=process.cwd();if(q.readdirSync(s).length===0)return e}else{let s=K.basename(e);if(!jt(s)){let o=K.resolve(process.cwd(),e);if(!q.pathExistsSync(o)||q.readdirSync(o).length===0)return e}}let a=!1,t="",r=y.projectName,n=1;for(;q.pathExistsSync(K.resolve(process.cwd(),r));)r=`${y.projectName}-${n}`,n++;for(;!a;){let s=await Wr({message:"Enter your project name or path (relative to current directory)",placeholder:r,initialValue:e,defaultValue:r,validate:i=>{let o=i.trim()||r;if(o==="."){if(q.readdirSync(process.cwd()).length>0)return"Current directory is not empty. Please choose a different directory.";a=!0;return}let p=K.resolve(process.cwd(),o),c=K.basename(p),l=jt(c);if(l)return l;if(!p.startsWith(process.cwd()))return"Project path must be within current directory";if(q.pathExistsSync(p)&&q.readdirSync(p).length>0)return`Directory "${o}" already exists and is not empty. Please choose a different name or path.`;a=!0}});Vr(s)&&(qr(Jr.red("Operation cancelled.")),process.exit(0)),t=s||r}return t}import{cancel as Qr,isCancel as Kr,select as Xr}from"@clack/prompts";import Yr from"picocolors";async function vt(e){if(e!==void 0)return e;let a=await Xr({message:"Select runtime",options:[{value:"bun",label:"Bun",hint:"Fast all-in-one JavaScript runtime"},{value:"node",label:"Node.js",hint:"Traditional Node.js runtime"}],initialValue:y.runtime});return Kr(a)&&(Qr(Yr.red("Operation cancelled")),process.exit(0)),a}async function $t(e){e.dbSetup&&(e.dbSetup==="turso"?(e.database="sqlite",e.orm==="prisma"&&(tn.warn(kt.yellow("Turso is not compatible with Prisma - switching to Drizzle")),e.orm="drizzle")):e.dbSetup==="prisma-postgres"?(e.database="postgres",e.orm="prisma"):e.dbSetup==="mongodb-atlas"&&(e.database="mongodb",e.orm="prisma"));let a=await en({projectName:async()=>xt(e.projectName),frontend:()=>ht(e.frontend),backend:()=>ot(e.backend),runtime:()=>vt(e.runtime),database:()=>ct(e.database),orm:({results:t})=>wt(e.orm,t.database!=="none",t.database),auth:({results:t})=>it(e.auth,t.database!=="none",t.frontend),dbSetup:({results:t})=>pt(t.database??"none",e.dbSetup),addons:({results:t})=>st(e.addons,t.frontend),examples:({results:t})=>dt(e.examples,t.database,t.frontend,t.backend),git:()=>gt(e.git),packageManager:()=>Pt(e.packageManager),noInstall:()=>bt(e.noInstall)},{onCancel:()=>{Zr(kt.red("Operation cancelled")),process.exit(0)}});return{projectName:a.projectName,frontend:a.frontend,database:a.database,orm:a.orm,auth:a.auth,addons:a.addons,examples:a.examples,git:a.git,packageManager:a.packageManager,noInstall:a.noInstall,dbSetup:a.dbSetup,backend:a.backend,runtime:a.runtime}}import R from"picocolors";function me(e){let a=[];if(e.projectName&&a.push(`${R.blue("Project Name:")} ${e.projectName}`),e.frontend!==void 0){let t=e.frontend.length>0?e.frontend.join(", "):"none";a.push(`${R.blue("Frontend:")} ${t}`)}if(e.backend!==void 0&&a.push(`${R.blue("Backend Framework:")} ${e.backend}`),e.runtime!==void 0&&a.push(`${R.blue("Runtime:")} ${e.runtime}`),e.database!==void 0&&a.push(`${R.blue("Database:")} ${e.database}`),e.orm!==void 0&&a.push(`${R.blue("ORM:")} ${e.orm}`),e.auth!==void 0&&a.push(`${R.blue("Authentication:")} ${e.auth}`),e.addons!==void 0){let t=e.addons.length>0?e.addons.join(", "):"none";a.push(`${R.blue("Addons:")} ${t}`)}if(e.examples!==void 0){let t=e.examples.length>0?e.examples.join(", "):"none";a.push(`${R.blue("Examples:")} ${t}`)}return e.git!==void 0&&a.push(`${R.blue("Git Init:")} ${e.git}`),e.packageManager!==void 0&&a.push(`${R.blue("Package Manager:")} ${e.packageManager}`),e.noInstall!==void 0&&a.push(`${R.blue("Skip Install:")} ${e.noInstall}`),e.dbSetup!==void 0&&a.push(`${R.blue("Database Setup:")} ${e.dbSetup}`),a.join(`
|
|
269
|
-
`)}function
|
|
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
|
-
`,
|
|
284
|
-
`),t=Math.max(...a.map(r=>r.length));e<t?console.log(
|
|
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(
|
|
289
|
-
${
|
|
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.
|
|
3
|
+
"version": "1.10.0",
|
|
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",
|
package/template/base/turbo.json
CHANGED
|
@@ -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
|
-
.
|
|
17
|
-
|
|
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
|
+
});
|
|
@@ -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
|
+
});
|
|
@@ -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
|
+
});
|
|
@@ -5,7 +5,7 @@ export default defineConfig({
|
|
|
5
5
|
out: "./src/db/migrations",
|
|
6
6
|
dialect: "turso",
|
|
7
7
|
dbCredentials: {
|
|
8
|
-
url: process.env.
|
|
9
|
-
authToken: process.env.
|
|
8
|
+
url: process.env.DATABASE_URL || "",
|
|
9
|
+
authToken: process.env.DATABASE_AUTH_TOKEN,
|
|
10
10
|
},
|
|
11
11
|
});
|
|
@@ -2,8 +2,8 @@ import { drizzle } from "drizzle-orm/libsql";
|
|
|
2
2
|
import { createClient } from "@libsql/client";
|
|
3
3
|
|
|
4
4
|
const client = createClient({
|
|
5
|
-
url: process.env.
|
|
6
|
-
authToken: process.env.
|
|
5
|
+
url: process.env.DATABASE_URL || "",
|
|
6
|
+
authToken: process.env.DATABASE_AUTH_TOKEN ,
|
|
7
7
|
});
|
|
8
8
|
|
|
9
9
|
export const db = drizzle({ client });
|
|
@@ -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
|
+
}
|