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