create-better-t-stack 1.8.1 → 1.9.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/README.md +10 -8
- package/dist/index.js +112 -80
- package/package.json +4 -4
- package/template/with-auth/apps/server/src/lib/with-express-context.ts +14 -0
- package/template/with-auth/apps/server/src/with-express-index.ts +34 -0
- package/template/with-auth/apps/server/src/with-prisma-mongodb-lib/auth.ts +17 -0
- package/template/with-express/apps/server/src/index.ts +29 -0
- package/template/with-express/apps/server/src/lib/context.ts +9 -0
- package/template/with-prisma-mongodb/apps/server/prisma/index.ts +5 -0
- package/template/with-prisma-mongodb/apps/server/prisma/schema/auth.prisma +59 -0
- package/template/with-prisma-mongodb/apps/server/prisma/schema/schema.prisma +9 -0
- package/template/with-prisma-mongodb/apps/server/prisma/schema/todo.prisma +7 -0
package/README.md
CHANGED
|
@@ -24,10 +24,10 @@ Follow the prompts to configure your project or use the `--yes` flag for default
|
|
|
24
24
|
- **Monorepo**: Turborepo for optimized build system and workspace management
|
|
25
25
|
- **Frontend**: React, TanStack Router, TanStack Query, Tailwind CSS with shadcn/ui components
|
|
26
26
|
- **Native Apps**: Create React Native apps with Expo for iOS and Android
|
|
27
|
-
- **Backend Frameworks**: Choose between Hono or Elysia
|
|
27
|
+
- **Backend Frameworks**: Choose between Hono, Express, or Elysia
|
|
28
28
|
- **API Layer**: End-to-end type safety with tRPC
|
|
29
29
|
- **Runtime Options**: Choose between Bun or Node.js for your server
|
|
30
|
-
- **Database Options**: SQLite (via Turso), PostgreSQL, or no database
|
|
30
|
+
- **Database Options**: SQLite (via Turso), PostgreSQL, MongoDB, or no database
|
|
31
31
|
- **ORM Selection**: Choose between Drizzle ORM or Prisma
|
|
32
32
|
- **Authentication**: Optional auth setup with Better-Auth
|
|
33
33
|
- **Progressive Web App**: Add PWA support with service workers and installable apps
|
|
@@ -45,7 +45,7 @@ Usage: create-better-t-stack [project-directory] [options]
|
|
|
45
45
|
Options:
|
|
46
46
|
-V, --version Output the version number
|
|
47
47
|
-y, --yes Use default configuration
|
|
48
|
-
--database <type> Database type (none, sqlite, postgres)
|
|
48
|
+
--database <type> Database type (none, sqlite, postgres, mongodb)
|
|
49
49
|
--orm <type> ORM type (none, drizzle, prisma)
|
|
50
50
|
--auth Include authentication
|
|
51
51
|
--no-auth Exclude authentication
|
|
@@ -58,11 +58,8 @@ Options:
|
|
|
58
58
|
--package-manager <pm> Package manager (npm, pnpm, bun)
|
|
59
59
|
--install Install dependencies
|
|
60
60
|
--no-install Skip installing dependencies
|
|
61
|
-
--
|
|
62
|
-
--
|
|
63
|
-
--prisma-postgres Set up Prisma Postgres
|
|
64
|
-
--no-prisma-postgres Skip Prisma Postgres setup
|
|
65
|
-
--backend <framework> Backend framework (hono, elysia)
|
|
61
|
+
--db-setup <setup> Database setup (turso, prisma-postgres, mongodb-atlas, none)
|
|
62
|
+
--backend <framework> Backend framework (hono, express, elysia)
|
|
66
63
|
--runtime <runtime> Runtime (bun, node)
|
|
67
64
|
-h, --help Display help
|
|
68
65
|
```
|
|
@@ -93,3 +90,8 @@ Create a project with examples:
|
|
|
93
90
|
```bash
|
|
94
91
|
npx create-better-t-stack my-app --examples todo ai
|
|
95
92
|
```
|
|
93
|
+
|
|
94
|
+
Create a project with Turso database setup:
|
|
95
|
+
```bash
|
|
96
|
+
npx create-better-t-stack my-app --db-setup turso
|
|
97
|
+
```
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{cancel as v,intro as
|
|
3
|
-
${
|
|
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 Lt=Ot(import.meta.url),Bt=be.dirname(Lt),$=be.join(Bt,"../"),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 B from"node:path";import E 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 Nt,spinner as _t}from"@clack/prompts";import{execa as Ut}from"execa";import Z from"fs-extra";import Pe from"picocolors";async function ye(e,a,t){let r=_t(),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 Ut(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&&Nt.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 B.join(e,"apps/web")}async function Gt(e){let a=B.join($,"template/with-biome");await E.pathExists(a)&&await E.copy(a,e,{overwrite:!0}),w({devDependencies:["@biomejs/biome"],projectDir:e});let t=B.join(e,"package.json");if(await E.pathExists(t)){let r=await E.readJson(t);r.scripts={...r.scripts,check:"biome check --write ."},await E.writeJson(t,r,{spaces:2})}}async function qt(e){let a=B.join($,"template/with-husky");await E.pathExists(a)&&await E.copy(a,e,{overwrite:!0}),w({devDependencies:["husky","lint-staged"],projectDir:e});let t=B.join(e,"package.json");if(await E.pathExists(t)){let r=await E.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 E.writeJson(t,r,{spaces:2})}}async function Vt(e,a){let t=B.join($,"template/with-pwa");await E.pathExists(t)&&await E.copy(t,e,{overwrite:!0});let r=zt(e,a);if(!await E.pathExists(r))return;w({dependencies:["vite-plugin-pwa"],devDependencies:["@vite-pwa/assets-generator"],projectDir:r});let n=B.join(r,"vite.config.ts");if(await E.pathExists(n)){let i=await E.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
4
|
${i}`}let o=`VitePWA({
|
|
5
5
|
registerType: "autoUpdate",
|
|
6
6
|
manifest: {
|
|
@@ -21,13 +21,13 @@ ${i}`}let o=`VitePWA({
|
|
|
21
21
|
${o}`):a.includes("tanstack-router")?i=i.replace(/plugins: \[\s*tailwindcss\(\)/,`plugins: [
|
|
22
22
|
tailwindcss(),
|
|
23
23
|
${o}`):i=i.replace(/plugins: \[/,`plugins: [
|
|
24
|
-
${o},`)),await E.writeFile(n,i)}let s=
|
|
24
|
+
${o},`)),await E.writeFile(n,i)}let s=B.join(r,"package.json");if(await E.pathExists(s)){let i=await E.readJson(s);i.scripts={...i.scripts,"generate-pwa-assets":"pwa-assets-generator"},await E.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 $e(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 Ee(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 Ae(e,a){let t=Jt.join(e,"README.md"),r=Qt(a);try{await Ht.writeFile(t,r)}catch(n){console.error("Failed to create README.md file:",n)}}function Qt(e){let{projectName:a,packageManager:t,database:r,auth:n,addons:s=[],orm:i="drizzle",runtime:o="bun",frontend:p=["tanstack-router"]}=e,c=p.includes("react-router"),l=p.includes("tanstack-router"),m=p.includes("native"),b=t==="npm"?"npm run":t,k=c?"5173":"3001";return`# ${a}
|
|
25
25
|
|
|
26
26
|
This project was created with [Better-T-Stack](https://github.com/AmanVarshney01/create-better-t-stack), a modern TypeScript stack that combines React, ${l?"TanStack Router":"React Router"}, Hono, tRPC, and more.
|
|
27
27
|
|
|
28
28
|
## Features
|
|
29
29
|
|
|
30
|
-
${
|
|
30
|
+
${Kt(r,n,s,i,o,p)}
|
|
31
31
|
|
|
32
32
|
## Getting Started
|
|
33
33
|
|
|
@@ -37,20 +37,20 @@ First, install the dependencies:
|
|
|
37
37
|
${t} install
|
|
38
38
|
\`\`\`
|
|
39
39
|
|
|
40
|
-
${
|
|
40
|
+
${Xt(r,n,b,i)}
|
|
41
41
|
|
|
42
42
|
Then, run the development server:
|
|
43
43
|
|
|
44
44
|
\`\`\`bash
|
|
45
|
-
${
|
|
45
|
+
${b} dev
|
|
46
46
|
\`\`\`
|
|
47
47
|
|
|
48
|
-
${l||
|
|
48
|
+
${l||c?`Open [http://localhost:${k}](http://localhost:${k}) in your browser to see the web application.`:""}
|
|
49
49
|
${m?`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
|
|
|
53
|
-
${s.includes("pwa")&&
|
|
53
|
+
${s.includes("pwa")&&c?`
|
|
54
54
|
## PWA Support with React Router v7
|
|
55
55
|
|
|
56
56
|
There is a known compatibility issue between VitePWA and React Router v7.
|
|
@@ -62,16 +62,16 @@ See: https://github.com/vite-pwa/vite-plugin-pwa/issues/809
|
|
|
62
62
|
\`\`\`
|
|
63
63
|
${a}/
|
|
64
64
|
\u251C\u2500\u2500 apps/
|
|
65
|
-
${l||
|
|
65
|
+
${l||c?`\u2502 \u251C\u2500\u2500 web/ # Frontend application (React, ${l?"TanStack Router":"React Router"})
|
|
66
66
|
`:""}${m?`\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
|
-
${
|
|
73
|
-
`}function
|
|
74
|
-
`)}function
|
|
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(`
|
|
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"}.
|
|
77
77
|
|
|
@@ -93,7 +93,7 @@ ${t} db:push
|
|
|
93
93
|
\`\`\`bash
|
|
94
94
|
${t} db:push
|
|
95
95
|
\`\`\``}
|
|
96
|
-
`,n}function
|
|
96
|
+
`,n}function Yt(e,a,t,r,n){let s=`- \`${e} dev\`: Start both web and server in development mode
|
|
97
97
|
- \`${e} build\`: Build both web and server
|
|
98
98
|
- \`${e} dev:web\`: Start only the web application
|
|
99
99
|
- \`${e} dev:server\`: Start only the server
|
|
@@ -101,27 +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
|
|
105
|
-
|
|
106
|
-
|
|
104
|
+
- \`cd apps/server && ${e} db:local\`: Start the local SQLite database`)),s}import Le from"node:path";import{log as va,spinner as ka}from"@clack/prompts";import $a from"fs-extra";import Be from"picocolors";import Re 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=Re.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:
|
|
106
|
+
|
|
107
|
+
1. Install Atlas CLI: https://www.mongodb.com/docs/atlas/cli/stable/install-atlas-cli/
|
|
108
|
+
2. Run 'atlas deployments setup' and follow prompts
|
|
109
|
+
3. Get your connection string from the output
|
|
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 Ce(e){let a=Re.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 _,password as oa}from"@clack/prompts";import{execa as ca}from"execa";import N from"fs-extra";import V from"picocolors";async function pa(e,a){try{_.info(V.blue("Initializing Prisma PostgreSQL"));let t=H.join(e,"prisma");await N.ensureDir(t),await ca(a==="npm"?"npx":a==="pnpm"?"pnpm dlx":"bunx",["prisma","init","--db"],{cwd:e,stdio:"inherit"}),_.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&&_.error(V.red(t.message)),null}}async function pe(e,a){let t=H.join(e,"apps/server",".env"),r="";await N.pathExists(t)&&(r=await N.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 N.writeFile(t,r.trim())}function De(){_.info(`Manual Prisma PostgreSQL Setup Instructions:
|
|
107
114
|
|
|
108
115
|
1. Visit https://console.prisma.io and create an account
|
|
109
116
|
2. Create a new PostgreSQL database from the dashboard
|
|
110
117
|
3. Get your database URL
|
|
111
118
|
4. Add the database URL to the .env file in apps/server/.env
|
|
112
119
|
|
|
113
|
-
DATABASE_URL="your_database_url"`)}async function
|
|
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),_.success(V.green("Prisma PostgreSQL database configured successfully!"))):(await pe(e),De())}catch(r){_.error(V.red(`Error during Prisma PostgreSQL setup: ${r}`)),await pe(e),De(),_.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 N.writeFile(a,`
|
|
114
121
|
import { PrismaClient } from '@prisma/client';
|
|
115
122
|
import { withAccelerate } from "@prisma/extension-accelerate";
|
|
116
123
|
|
|
117
124
|
const prisma = new PrismaClient().$extends(withAccelerate());
|
|
118
125
|
|
|
119
126
|
export default prisma;
|
|
120
|
-
`.trim());let r=
|
|
121
|
-
${n}`,n=n.replace("export const db = new PrismaClient();","export const db = new PrismaClient().$extends(withAccelerate());"),await
|
|
122
|
-
`);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
|
|
127
|
+
`.trim());let r=H.join(e,"src/db/index.ts");if(await N.pathExists(r)){let n=await N.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 N.writeFile(r,n))}}catch{_.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 D 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(D.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(D.yellow("Turso CLI installation cancelled by user")),new Error("Installation cancelled")):(a.stop(D.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(D.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?`TURSO_CONNECTION_URL="${a.dbUrl}"
|
|
123
130
|
TURSO_AUTH_TOKEN="${a.authToken}"`:`TURSO_CONNECTION_URL=
|
|
124
|
-
TURSO_AUTH_TOKEN=`;await
|
|
131
|
+
TURSO_AUTH_TOKEN=`;await ha.writeFile(t,r)}function te(){W.info(`Manual Turso Setup Instructions:
|
|
125
132
|
|
|
126
133
|
1. Visit https://turso.tech and create an account
|
|
127
134
|
2. Create a new database from the dashboard
|
|
@@ -129,17 +136,18 @@ TURSO_AUTH_TOKEN=`;await Zt.writeFile(t,r)}function Y(){V.info(`Manual Turso Set
|
|
|
129
136
|
4. Add these credentials to the .env file in apps/server/.env
|
|
130
137
|
|
|
131
138
|
TURSO_CONNECTION_URL=your_database_url
|
|
132
|
-
TURSO_AUTH_TOKEN=your_auth_token`)}async function
|
|
133
|
-
CORS_ORIGIN=${
|
|
134
|
-
BETTER_AUTH_SECRET=${
|
|
135
|
-
BETTER_AUTH_URL=http://localhost:3000`)),a.database!=="none"){if(a.orm==="prisma"&&!n.includes("DATABASE_URL")){let
|
|
136
|
-
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/mydb?schema=public"
|
|
139
|
+
TURSO_AUTH_TOKEN=your_auth_token`)}async function Oe(e,a){if(!a){await Q(e),W.info(D.blue("Skipping Turso setup. Setting up empty configuration.")),te();return}let t=da.platform(),r=t==="darwin";if(!(t!=="win32")){W.warn(D.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(D.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(D.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(D.yellow(`Database "${D.red(c)}" already exists`)),l=`${c}-${Math.floor(Math.random()*1e3)}`;else throw b.stop(D.red("Failed to create Turso database")),k}}}catch(s){W.error(D.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=Le.join(e,"apps/server");if(a==="none"){await $a.remove(Le.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 Ce(e))}catch(c){throw o.stop(Be.red("Failed to set up database")),c instanceof Error&&va.error(Be.red(c.message)),c}}import J from"node:path";import L from"fs-extra";async function Ne(e,a){let t=J.join(e,"apps/server"),r=J.join(t,".env"),n="";if(await L.pathExists(r)&&(n=await L.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("TURSO_CONNECTION_URL")||(n+=`
|
|
137
145
|
TURSO_CONNECTION_URL=http://127.0.0.1:8080`))}a.examples?.includes("ai")&&!n.includes("GOOGLE_GENERATIVE_AI_API_KEY")&&(n+=`
|
|
138
|
-
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
|
|
139
|
-
`),await L.writeFile(l,m.trim())}}async function
|
|
140
|
-
`),await L.writeFile(a,t.trim())}import
|
|
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";
|
|
141
149
|
import { google } from "@ai-sdk/google";
|
|
142
|
-
import { stream } from "hono/streaming";`,
|
|
150
|
+
import { stream } from "hono/streaming";`,i=`
|
|
143
151
|
// AI chat endpoint
|
|
144
152
|
app.post("/ai", async (c) => {
|
|
145
153
|
const body = await c.req.json();
|
|
@@ -154,69 +162,93 @@ app.post("/ai", async (c) => {
|
|
|
154
162
|
c.header("Content-Type", "text/plain; charset=utf-8");
|
|
155
163
|
|
|
156
164
|
return stream(c, (stream) => stream.pipe(result.toDataStream()));
|
|
157
|
-
});`;if(t.includes("import {")){let
|
|
158
|
-
`,
|
|
159
|
-
${
|
|
160
|
-
${t.substring(c+1)}`}else t=`${
|
|
165
|
+
});`;if(t.includes("import {")){let p=t.lastIndexOf("import"),c=t.indexOf(`
|
|
166
|
+
`,p);t=`${t.substring(0,c+1)}
|
|
167
|
+
${s}
|
|
168
|
+
${t.substring(c+1)}`}else t=`${s}
|
|
169
|
+
|
|
170
|
+
${t}`;let o=t.indexOf('app.use("/trpc"')||t.indexOf("app.use(trpc(");if(o!==-1)t=`${t.substring(0,o)}${i}
|
|
171
|
+
|
|
172
|
+
${t.substring(o)}`;else{let p=t.indexOf("export default");p!==-1?t=`${t.substring(0,p)}${i}
|
|
173
|
+
|
|
174
|
+
${t.substring(p)}`:t=`${t}
|
|
175
|
+
|
|
176
|
+
${i}`}}else if(n){let s=`import { streamText } from "ai";
|
|
177
|
+
import { google } from "@ai-sdk/google";`,i=`
|
|
178
|
+
// AI chat endpoint
|
|
179
|
+
app.post("/ai", async (req, res) => {
|
|
180
|
+
const { messages = [] } = req.body;
|
|
181
|
+
|
|
182
|
+
const result = streamText({
|
|
183
|
+
model: google("gemini-1.5-flash"),
|
|
184
|
+
messages,
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
result.pipeDataStreamToResponse(res);
|
|
188
|
+
});`;if(t.includes("import {")||t.includes("import ")){let p=t.lastIndexOf("import"),c=t.indexOf(`
|
|
189
|
+
`,p);t=`${t.substring(0,c+1)}
|
|
190
|
+
${s}
|
|
191
|
+
${t.substring(c+1)}`}else t=`${s}
|
|
161
192
|
|
|
162
|
-
${t}`;let
|
|
193
|
+
${t}`;let o=t.indexOf('app.use("/trpc"');if(o!==-1)t=`${t.substring(0,o)}${i}
|
|
163
194
|
|
|
164
|
-
${t.substring(
|
|
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}
|
|
165
197
|
|
|
166
|
-
${t.substring(
|
|
198
|
+
${t.substring(c)}`}else t=`${t}
|
|
167
199
|
|
|
168
|
-
${
|
|
200
|
+
${i}`}}await P.writeFile(a,t)}}async function Ta(e,a){let t=A.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 = [
|
|
169
201
|
${i}${i.trim().endsWith(",")?"":","}
|
|
170
202
|
{ to: "/ai", label: "AI Chat" },
|
|
171
|
-
];`;r=r.replace(n,o),await P.writeFile(t,r)}}}}async function
|
|
203
|
+
];`;r=r.replace(n,o),await P.writeFile(t,r)}}}}async function Ra(e,a,t,r){let n=A.join($,"template/examples/todo");if(await P.pathExists(n)){let s=A.join(n,`apps/${r}/src/routes/todos.tsx`),i=A.join(e,"apps/web/src/routes/todos.tsx");if(await P.pathExists(s)&&await P.copy(s,i,{overwrite:!0}),a!=="none"){let o=A.join(n,`apps/server/src/routers/with-${a}-todo.ts`),p=A.join(e,"apps/server/src/routers/todo.ts");await P.pathExists(o)&&await P.copy(o,p,{overwrite:!0}),await Ca(e)}await Da(e,r)}}async function Ca(e){let a=A.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(`
|
|
172
204
|
|
|
173
205
|
`,r);n!==-1?t=`${t.slice(0,n)}
|
|
174
206
|
import { todoRouter } from "./todo";${t.slice(n)}`:t=`import { todoRouter } from "./todo";
|
|
175
207
|
${t}`;let s=t.indexOf("export const appRouter = router({");if(s!==-1){let i=t.indexOf("{",s)+1;t=`${t.slice(0,i)}
|
|
176
|
-
todo: todoRouter,${t.slice(i)}`}await P.writeFile(a,t)}}}async function
|
|
208
|
+
todo: todoRouter,${t.slice(i)}`}await P.writeFile(a,t)}}}async function Da(e,a){let t=A.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 = [
|
|
177
209
|
${i}${i.trim().endsWith(",")?"":","}
|
|
178
210
|
{ to: "/todos", label: "Todos" },
|
|
179
|
-
];`;r=r.replace(n,o),await P.writeFile(t,r)}}}}async function
|
|
180
|
-
${r?"":`${
|
|
181
|
-
`}${
|
|
182
|
-
|
|
183
|
-
${
|
|
184
|
-
${
|
|
185
|
-
`:""}`:`${
|
|
186
|
-
`}${
|
|
211
|
+
];`;r=r.replace(n,o),await P.writeFile(t,r)}}}}async function Ia(e,a){if(a==="drizzle"){let r=A.join(e,"apps/server/src/db/schema/todo.ts");await P.pathExists(r)&&await P.remove(r)}else if(a==="prisma"){let r=A.join(e,"apps/server/prisma/schema/todo.prisma");await P.pathExists(r)&&await P.remove(r)}let t=A.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=A.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 Ue,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&&Ue.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")),Ue.warn(ae.yellow("Some files may need manual formatting"))}}import{note as La}from"@clack/prompts";import j 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"?Na(e,n,c,i):"",k=s?.includes("tauri")?_a(c):"",x=m?Ma(c):"",C=o?.includes("native")?Ba():"",T=s?.includes("pwa")&&o?.includes("react-router")?Ua():"",O=o?.includes("tanstack-router"),I=o?.includes("tanstack-start"),he=o?.includes("react-router"),ge=O||he||I,Dt=o?.includes("native"),It=ge||Dt,Ft=he?"5173":"3001";La(`${j.cyan("1.")} ${l}
|
|
212
|
+
${r?"":`${j.cyan("2.")} ${t} install
|
|
213
|
+
`}${j.cyan(r?"2.":"3.")} ${c} dev
|
|
214
|
+
|
|
215
|
+
${j.bold("Your project will be available at:")}
|
|
216
|
+
${It?`${ge?`${j.cyan("\u2022")} Frontend: http://localhost:${Ft}
|
|
217
|
+
`:""}`:`${j.yellow("NOTE:")} You are creating a backend-only app (no frontend selected)
|
|
218
|
+
`}${j.cyan("\u2022")} API: http://localhost:3000
|
|
187
219
|
${C?`
|
|
188
|
-
${C.trim()}`:""}${
|
|
189
|
-
${
|
|
190
|
-
${
|
|
191
|
-
${
|
|
192
|
-
${
|
|
193
|
-
|
|
194
|
-
${
|
|
195
|
-
${
|
|
220
|
+
${C.trim()}`:""}${b?`
|
|
221
|
+
${b.trim()}`:""}${k?`
|
|
222
|
+
${k.trim()}`:""}${x?`
|
|
223
|
+
${x.trim()}`:""}${T?`
|
|
224
|
+
${T.trim()}`:""}
|
|
225
|
+
|
|
226
|
+
${j.bold("Like Better-T Stack?")} Please consider giving us a star on GitHub:
|
|
227
|
+
${j.cyan("https://github.com/AmanVarshney01/create-better-t-stack")}`,"Next steps")}function Ba(){return`${j.yellow("NOTE:")} For Expo connectivity issues, update apps/native/.env
|
|
196
228
|
with your local IP:
|
|
197
229
|
EXPO_PUBLIC_SERVER_URL=http://192.168.0.103:3000
|
|
198
|
-
`}function
|
|
199
|
-
${
|
|
230
|
+
`}function Ma(e){return`${j.bold("Linting and formatting:")}
|
|
231
|
+
${j.cyan("\u2022")} Format and lint fix: ${`${e} check`}
|
|
200
232
|
|
|
201
|
-
`}function
|
|
202
|
-
follow the guidance provided in the error messages`),n.push(`${
|
|
233
|
+
`}function Na(e,a,t,r){let n=[];return a==="prisma"?(e==="sqlite"&&n.push(`${j.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(`${j.yellow("NOTE:")} Prisma with Bun may require additional configuration. If you encounter errors,
|
|
234
|
+
follow the guidance provided in the error messages`),n.push(`${j.cyan("\u2022")} Apply schema: ${`${t} db:push`}`),n.push(`${j.cyan("\u2022")} Database UI: ${`${t} db:studio`}`)):a==="drizzle"&&(e==="sqlite"&&n.push(`${j.cyan("\u2022")} Start local DB: ${`cd apps/server && ${t} db:local`}`),n.push(`${j.cyan("\u2022")} Apply schema: ${`${t} db:push`}`),n.push(`${j.cyan("\u2022")} Database UI: ${`${t} db:studio`}`)),n.length?`${j.bold("Database commands:")}
|
|
203
235
|
${n.join(`
|
|
204
236
|
`)}
|
|
205
237
|
|
|
206
|
-
`:""}function
|
|
207
|
-
${
|
|
208
|
-
${
|
|
209
|
-
${
|
|
210
|
-
${
|
|
238
|
+
`:""}function _a(e){return`
|
|
239
|
+
${j.bold("Desktop app with Tauri:")}
|
|
240
|
+
${j.cyan("\u2022")} Start desktop app: ${`cd apps/web && ${e} desktop:dev`}
|
|
241
|
+
${j.cyan("\u2022")} Build desktop app: ${`cd apps/web && ${e} desktop:build`}
|
|
242
|
+
${j.yellow("NOTE:")} Tauri requires Rust and platform-specific dependencies.
|
|
211
243
|
See: https://v2.tauri.app/start/prerequisites/
|
|
212
244
|
|
|
213
|
-
`}function
|
|
214
|
-
${
|
|
245
|
+
`}function Ua(){return`${j.bold("PWA with React Router v7:")}
|
|
246
|
+
${j.yellow("NOTE:")} There is a known compatibility issue between VitePWA and React Router v7.
|
|
215
247
|
See: https://github.com/vite-pwa/vite-plugin-pwa/issues/809
|
|
216
|
-
`}import
|
|
248
|
+
`}import re from"node:path";import{log as za}from"@clack/prompts";import{$ as We,execa as Ga}from"execa";import U 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 U.pathExists(t)){let r=await U.readJson(t);r.name=a.projectName;let{stdout:n}=await Ga(a.packageManager,["-v"],{cwd:e});if(r.packageManager=`${a.packageManager}@${n.trim()}`,await U.writeJson(t,r,{spaces:2}),a.packageManager==="pnpm"){let s=re.join($,"template/with-pnpm/pnpm-workspace.yaml"),i=re.join(e,"pnpm-workspace.yaml");await U.pathExists(s)&&await U.copy(s,i)}}}async function Wa(e,a){let t=re.join(e,"apps/server/package.json");if(await U.pathExists(t)){let r=await U.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 U.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}
|
|
217
249
|
|
|
218
250
|
export default app;
|
|
219
|
-
`;await
|
|
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";
|
|
220
252
|
`,o=`
|
|
221
253
|
serve(
|
|
222
254
|
{
|
|
@@ -227,14 +259,14 @@ serve(
|
|
|
227
259
|
console.log(\`Server is running on http://localhost:\${info.port}\`);
|
|
228
260
|
},
|
|
229
261
|
);
|
|
230
|
-
`;if(!t.includes("@hono/node-server")){let
|
|
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";
|
|
231
263
|
`,o=t.indexOf(`
|
|
232
|
-
`,t.indexOf("import")),
|
|
233
|
-
`)}}async function
|
|
234
|
-
`,o=s.lastIndexOf("import"),
|
|
235
|
-
`,o)+1;s=s.substring(0,
|
|
236
|
-
});`),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 qe(e){let a=await We(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 We(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 We(s);a.push(...i)}}catch{}return a}function Oa(e,a){return e==="drizzle"?a==="sqlite"?"template/with-drizzle-sqlite":"template/with-drizzle-postgres":e==="prisma"?a==="sqlite"?"template/with-prisma-sqlite":"template/with-prisma-postgres":"template/base"}function Da(e,a){if(e==="drizzle")return a==="sqlite"?"with-drizzle-sqlite-lib":"with-drizzle-postgres-lib";if(e==="prisma")return a==="sqlite"?"with-prisma-sqlite-lib":"with-prisma-postgres-lib";throw new Error("Invalid ORM or database configuration for auth setup")}async function He(e){let a=_a(),t=La.resolve(process.cwd(),e.projectName);try{return await Ua.ensureDir(t),await Me(t),await Be(t,e.frontend),await qe(t),await ze(t,e.backend),await ye(t,e.backend,e.runtime),await Ge(t,e.orm,e.database,e.auth),await Ae(t,e.database,e.orm,e.packageManager,e.turso??e.database==="sqlite",e.prismaPostgres),await Ve(t,e.auth,e.backend,e.orm,e.database,e.frontend),await Pe(t,e.auth,e.frontend),await Ue(t,e.runtime,e.backend),await Re(t,e.examples,e.orm,e.auth,e.backend,e.frontend),await Ce(t,e),await _e(t,e.git),e.addons.length>0&&await he(t,e.addons,e.packageManager,e.frontend),await Ne(t,e),await je(t,e),e.noInstall||await Oe({projectDir:t,packageManager:e.packageManager,addons:e.addons}),De(e.database,e.projectName,e.packageManager,!e.noInstall,e.orm,e.addons,e.runtime,e.frontend),t}catch(r){throw a.message(Je.red("Failed")),r instanceof Error&&(Na(Je.red(`Error during project creation: ${r.message}`)),process.exit(1)),r}}import{cancel as Mr,group as Br}from"@clack/prompts";import zr from"picocolors";import{cancel as Ma,isCancel as Ba,multiselect as za}from"@clack/prompts";import Ga from"picocolors";async function Qe(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=w.addons.filter(c=>t||c!=="pwa"&&c!=="tauri"),o=await za({message:"Select addons",options:s,initialValues:i,required:!1});return Ba(o)&&(Ma(Ga.red("Operation cancelled")),process.exit(0)),o.includes("husky")&&!o.includes("biome")&&o.push("biome"),o}import{cancel as Va,confirm as qa,isCancel as Wa}from"@clack/prompts";import Ja from"picocolors";async function Ke(e,a,t){if(!a)return!1;if(e!==void 0)return e;let r=await qa({message:"Add authentication with Better-Auth?",initialValue:w.auth});return Wa(r)&&(Va(Ja.red("Operation cancelled")),process.exit(0)),r}import{cancel as Ha,isCancel as Qa,select as Ka}from"@clack/prompts";import Xa from"picocolors";async function Xe(e){if(e!==void 0)return e;let a=await Ka({message:"Select backend framework",options:[{value:"hono",label:"Hono",hint:"Lightweight, ultrafast web framework"},{value:"elysia",label:"Elysia",hint:"Ergonomic web framework for building backend servers"}],initialValue:w.backend});return Qa(a)&&(Ha(Xa.red("Operation cancelled")),process.exit(0)),a}import{cancel as Ya,isCancel as Za,select as er}from"@clack/prompts";import tr from"picocolors";async function Ye(e){if(e!==void 0)return e;let a=await er({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"}],initialValue:w.database});return Za(a)&&(Ya(tr.red("Operation cancelled")),process.exit(0)),a}import{cancel as ar,isCancel as rr,multiselect as Ze}from"@clack/prompts";import nr from"picocolors";async function et(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 Ze({message:"Include examples",options:[{value:"todo",label:"Todo App",hint:"A simple CRUD example app"}],required:!1,initialValues:w.examples})),r==="hono"&&(s=await Ze({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:w.examples})),rr(s)&&(ar(nr.red("Operation cancelled")),process.exit(0)),s}import{cancel as tt,isCancel as at,multiselect as sr,select as ir}from"@clack/prompts";import rt from"picocolors";async function nt(e){if(e!==void 0)return e;let a=await sr({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:w.frontend.some(r=>r==="tanstack-router"||r==="react-router"||r==="tanstack-start")?["web"]:[]});at(a)&&(tt(rt.red("Operation cancelled")),process.exit(0));let t=[];if(a.includes("web")){let r=await ir({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:w.frontend.find(n=>n==="tanstack-router"||n==="react-router"||n==="tanstack-start")||"tanstack-router"});at(r)&&(tt(rt.red("Operation cancelled")),process.exit(0)),t.push(r)}return a.includes("native")&&t.push("native"),t}import{cancel as or,confirm as cr,isCancel as pr}from"@clack/prompts";import lr from"picocolors";async function st(e){if(e!==void 0)return e;let a=await cr({message:"Initialize git repository?",initialValue:w.git});return pr(a)&&(or(lr.red("Operation cancelled")),process.exit(0)),a}import{cancel as dr,confirm as ur,isCancel as mr}from"@clack/prompts";import fr from"picocolors";async function it(e){if(e!==void 0)return e;let a=await ur({message:"Install dependencies?",initialValue:!w.noInstall});return mr(a)&&(dr(fr.red("Operation cancelled")),process.exit(0)),!a}import{cancel as hr,isCancel as gr,select as wr}from"@clack/prompts";import br from"picocolors";async function ot(e,a){if(!a)return"none";if(e!==void 0)return e;let t=await wr({message:"Select ORM",options:[{value:"drizzle",label:"Drizzle",hint:"Type-safe, lightweight ORM"},{value:"prisma",label:"Prisma",hint:"Powerful, feature-rich ORM"}],initialValue:w.orm});return gr(t)&&(hr(br.red("Operation cancelled")),process.exit(0)),t}import{cancel as Pr,isCancel as yr,select as jr}from"@clack/prompts";import kr from"picocolors";async function ct(e){if(e!==void 0)return e;let a=Q(),t=await jr({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 yr(t)&&(Pr(kr.red("Operation cancelled")),process.exit(0)),t}import{cancel as vr,confirm as xr,isCancel as $r}from"@clack/prompts";import Er from"picocolors";async function pt(e){if(e!==void 0)return e;let a=await xr({message:"Set up Prisma Postgres database?",initialValue:w.prismaPostgres});return $r(a)&&(vr(Er.red("Operation cancelled")),process.exit(0)),a}import H from"node:path";import{cancel as Tr,isCancel as Ar,text as Cr}from"@clack/prompts";import z from"fs-extra";import Rr from"picocolors";var Sr=["<",">",":",'"',"|","?","*"],lt=255;function dt(e){if(e!=="."){if(!e)return"Project name cannot be empty";if(e.length>lt)return`Project name must be less than ${lt} characters`;if(Sr.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 ut(e){if(e)if(e==="."){let s=process.cwd();if(z.readdirSync(s).length===0)return e}else{let s=H.basename(e);if(!dt(s)){let o=H.resolve(process.cwd(),e);if(!z.pathExistsSync(o)||z.readdirSync(o).length===0)return e}}let a=!1,t="",r=w.projectName,n=1;for(;z.pathExistsSync(H.resolve(process.cwd(),r));)r=`${w.projectName}-${n}`,n++;for(;!a;){let s=await Cr({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(z.readdirSync(process.cwd()).length>0)return"Current directory is not empty. Please choose a different directory.";a=!0;return}let c=H.resolve(process.cwd(),o),p=H.basename(c),l=dt(p);if(l)return l;if(!c.startsWith(process.cwd()))return"Project path must be within current directory";if(z.pathExistsSync(c)&&z.readdirSync(c).length>0)return`Directory "${o}" already exists and is not empty. Please choose a different name or path.`;a=!0}});Ar(s)&&(Tr(Rr.red("Operation cancelled.")),process.exit(0)),t=s||r}return t}import{cancel as Fr,isCancel as Ir,select as Or}from"@clack/prompts";import Dr from"picocolors";async function mt(e){if(e!==void 0)return e;let a=await Or({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:w.runtime});return Ir(a)&&(Fr(Dr.red("Operation cancelled")),process.exit(0)),a}import{cancel as Lr,confirm as Nr,isCancel as _r}from"@clack/prompts";import Ur from"picocolors";async function ft(e){if(e!==void 0)return e;let a=await Nr({message:"Set up Turso database?",initialValue:w.turso});return _r(a)&&(Lr(Ur.red("Operation cancelled")),process.exit(0)),a}async function ht(e){let a=await Br({projectName:async()=>ut(e.projectName),frontend:()=>nt(e.frontend),backend:()=>Xe(e.backend),runtime:()=>mt(e.runtime),database:()=>Ye(e.database),orm:({results:t})=>ot(e.orm,t.database!=="none"),auth:({results:t})=>Ke(e.auth,t.database!=="none",t.frontend),turso:({results:t})=>t.database==="sqlite"&&t.orm!=="prisma"?ft(e.turso):Promise.resolve(!1),prismaPostgres:({results:t})=>t.database==="postgres"&&t.orm==="prisma"?pt(e.prismaPostgres):Promise.resolve(!1),addons:({results:t})=>Qe(e.addons,t.frontend),examples:({results:t})=>et(e.examples,t.database,t.frontend,t.backend),git:()=>st(e.git),packageManager:()=>ct(e.packageManager),noInstall:()=>it(e.noInstall)},{onCancel:()=>{Mr(zr.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,turso:a.turso,prismaPostgres:a.prismaPostgres,backend:a.backend,runtime:a.runtime}}import R from"picocolors";function ce(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.turso!==void 0&&a.push(`${R.blue("Turso Setup:")} ${e.turso}`),e.prismaPostgres!==void 0&&a.push(`${R.blue("Prisma Postgres Setup:")} ${e.prismaPostgres?"Yes":"No"}`),a.join(`
|
|
237
|
-
`)}function
|
|
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($,"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($,"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($,`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($,"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($,`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($,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($,"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 x=Xa(r,n),C=u.join(l,x);if(await d.pathExists(C)){let T=await d.readdir(C);for(let O of T)await d.copy(u.join(C,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 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 Et(e){let a=[];e.database==="none"?a.push("--database none"):(a.push(`--database ${e.database}`),e.orm&&a.push(`--orm ${e.orm}`),e.dbSetup&&e.dbSetup!=="none"&&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 At=()=>{let e=an.join($,"package.json");return rn.readJSONSync(e).version??"1.0.0"};import St from"gradient-string";var Tt=`
|
|
238
270
|
\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2557
|
|
239
271
|
\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u2550\u2588\u2588\u2554\u2550\u2550\u255D\u255A\u2550\u2550\u2588\u2588\u2554\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557
|
|
240
272
|
\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D
|
|
@@ -248,10 +280,10 @@ serve(
|
|
|
248
280
|
\u2588\u2588\u2551 \u255A\u2550\u2550\u2550\u2550\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2588\u2588\u2557
|
|
249
281
|
\u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2557
|
|
250
282
|
\u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D
|
|
251
|
-
`,
|
|
252
|
-
`),t=Math.max(...a.map(r=>r.length));e<t?console.log(
|
|
283
|
+
`,Rt={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(`
|
|
284
|
+
`),t=Math.max(...a.map(r=>r.length));e<t?console.log(St(Object.values(Rt)).multiline(`
|
|
253
285
|
\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557
|
|
254
286
|
\u2551 Better T-Stack \u2551
|
|
255
287
|
\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D
|
|
256
|
-
`)):console.log(
|
|
257
|
-
${g.white(
|
|
288
|
+
`)):console.log(St(Object.values(Rt)).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(At()).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{Ct(),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 $t(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(Et(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(x=>x==="tanstack-router"||x==="react-router"||x==="tanstack-start"||x==="native");let k=t.filter(x=>x==="tanstack-router"||x==="react-router"||x==="tanstack-start");if(k.length>1){let x=k[0];t=t.filter(C=>C==="native"||C===x)}}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(x=>x==="pwa"||x==="tauri"||x==="biome"||x==="husky"),!t?.some(x=>x==="tanstack-router"||x==="react-router")){let x=["pwa","tauri"],C=n.filter(T=>!x.includes(T));C.length!==n.length&&(S.warn(g.yellow("PWA and Tauri addons require tanstack-router or react-router - removing these addons")),n=C)}n.includes("husky")&&!n.includes("biome")&&n.push("biome")}let s=e.database,i=e.orm,o="auth"in e?e.auth:void 0,p=e.backend,c=e.runtime,l=e.packageManager,m;e.dbSetup&&(e.dbSetup==="none"?m="none":(m=e.dbSetup,m==="turso"?(s="sqlite",i==="prisma"&&(S.warn(g.yellow("Turso is not compatible with Prisma - switching to Drizzle")),i="drizzle")):m==="prisma-postgres"?(s="postgres",i="prisma"):m==="mongodb-atlas"&&(s="mongodb",i="prisma")));let b={};return a&&(b.projectName=a),s!==void 0&&(b.database=s),i!==void 0&&(b.orm=i),o!==void 0&&(b.auth=o),l&&(b.packageManager=l),"git"in e&&(b.git=e.git),"install"in e&&(b.noInstall=!e.install),m!==void 0&&(b.dbSetup=m),p&&(b.backend=p),c&&(b.runtime=c),t!==void 0&&(b.frontend=t),n!==void 0&&(b.addons=n),r!==void 0&&(b.examples=r),b}pn().catch(e=>{S.error("Aborting installation..."),e instanceof Error?S.error(e.message):(S.error("An unknown error has occurred. Please open an issue on GitHub with the below:"),console.log(e)),process.exit(1)});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-better-t-stack",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.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",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"prepublishOnly": "npm run build"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@clack/prompts": "^0.10.
|
|
55
|
+
"@clack/prompts": "^0.10.1",
|
|
56
56
|
"commander": "^13.1.0",
|
|
57
57
|
"execa": "^8.0.1",
|
|
58
58
|
"fs-extra": "^11.3.0",
|
|
@@ -61,8 +61,8 @@
|
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@types/fs-extra": "^11.0.4",
|
|
64
|
-
"@types/node": "^20.17.
|
|
64
|
+
"@types/node": "^20.17.30",
|
|
65
65
|
"tsup": "^8.4.0",
|
|
66
|
-
"typescript": "^5.
|
|
66
|
+
"typescript": "^5.8.3"
|
|
67
67
|
}
|
|
68
68
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CreateExpressContextOptions } from "@trpc/server/adapters/express";
|
|
2
|
+
import { fromNodeHeaders } from "better-auth/node";
|
|
3
|
+
import { auth } from "./auth";
|
|
4
|
+
|
|
5
|
+
export async function createContext(opts: CreateExpressContextOptions) {
|
|
6
|
+
const session = await auth.api.getSession({
|
|
7
|
+
headers: fromNodeHeaders(opts.req.headers),
|
|
8
|
+
});
|
|
9
|
+
return {
|
|
10
|
+
session,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type Context = Awaited<ReturnType<typeof createContext>>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import "dotenv/config";
|
|
2
|
+
import { createExpressMiddleware } from "@trpc/server/adapters/express";
|
|
3
|
+
import { toNodeHandler } from "better-auth/node";
|
|
4
|
+
import cors from "cors";
|
|
5
|
+
import express from "express";
|
|
6
|
+
import { auth } from "./lib/auth";
|
|
7
|
+
import { createContext } from "./lib/context";
|
|
8
|
+
import { appRouter } from "./routers/index";
|
|
9
|
+
|
|
10
|
+
const app = express();
|
|
11
|
+
|
|
12
|
+
app.use(
|
|
13
|
+
cors({
|
|
14
|
+
origin: process.env.CORS_ORIGIN || "",
|
|
15
|
+
methods: ["GET", "POST", "OPTIONS"],
|
|
16
|
+
allowedHeaders: ["Content-Type", "Authorization"],
|
|
17
|
+
credentials: true,
|
|
18
|
+
}),
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
app.all("/api/auth{/*path}", toNodeHandler(auth));
|
|
22
|
+
app.use(express.json());
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
app.use("/trpc", createExpressMiddleware({ router: appRouter, createContext }));
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
app.get("/", (_req, res) => {
|
|
29
|
+
res.status(200).send("OK");
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
app.listen(3000, () => {
|
|
33
|
+
console.log("Server is running on port 3000");
|
|
34
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
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: "mongodb",
|
|
8
|
+
}),
|
|
9
|
+
trustedOrigins: [process.env.CORS_ORIGIN || ""],
|
|
10
|
+
emailAndPassword: { enabled: true },
|
|
11
|
+
advanced: {
|
|
12
|
+
defaultCookieAttributes: {
|
|
13
|
+
sameSite: "none",
|
|
14
|
+
secure: true,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import "dotenv/config";
|
|
2
|
+
import { createExpressMiddleware } from "@trpc/server/adapters/express";
|
|
3
|
+
import cors from "cors";
|
|
4
|
+
import express from "express";
|
|
5
|
+
import { createContext } from "./lib/context";
|
|
6
|
+
import { appRouter } from "./routers/index";
|
|
7
|
+
|
|
8
|
+
const app = express();
|
|
9
|
+
|
|
10
|
+
app.use(
|
|
11
|
+
cors({
|
|
12
|
+
origin: process.env.CORS_ORIGIN || "",
|
|
13
|
+
methods: ["GET", "POST", "OPTIONS"],
|
|
14
|
+
allowedHeaders: ["Content-Type", "Authorization"],
|
|
15
|
+
credentials: true,
|
|
16
|
+
}),
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
app.use(express.json());
|
|
20
|
+
|
|
21
|
+
app.use("/trpc", createExpressMiddleware({ router: appRouter, createContext }));
|
|
22
|
+
|
|
23
|
+
app.get("/", (_req, res) => {
|
|
24
|
+
res.status(200).send("OK");
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
app.listen(3000, () => {
|
|
28
|
+
console.log("Server is running on port 3000");
|
|
29
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CreateExpressContextOptions } from "@trpc/server/adapters/express";
|
|
2
|
+
|
|
3
|
+
export async function createContext(opts: CreateExpressContextOptions) {
|
|
4
|
+
return {
|
|
5
|
+
session: null,
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type Context = Awaited<ReturnType<typeof createContext>>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
model User {
|
|
2
|
+
id String @id @map("_id")
|
|
3
|
+
name String
|
|
4
|
+
email String
|
|
5
|
+
emailVerified Boolean
|
|
6
|
+
image String?
|
|
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 @map("_id")
|
|
18
|
+
expiresAt DateTime
|
|
19
|
+
token String
|
|
20
|
+
createdAt DateTime
|
|
21
|
+
updatedAt DateTime
|
|
22
|
+
ipAddress String?
|
|
23
|
+
userAgent String?
|
|
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 @map("_id")
|
|
33
|
+
accountId String
|
|
34
|
+
providerId String
|
|
35
|
+
userId String
|
|
36
|
+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
37
|
+
accessToken String?
|
|
38
|
+
refreshToken String?
|
|
39
|
+
idToken String?
|
|
40
|
+
accessTokenExpiresAt DateTime?
|
|
41
|
+
refreshTokenExpiresAt DateTime?
|
|
42
|
+
scope String?
|
|
43
|
+
password String?
|
|
44
|
+
createdAt DateTime
|
|
45
|
+
updatedAt DateTime
|
|
46
|
+
|
|
47
|
+
@@map("account")
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
model Verification {
|
|
51
|
+
id String @id @map("_id")
|
|
52
|
+
identifier String
|
|
53
|
+
value String
|
|
54
|
+
expiresAt DateTime
|
|
55
|
+
createdAt DateTime?
|
|
56
|
+
updatedAt DateTime?
|
|
57
|
+
|
|
58
|
+
@@map("verification")
|
|
59
|
+
}
|