create-better-t-stack 1.12.4 → 1.13.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 +1 -2
- package/dist/index.js +73 -73
- package/package.json +1 -1
- package/template/base/apps/server/_gitignore +17 -2
- package/template/base/apps/web-base/_gitignore +39 -13
- package/template/base/apps/web-base/src/index.css +1 -1
- package/template/base/apps/web-next/next-env.d.ts +5 -0
- package/template/base/apps/web-next/next.config.ts +7 -0
- package/template/base/apps/web-next/package.json +41 -0
- package/template/base/apps/web-next/postcss.config.mjs +5 -0
- package/template/base/apps/web-next/src/app/favicon.ico +0 -0
- package/template/base/apps/web-next/src/app/layout.tsx +41 -0
- package/template/base/apps/web-next/src/app/page.tsx +83 -0
- package/template/base/apps/web-next/src/components/header.tsx +30 -0
- package/template/base/apps/web-next/src/components/mode-toggle.tsx +39 -0
- package/template/base/apps/web-next/src/components/providers.tsx +25 -0
- package/template/base/apps/web-next/src/components/theme-provider.tsx +11 -0
- package/template/base/apps/web-next/src/utils/trpc.ts +33 -0
- package/template/base/apps/web-next/tsconfig.json +28 -0
- package/template/with-auth/apps/server/src/lib/with-next-context.ts +14 -0
- package/template/with-auth/apps/server/src/with-next-app/api/auth/[...all]/route.ts +4 -0
- package/template/with-auth/apps/web-next/src/app/dashboard/page.tsx +31 -0
- package/template/with-auth/apps/web-next/src/app/login/page.tsx +16 -0
- package/template/with-auth/apps/web-next/src/components/header.tsx +33 -0
- package/template/with-auth/apps/web-next/src/components/sign-in-form.tsx +135 -0
- package/template/with-auth/apps/web-next/src/components/sign-up-form.tsx +160 -0
- package/template/with-auth/apps/web-next/src/components/theme-provider.tsx +11 -0
- package/template/with-auth/apps/web-next/src/components/user-menu.tsx +60 -0
- package/template/with-auth/apps/web-next/src/lib/auth-client.ts +5 -0
- package/template/with-auth/apps/web-next/src/utils/trpc.ts +39 -0
- package/template/with-next/apps/server/next-env.d.ts +5 -0
- package/template/with-next/apps/server/next.config.ts +7 -0
- package/template/with-next/apps/server/package.json +20 -0
- package/template/with-next/apps/server/src/app/route.ts +5 -0
- package/template/with-next/apps/server/src/app/trpc/[trpc]/route.ts +14 -0
- package/template/with-next/apps/server/src/lib/context.ts +9 -0
- package/template/with-next/apps/server/src/middleware.ts +19 -0
- package/template/with-next/apps/server/tsconfig.json +27 -0
- package/template/base/apps/web-tanstack-start/src/index.css +0 -135
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{cancel as
|
|
3
|
-
${
|
|
2
|
+
import{cancel as $,intro as Cn,log as L,outro as Fn,spinner as Rn}from"@clack/prompts";import y from"picocolors";import In from"yargs";import{hideBin as On}from"yargs/helpers";import Se from"node:path";import{fileURLToPath as Xt}from"node:url";var ae=()=>{let e=process.env.npm_config_user_agent;return e?.startsWith("pnpm")?"pnpm":e?.startsWith("bun")?"bun":"npm"};var Zt=Xt(import.meta.url),er=Se.dirname(Zt),v=Se.join(er,"../"),h={projectName:"my-better-t-app",frontend:["tanstack-router"],database:"sqlite",orm:"drizzle",auth:!0,addons:[],examples:[],git:!0,packageManager:ae(),noInstall:!1,dbSetup:"none",backend:"hono",runtime:"bun"},me={"better-auth":"^1.2.5","@better-auth/expo":"^1.2.5","drizzle-orm":"^0.38.4","drizzle-kit":"^0.30.5","@libsql/client":"^0.14.0",pg:"^8.14.1","@types/pg":"^8.11.11",mysql2:"^3.14.0","@prisma/client":"^6.6.0",prisma:"^6.6.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.6",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 ka from"node:path";import{cancel as $a,spinner as Sa}from"@clack/prompts";import Aa from"fs-extra";import Pt from"picocolors";import N from"node:path";import A from"fs-extra";import tr from"node:path";import Ae from"fs-extra";var g=e=>{let{dependencies:r=[],devDependencies:t=[],projectDir:a}=e,n=tr.join(a,"package.json"),s=Ae.readJSONSync(n);s.dependencies||(s.dependencies={}),s.devDependencies||(s.devDependencies={});for(let o of r){let i=me[o];s.dependencies[o]=i}for(let o of t){let i=me[o];s.devDependencies[o]=i}Ae.writeJSONSync(n,s,{spaces:2})};import rr from"node:path";import{log as ar,spinner as nr}from"@clack/prompts";import{execa as sr}from"execa";import Ee from"picocolors";async function De(e,r){let t=nr();try{t.start("Setting up Starlight documentation site...");let a,n;switch(r){case"npm":a="npx",n=["create-astro@latest"];break;case"pnpm":a="pnpm",n=["dlx","create-astro@latest"];break;case"bun":a="bunx",n=["create-astro@latest"];break;default:a="npx",n=["create-astro@latest"]}n=[...n,"docs","--template","starlight","--no-install","--add","tailwind","--no-git","--skip-houston"],await sr(a,n,{cwd:rr.join(e,"apps"),env:{CI:"true"}}),t.stop("Starlight documentation site setup successfully!")}catch(a){throw t.stop(Ee.red("Failed to set up Starlight documentation site")),a instanceof Error&&ar.error(Ee.red(a.message)),a}}import ne from"node:path";import{log as or,spinner as ir}from"@clack/prompts";import{execa as cr}from"execa";import se from"fs-extra";import Te from"picocolors";async function Ce(e,r,t){let a=ir(),n=ne.join(e,"apps/web");if(await se.pathExists(n))try{a.start("Setting up Tauri desktop app support..."),g({devDependencies:["@tauri-apps/cli"],projectDir:n});let s=ne.join(n,"package.json");if(await se.pathExists(s)){let d=await se.readJson(s);d.scripts={...d.scripts,tauri:"tauri","desktop:dev":"tauri dev","desktop:build":"tauri build"},await se.writeJson(s,d,{spaces:2})}let o,i;switch(r){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 p=t.includes("react-router")?"http://localhost:5173":"http://localhost:3001";i=[...i,"init",`--app-name=${ne.basename(e)}`,`--window-title=${ne.basename(e)}`,"--frontend-dist=dist",`--dev-url=${p}`,`--before-dev-command=${r} run dev`,`--before-build-command=${r} run build`],await cr(o,i,{cwd:n,env:{CI:"true"}}),a.stop("Tauri desktop app support configured successfully!")}catch(s){throw a.stop(Te.red("Failed to set up Tauri")),s instanceof Error&&or.error(Te.red(s.message)),s}}async function Fe(e,r,t,a){let n=a.includes("react-router")||a.includes("tanstack-router");r.includes("pwa")&&n&&await dr(e,a),r.includes("tauri")&&n&&await Ce(e,t,a),r.includes("biome")&&await lr(e),r.includes("husky")&&await ur(e),r.includes("starlight")&&await De(e,t)}function pr(e,r){return N.join(e,"apps/web")}async function lr(e){let r=N.join(v,"template/with-biome");await A.pathExists(r)&&await A.copy(r,e,{overwrite:!0}),g({devDependencies:["@biomejs/biome"],projectDir:e});let t=N.join(e,"package.json");if(await A.pathExists(t)){let a=await A.readJson(t);a.scripts={...a.scripts,check:"biome check --write ."},await A.writeJson(t,a,{spaces:2})}}async function ur(e){let r=N.join(v,"template/with-husky");await A.pathExists(r)&&await A.copy(r,e,{overwrite:!0}),g({devDependencies:["husky","lint-staged"],projectDir:e});let t=N.join(e,"package.json");if(await A.pathExists(t)){let a=await A.readJson(t);a.scripts={...a.scripts,prepare:"husky"},a["lint-staged"]={"*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json,jsonc}":["biome check --write ."]},await A.writeJson(t,a,{spaces:2})}}async function dr(e,r){let t=N.join(v,"template/with-pwa");await A.pathExists(t)&&await A.copy(t,e,{overwrite:!0});let a=pr(e,r);if(!await A.pathExists(a))return;g({dependencies:["vite-plugin-pwa"],devDependencies:["@vite-pwa/assets-generator"],projectDir:a});let n=N.join(a,"vite.config.ts");if(await A.pathExists(n)){let o=await A.readFile(n,"utf8");if(!o.includes("vite-plugin-pwa")){let l=o.match(/^import .* from ['"](.*)['"]/m);l?o=o.replace(l[0],`import { VitePWA } from "vite-plugin-pwa";
|
|
3
|
+
${l[0]}`):o=`import { VitePWA } from "vite-plugin-pwa";
|
|
4
4
|
${o}`}let i=`VitePWA({
|
|
5
5
|
registerType: "autoUpdate",
|
|
6
6
|
manifest: {
|
|
@@ -21,13 +21,13 @@ ${o}`}let i=`VitePWA({
|
|
|
21
21
|
${i}`):r.includes("tanstack-router")?o=o.replace(/plugins: \[\s*tailwindcss\(\)/,`plugins: [
|
|
22
22
|
tailwindcss(),
|
|
23
23
|
${i}`):o=o.replace(/plugins: \[/,`plugins: [
|
|
24
|
-
${i},`)),await
|
|
24
|
+
${i},`)),await A.writeFile(n,o)}let s=N.join(a,"package.json");if(await A.pathExists(s)){let o=await A.readJson(s);o.scripts={...o.scripts,"generate-pwa-assets":"pwa-assets-generator"},await A.writeJson(s,o,{spaces:2})}}import fe from"node:path";import{log as Re}from"@clack/prompts";import Ie from"picocolors";function Oe(e=32){let r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",t="",a=r.length;for(let n=0;n<e;n++)t+=r.charAt(Math.floor(Math.random()*a));return t}async function Be(e,r,t=[]){if(!r)return;let a=fe.join(e,"apps/server"),n=fe.join(e,"apps/web"),s=fe.join(e,"apps/native");try{g({dependencies:["better-auth"],projectDir:a}),(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:a}))}catch(o){throw Re.error(Ie.red("Failed to configure authentication")),o instanceof Error&&Re.error(Ie.red(o.message)),o}}import mr from"node:path";async function Le(e,r,t){let a=mr.join(e,"apps/server"),n=[],s=[];r==="hono"?(n.push("hono","@hono/trpc-server"),t==="node"&&(n.push("@hono/node-server"),s.push("tsx","@types/node"))):r==="elysia"?(n.push("elysia","@elysiajs/cors","@elysiajs/trpc"),t==="node"&&(n.push("@elysiajs/node"),s.push("tsx","@types/node"))):r==="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:a})}import fr from"node:path";import hr from"fs-extra";async function Ne(e,r){let t=fr.join(e,"README.md"),a=gr(r);try{await hr.writeFile(t,a)}catch(n){console.error("Failed to create README.md file:",n)}}function gr(e){let{projectName:r,packageManager:t,database:a,auth:n,addons:s=[],orm:o="drizzle",runtime:i="bun",frontend:l=["tanstack-router"]}=e,p=l.includes("react-router"),d=l.includes("tanstack-router"),P=l.includes("native"),x=t==="npm"?"npm run":t,j=p?"5173":"3001";return`# ${r}
|
|
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, ${d?"TanStack Router":"React Router"}, Hono, tRPC, and more.
|
|
27
27
|
|
|
28
28
|
## Features
|
|
29
29
|
|
|
30
|
-
${
|
|
30
|
+
${br(a,n,s,o,i,l)}
|
|
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
|
+
${wr(a,n,x,o)}
|
|
41
41
|
|
|
42
42
|
Then, run the development server:
|
|
43
43
|
|
|
44
44
|
\`\`\`bash
|
|
45
|
-
${
|
|
45
|
+
${x} dev
|
|
46
46
|
\`\`\`
|
|
47
47
|
|
|
48
|
-
${d||
|
|
48
|
+
${d||p?`Open [http://localhost:${j}](http://localhost:${j}) in your browser to see the web application.`:""}
|
|
49
49
|
${P?`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")&&p?`
|
|
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
|
${r}/
|
|
64
64
|
\u251C\u2500\u2500 apps/
|
|
65
|
-
${d||
|
|
65
|
+
${d||p?`\u2502 \u251C\u2500\u2500 web/ # Frontend application (React, ${d?"TanStack Router":"React Router"})
|
|
66
66
|
`:""}${P?`\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
|
+
${yr(x,a,o,n,P)}
|
|
73
|
+
`}function br(e,r,t,a,n,s){let o=s.includes("tanstack-router"),i=s.includes("react-router"),l=s.includes("native"),p=["- **TypeScript** - For type safety and improved developer experience"];o?p.push("- **TanStack Router** - File-based routing with full type safety"):i&&p.push("- **React Router** - Declarative routing for React"),l&&(p.push("- **React Native** - Build mobile apps using React"),p.push("- **Expo** - Tools for React Native development")),p.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"&&p.push(`- **${a==="drizzle"?"Drizzle":"Prisma"}** - TypeScript-first ORM`,`- **${e==="sqlite"?"SQLite/Turso":"PostgreSQL"}** - Database engine`),r&&p.push("- **Authentication** - Email & password authentication with Better Auth");for(let d of t)d==="pwa"?p.push("- **PWA** - Progressive Web App support"):d==="tauri"?p.push("- **Tauri** - Build native desktop applications"):d==="biome"?p.push("- **Biome** - Linting and formatting"):d==="husky"&&p.push("- **Husky** - Git hooks for code quality");return p.join(`
|
|
74
|
+
`)}function wr(e,r,t,a){if(e==="none")return"";let n=`## Database Setup
|
|
75
75
|
|
|
76
76
|
`;return e==="sqlite"?n+=`This project uses SQLite${a==="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 yr(e,r,t,a,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,49 +101,49 @@ ${t} db:push
|
|
|
101
101
|
- \`${e} dev:native\`: Start the React Native/Expo development server`),r!=="none"&&(s+=`
|
|
102
102
|
- \`${e} db:push\`: Push schema changes to database
|
|
103
103
|
- \`${e} db:studio\`: Open database studio UI`,r==="sqlite"&&t==="drizzle"&&(s+=`
|
|
104
|
-
- \`cd apps/server && ${e} db:local\`: Start the local SQLite database`)),s}import
|
|
105
|
-
${n}`,await Y.writeFile(t,a.trim())}catch(t){throw
|
|
106
|
-
${
|
|
104
|
+
- \`cd apps/server && ${e} db:local\`: Start the local SQLite database`)),s}import Xe from"node:path";import{log as Kr,spinner as Yr}from"@clack/prompts";import Xr from"fs-extra";import Ze from"picocolors";import ge from"node:path";import{cancel as Pr,isCancel as jr,log as I,spinner as ze,text as vr}from"@clack/prompts";import{execa as xr}from"execa";import Y from"fs-extra";import T from"picocolors";import{execa as Me}from"execa";async function oe(e){try{return process.platform==="win32"?(await Me("where",[e])).exitCode===0:(await Me("which",[e])).exitCode===0}catch{return!1}}async function kr(){let e=ze();e.start("Checking for MongoDB Atlas CLI");try{let r=await oe("atlas");return e.stop(r?"MongoDB Atlas CLI found":T.yellow("MongoDB Atlas CLI not found")),r}catch{return e.stop(T.red("Error checking for MongoDB Atlas CLI")),!1}}async function $r(e){try{if(!await kr())return I.error(T.red("MongoDB Atlas CLI not found.")),I.info(T.yellow("Please install it from: https://www.mongodb.com/docs/atlas/cli/current/install-atlas-cli/")),null;I.info(T.blue("Running MongoDB Atlas setup...")),await xr("atlas",["deployments","setup"],{cwd:e,stdio:"inherit"}),I.info(T.green("Atlas setup complete!"));let t=await vr({message:"Enter your MongoDB connection string:",placeholder:"mongodb+srv://username:password@cluster.mongodb.net/database",validate(a){if(!a)return"Please enter a connection string";if(!a.startsWith("mongodb"))return"URL should start with mongodb:// or mongodb+srv://"}});return jr(t)?(Pr("MongoDB setup cancelled"),null):{connectionString:t}}catch(r){return r instanceof Error&&I.error(T.red(r.message)),null}}async function he(e,r){try{let t=ge.join(e,"apps/server",".env");await Y.ensureDir(ge.dirname(t));let a="";await Y.pathExists(t)&&(a=await Y.readFile(t,"utf8"));let n=r?`DATABASE_URL="${r.connectionString}"`:'DATABASE_URL="mongodb://localhost:27017/mydb"';a.includes("DATABASE_URL=")?a=a.replace(/DATABASE_URL=.*(\r?\n|$)/,`${n}$1`):a+=`
|
|
105
|
+
${n}`,await Y.writeFile(t,a.trim())}catch(t){throw I.error("Failed to update environment configuration"),t}}function _e(){I.info(`
|
|
106
|
+
${T.green("MongoDB Atlas Manual Setup Instructions:")}
|
|
107
107
|
|
|
108
108
|
1. Install Atlas CLI:
|
|
109
|
-
${
|
|
109
|
+
${T.blue("https://www.mongodb.com/docs/atlas/cli/stable/install-atlas-cli/")}
|
|
110
110
|
|
|
111
111
|
2. Run the following command and follow the prompts:
|
|
112
|
-
${
|
|
112
|
+
${T.blue("atlas deployments setup")}
|
|
113
113
|
|
|
114
114
|
3. Get your connection string from the Atlas dashboard:
|
|
115
|
-
Format: ${
|
|
115
|
+
Format: ${T.dim("mongodb+srv://USERNAME:PASSWORD@CLUSTER.mongodb.net/DATABASE_NAME")}
|
|
116
116
|
|
|
117
117
|
4. Add the connection string to your .env file:
|
|
118
|
-
${
|
|
119
|
-
`)}async function
|
|
118
|
+
${T.dim('DATABASE_URL="your_connection_string"')}
|
|
119
|
+
`)}async function Ue(e){let r=ze();r.start("Setting up MongoDB Atlas");let t=ge.join(e,"apps/server");try{await Y.ensureDir(t),r.stop("Starting MongoDB Atlas setup");let a=await $r(t);a?(await he(e,a),I.success(T.green("MongoDB Atlas setup complete! Connection saved to .env file."))):(I.warn(T.yellow("Falling back to local MongoDB configuration")),await he(e),_e())}catch(a){r.stop(T.red("MongoDB Atlas setup failed")),I.error(T.red(`Error during MongoDB Atlas setup: ${a instanceof Error?a.message:String(a)}`));try{await he(e),_e()}catch{}}}import ie from"node:path";import{cancel as Sr,isCancel as Ar,log as V,spinner as be,text as Er}from"@clack/prompts";import{execa as Ve}from"execa";import we from"fs-extra";import q from"picocolors";function We(e,r){let t,a;switch(e){case"pnpm":t="pnpm",a=["dlx","neonctl",...r];break;case"bun":t="bunx",a=["neonctl",...r];break;default:t="npx",a=["neonctl",...r]}return{cmd:t,cmdArgs:a}}async function Ge(e,r,t){let a=t?be():null;try{let{cmd:n,cmdArgs:s}=We(e,r);a&&a.start(t);let o=await Ve(n,s);return a&&a.stop(t),o}catch(n){throw a&&a.stop(q.red(`Failed: ${t}`)),n}}async function Dr(e){try{let{cmd:r,cmdArgs:t}=We(e,["projects","list"]),a=await Ve(r,t);return!a.stdout.includes("not authenticated")&&!a.stdout.includes("error")}catch{return!1}}async function Tr(e){try{return await Ge(e,["auth"],"Authenticating with Neon..."),V.success("Authenticated with Neon successfully!"),!0}catch(r){throw V.error(q.red("Failed to authenticate with Neon")),r}}async function Cr(e,r){try{let{stdout:t}=await Ge(r,["projects","create","--name",e,"--output","json"],`Creating Neon project "${e}"...`),a=JSON.parse(t);if(a.project&&a.connection_uris&&a.connection_uris.length>0){let n=a.project.id,s=a.connection_uris[0].connection_uri,o=a.connection_uris[0].connection_parameters;return{connectionString:s,projectId:n,dbName:o.database,roleName:o.role}}return V.error(q.red("Failed to extract connection information from response")),null}catch(t){throw V.error(q.red("Failed to create Neon project")),t}}async function qe(e,r){let t=ie.join(e,"apps/server",".env"),a=r?`DATABASE_URL="${r.connectionString}"`:'DATABASE_URL="postgresql://postgres:postgres@localhost:5432/mydb?schema=public"';return await we.ensureDir(ie.dirname(t)),await we.writeFile(t,a),!0}function Fr(){V.info(`Manual Neon PostgreSQL Setup Instructions:
|
|
120
120
|
|
|
121
121
|
1. Visit https://neon.tech and create an account
|
|
122
122
|
2. Create a new project from the dashboard
|
|
123
123
|
3. Get your connection string
|
|
124
124
|
4. Add the database URL to the .env file in apps/server/.env
|
|
125
125
|
|
|
126
|
-
DATABASE_URL="your_connection_string"`)}async function
|
|
127
|
-
It looks like: prisma+postgres://accelerate.prisma-data.net/?api_key=...`));let s=await
|
|
128
|
-
${n}`,await
|
|
126
|
+
DATABASE_URL="your_connection_string"`)}async function Je(e,r){let t=be();t.start("Setting up Neon PostgreSQL");try{let a=await Dr(r);t.stop("Setting up Neon PostgreSQL"),a||(V.info("Please authenticate with Neon to continue:"),await Tr(r));let n=ie.basename(e),s=await Er({message:"Enter a name for your Neon project:",defaultValue:n,initialValue:n});Ar(s)&&(Sr(q.red("Operation cancelled")),process.exit(0));let o=await Cr(s,r);if(!o)throw new Error("Failed to create project - couldn't get connection information");let i=be();i.start("Configuring database connection"),await we.ensureDir(ie.join(e,"apps/server")),await qe(e,o),i.stop("Neon database configured successfully!")}catch(a){t.stop(q.red("Neon PostgreSQL setup failed")),a instanceof Error&&V.error(q.red(a.message)),await qe(e),Fr()}}import H from"node:path";import{cancel as Rr,isCancel as Ir,log as M,password as Or,spinner as Pe}from"@clack/prompts";import{execa as Br}from"execa";import O from"fs-extra";import Q from"picocolors";async function Lr(e,r){let t=Pe();try{t.start("Initializing Prisma PostgreSQL");let a=H.join(e,"prisma");await O.ensureDir(a);let n=r==="npm"?"npx":r==="pnpm"?"pnpm dlx":"bunx";t.stop("Initializing Prisma. Follow the prompts below:"),await Br(n,["prisma","init","--db"],{cwd:e,stdio:"inherit"}),M.info(Q.yellow(`Please copy the Prisma Postgres URL from the output above.
|
|
127
|
+
It looks like: prisma+postgres://accelerate.prisma-data.net/?api_key=...`));let s=await Or({message:"Paste your Prisma Postgres database URL:",validate(o){if(!o)return"Please enter a database URL";if(!o.startsWith("prisma+postgres://"))return"URL should start with prisma+postgres://"}});return Ir(s)?(Rr("Database setup cancelled"),null):{databaseUrl:s}}catch(a){return t.stop(Q.red("Failed to initialize Prisma PostgreSQL")),a instanceof Error&&M.error(a.message),null}}async function ye(e,r){try{let t=H.join(e,"apps/server",".env");await O.ensureDir(H.dirname(t));let a="";await O.pathExists(t)&&(a=await O.readFile(t,"utf8"));let n=r?`DATABASE_URL="${r.databaseUrl}"`:'DATABASE_URL="postgresql://postgres:postgres@localhost:5432/mydb?schema=public"';a.includes("DATABASE_URL=")?a=a.replace(/DATABASE_URL=.*(\r?\n|$)/,`${n}$1`):a+=`
|
|
128
|
+
${n}`,await O.writeFile(t,a.trim())}catch(t){throw M.error("Failed to update environment configuration"),t}}function Qe(){M.info(`Manual Prisma PostgreSQL Setup Instructions:
|
|
129
129
|
|
|
130
130
|
1. Visit https://console.prisma.io and create an account
|
|
131
131
|
2. Create a new PostgreSQL database from the dashboard
|
|
132
132
|
3. Get your database URL
|
|
133
133
|
4. Add the database URL to the .env file in apps/server/.env
|
|
134
134
|
|
|
135
|
-
DATABASE_URL="your_database_url"`)}async function
|
|
135
|
+
DATABASE_URL="your_database_url"`)}async function Nr(e){try{g({dependencies:["@prisma/extension-accelerate"],projectDir:e});let r=H.join(e,"prisma/index.ts");await O.writeFile(r,`
|
|
136
136
|
import { PrismaClient } from '@prisma/client';
|
|
137
137
|
import { withAccelerate } from "@prisma/extension-accelerate";
|
|
138
138
|
|
|
139
139
|
const prisma = new PrismaClient().$extends(withAccelerate());
|
|
140
140
|
|
|
141
141
|
export default prisma;
|
|
142
|
-
`.trim());let a=H.join(e,"src/db/index.ts");if(await
|
|
143
|
-
${n}`,n=n.replace("export const db = new PrismaClient();","export const db = new PrismaClient().$extends(withAccelerate());"),await
|
|
144
|
-
`);if(t.length<=1)return e.stop("No Turso groups found"),[];let a=t.slice(1).map(n=>{let[s,o,i,
|
|
142
|
+
`.trim());let a=H.join(e,"src/db/index.ts");if(await O.pathExists(a)){let n=await O.readFile(a,"utf8");n.includes("@prisma/extension-accelerate")||(n=`import { withAccelerate } from "@prisma/extension-accelerate";
|
|
143
|
+
${n}`,n=n.replace("export const db = new PrismaClient();","export const db = new PrismaClient().$extends(withAccelerate());"),await O.writeFile(a,n))}return!0}catch{return M.warn(Q.yellow("Could not add Prisma Accelerate extension automatically")),!1}}async function He(e,r="npm"){let t=H.join(e,"apps/server"),a=Pe();a.start("Setting up Prisma PostgreSQL");try{await O.ensureDir(t),a.stop("Starting Prisma setup");let n=await Lr(t,r);if(n)await ye(e,n),await Nr(t),M.success(Q.green("Prisma PostgreSQL database configured successfully!"));else{let s=Pe();s.start("Setting up fallback configuration"),await ye(e),s.stop("Manual setup required"),Qe()}}catch(n){a.stop(Q.red("Prisma PostgreSQL setup failed")),M.error(Q.red(`Error during Prisma PostgreSQL setup: ${n instanceof Error?n.message:String(n)}`));try{await ye(e),Qe()}catch{}M.info("Setup completed with manual configuration required.")}}import Mr from"node:os";import je from"node:path";import{cancel as ve,confirm as _r,isCancel as xe,log as _,select as zr,spinner as K,text as Ur}from"@clack/prompts";import{$ as B}from"execa";import Ke from"fs-extra";import D from"picocolors";async function qr(){return oe("turso")}async function Vr(){try{return!(await B`turso auth whoami`).stdout.includes("You are not logged in")}catch{return!1}}async function Wr(){let e=K();try{return e.start("Logging in to Turso..."),await B`turso auth login`,e.stop("Logged in to Turso successfully!"),!0}catch(r){throw e.stop(D.red("Failed to log in to Turso")),r}}async function Gr(e){let r=K();try{if(r.start("Installing Turso CLI..."),e)await B`brew install tursodatabase/tap/turso`;else{let{stdout:t}=await B`curl -sSfL https://get.tur.so/install.sh`;await B`bash -c '${t}'`}return r.stop("Turso CLI installed successfully!"),!0}catch(t){throw t instanceof Error&&t.message.includes("User force closed")?(r.stop("Turso CLI installation cancelled"),_.warn(D.yellow("Turso CLI installation cancelled by user")),new Error("Installation cancelled")):(r.stop(D.red("Failed to install Turso CLI")),t)}}async function Jr(){let e=K();try{e.start("Fetching Turso groups...");let{stdout:r}=await B`turso group list`,t=r.trim().split(`
|
|
144
|
+
`);if(t.length<=1)return e.stop("No Turso groups found"),[];let a=t.slice(1).map(n=>{let[s,o,i,l]=n.trim().split(/\s{2,}/);return{name:s,locations:o,version:i,status:l}});return e.stop(`Found ${a.length} Turso groups`),a}catch(r){return e.stop(D.red("Error fetching Turso groups")),console.error("Error fetching Turso groups:",r),[]}}async function Qr(){let e=await Jr();if(e.length===0)return null;if(e.length===1)return _.info(`Using the only available group: ${D.blue(e[0].name)}`),e[0].name;let r=e.map(a=>({value:a.name,label:`${a.name} (${a.locations})`})),t=await zr({message:"Select a Turso database group:",options:r});return xe(t)&&(ve(D.red("Operation cancelled")),process.exit(0)),t}async function Hr(e,r){let t=K();try{t.start(`Creating Turso database "${e}"${r?` in group "${r}"`:""}...`),r?await B`turso db create ${e} --group ${r}`:await B`turso db create ${e}`,t.stop(`Created database "${e}"`)}catch(a){throw t.stop(D.red(`Failed to create database "${e}"`)),a instanceof Error&&a.message.includes("already exists")?new Error("DATABASE_EXISTS"):a}t.start("Retrieving database connection details...");try{let{stdout:a}=await B`turso db show ${e} --url`,{stdout:n}=await B`turso db tokens create ${e}`;return t.stop("Retrieved database connection details"),{dbUrl:a.trim(),authToken:n.trim()}}catch(a){throw t.stop(D.red("Failed to retrieve database connection details")),a}}async function X(e,r){let t=je.join(e,"apps/server",".env"),a=r?`DATABASE_URL="${r.dbUrl}"
|
|
145
145
|
DATABASE_AUTH_TOKEN="${r.authToken}"`:`DATABASE_URL=
|
|
146
|
-
DATABASE_AUTH_TOKEN=`;await
|
|
146
|
+
DATABASE_AUTH_TOKEN=`;await Ke.ensureDir(je.dirname(t)),await Ke.writeFile(t,a)}function ce(){_.info(`Manual Turso Setup Instructions:
|
|
147
147
|
|
|
148
148
|
1. Visit https://turso.tech and create an account
|
|
149
149
|
2. Create a new database from the dashboard
|
|
@@ -151,8 +151,8 @@ DATABASE_AUTH_TOKEN=`;await He.ensureDir(we.dirname(t)),await He.writeFile(t,a)}
|
|
|
151
151
|
4. Add these credentials to the .env file in apps/server/.env
|
|
152
152
|
|
|
153
153
|
DATABASE_URL=your_database_url
|
|
154
|
-
DATABASE_AUTH_TOKEN=your_auth_token`)}async function
|
|
155
|
-
${n}=${s}`,a=!0)}a&&await
|
|
154
|
+
DATABASE_AUTH_TOKEN=your_auth_token`)}async function Ye(e,r){let t=K();t.start("Setting up Turso database");try{if(!r){t.stop("Skipping Turso setup"),await X(e),_.info(D.blue("Skipping Turso setup. Setting up empty configuration.")),ce();return}let a=Mr.platform(),n=a==="darwin";if(!(a!=="win32")){t.stop(D.yellow("Turso setup not supported on Windows")),_.warn(D.yellow("Automatic Turso setup is not supported on Windows.")),await X(e),ce();return}if(t.stop("Checking Turso CLI"),!await qr()){let x=await _r({message:"Would you like to install Turso CLI?",initialValue:!0});if(xe(x)&&(ve(D.red("Operation cancelled")),process.exit(0)),!x){await X(e),ce();return}await Gr(n)}await Vr()||await Wr();let l=await Qr(),p=!1,d="",P=je.basename(e);for(;!p;){let x=await Ur({message:"Enter a name for your database:",defaultValue:P,initialValue:P,placeholder:P});xe(x)&&(ve(D.red("Operation cancelled")),process.exit(0)),d=x;try{let j=await Hr(d,l),S=K();S.start("Writing configuration to .env file"),await X(e,j),S.stop("Turso database configured successfully!"),p=!0}catch(j){if(j instanceof Error&&j.message==="DATABASE_EXISTS")_.warn(D.yellow(`Database "${D.red(d)}" already exists`)),P=`${d}-${Math.floor(Math.random()*1e3)}`;else throw j}}}catch(a){t.stop(D.red("Failed to set up Turso database")),_.error(D.red(`Error during Turso setup: ${a instanceof Error?a.message:String(a)}`)),await X(e),ce(),_.success("Setup completed with manual configuration required.")}}async function et(e,r,t,a,n,s,o,i){let l=Yr(),p=Xe.join(e,"apps/server");if(r==="none"){await Xr.remove(Xe.join(p,"src/db"));return}try{t==="prisma"?g({dependencies:["@prisma/client"],devDependencies:["prisma"],projectDir:p}):t==="drizzle"&&(r==="sqlite"?g({dependencies:["drizzle-orm","@libsql/client"],devDependencies:["drizzle-kit"],projectDir:p}):r==="postgres"?g({dependencies:["drizzle-orm","pg"],devDependencies:["drizzle-kit","@types/pg"],projectDir:p}):r==="mysql"&&g({dependencies:["drizzle-orm","mysql2"],devDependencies:["drizzle-kit"],projectDir:p})),r==="sqlite"&&n?await Ye(e,t==="drizzle"):r==="postgres"?t==="prisma"&&s?await He(e,a):i&&await Je(e,a):r==="mongodb"&&o&&await Ue(e)}catch(d){throw l.stop(Ze.red("Failed to set up database")),d instanceof Error&&Kr.error(Ze.red(d.message)),d}}import W from"node:path";import pe from"fs-extra";async function ke(e,r){await pe.ensureDir(W.dirname(e));let t="";await pe.pathExists(e)&&(t=await pe.readFile(e,"utf8"));let a=!1;for(let{key:n,value:s,condition:o}of r)if(o){let i=new RegExp(`^${n}=.*$`,"m");i.test(t)?s&&(t=t.replace(i,`${n}=${s}`),a=!0):(t+=`
|
|
155
|
+
${n}=${s}`,a=!0)}a&&await pe.writeFile(e,t.trim())}async function tt(e,r){let t=W.join(e,"apps/server"),a=W.join(t,".env"),n=r.frontend.includes("react-router"),s=r.frontend.includes("tanstack-router"),o=r.frontend.includes("tanstack-start"),i=r.frontend.includes("next"),l=n||s||o||i,p="http://localhost:3000";n?p="http://localhost:5173":(s||o||i)&&(p="http://localhost:3001");let d="",P=r.dbSetup==="turso"||r.dbSetup==="prisma-postgres"||r.dbSetup==="mongodb-atlas"||r.dbSetup==="neon";P||(r.database==="postgres"?d="postgresql://postgres:postgres@localhost:5432/mydb?schema=public":r.database==="mysql"?d="mysql://root:password@localhost:3306/mydb":r.database==="mongodb"?d="mongodb://localhost:27017/mydatabase":r.database==="sqlite"&&(d="file:./local.db"));let x=[{key:"CORS_ORIGIN",value:p,condition:!0},{key:"BETTER_AUTH_SECRET",value:Oe(),condition:!!r.auth},{key:"BETTER_AUTH_URL",value:"http://localhost:3000",condition:!!r.auth},{key:"DATABASE_URL",value:d,condition:r.database!=="none"&&d!==""&&!P},{key:"GOOGLE_GENERATIVE_AI_API_KEY",value:"",condition:r.examples?.includes("ai")||!1}];if(await ke(a,x),l){let j=W.join(e,"apps/web"),S="VITE_SERVER_URL";i&&(S="NEXT_PUBLIC_SERVER_URL");let k=[{key:S,value:"http://localhost:3000",condition:!0}];await ke(W.join(j,".env"),k)}if(r.frontend.includes("native")){let j=W.join(e,"apps/native"),S=[{key:"EXPO_PUBLIC_SERVER_URL",value:"http://localhost:3000",condition:!0}];await ke(W.join(j,".env"),S)}}import E from"node:path";import b from"fs-extra";async function rt(e,r,t,a,n,s=["tanstack-router"]){let o=s.includes("tanstack-router"),i=s.includes("tanstack-start"),l=s.includes("react-router"),p=o||l||i,d;o?d="web-tanstack-router":i?d="web-tanstack-start":d="web-react-router";let P=await b.pathExists(E.join(e,"apps/web"));r.includes("todo")&&p&&P?await ra(e,t,a,d):await sa(e,t),r.includes("ai")&&(n==="hono"||n==="express")&&p&&P&&await Zr(e,d)}async function Zr(e,r){let t=E.join(v,"template/examples/ai");if(await b.pathExists(t)){let a=E.join(t,`apps/${r}/src/routes/ai.tsx`),n=E.join(e,"apps/web/src/routes/ai.tsx");await b.pathExists(a)&&await b.copy(a,n,{overwrite:!0}),await ta(e,r);let s=E.join(e,"apps/web");g({dependencies:["ai"],projectDir:s});let o=E.join(e,"apps/server");g({dependencies:["ai","@ai-sdk/google"],projectDir:o}),await ea(e)}}async function ea(e){let r=E.join(e,"apps/server/src/index.ts");if(await b.pathExists(r)){let t=await b.readFile(r,"utf8"),a=t.includes("hono"),n=t.includes("express");if(a){let s=`import { streamText } from "ai";
|
|
156
156
|
import { google } from "@ai-sdk/google";
|
|
157
157
|
import { stream } from "hono/streaming";`,o=`
|
|
158
158
|
// AI chat endpoint
|
|
@@ -169,16 +169,16 @@ app.post("/ai", async (c) => {
|
|
|
169
169
|
c.header("Content-Type", "text/plain; charset=utf-8");
|
|
170
170
|
|
|
171
171
|
return stream(c, (stream) => stream.pipe(result.toDataStream()));
|
|
172
|
-
});`;if(t.includes("import {")){let
|
|
173
|
-
`,
|
|
172
|
+
});`;if(t.includes("import {")){let l=t.lastIndexOf("import"),p=t.indexOf(`
|
|
173
|
+
`,l);t=`${t.substring(0,p+1)}
|
|
174
174
|
${s}
|
|
175
|
-
${t.substring(
|
|
175
|
+
${t.substring(p+1)}`}else t=`${s}
|
|
176
176
|
|
|
177
177
|
${t}`;let i=t.indexOf('app.use("/trpc"')||t.indexOf("app.use(trpc(");if(i!==-1)t=`${t.substring(0,i)}${o}
|
|
178
178
|
|
|
179
|
-
${t.substring(i)}`;else{let
|
|
179
|
+
${t.substring(i)}`;else{let l=t.indexOf("export default");l!==-1?t=`${t.substring(0,l)}${o}
|
|
180
180
|
|
|
181
|
-
${t.substring(
|
|
181
|
+
${t.substring(l)}`:t=`${t}
|
|
182
182
|
|
|
183
183
|
${o}`}}else if(n){let s=`import { streamText } from "ai";
|
|
184
184
|
import { google } from "@ai-sdk/google";`,o=`
|
|
@@ -192,54 +192,54 @@ app.post("/ai", async (req, res) => {
|
|
|
192
192
|
});
|
|
193
193
|
|
|
194
194
|
result.pipeDataStreamToResponse(res);
|
|
195
|
-
});`;if(t.includes("import {")||t.includes("import ")){let
|
|
196
|
-
`,
|
|
195
|
+
});`;if(t.includes("import {")||t.includes("import ")){let l=t.lastIndexOf("import"),p=t.indexOf(`
|
|
196
|
+
`,l);t=`${t.substring(0,p+1)}
|
|
197
197
|
${s}
|
|
198
|
-
${t.substring(
|
|
198
|
+
${t.substring(p+1)}`}else t=`${s}
|
|
199
199
|
|
|
200
200
|
${t}`;let i=t.indexOf('app.use("/trpc"');if(i!==-1)t=`${t.substring(0,i)}${o}
|
|
201
201
|
|
|
202
|
-
${t.substring(i)}`;else{let
|
|
203
|
-
`,
|
|
202
|
+
${t.substring(i)}`;else{let l=t.indexOf("app.listen(");if(l!==-1){let p=t.lastIndexOf(`
|
|
203
|
+
`,l);t=`${t.substring(0,p)}${o}
|
|
204
204
|
|
|
205
|
-
${t.substring(
|
|
205
|
+
${t.substring(p)}`}else t=`${t}
|
|
206
206
|
|
|
207
|
-
${o}`}}await b.writeFile(r,t)}}async function
|
|
207
|
+
${o}`}}await b.writeFile(r,t)}}async function ta(e,r){let t=E.join(e,"apps/web/src/components/header.tsx");if(await b.pathExists(t)){let a=await b.readFile(t,"utf8"),n=/const links = \[\s*([^;]*?)\s*\];/s,s=a.match(n);if(s){let o=s[1];if(!o.includes('"/ai"')){let i=`const links = [
|
|
208
208
|
${o}${o.trim().endsWith(",")?"":","}
|
|
209
209
|
{ to: "/ai", label: "AI Chat" },
|
|
210
|
-
];`;a=a.replace(n,i),await b.writeFile(t,a)}}}}async function
|
|
210
|
+
];`;a=a.replace(n,i),await b.writeFile(t,a)}}}}async function ra(e,r,t,a){let n=E.join(v,"template/examples/todo");if(await b.pathExists(n)){let s=E.join(n,`apps/${a}/src/routes/todos.tsx`),o=E.join(e,"apps/web/src/routes/todos.tsx");if(await b.pathExists(s)&&await b.copy(s,o,{overwrite:!0}),r!=="none"){let i=E.join(n,`apps/server/src/routers/with-${r}-todo.ts`),l=E.join(e,"apps/server/src/routers/todo.ts");await b.pathExists(i)&&await b.copy(i,l,{overwrite:!0}),await aa(e)}await na(e,a)}}async function aa(e){let r=E.join(e,"apps/server/src/routers/index.ts");if(await b.pathExists(r)){let t=await b.readFile(r,"utf8");if(!t.includes("import { todoRouter }")){let a=t.lastIndexOf("import"),n=t.indexOf(`
|
|
211
211
|
|
|
212
212
|
`,a);n!==-1?t=`${t.slice(0,n)}
|
|
213
213
|
import { todoRouter } from "./todo";${t.slice(n)}`:t=`import { todoRouter } from "./todo";
|
|
214
214
|
${t}`;let s=t.indexOf("export const appRouter = router({");if(s!==-1){let o=t.indexOf("{",s)+1;t=`${t.slice(0,o)}
|
|
215
|
-
todo: todoRouter,${t.slice(o)}`}await b.writeFile(r,t)}}}async function
|
|
215
|
+
todo: todoRouter,${t.slice(o)}`}await b.writeFile(r,t)}}}async function na(e,r){let t=E.join(e,"apps/web/src/components/header.tsx");if(await b.pathExists(t)){let a=await b.readFile(t,"utf8"),n=/const links = \[\s*([^;]*?)\s*\];/s,s=a.match(n);if(s){let o=s[1];if(!o.includes('"/todos"')){let i=`const links = [
|
|
216
216
|
${o}${o.trim().endsWith(",")?"":","}
|
|
217
217
|
{ to: "/todos", label: "Todos" },
|
|
218
|
-
];`;a=a.replace(n,i),await b.writeFile(t,a)}}}}async function
|
|
218
|
+
];`;a=a.replace(n,i),await b.writeFile(t,a)}}}}async function sa(e,r){if(r==="drizzle"){let a=E.join(e,"apps/server/src/db/schema/todo.ts");await b.pathExists(a)&&await b.remove(a)}else if(r==="prisma"){let a=E.join(e,"apps/server/prisma/schema/todo.prisma");await b.pathExists(a)&&await b.remove(a)}let t=E.join(e,"apps/server/src/routers/todo.ts");await b.pathExists(t)&&await b.remove(t),await oa(e)}async function oa(e){let r=E.join(e,"apps/server/src/routers/index.ts");if(await b.pathExists(r)){let t=await b.readFile(r,"utf8");t=t.replace(/import { todoRouter } from ".\/todo";/,""),t=t.replace(/todo: todoRouter,/,""),await b.writeFile(r,t)}}import{log as at,spinner as nt}from"@clack/prompts";import{$ as st}from"execa";import le from"picocolors";async function ot({projectDir:e,packageManager:r,addons:t=[]}){let a=nt();try{a.start(`Running ${r} install...`),await st({cwd:e,stderr:"inherit"})`${r} install`,a.stop("Dependencies installed successfully"),(t.includes("biome")||t.includes("husky"))&&await ia(e,r)}catch(n){throw a.stop(le.red("Failed to install dependencies")),n instanceof Error&&at.error(le.red(`Installation error: ${n.message}`)),n}}async function ia(e,r){let t=nt();try{t.start("Running Biome format check..."),await st({cwd:e,stderr:"inherit"})`${r} biome check --write .`,t.stop("Biome check completed successfully")}catch{t.stop(le.yellow("Biome check encountered issues")),at.warn(le.yellow("Some files may need manual formatting"))}}import{note as ca}from"@clack/prompts";import w from"picocolors";function it(e,r,t,a,n,s,o,i,l){let p=t==="npm"?"npm run":t,d=`cd ${r}`,P=s?.includes("husky")||s?.includes("biome"),x=e!=="none"?ua(e,n,p,o):"",j=s?.includes("tauri")?da(p):"",S=P?la(p):"",k=i?.includes("native")?pa():"",F=s?.includes("pwa")&&i?.includes("react-router")?ma():"",R=s?.includes("starlight")?fa(p):"",J=i?.includes("tanstack-router"),ee=i?.includes("tanstack-start"),te=i?.includes("react-router"),re=J||te||ee,Ht=i?.includes("native"),Kt=re||Ht,Yt=te?"5173":"3001";ca(`${w.cyan("1.")} ${d}
|
|
219
219
|
${a?"":`${w.cyan("2.")} ${t} install
|
|
220
|
-
`}${w.cyan(a?"2.":"3.")} ${
|
|
220
|
+
`}${w.cyan(a?"2.":"3.")} ${p} dev
|
|
221
221
|
|
|
222
222
|
${w.bold("Your project will be available at:")}
|
|
223
|
-
${
|
|
223
|
+
${Kt?`${re?`${w.cyan("\u2022")} Frontend: http://localhost:${Yt}
|
|
224
224
|
`:""}`:`${w.yellow("NOTE:")} You are creating a backend-only app (no frontend selected)
|
|
225
225
|
`}${w.cyan("\u2022")} API: http://localhost:3000
|
|
226
226
|
${s?.includes("starlight")?`${w.cyan("\u2022")} Docs: http://localhost:4321
|
|
227
|
-
`:""}${
|
|
228
|
-
${
|
|
229
|
-
${
|
|
230
|
-
${
|
|
231
|
-
${
|
|
232
|
-
${
|
|
233
|
-
${
|
|
227
|
+
`:""}${k?`
|
|
228
|
+
${k.trim()}`:""}${x?`
|
|
229
|
+
${x.trim()}`:""}${j?`
|
|
230
|
+
${j.trim()}`:""}${S?`
|
|
231
|
+
${S.trim()}`:""}${F?`
|
|
232
|
+
${F.trim()}`:""}${R?`
|
|
233
|
+
${R.trim()}`:""}
|
|
234
234
|
|
|
235
235
|
${w.bold("Like Better-T Stack?")} Please consider giving us a star on GitHub:
|
|
236
|
-
${w.cyan("https://github.com/AmanVarshney01/create-better-t-stack")}`,"Next steps")}function
|
|
236
|
+
${w.cyan("https://github.com/AmanVarshney01/create-better-t-stack")}`,"Next steps")}function pa(){return`${w.yellow("NOTE:")} For Expo connectivity issues, update apps/native/.env
|
|
237
237
|
with your local IP:
|
|
238
238
|
EXPO_PUBLIC_SERVER_URL=http://192.168.0.103:3000
|
|
239
|
-
`}function
|
|
239
|
+
`}function la(e){return`${w.bold("Linting and formatting:")}
|
|
240
240
|
${w.cyan("\u2022")} Format and lint fix: ${`${e} check`}
|
|
241
241
|
|
|
242
|
-
`}function
|
|
242
|
+
`}function ua(e,r,t,a){let n=[];return r==="prisma"?(e==="sqlite"&&n.push(`${w.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"),a==="bun"&&n.push(`${w.yellow("NOTE:")} Prisma with Bun may require additional configuration. If you encounter errors,
|
|
243
243
|
follow the guidance provided in the error messages`),n.push(`${w.cyan("\u2022")} Apply schema: ${`${t} db:push`}`),n.push(`${w.cyan("\u2022")} Database UI: ${`${t} db:studio`}`)):r==="drizzle"&&(n.push(`${w.cyan("\u2022")} Apply schema: ${`${t} db:push`}`),n.push(`${w.cyan("\u2022")} Database UI: ${`${t} db:studio`}`)),n.length?`${w.bold("Database commands:")}
|
|
244
244
|
${n.join(`
|
|
245
245
|
`)}
|
|
@@ -251,16 +251,16 @@ ${w.cyan("\u2022")} Build desktop app: ${`cd apps/web && ${e} desktop:build`}
|
|
|
251
251
|
${w.yellow("NOTE:")} Tauri requires Rust and platform-specific dependencies.
|
|
252
252
|
See: https://v2.tauri.app/start/prerequisites/
|
|
253
253
|
|
|
254
|
-
`}function
|
|
254
|
+
`}function ma(){return`${w.bold("PWA with React Router v7:")}
|
|
255
255
|
${w.yellow("NOTE:")} There is a known compatibility issue between VitePWA and React Router v7.
|
|
256
256
|
See: https://github.com/vite-pwa/vite-plugin-pwa/issues/809
|
|
257
|
-
`}function
|
|
257
|
+
`}function fa(e){return`${w.bold("Documentation with Starlight:")}
|
|
258
258
|
${w.cyan("\u2022")} Start docs site: ${`cd apps/docs && ${e} dev`}
|
|
259
259
|
${w.cyan("\u2022")} Build docs site: ${`cd apps/docs && ${e} build`}
|
|
260
|
-
`}import
|
|
260
|
+
`}import ue from"node:path";import{log as ha}from"@clack/prompts";import{$ as ct,execa as ga}from"execa";import z from"fs-extra";import ba from"picocolors";async function pt(e,r){await wa(e,r),await ya(e,r)}async function wa(e,r){let t=ue.join(e,"package.json");if(await z.pathExists(t)){let a=await z.readJson(t);a.name=r.projectName;let{stdout:n}=await ga(r.packageManager,["-v"],{cwd:e});if(a.packageManager=`${r.packageManager}@${n.trim()}`,await z.writeJson(t,a,{spaces:2}),r.packageManager==="pnpm"){let s=ue.join(v,"template/with-pnpm/pnpm-workspace.yaml"),o=ue.join(e,"pnpm-workspace.yaml");await z.pathExists(s)&&await z.copy(s,o)}}}async function ya(e,r){let t=ue.join(e,"apps/server/package.json");if(await z.pathExists(t)){let a=await z.readJson(t);r.database!=="none"&&(r.database==="sqlite"&&(a.scripts["db:local"]="turso dev --db-file local.db"),r.orm==="prisma"?(a.scripts["db:push"]="prisma db push --schema ./prisma/schema",a.scripts["db:studio"]="prisma studio"):r.orm==="drizzle"&&(a.scripts["db:push"]="drizzle-kit push",a.scripts["db:studio"]="drizzle-kit studio")),await z.writeJson(t,a,{spaces:2})}}async function lt(e,r){if(!r)return;if((await ct({cwd:e,reject:!1,stderr:"pipe"})`git --version`).exitCode!==0){ha.warn(ba.yellow("Git is not installed"));return}let a=await ct({cwd:e,reject:!1,stderr:"pipe"})`git init`;if(a.exitCode!==0)throw new Error(`Git initialization failed: ${a.stderr}`)}import de from"node:path";import U from"fs-extra";async function ut(e,r,t){if(t==="next")return;let a=de.join(e,"apps/server"),n=de.join(a,"src/index.ts"),s=await U.readFile(n,"utf-8");r==="bun"?await Pa(a,n,s,t):r==="node"&&await ja(a,n,s,t)}async function Pa(e,r,t,a){let n=de.join(e,"package.json"),s=await U.readJson(n);if(s.scripts={...s.scripts,dev:"bun run --hot src/index.ts",start:"bun run dist/src/index.js"},await U.writeJson(n,s,{spaces:2}),g({devDependencies:["@types/bun"],projectDir:e}),a==="hono"){let o=`${t}
|
|
261
261
|
|
|
262
262
|
export default app;
|
|
263
|
-
`;await
|
|
263
|
+
`;await U.writeFile(r,o)}}async function ja(e,r,t,a){let n=de.join(e,"package.json"),s=await U.readJson(n);if(s.scripts={...s.scripts,dev:"tsx watch src/index.ts",start:"node dist/src/index.js"},await U.writeJson(n,s,{spaces:2}),g({devDependencies:["tsx","@types/node"],projectDir:e}),a==="hono"){g({dependencies:["@hono/node-server"],projectDir:e});let o=`import { serve } from "@hono/node-server";
|
|
264
264
|
`,i=`
|
|
265
265
|
serve(
|
|
266
266
|
{
|
|
@@ -271,14 +271,14 @@ serve(
|
|
|
271
271
|
console.log(\`Server is running on http://localhost:\${info.port}\`);
|
|
272
272
|
},
|
|
273
273
|
);
|
|
274
|
-
`;if(!t.includes("@hono/node-server")){let
|
|
274
|
+
`;if(!t.includes("@hono/node-server")){let l=t.lastIndexOf("import"),p=t.substring(0,l),d=t.substring(l),P=p+o+d+i;await U.writeFile(r,P)}}else if(a==="elysia"&&(g({dependencies:["@elysiajs/node"],projectDir:e}),!t.includes("@elysiajs/node"))){let o=`import { node } from "@elysiajs/node";
|
|
275
275
|
`,i=t.indexOf(`
|
|
276
|
-
`,t.indexOf("import")),
|
|
277
|
-
`)}}async function
|
|
278
|
-
`,i=s.lastIndexOf("import"),
|
|
279
|
-
`,i)+1;s=s.substring(0,
|
|
280
|
-
});`),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 gt(e){let r=await bt(e);for(let t of r)if(await l.pathExists(t)){let a=u.join(u.dirname(t),".gitignore");await l.move(t,a,{overwrite:!0})}}async function bt(e){let r=[],t=u.join(e,"_gitignore");await l.pathExists(t)&&r.push(t);try{let a=await l.readdir(e,{withFileTypes:!0});for(let n of a)if(n.isDirectory()&&n.name!=="node_modules"){let s=u.join(e,n.name),o=await bt(s);r.push(...o)}}catch{}return r}function va(e,r){if(e==="drizzle"){if(r==="sqlite")return"template/with-drizzle-sqlite";if(r==="postgres")return"template/with-drizzle-postgres";if(r==="mysql")return"template/with-drizzle-mysql"}if(e==="prisma"){if(r==="sqlite")return"template/with-prisma-sqlite";if(r==="postgres")return"template/with-prisma-postgres";if(r==="mysql")return"template/with-prisma-mysql";if(r==="mongodb")return"template/with-prisma-mongodb"}return"template/base"}function ka(e,r){if(e==="drizzle"){if(r==="sqlite")return"with-drizzle-sqlite-lib";if(r==="postgres")return"with-drizzle-postgres-lib";if(r==="mysql")return"with-drizzle-mysql-lib"}if(e==="prisma"){if(r==="sqlite")return"with-prisma-sqlite-lib";if(r==="postgres")return"with-prisma-postgres-lib";if(r==="mysql")return"with-prisma-mysql-lib";if(r==="mongodb")return"with-prisma-mongodb-lib"}throw new Error("Invalid ORM or database configuration for auth setup")}async function yt(e){let r=Sa(),t=xa.resolve(process.cwd(),e.projectName);try{return await Aa.ensureDir(t),await dt(t),await ut(t,e.frontend),await gt(t),await mt(t,e.backend),await Be(t,e.backend,e.runtime),await ft(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",e.dbSetup==="neon"),await ht(t,e.auth,e.backend,e.orm,e.database,e.frontend),await Oe(t,e.auth,e.frontend),await lt(t,e.runtime,e.backend),await tt(t,e.examples,e.orm,e.auth,e.backend,e.frontend),await et(t,e),await pt(t,e.git),e.addons.length>0&&await Ce(t,e.addons,e.packageManager,e.frontend),await ct(t,e),await Le(t,e),e.noInstall||await st({projectDir:t,packageManager:e.packageManager,addons:e.addons}),ot(e.database,e.projectName,e.packageManager,!e.noInstall,e.orm,e.addons,e.runtime,e.frontend),t}catch(a){throw r.message(wt.red("Failed")),a instanceof Error&&($a(wt.red(`Error during project creation: ${a.message}`)),process.exit(1)),a}}import{cancel as Sn,group as An}from"@clack/prompts";import En from"picocolors";import{cancel as Ea,isCancel as Da,multiselect as Ta}from"@clack/prompts";import Ca from"picocolors";async function Pt(e,r){if(e!==void 0)return e;let t=r?.includes("react-router")||r?.includes("tanstack-router"),a=[{value:"starlight",label:"Starlight",hint:"Add Astro Starlight documentation site"},{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"}],...a]:a,o=h.addons.filter(p=>t||p!=="pwa"&&p!=="tauri"),i=await Ta({message:"Select addons",options:s,initialValues:o,required:!1});return Da(i)&&(Ea(Ca.red("Operation cancelled")),process.exit(0)),i.includes("husky")&&!i.includes("biome")&&i.push("biome"),i}import{cancel as Fa,confirm as Ra,isCancel as Ia}from"@clack/prompts";import Oa from"picocolors";async function jt(e,r,t){if(!r)return!1;if(e!==void 0)return e;let a=await Ra({message:"Add authentication with Better-Auth?",initialValue:h.auth});return Ia(a)&&(Fa(Oa.red("Operation cancelled")),process.exit(0)),a}import{cancel as Ba,isCancel as La,select as Ma}from"@clack/prompts";import Na from"picocolors";async function vt(e){if(e!==void 0)return e;let r=await Ma({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:h.backend});return La(r)&&(Ba(Na.red("Operation cancelled")),process.exit(0)),r}import{cancel as _a,isCancel as za,select as Ua}from"@clack/prompts";import qa from"picocolors";async function kt(e){if(e!==void 0)return e;let r=await Ua({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:h.database});return za(r)&&(_a(qa.red("Operation cancelled")),process.exit(0)),r}import{cancel as Va,isCancel as Ga,select as Wa}from"@clack/prompts";import Ja from"picocolors";async function xt(e,r,t){if(r!==void 0)return r;if(e==="sqlite"&&t==="prisma")return"none";let a=[];if(e==="sqlite")a=[{value:"turso",label:"Turso",hint:"SQLite for Production. Powered by libSQL"},{value:"none",label:"None",hint:"Manual setup"}];else if(e==="postgres")a=[{value:"neon",label:"Neon Postgres",hint:"Serverless Postgres with branching capability"},...t==="prisma"?[{value:"prisma-postgres",label:"Prisma Postgres",hint:"Instant Postgres for Global Applications"}]:[],{value:"none",label:"None",hint:"Manual setup"}];else if(e==="mongodb")a=[{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 Wa({message:`Select ${e} setup option`,options:a,initialValue:"none"});return Ga(n)&&(Va(Ja.red("Operation cancelled")),process.exit(0)),n}import{cancel as Qa,isCancel as Ha,multiselect as $t}from"@clack/prompts";import Ka from"picocolors";async function St(e,r,t,a){if(e!==void 0)return e;if(r==="none")return[];if(!(t?.includes("react-router")||t?.includes("tanstack-router")||t?.includes("tanstack-start")))return[];let s=[];return a==="elysia"&&(s=await $t({message:"Include examples",options:[{value:"todo",label:"Todo App",hint:"A simple CRUD example app"}],required:!1,initialValues:h.examples})),(a==="hono"||a==="express")&&(s=await $t({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:h.examples})),Ha(s)&&(Qa(Ka.red("Operation cancelled")),process.exit(0)),s}import{cancel as At,isCancel as Et,multiselect as Ya,select as Xa}from"@clack/prompts";import Dt from"picocolors";async function Tt(e){if(e!==void 0)return e;let r=await Ya({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:h.frontend.some(a=>a==="tanstack-router"||a==="react-router"||a==="tanstack-start")?["web"]:[]});Et(r)&&(At(Dt.red("Operation cancelled")),process.exit(0));let t=[];if(r.includes("web")){let a=await Xa({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"},{value:"tanstack-start",label:"TanStack Start (beta)",hint:"SSR, Server Functions, API Routes and more with TanStack Router"}],initialValue:h.frontend.find(n=>n==="tanstack-router"||n==="react-router"||n==="tanstack-start")||"tanstack-router"});Et(a)&&(At(Dt.red("Operation cancelled")),process.exit(0)),t.push(a)}return r.includes("native")&&t.push("native"),t}import{cancel as Za,confirm as en,isCancel as tn}from"@clack/prompts";import rn from"picocolors";async function Ct(e){if(e!==void 0)return e;let r=await en({message:"Initialize git repository?",initialValue:h.git});return tn(r)&&(Za(rn.red("Operation cancelled")),process.exit(0)),r}import{cancel as an,confirm as nn,isCancel as sn}from"@clack/prompts";import on from"picocolors";async function Ft(e){if(e!==void 0)return e;let r=await nn({message:"Install dependencies?",initialValue:!h.noInstall});return sn(r)&&(an(on.red("Operation cancelled")),process.exit(0)),!r}import{cancel as cn,isCancel as pn,log as ln,select as dn}from"@clack/prompts";import un from"picocolors";async function Rt(e,r,t){if(!r)return"none";if(e!==void 0)return e;if(t==="mongodb")return ln.info("Only Prisma is supported with MongoDB."),"prisma";let a=await dn({message:"Select ORM",options:[{value:"drizzle",label:"Drizzle",hint:"lightweight and performant TypeScript ORM"},{value:"prisma",label:"Prisma",hint:"Powerful, feature-rich ORM"}],initialValue:h.orm});return pn(a)&&(cn(un.red("Operation cancelled")),process.exit(0)),a}import{cancel as mn,isCancel as fn,select as hn}from"@clack/prompts";import gn from"picocolors";async function It(e){if(e!==void 0)return e;let r=ee(),t=await hn({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:r});return fn(t)&&(mn(gn.red("Operation cancelled")),process.exit(0)),t}import Z from"node:path";import{cancel as bn,isCancel as wn,text as yn}from"@clack/prompts";import W from"fs-extra";import Pn from"picocolors";var jn=["<",">",":",'"',"|","?","*"],Ot=255;function Bt(e){if(e!=="."){if(!e)return"Project name cannot be empty";if(e.length>Ot)return`Project name must be less than ${Ot} characters`;if(jn.some(r=>e.includes(r)))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 Lt(e){if(e)if(e==="."){let s=process.cwd();if(W.readdirSync(s).length===0)return e}else{let s=Z.basename(e);if(!Bt(s)){let i=Z.resolve(process.cwd(),e);if(!W.pathExistsSync(i)||W.readdirSync(i).length===0)return e}}let r=!1,t="",a=h.projectName,n=1;for(;W.pathExistsSync(Z.resolve(process.cwd(),a));)a=`${h.projectName}-${n}`,n++;for(;!r;){let s=await yn({message:"Enter your project name or path (relative to current directory)",placeholder:a,initialValue:e,defaultValue:a,validate:o=>{let i=o.trim()||a;if(i==="."){if(W.readdirSync(process.cwd()).length>0)return"Current directory is not empty. Please choose a different directory.";r=!0;return}let p=Z.resolve(process.cwd(),i),c=Z.basename(p),d=Bt(c);if(d)return d;if(!p.startsWith(process.cwd()))return"Project path must be within current directory";if(W.pathExistsSync(p)&&W.readdirSync(p).length>0)return`Directory "${i}" already exists and is not empty. Please choose a different name or path.`;r=!0}});wn(s)&&(bn(Pn.red("Operation cancelled.")),process.exit(0)),t=s||a}return t}import{cancel as vn,isCancel as kn,select as xn}from"@clack/prompts";import $n from"picocolors";async function Mt(e){if(e!==void 0)return e;let r=await xn({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:h.runtime});return kn(r)&&(vn($n.red("Operation cancelled")),process.exit(0)),r}async function Nt(e){let r=await An({projectName:async()=>Lt(e.projectName),frontend:()=>Tt(e.frontend),backend:()=>vt(e.backend),runtime:()=>Mt(e.runtime),database:()=>kt(e.database),orm:({results:t})=>Rt(e.orm,t.database!=="none",t.database),auth:({results:t})=>jt(e.auth,t.database!=="none",t.frontend),addons:({results:t})=>Pt(e.addons,t.frontend),examples:({results:t})=>St(e.examples,t.database,t.frontend,t.backend),dbSetup:({results:t})=>xt(t.database??"none",e.dbSetup,t.orm),git:()=>Ct(e.git),packageManager:()=>It(e.packageManager),noInstall:()=>Ft(e.noInstall)},{onCancel:()=>{Sn(En.red("Operation cancelled")),process.exit(0)}});return{projectName:r.projectName,frontend:r.frontend,database:r.database,orm:r.orm,auth:r.auth,addons:r.addons,examples:r.examples,git:r.git,packageManager:r.packageManager,noInstall:r.noInstall,dbSetup:r.dbSetup,backend:r.backend,runtime:r.runtime}}import D from"picocolors";function ve(e){let r=[];if(e.projectName&&r.push(`${D.blue("Project Name:")} ${e.projectName}`),e.frontend!==void 0){let t=e.frontend.length>0?e.frontend.join(", "):"none";r.push(`${D.blue("Frontend:")} ${t}`)}if(e.backend!==void 0&&r.push(`${D.blue("Backend Framework:")} ${e.backend}`),e.runtime!==void 0&&r.push(`${D.blue("Runtime:")} ${e.runtime}`),e.database!==void 0&&r.push(`${D.blue("Database:")} ${e.database}`),e.orm!==void 0&&r.push(`${D.blue("ORM:")} ${e.orm}`),e.auth!==void 0&&r.push(`${D.blue("Authentication:")} ${e.auth}`),e.addons!==void 0){let t=e.addons.length>0?e.addons.join(", "):"none";r.push(`${D.blue("Addons:")} ${t}`)}if(e.examples!==void 0){let t=e.examples.length>0?e.examples.join(", "):"none";r.push(`${D.blue("Examples:")} ${t}`)}return e.git!==void 0&&r.push(`${D.blue("Git Init:")} ${e.git}`),e.packageManager!==void 0&&r.push(`${D.blue("Package Manager:")} ${e.packageManager}`),e.noInstall!==void 0&&r.push(`${D.blue("Skip Install:")} ${e.noInstall}`),e.dbSetup!==void 0&&r.push(`${D.blue("Database Setup:")} ${e.dbSetup}`),r.join(`
|
|
281
|
-
`)}function
|
|
276
|
+
`,t.indexOf("import")),l=t.substring(0,i+1),p=t.substring(i+1),d=l+o+p;d=d.replace(/const app = new Elysia\([^)]*\)/,"const app = new Elysia({ adapter: node() })"),await U.writeFile(r,d)}}import u from"node:path";import c from"fs-extra";async function mt(e){let r=u.join(v,"template/base");if(!await c.pathExists(r))throw new Error(`Template directory not found: ${r}`);await c.ensureDir(e);let t=await c.readdir(r);for(let s of t){let o=u.join(r,s),i=u.join(e,s);s!=="apps"&&(await c.stat(o).then(l=>l.isDirectory())?await c.copy(o,i):await c.copy(o,i))}await c.ensureDir(u.join(e,"apps"));let a=u.join(r,"apps/server"),n=u.join(e,"apps/server");await c.pathExists(a)&&await c.copy(a,n)}async function ft(e,r){let t=r.includes("tanstack-router"),a=r.includes("tanstack-start"),n=r.includes("react-router"),s=r.includes("next"),o=r.includes("native");if(t||n||a||s){let i=u.join(e,"apps/web");await c.ensureDir(i);let l=u.join(v,"template/base/apps/web-base");if(await c.pathExists(l)&&await c.copy(l,i),t){let d=u.join(v,"template/base/apps/web-tanstack-router");await c.pathExists(d)&&await c.copy(d,i,{overwrite:!0})}else if(a){let d=u.join(v,"template/base/apps/web-tanstack-start");await c.pathExists(d)&&await c.copy(d,i,{overwrite:!0})}else if(n){let d=u.join(v,"template/base/apps/web-react-router");await c.pathExists(d)&&await c.copy(d,i,{overwrite:!0})}else if(s){let d=u.join(v,"template/base/apps/web-next");await c.pathExists(d)&&await c.copy(d,i,{overwrite:!0})}let p=u.join(i,"package.json");if(await c.pathExists(p)){let d=await c.readJson(p);d.name="web",await c.writeJson(p,d,{spaces:2})}}if(o){let i=u.join(v,"template/base/apps/native"),l=u.join(e,"apps/native");await c.pathExists(i)&&await c.copy(i,l),await c.writeFile(u.join(e,".npmrc"),`node-linker=hoisted
|
|
277
|
+
`)}}async function ht(e,r){if(r==="next"){let a=u.join(e,"apps/server"),n=u.join(v,"template/with-next/apps/server");if(await c.ensureDir(a),await c.pathExists(n)){await c.copy(n,a,{overwrite:!0});let s=u.join(a,"package.json");if(await c.pathExists(s)){let o=await c.readJson(s);o.name="server",await c.writeJson(s,o,{spaces:2})}}return}let t=u.join(v,`template/with-${r}`);await c.pathExists(t)&&await c.copy(t,e,{overwrite:!0})}async function gt(e,r,t,a){if(r==="none"||t==="none")return;let n=u.join(v,xa(r,t));if(await c.pathExists(n)&&(await c.copy(n,e,{overwrite:!0}),!a)){if(r==="prisma"){let s=u.join(e,"apps/server/prisma/schema/auth.prisma");await c.pathExists(s)&&await c.remove(s)}else if(r==="drizzle"){let s=u.join(e,"apps/server/src/db/schema/auth.ts");await c.pathExists(s)&&await c.remove(s)}}}async function bt(e,r,t,a,n,s){if(!r)return;let o=u.join(v,"template/with-auth");if(await c.pathExists(o)){let i=s.includes("react-router"),l=s.includes("tanstack-router"),p=s.includes("tanstack-start"),d=s.includes("next");if(i||l||p||d){let j=u.join(e,"apps/web"),S=u.join(o,"apps/web-base");if(await c.pathExists(S)&&await c.copy(S,j,{overwrite:!0}),i){let k=u.join(o,"apps/web-react-router");await c.pathExists(k)&&await c.copy(k,j,{overwrite:!0})}if(l){let k=u.join(o,"apps/web-tanstack-router");await c.pathExists(k)&&await c.copy(k,j,{overwrite:!0})}if(p){let k=u.join(o,"apps/web-tanstack-start");await c.pathExists(k)&&await c.copy(k,j,{overwrite:!0})}if(d){let k=u.join(o,"apps/web-next");await c.pathExists(k)&&await c.copy(k,j,{overwrite:!0})}}let P=u.join(o,"apps/server/src"),x=u.join(e,"apps/server/src");if(await c.copy(u.join(P,"lib/trpc.ts"),u.join(x,"lib/trpc.ts"),{overwrite:!0}),await c.copy(u.join(P,"routers/index.ts"),u.join(x,"routers/index.ts"),{overwrite:!0}),t==="next"){if(await c.pathExists(u.join(o,"apps/server/src/with-next-app"))){let F=u.join(o,"apps/server/src/with-next-app"),R=u.join(e,"apps/server/src/app");await c.ensureDir(R);let J=await c.readdir(F);for(let ee of J){let te=u.join(F,ee),re=u.join(R,ee);await c.copy(te,re,{overwrite:!0})}}await c.copy(u.join(P,"lib","with-next-context.ts"),u.join(x,"lib/context.ts"),{overwrite:!0});let S=dt(a,n),k=u.join(P,S);if(await c.pathExists(k)){let F=await c.readdir(k);for(let R of F)await c.copy(u.join(k,R),u.join(x,"lib",R),{overwrite:!0})}}else{let j=`with-${t}-context.ts`;await c.copy(u.join(P,"lib",j),u.join(x,"lib/context.ts"),{overwrite:!0});let S=`with-${t}-index.ts`;await c.copy(u.join(P,S),u.join(x,"index.ts"),{overwrite:!0});let k=dt(a,n),F=u.join(P,k);if(await c.pathExists(F)){let R=await c.readdir(F);for(let J of R)await c.copy(u.join(F,J),u.join(x,"lib",J),{overwrite:!0})}}if(s.includes("native")){let j=u.join(o,"apps/native"),S=u.join(e,"apps/native");await c.pathExists(j)&&await c.copy(j,S,{overwrite:!0}),g({dependencies:["@better-auth/expo"],projectDir:u.join(e,"apps/server")}),await va(e,a,n)}}}async function va(e,r,t){let a=u.join(e,"apps/server"),n;if(r==="drizzle"?t==="sqlite"?n=u.join(a,"src/lib/auth.ts"):t==="postgres"&&(n=u.join(a,"src/lib/auth.ts")):r==="prisma"&&(t==="sqlite"?n=u.join(a,"src/lib/auth.ts"):t==="postgres"&&(n=u.join(a,"src/lib/auth.ts"))),n&&await c.pathExists(n)){let s=await c.readFile(n,"utf8");if(!s.includes("@better-auth/expo")){let o=`import { expo } from "@better-auth/expo";
|
|
278
|
+
`,i=s.lastIndexOf("import"),l=s.indexOf(`
|
|
279
|
+
`,i)+1;s=s.substring(0,l)+o+s.substring(l)}s.includes("plugins:")?s.includes("expo()")||(s=s.replace(/plugins: \[(.*?)\]/s,(o,i)=>`plugins: [${i}${i.trim()?", ":""}expo()]`)):s=s.replace(/}\);/,` plugins: [expo()],
|
|
280
|
+
});`),s.includes("my-better-t-app://")||(s=s.replace(/trustedOrigins: \[(.*?)\]/s,(o,i)=>`trustedOrigins: [${i}${i.trim()?", ":""}"my-better-t-app://"]`)),await c.writeFile(n,s)}}async function wt(e){let r=await yt(e);for(let t of r)if(await c.pathExists(t)){let a=u.join(u.dirname(t),".gitignore");await c.move(t,a,{overwrite:!0})}}async function yt(e){let r=[],t=u.join(e,"_gitignore");await c.pathExists(t)&&r.push(t);try{let a=await c.readdir(e,{withFileTypes:!0});for(let n of a)if(n.isDirectory()&&n.name!=="node_modules"){let s=u.join(e,n.name),o=await yt(s);r.push(...o)}}catch{}return r}function xa(e,r){if(e==="drizzle"){if(r==="sqlite")return"template/with-drizzle-sqlite";if(r==="postgres")return"template/with-drizzle-postgres";if(r==="mysql")return"template/with-drizzle-mysql"}if(e==="prisma"){if(r==="sqlite")return"template/with-prisma-sqlite";if(r==="postgres")return"template/with-prisma-postgres";if(r==="mysql")return"template/with-prisma-mysql";if(r==="mongodb")return"template/with-prisma-mongodb"}return"template/base"}function dt(e,r){if(e==="drizzle"){if(r==="sqlite")return"with-drizzle-sqlite-lib";if(r==="postgres")return"with-drizzle-postgres-lib";if(r==="mysql")return"with-drizzle-mysql-lib"}if(e==="prisma"){if(r==="sqlite")return"with-prisma-sqlite-lib";if(r==="postgres")return"with-prisma-postgres-lib";if(r==="mysql")return"with-prisma-mysql-lib";if(r==="mongodb")return"with-prisma-mongodb-lib"}throw new Error("Invalid ORM or database configuration for auth setup")}async function jt(e){let r=Sa(),t=ka.resolve(process.cwd(),e.projectName);try{return await Aa.ensureDir(t),await mt(t),await ft(t,e.frontend),await wt(t),await ht(t,e.backend),await Le(t,e.backend,e.runtime),await gt(t,e.orm,e.database,e.auth),await et(t,e.database,e.orm,e.packageManager,e.dbSetup==="turso",e.dbSetup==="prisma-postgres",e.dbSetup==="mongodb-atlas",e.dbSetup==="neon"),await bt(t,e.auth,e.backend,e.orm,e.database,e.frontend),await Be(t,e.auth,e.frontend),await ut(t,e.runtime,e.backend),await rt(t,e.examples,e.orm,e.auth,e.backend,e.frontend),await tt(t,e),await lt(t,e.git),e.addons.length>0&&await Fe(t,e.addons,e.packageManager,e.frontend),await pt(t,e),await Ne(t,e),e.noInstall||await ot({projectDir:t,packageManager:e.packageManager,addons:e.addons}),it(e.database,e.projectName,e.packageManager,!e.noInstall,e.orm,e.addons,e.runtime,e.frontend),t}catch(a){throw r.message(Pt.red("Failed")),a instanceof Error&&($a(Pt.red(`Error during project creation: ${a.message}`)),process.exit(1)),a}}import{cancel as Sn,group as An}from"@clack/prompts";import En from"picocolors";import{cancel as Ea,isCancel as Da,multiselect as Ta}from"@clack/prompts";import Ca from"picocolors";async function vt(e,r){if(e!==void 0)return e;let t=r?.includes("react-router")||r?.includes("tanstack-router"),a=[{value:"starlight",label:"Starlight",hint:"Add Astro Starlight documentation site"},{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"}],...a]:a,o=h.addons.filter(l=>t||l!=="pwa"&&l!=="tauri"),i=await Ta({message:"Select addons",options:s,initialValues:o,required:!1});return Da(i)&&(Ea(Ca.red("Operation cancelled")),process.exit(0)),i.includes("husky")&&!i.includes("biome")&&i.push("biome"),i}import{cancel as Fa,confirm as Ra,isCancel as Ia}from"@clack/prompts";import Oa from"picocolors";async function xt(e,r,t){if(!r)return!1;if(e!==void 0)return e;let a=await Ra({message:"Add authentication with Better-Auth?",initialValue:h.auth});return Ia(a)&&(Fa(Oa.red("Operation cancelled")),process.exit(0)),a}import{cancel as Ba,isCancel as La,select as Na}from"@clack/prompts";import Ma from"picocolors";async function kt(e){if(e!==void 0)return e;let r=await Na({message:"Select backend framework",options:[{value:"hono",label:"Hono",hint:"Lightweight, ultrafast web framework"},{value:"next",label:"Next.js",hint:"Full-stack framework with API routes"},{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:h.backend});return La(r)&&(Ba(Ma.red("Operation cancelled")),process.exit(0)),r}import{cancel as _a,isCancel as za,select as Ua}from"@clack/prompts";import qa from"picocolors";async function $t(e){if(e!==void 0)return e;let r=await Ua({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:h.database});return za(r)&&(_a(qa.red("Operation cancelled")),process.exit(0)),r}import{cancel as Va,isCancel as Wa,select as Ga}from"@clack/prompts";import Ja from"picocolors";async function St(e,r,t){if(r!==void 0)return r;if(e==="sqlite"&&t==="prisma")return"none";let a=[];if(e==="sqlite")a=[{value:"turso",label:"Turso",hint:"SQLite for Production. Powered by libSQL"},{value:"none",label:"None",hint:"Manual setup"}];else if(e==="postgres")a=[{value:"neon",label:"Neon Postgres",hint:"Serverless Postgres with branching capability"},...t==="prisma"?[{value:"prisma-postgres",label:"Prisma Postgres",hint:"Instant Postgres for Global Applications"}]:[],{value:"none",label:"None",hint:"Manual setup"}];else if(e==="mongodb")a=[{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 Ga({message:`Select ${e} setup option`,options:a,initialValue:"none"});return Wa(n)&&(Va(Ja.red("Operation cancelled")),process.exit(0)),n}import{cancel as Qa,isCancel as Ha,multiselect as At}from"@clack/prompts";import Ka from"picocolors";async function Et(e,r,t,a){if(e!==void 0)return e;if(r==="none")return[];if(!(t?.includes("react-router")||t?.includes("tanstack-router")||t?.includes("tanstack-start")))return[];let s=[];return a==="elysia"&&(s=await At({message:"Include examples",options:[{value:"todo",label:"Todo App",hint:"A simple CRUD example app"}],required:!1,initialValues:h.examples})),(a==="hono"||a==="express")&&(s=await At({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:h.examples})),Ha(s)&&(Qa(Ka.red("Operation cancelled")),process.exit(0)),s}import{cancel as Dt,isCancel as Tt,multiselect as Ya,select as Xa}from"@clack/prompts";import Ct from"picocolors";async function Ft(e){if(e!==void 0)return e;let r=await Ya({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:h.frontend.some(a=>a==="tanstack-router"||a==="react-router"||a==="tanstack-start"||a==="next")?["web"]:[]});Tt(r)&&(Dt(Ct.red("Operation cancelled")),process.exit(0));let t=[];if(r.includes("web")){let a=await Xa({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"},{value:"next",label:"Next.js",hint:"The React Framework for the Web"},{value:"tanstack-start",label:"TanStack Start (beta)",hint:"SSR, Server Functions, API Routes and more with TanStack Router"}],initialValue:h.frontend.find(n=>n==="tanstack-router"||n==="react-router"||n==="tanstack-start"||n==="next")||"tanstack-router"});Tt(a)&&(Dt(Ct.red("Operation cancelled")),process.exit(0)),t.push(a)}return r.includes("native")&&t.push("native"),t}import{cancel as Za,confirm as en,isCancel as tn}from"@clack/prompts";import rn from"picocolors";async function Rt(e){if(e!==void 0)return e;let r=await en({message:"Initialize git repository?",initialValue:h.git});return tn(r)&&(Za(rn.red("Operation cancelled")),process.exit(0)),r}import{cancel as an,confirm as nn,isCancel as sn}from"@clack/prompts";import on from"picocolors";async function It(e){if(e!==void 0)return e;let r=await nn({message:"Install dependencies?",initialValue:!h.noInstall});return sn(r)&&(an(on.red("Operation cancelled")),process.exit(0)),!r}import{cancel as cn,isCancel as pn,log as ln,select as un}from"@clack/prompts";import dn from"picocolors";async function Ot(e,r,t){if(!r)return"none";if(e!==void 0)return e;if(t==="mongodb")return ln.info("Only Prisma is supported with MongoDB."),"prisma";let a=await un({message:"Select ORM",options:[{value:"drizzle",label:"Drizzle",hint:"lightweight and performant TypeScript ORM"},{value:"prisma",label:"Prisma",hint:"Powerful, feature-rich ORM"}],initialValue:h.orm});return pn(a)&&(cn(dn.red("Operation cancelled")),process.exit(0)),a}import{cancel as mn,isCancel as fn,select as hn}from"@clack/prompts";import gn from"picocolors";async function Bt(e){if(e!==void 0)return e;let r=ae(),t=await hn({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:r});return fn(t)&&(mn(gn.red("Operation cancelled")),process.exit(0)),t}import Z from"node:path";import{cancel as bn,isCancel as wn,text as yn}from"@clack/prompts";import G from"fs-extra";import Pn from"picocolors";var jn=["<",">",":",'"',"|","?","*"],Lt=255;function Nt(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(jn.some(r=>e.includes(r)))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 Mt(e){if(e)if(e==="."){let s=process.cwd();if(G.readdirSync(s).length===0)return e}else{let s=Z.basename(e);if(!Nt(s)){let i=Z.resolve(process.cwd(),e);if(!G.pathExistsSync(i)||G.readdirSync(i).length===0)return e}}let r=!1,t="",a=h.projectName,n=1;for(;G.pathExistsSync(Z.resolve(process.cwd(),a));)a=`${h.projectName}-${n}`,n++;for(;!r;){let s=await yn({message:"Enter your project name or path (relative to current directory)",placeholder:a,initialValue:e,defaultValue:a,validate:o=>{let i=o.trim()||a;if(i==="."){if(G.readdirSync(process.cwd()).length>0)return"Current directory is not empty. Please choose a different directory.";r=!0;return}let l=Z.resolve(process.cwd(),i),p=Z.basename(l),d=Nt(p);if(d)return d;if(!l.startsWith(process.cwd()))return"Project path must be within current directory";if(G.pathExistsSync(l)&&G.readdirSync(l).length>0)return`Directory "${i}" already exists and is not empty. Please choose a different name or path.`;r=!0}});wn(s)&&(bn(Pn.red("Operation cancelled.")),process.exit(0)),t=s||a}return t}import{cancel as vn,isCancel as xn,select as kn}from"@clack/prompts";import $n from"picocolors";async function _t(e,r){if(e!==void 0)return e;if(r==="next")return"node";let t=await kn({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:h.runtime});return xn(t)&&(vn($n.red("Operation cancelled")),process.exit(0)),t}async function zt(e){let r=await An({projectName:async()=>Mt(e.projectName),frontend:()=>Ft(e.frontend),backend:()=>kt(e.backend),runtime:({results:t})=>_t(e.runtime,t.backend),database:()=>$t(e.database),orm:({results:t})=>Ot(e.orm,t.database!=="none",t.database),auth:({results:t})=>xt(e.auth,t.database!=="none",t.frontend),addons:({results:t})=>vt(e.addons,t.frontend),examples:({results:t})=>Et(e.examples,t.database,t.frontend,t.backend),dbSetup:({results:t})=>St(t.database??"none",e.dbSetup,t.orm),git:()=>Rt(e.git),packageManager:()=>Bt(e.packageManager),noInstall:()=>It(e.noInstall)},{onCancel:()=>{Sn(En.red("Operation cancelled")),process.exit(0)}});return{projectName:r.projectName,frontend:r.frontend,database:r.database,orm:r.orm,auth:r.auth,addons:r.addons,examples:r.examples,git:r.git,packageManager:r.packageManager,noInstall:r.noInstall,dbSetup:r.dbSetup,backend:r.backend,runtime:r.runtime}}import C from"picocolors";function $e(e){let r=[];if(e.projectName&&r.push(`${C.blue("Project Name:")} ${e.projectName}`),e.frontend!==void 0){let t=e.frontend.length>0?e.frontend.join(", "):"none";r.push(`${C.blue("Frontend:")} ${t}`)}if(e.backend!==void 0&&r.push(`${C.blue("Backend Framework:")} ${e.backend}`),e.runtime!==void 0&&r.push(`${C.blue("Runtime:")} ${e.runtime}`),e.database!==void 0&&r.push(`${C.blue("Database:")} ${e.database}`),e.orm!==void 0&&r.push(`${C.blue("ORM:")} ${e.orm}`),e.auth!==void 0&&r.push(`${C.blue("Authentication:")} ${e.auth}`),e.addons!==void 0){let t=e.addons.length>0?e.addons.join(", "):"none";r.push(`${C.blue("Addons:")} ${t}`)}if(e.examples!==void 0){let t=e.examples.length>0?e.examples.join(", "):"none";r.push(`${C.blue("Examples:")} ${t}`)}return e.git!==void 0&&r.push(`${C.blue("Git Init:")} ${e.git}`),e.packageManager!==void 0&&r.push(`${C.blue("Package Manager:")} ${e.packageManager}`),e.noInstall!==void 0&&r.push(`${C.blue("Skip Install:")} ${e.noInstall}`),e.dbSetup!==void 0&&r.push(`${C.blue("Database Setup:")} ${e.dbSetup}`),r.join(`
|
|
281
|
+
`)}function Ut(e){let r=[];e.database==="none"?r.push("--database none"):(r.push(`--database ${e.database}`),e.orm&&r.push(`--orm ${e.orm}`),e.dbSetup&&r.push(`--db-setup ${e.dbSetup}`)),r.push(e.auth?"--auth":"--no-auth"),r.push(e.git?"--git":"--no-git"),r.push(e.noInstall?"--no-install":"--install"),e.runtime&&r.push(`--runtime ${e.runtime}`),e.backend&&r.push(`--backend ${e.backend}`),e.frontend&&e.frontend.length>0&&r.push(`--frontend ${e.frontend.join(" ")}`),e.addons&&e.addons.length>0?r.push(`--addons ${e.addons.join(" ")}`):r.push("--addons none"),e.examples&&e.examples.length>0?r.push(`--examples ${e.examples.join(" ")}`):r.push("--examples none"),e.packageManager&&r.push(`--package-manager ${e.packageManager}`);let t="",a=e.packageManager;a==="npm"?t="npx create-better-t-stack@latest":a==="pnpm"?t="pnpm create better-t-stack@latest":a==="bun"&&(t="bun create better-t-stack@latest");let n=e.projectName?` ${e.projectName}`:"";return`${t}${n} ${r.join(" ")}`}import Dn from"node:path";import Tn from"fs-extra";var qt=()=>{let e=Dn.join(v,"package.json");return Tn.readJSONSync(e).version??"1.0.0"};import Vt from"gradient-string";var Wt=`
|
|
282
282
|
\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
|
|
283
283
|
\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
|
|
284
284
|
\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
|
|
@@ -292,10 +292,10 @@ serve(
|
|
|
292
292
|
\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
|
|
293
293
|
\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
|
|
294
294
|
\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
|
|
295
|
-
`,
|
|
296
|
-
`),t=Math.max(...r.map(a=>a.length));e<t?console.log(
|
|
295
|
+
`,Gt={pink:"#F5C2E7",mauve:"#CBA6F7",red:"#F38BA8",maroon:"#E78284",peach:"#FAB387",yellow:"#F9E2AF",green:"#A6E3A1",teal:"#94E2D5",sky:"#89DCEB",sapphire:"#74C7EC",lavender:"#B4BEFE"},Jt=()=>{let e=process.stdout.columns||80,r=Wt.split(`
|
|
296
|
+
`),t=Math.max(...r.map(a=>a.length));e<t?console.log(Vt(Object.values(Gt)).multiline(`
|
|
297
297
|
\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557
|
|
298
298
|
\u2551 Better T-Stack \u2551
|
|
299
299
|
\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D
|
|
300
|
-
`)):console.log(
|
|
301
|
-
${y.white(
|
|
300
|
+
`)):console.log(Vt(Object.values(Gt)).multiline(Wt))};var Qt=()=>process.exit(0);process.on("SIGINT",Qt);process.on("SIGTERM",Qt);async function Bn(){let e=Date.now(),r=Rn();try{let t=await In(On(process.argv)).scriptName("create-better-t-stack").usage("$0 [project-directory] [options]","Create a new Better-T Stack project").positional("project-directory",{describe:"Project name/directory",type:"string"}).option("yes",{alias:"y",type:"boolean",describe:"Use default configuration and skip prompts",default:!1}).option("database",{type:"string",describe:"Database type",choices:["none","sqlite","postgres","mysql","mongodb"]}).option("orm",{type:"string",describe:"ORM type",choices:["drizzle","prisma","none"]}).option("auth",{type:"boolean",describe:"Include authentication"}).option("frontend",{type:"array",string:!0,describe:"Frontend types",choices:["tanstack-router","react-router","tanstack-start","next","native","none"]}).option("addons",{type:"array",string:!0,describe:"Additional addons",choices:["pwa","tauri","starlight","biome","husky","none"]}).option("examples",{type:"array",string:!0,describe:"Examples to include",choices:["todo","ai","none"]}).option("git",{type:"boolean",describe:"Initialize git repository"}).option("package-manager",{alias:"pm",type:"string",describe:"Package manager",choices:["npm","pnpm","bun"]}).option("install",{type:"boolean",describe:"Install dependencies (use --no-install to explicitly skip)"}).option("db-setup",{type:"string",describe:"Database setup",choices:["turso","neon","prisma-postgres","mongodb-atlas","none"]}).option("backend",{type:"string",describe:"Backend framework",choices:["hono","express","next","elysia"]}).option("runtime",{type:"string",describe:"Runtime",choices:["bun","node"]}).completion().recommendCommands().version(qt()).alias("version","v").help().alias("help","h").strict().wrap(null).parse();Jt(),Cn(y.magenta("Creating a new Better-T-Stack project"));let a=t,n=a.projectDirectory,s=Ln(a,n);!a.yes&&Object.keys(s).length>0&&(L.info(y.yellow("Using these pre-selected options:")),L.message($e(s)),L.message(""));let o=a.yes?{...h,projectName:n??h.projectName,...s}:await zt(s);a.yes&&(L.info(y.yellow("Using these default options:")),L.message($e(o)),L.message("")),await jt(o),L.success(`You can reproduce this setup with the following command:
|
|
301
|
+
${y.white(Ut(o))}`);let i=((Date.now()-e)/1e3).toFixed(2);Fn(y.magenta(`Project created successfully in ${y.bold(i)} seconds!`))}catch(t){r.stop(y.red("Failed")),t instanceof Error?(t.name==="YError"?$(y.red(`Invalid arguments: ${t.message}`)):$(y.red(`An unexpected error occurred: ${t.message}`)),process.exit(1)):($(y.red("An unexpected error occurred.")),console.error(t),process.exit(1))}}function Ln(e,r){let t={};if(e.database&&(t.database=e.database),e.orm&&(e.orm==="none"?t.orm="none":t.orm=e.orm),(t.database??e.database)==="mongodb"&&(t.orm??e.orm)==="drizzle"&&($(y.red("MongoDB is only available with Prisma. Cannot use --database mongodb with --orm drizzle")),process.exit(1)),e.dbSetup){let n=e.dbSetup;n!=="none"?(t.dbSetup=n,n==="turso"?(e.database&&e.database!=="sqlite"&&($(y.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"&&($(y.red("Turso setup is not compatible with Prisma. Cannot use --db-setup turso with --orm prisma")),process.exit(1)),t.orm="drizzle"):n==="prisma-postgres"?(e.database&&e.database!=="postgres"&&($(y.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"&&e.orm!=="none"&&($(y.red("Prisma PostgreSQL setup requires Prisma ORM. Cannot use --db-setup prisma-postgres with a different ORM.")),process.exit(1)),t.orm="prisma"):n==="mongodb-atlas"?(e.database&&e.database!=="mongodb"&&($(y.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"):n==="neon"&&(e.database&&e.database!=="postgres"&&($(y.red("Neon PostgreSQL setup requires PostgreSQL database. Cannot use --db-setup neon with a different database type.")),process.exit(1)),t.database="postgres")):t.dbSetup="none"}if((t.database??e.database)==="none"){e.auth===!0&&($(y.red("Authentication requires a database. Cannot use --auth with --database none.")),process.exit(1));let n=t.orm??e.orm;n&&n!=="none"&&($(y.red(`Cannot use ORM with no database. Cannot use --orm ${n} with --database none.`)),process.exit(1)),t.orm="none";let s=t.dbSetup??e.dbSetup;s&&s!=="none"&&($(y.red(`Database setup requires a database. Cannot use --db-setup ${s} with --database none.`)),process.exit(1)),t.dbSetup="none"}if(e.auth!==void 0&&(t.auth=e.auth),e.backend&&(t.backend=e.backend),e.runtime&&(t.runtime=e.runtime),e.frontend&&e.frontend.length>0)if(e.frontend.includes("none"))e.frontend.length>1&&($(y.red("Cannot combine 'none' with other frontend options.")),process.exit(1)),t.frontend=[];else{let n=e.frontend.filter(o=>o!=="none");n.filter(o=>o==="tanstack-router"||o==="react-router"||o==="tanstack-start").length>1&&($(y.red("Cannot select multiple web frameworks. Choose only one of: tanstack-router, tanstack-start, react-router")),process.exit(1)),t.frontend=n}if(e.addons&&e.addons.length>0)if(e.addons.includes("none"))e.addons.length>1&&($(y.red("Cannot combine 'none' with other addons.")),process.exit(1)),t.addons=[];else{let n=e.addons.filter(p=>p!=="none"),s=["pwa","tauri"],o=n.some(p=>s.includes(p)),l=(t.frontend??(e.yes?h.frontend:void 0))?.some(p=>p==="tanstack-router"||p==="react-router");o&&!l&&(e.frontend?($(y.red("PWA and Tauri addons require tanstack-router or react-router. Cannot use these addons with your frontend selection.")),process.exit(1)):e.yes&&($(y.red("PWA and Tauri addons require tanstack-router or react-router (default frontend incompatible).")),process.exit(1))),n.includes("husky")&&!n.includes("biome")&&n.push("biome"),t.addons=[...new Set(n)]}if(e.examples&&e.examples.length>0)if(e.examples.includes("none"))e.examples.length>1&&($(y.red("Cannot combine 'none' with other examples.")),process.exit(1)),t.examples=[];else{let n=e.examples.filter(l=>l!=="none"),s=t.backend??e.backend;n.includes("ai")&&s==="elysia"&&!(e.yes&&h.backend!=="elysia")&&($(y.red("AI example is only compatible with Hono backend. Cannot use --examples ai with --backend elysia")),process.exit(1)),(t.frontend??e.frontend?.filter(l=>l!=="none")??(e.yes?h.frontend:void 0))?.some(l=>["tanstack-router","react-router","tanstack-start"].includes(l))||(e.frontend?($(y.red("Examples require a web frontend (tanstack-router, react-router, or tanstack-start). Cannot use --examples with your frontend selection.")),process.exit(1)):e.yes&&($(y.red("Examples require a web frontend (tanstack-router, react-router, or tanstack-start) (default frontend incompatible).")),process.exit(1))),t.examples=n}return e.packageManager&&(t.packageManager=e.packageManager),e.git!==void 0&&(t.git=e.git),e.install!==void 0&&(t.noInstall=!e.install),r&&(t.projectName=r),t}Bn().catch(e=>{L.error("Aborting installation due to unexpected error..."),e instanceof Error?(L.error(e.message),console.error(e.stack)):(L.error("An unknown error has occurred. Please open an issue on GitHub with the below:"),console.error(e)),process.exit(1)});
|