create-better-t-stack 1.4.2 → 1.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Create Better-T-Stack CLI
|
|
2
2
|
|
|
3
|
-
A CLI tool for scaffolding type-safe
|
|
3
|
+
A modern CLI tool for scaffolding end-to-end type-safe TypeScript projects with best practices and customizable configurations
|
|
4
4
|
|
|
5
5
|
## Quick Start
|
|
6
6
|
|
|
@@ -49,10 +49,10 @@ Options:
|
|
|
49
49
|
--orm <type> ORM type (none, drizzle, prisma)
|
|
50
50
|
--auth Include authentication
|
|
51
51
|
--no-auth Exclude authentication
|
|
52
|
-
--frontend <types
|
|
53
|
-
--addons <types
|
|
52
|
+
--frontend <types...> Frontend types (web, native, none)
|
|
53
|
+
--addons <types...> Additional addons (pwa, tauri, biome, husky)
|
|
54
54
|
--no-addons Skip all additional addons
|
|
55
|
-
--examples <types
|
|
55
|
+
--examples <types...> Examples to include (todo, ai)
|
|
56
56
|
--no-examples Skip all examples
|
|
57
57
|
--git Initialize git repository
|
|
58
58
|
--no-git Skip git initialization
|
|
@@ -75,7 +75,7 @@ npx create-better-t-stack my-app -y
|
|
|
75
75
|
|
|
76
76
|
Create a project with specific options:
|
|
77
77
|
```bash
|
|
78
|
-
npx create-better-t-stack my-app --database postgres --orm drizzle --auth --addons pwa
|
|
78
|
+
npx create-better-t-stack my-app --database postgres --orm drizzle --auth --addons pwa biome
|
|
79
79
|
```
|
|
80
80
|
|
|
81
81
|
Create a project with Elysia and Node.js runtime:
|
|
@@ -85,10 +85,10 @@ npx create-better-t-stack my-app --backend elysia --runtime node
|
|
|
85
85
|
|
|
86
86
|
Create a project with specific frontend options:
|
|
87
87
|
```bash
|
|
88
|
-
npx create-better-t-stack my-app --frontend web
|
|
88
|
+
npx create-better-t-stack my-app --frontend web native
|
|
89
89
|
```
|
|
90
90
|
|
|
91
91
|
Create a project with examples:
|
|
92
92
|
```bash
|
|
93
|
-
npx create-better-t-stack my-app --examples todo
|
|
93
|
+
npx create-better-t-stack my-app --examples todo ai
|
|
94
94
|
```
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{cancel as
|
|
2
|
+
import{cancel as j,intro as hr,log as E,outro as gr,spinner as br}from"@clack/prompts";import{Command as wr}from"commander";import u from"picocolors";import te from"node:path";import{fileURLToPath as ct}from"node:url";var U=()=>{let e=process.env.npm_config_user_agent;return e?.startsWith("pnpm")?"pnpm":e?.startsWith("bun")?"bun":"npm"};var pt=ct(import.meta.url),dt=te.dirname(pt),x=te.join(dt,"../"),m={projectName:"my-better-t-app",frontend:["web"],database:"sqlite",orm:"drizzle",auth:!0,addons:[],examples:[],git:!0,packageManager:U(),noInstall:!1,turso:!1,backend:"hono",runtime:"bun"},Q={"better-auth":"^1.2.4","drizzle-orm":"^0.38.4","drizzle-kit":"^0.30.5","@libsql/client":"^0.14.0",postgres:"^3.4.5","@prisma/client":"^6.5.0",prisma:"^6.5.0","vite-plugin-pwa":"^0.21.2","@vite-pwa/assets-generator":"^0.2.6","@tauri-apps/cli":"^2.4.0","@biomejs/biome":"1.9.4",husky:"^9.1.7","lint-staged":"^15.5.0","@hono/node-server":"^1.14.0",tsx:"^4.19.2","@types/node":"^22.13.11","@types/bun":"^1.2.6","@elysiajs/node":"^1.2.6","@elysiajs/cors":"^1.2.0","@elysiajs/trpc":"^1.1.0",elysia:"^1.2.25","@hono/trpc-server":"^0.3.4",hono:"^4.7.5",ai:"^4.2.8","@ai-sdk/google":"^1.2.3"};import ca from"node:path";import{cancel as pa,spinner as da}from"@clack/prompts";import la from"fs-extra";import Se from"picocolors";import S from"node:path";import T from"fs-extra";import lt from"node:path";import ae from"fs-extra";var b=e=>{let{dependencies:a=[],devDependencies:t=[],projectDir:r}=e,n=lt.join(r,"package.json"),o=ae.readJSONSync(n);o.dependencies||(o.dependencies={}),o.devDependencies||(o.devDependencies={});for(let i of a){let s=Q[i];o.dependencies[i]=s}for(let i of t){let s=Q[i];o.devDependencies[i]=s}ae.writeJSONSync(n,o,{spaces:2})};import G from"node:path";import{log as ut,spinner as mt}from"@clack/prompts";import{execa as ft}from"execa";import q from"fs-extra";import re from"picocolors";async function ne(e,a){let t=mt(),r=G.join(e,"apps/web");if(await q.pathExists(r))try{t.start("Setting up Tauri desktop app support..."),b({devDependencies:["@tauri-apps/cli"],projectDir:r});let n=G.join(r,"package.json");if(await q.pathExists(n)){let s=await q.readJson(n);s.scripts={...s.scripts,tauri:"tauri","desktop:dev":"tauri dev","desktop:build":"tauri build"},await q.writeJson(n,s,{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"]}i=[...i,"init",`--app-name=${G.basename(e)}`,`--window-title=${G.basename(e)}`,"--frontend-dist=dist","--dev-url=http://localhost:3001",`--before-dev-command=${a} run dev`,`--before-build-command=${a} run build`],await ft(o,i,{cwd:r,env:{CI:"true"}}),t.stop("Tauri desktop app support configured successfully!")}catch(n){throw t.stop(re.red("Failed to set up Tauri")),n instanceof Error&&ut.error(re.red(n.message)),n}}async function oe(e,a,t,r){let n=r.includes("web");a.includes("pwa")&&n&&await bt(e),a.includes("tauri")&&n&&await ne(e,t),a.includes("biome")&&await ht(e),a.includes("husky")&&await gt(e)}async function ht(e){let a=S.join(x,"template/with-biome");await T.pathExists(a)&&await T.copy(a,e,{overwrite:!0}),b({devDependencies:["@biomejs/biome"],projectDir:e});let t=S.join(e,"package.json");if(await T.pathExists(t)){let r=await T.readJson(t);r.scripts={...r.scripts,check:"biome check --write ."},await T.writeJson(t,r,{spaces:2})}}async function gt(e){let a=S.join(x,"template/with-husky");await T.pathExists(a)&&await T.copy(a,e,{overwrite:!0}),b({devDependencies:["husky","lint-staged"],projectDir:e});let t=S.join(e,"package.json");if(await T.pathExists(t)){let r=await T.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 T.writeJson(t,r,{spaces:2})}}async function bt(e){let a=S.join(x,"template/with-pwa");await T.pathExists(a)&&await T.copy(a,e,{overwrite:!0});let t=S.join(e,"apps/web");if(!await T.pathExists(t))return;b({dependencies:["vite-plugin-pwa"],devDependencies:["@vite-pwa/assets-generator"],projectDir:t});let r=S.join(t,"package.json");if(await T.pathExists(r)){let n=await T.readJson(r);n.scripts={...n.scripts,"generate-pwa-assets":"pwa-assets-generator"},await T.writeJson(r,n,{spaces:2})}}import ie from"node:path";import{log as se}from"@clack/prompts";import ce from"picocolors";function pe(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 de(e,a){if(!a)return;let t=ie.join(e,"apps/server"),r=ie.join(e,"apps/web");try{b({dependencies:["better-auth"],projectDir:t}),b({dependencies:["better-auth"],projectDir:r})}catch(n){throw se.error(ce.red("Failed to configure authentication")),n instanceof Error&&se.error(ce.red(n.message)),n}}import wt from"node:path";async function le(e,a,t){let r=wt.join(e,"apps/server"),n=[],o=[];a==="hono"?(n.push("hono","@hono/trpc-server"),t==="node"&&(n.push("@hono/node-server"),o.push("tsx","@types/node"))):a==="elysia"&&(n.push("elysia","@elysiajs/cors","@elysiajs/trpc"),t==="node"&&(n.push("@elysiajs/node"),o.push("tsx","@types/node"))),t==="bun"&&o.push("@types/bun"),b({dependencies:n,devDependencies:o,projectDir:r})}import yt from"node:path";import Pt from"fs-extra";async function ue(e,a){let t=yt.join(e,"README.md"),r=jt(a);try{await Pt.writeFile(t,r)}catch(n){console.error("Failed to create README.md file:",n)}}function jt(e){let{projectName:a,packageManager:t,database:r,auth:n,addons:o=[],orm:i="drizzle",runtime:s="bun"}=e,c=t==="npm"?"npm run":t;return`# ${a}
|
|
3
3
|
|
|
4
4
|
This project was created with [Better-T-Stack](https://github.com/better-t-stack/Better-T-Stack), a modern TypeScript stack that combines React, TanStack Router, Hono, tRPC, and more.
|
|
5
5
|
|
|
6
6
|
## Features
|
|
7
7
|
|
|
8
|
-
${vt(
|
|
8
|
+
${vt(r,n,o,i,s)}
|
|
9
9
|
|
|
10
10
|
## Getting Started
|
|
11
11
|
|
|
@@ -15,7 +15,7 @@ First, install the dependencies:
|
|
|
15
15
|
${t} install
|
|
16
16
|
\`\`\`
|
|
17
17
|
|
|
18
|
-
${kt(
|
|
18
|
+
${kt(r,n,c,i)}
|
|
19
19
|
|
|
20
20
|
Then, run the development server:
|
|
21
21
|
|
|
@@ -37,11 +37,11 @@ ${a}/
|
|
|
37
37
|
|
|
38
38
|
## Available Scripts
|
|
39
39
|
|
|
40
|
-
${xt(c,
|
|
41
|
-
`}function vt(e,a,t,
|
|
42
|
-
`)}function kt(e,a,t,
|
|
40
|
+
${xt(c,r,i,n)}
|
|
41
|
+
`}function vt(e,a,t,r,n){let o=["- **TypeScript** - For type safety and improved developer experience","- **TanStack Router** - File-based routing with full type safety","- **TailwindCSS** - Utility-first CSS for rapid UI development","- **shadcn/ui** - Reusable UI components","- **Hono** - Lightweight, performant server framework","- **tRPC** - End-to-end type-safe APIs",`- **${n==="bun"?"Bun":"Node.js"}** - Runtime environment`];e!=="none"&&o.push(`- **${r==="drizzle"?"Drizzle":"Prisma"}** - TypeScript-first ORM`,`- **${e==="sqlite"?"SQLite/Turso":"PostgreSQL"}** - Database engine`),a&&o.push("- **Authentication** - Email & password authentication with Better Auth");for(let i of t)i==="pwa"?o.push("- **PWA** - Progressive Web App support"):i==="tauri"?o.push("- **Tauri** - Build native desktop applications"):i==="biome"?o.push("- **Biome** - Linting and formatting"):i==="husky"&&o.push("- **Husky** - Git hooks for code quality");return o.join(`
|
|
42
|
+
`)}function kt(e,a,t,r){if(e==="none")return"";let n=`## Database Setup
|
|
43
43
|
|
|
44
|
-
`;return e==="sqlite"?
|
|
44
|
+
`;return e==="sqlite"?n+=`This project uses SQLite${r==="drizzle"?" with Drizzle ORM":" with Prisma"}.
|
|
45
45
|
|
|
46
46
|
1. Start the local SQLite database:
|
|
47
47
|
\`\`\`bash
|
|
@@ -49,29 +49,29 @@ cd apps/server && ${t} db:local
|
|
|
49
49
|
\`\`\`
|
|
50
50
|
|
|
51
51
|
2. Update your \`.env\` file in the \`apps/server\` directory with the appropriate connection details if needed.
|
|
52
|
-
`:e==="postgres"&&(
|
|
52
|
+
`:e==="postgres"&&(n+=`This project uses PostgreSQL${r==="drizzle"?" with Drizzle ORM":" with Prisma"}.
|
|
53
53
|
|
|
54
54
|
1. Make sure you have a PostgreSQL database set up.
|
|
55
55
|
2. Update your \`apps/server/.env\` file with your PostgreSQL connection details.
|
|
56
|
-
`),
|
|
57
|
-
${a?"4":"3"}. ${
|
|
56
|
+
`),n+=`
|
|
57
|
+
${a?"4":"3"}. ${r==="prisma"?`Generate the Prisma client and push the schema:
|
|
58
58
|
\`\`\`bash
|
|
59
59
|
${t} db:push
|
|
60
60
|
\`\`\``:`Apply the schema to your database:
|
|
61
61
|
\`\`\`bash
|
|
62
62
|
${t} db:push
|
|
63
63
|
\`\`\``}
|
|
64
|
-
`,
|
|
64
|
+
`,n}function xt(e,a,t,r){let n=`- \`${e} dev\`: Start both web and server in development mode
|
|
65
65
|
- \`${e} build\`: Build both web and server
|
|
66
66
|
- \`${e} dev:web\`: Start only the web application
|
|
67
67
|
- \`${e} dev:server\`: Start only the server
|
|
68
|
-
- \`${e} check-types\`: Check TypeScript types across all apps`;return a!=="none"&&(
|
|
68
|
+
- \`${e} check-types\`: Check TypeScript types across all apps`;return a!=="none"&&(n+=`
|
|
69
69
|
- \`${e} db:push\`: Push schema changes to database
|
|
70
|
-
- \`${e} db:studio\`: Open database studio UI`,a==="sqlite"&&t==="drizzle"&&(
|
|
71
|
-
- \`cd apps/server && ${e} db:local\`: Start the local SQLite database`)),
|
|
72
|
-
`);return a.length<=1?[]:a.slice(1).map(
|
|
70
|
+
- \`${e} db:studio\`: Open database studio UI`,a==="sqlite"&&t==="drizzle"&&(n+=`
|
|
71
|
+
- \`cd apps/server && ${e} db:local\`: Start the local SQLite database`)),n}import he from"node:path";import{log as Nt,spinner as _t}from"@clack/prompts";import Bt from"fs-extra";import ge from"picocolors";import Tt from"node:os";import me from"node:path";import{cancel as K,confirm as Et,isCancel as X,log as L,select as $t,spinner as Y,text as Ct}from"@clack/prompts";import{$ as O}from"execa";import At from"fs-extra";import A from"picocolors";async function Ot(){try{return(await O`turso --version`).exitCode===0}catch{return!1}}async function It(){try{return!(await O`turso auth whoami`).stdout.includes("You are not logged in")}catch{return!1}}async function Ft(){let e=Y();try{return e.start("Logging in to Turso..."),await O`turso auth login`,e.stop("Logged in to Turso successfully!"),!0}catch(a){throw e.stop(A.red("Failed to log in to Turso")),a}}async function Dt(e){let a=Y();try{if(a.start("Installing Turso CLI..."),e)await O`brew install tursodatabase/tap/turso`;else{let{stdout:t}=await O`curl -sSfL https://get.tur.so/install.sh`;await O`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(),L.warn(A.yellow("Turso CLI installation cancelled by user")),new Error("Installation cancelled")):(a.stop(A.red("Failed to install Turso CLI")),t)}}async function St(){try{let{stdout:e}=await O`turso group list`,a=e.trim().split(`
|
|
72
|
+
`);return a.length<=1?[]:a.slice(1).map(r=>{let[n,o,i,s]=r.trim().split(/\s{2,}/);return{name:n,locations:o,version:i,status:s}})}catch(e){return console.error("Error fetching Turso groups:",e),[]}}async function Rt(){let e=await St();if(e.length===0)return null;if(e.length===1)return e[0].name;let a=e.map(r=>({value:r.name,label:`${r.name} (${r.locations})`})),t=await $t({message:"Select a Turso database group:",options:a});return X(t)&&(K(A.red("Operation cancelled")),process.exit(0)),t}async function Lt(e,a){try{a?await O`turso db create ${e} --group ${a}`:await O`turso db create ${e}`}catch(n){throw n instanceof Error&&n.message.includes("already exists")?new Error("DATABASE_EXISTS"):n}let{stdout:t}=await O`turso db show ${e} --url`,{stdout:r}=await O`turso db tokens create ${e}`;return{dbUrl:t.trim(),authToken:r.trim()}}async function B(e,a){let t=me.join(e,"apps/server",".env"),r=a?`TURSO_CONNECTION_URL="${a.dbUrl}"
|
|
73
73
|
TURSO_AUTH_TOKEN="${a.authToken}"`:`TURSO_CONNECTION_URL=
|
|
74
|
-
TURSO_AUTH_TOKEN=`;await
|
|
74
|
+
TURSO_AUTH_TOKEN=`;await At.writeFile(t,r)}function J(){L.info(`Manual Turso Setup Instructions:
|
|
75
75
|
|
|
76
76
|
1. Visit https://turso.tech and create an account
|
|
77
77
|
2. Create a new database from the dashboard
|
|
@@ -79,17 +79,17 @@ TURSO_AUTH_TOKEN=`;await Ot.writeFile(t,o)}function V(){L.info(`Manual Turso Set
|
|
|
79
79
|
4. Add these credentials to the .env file in apps/server/.env
|
|
80
80
|
|
|
81
81
|
TURSO_CONNECTION_URL=your_database_url
|
|
82
|
-
TURSO_AUTH_TOKEN=your_auth_token`)}async function fe(e,a){if(!a){await B(e),L.info(
|
|
83
|
-
CORS_ORIGIN=http://localhost:3001`),a.auth&&(
|
|
84
|
-
BETTER_AUTH_SECRET=${pe()}`),
|
|
85
|
-
BETTER_AUTH_URL=http://localhost:3000`)),a.database!=="none"){if(a.orm==="prisma"&&!
|
|
86
|
-
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/mydb?schema=public"`;
|
|
87
|
-
TURSO_CONNECTION_URL=http://127.0.0.1:8080`))}if(a.examples?.includes("ai")&&!
|
|
88
|
-
GOOGLE_GENERATIVE_AI_API_KEY=`),await I.writeFile(
|
|
89
|
-
`),await I.writeFile(i,s.trim())}if(a.frontend.includes("native")){let
|
|
90
|
-
`),await I.writeFile(i,s.trim())}}import
|
|
82
|
+
TURSO_AUTH_TOKEN=your_auth_token`)}async function fe(e,a){if(!a){await B(e),L.info(A.blue("Skipping Turso setup. Setting up empty configuration.")),J();return}let t=Tt.platform(),r=t==="darwin";if(!(t!=="win32")){L.warn(A.yellow("Automatic Turso setup is not supported on Windows.")),await B(e),J();return}try{if(!await Ot()){let v=await Et({message:"Would you like to install Turso CLI?",initialValue:!0});if(X(v)&&(K(A.red("Operation cancelled")),process.exit(0)),!v){await B(e),J();return}await Dt(r)}await It()||await Ft();let s=await Rt(),c=!1,w="",P=me.basename(e);for(;!c;){let v=await Ct({message:"Enter a name for your database:",defaultValue:P,initialValue:P,placeholder:P});X(v)&&(K(A.red("Operation cancelled")),process.exit(0)),w=v;let g=Y();try{g.start(`Creating Turso database "${w}"${s?` in group "${s}"`:""}...`);let C=await Lt(w,s);await B(e,C),g.stop("Turso database configured successfully!"),c=!0}catch(C){if(C instanceof Error&&C.message==="DATABASE_EXISTS")g.stop(A.yellow(`Database "${A.red(w)}" already exists`)),P=`${w}-${Math.floor(Math.random()*1e3)}`;else throw g.stop(A.red("Failed to create Turso database")),C}}}catch(o){L.error(A.red(`Error during Turso setup: ${o}`)),await B(e),J(),L.success("Setup completed with manual configuration required.")}}async function be(e,a,t,r=!0){let n=_t(),o=he.join(e,"apps/server");if(a==="none"){await Bt.remove(he.join(o,"src/db"));return}try{a==="sqlite"?(t==="drizzle"?b({dependencies:["drizzle-orm","@libsql/client"],devDependencies:["drizzle-kit"],projectDir:o}):t==="prisma"&&b({dependencies:["@prisma/client"],devDependencies:["prisma"],projectDir:o}),r&&await fe(e,!0)):a==="postgres"&&(t==="drizzle"?b({dependencies:["drizzle-orm","postgres"],devDependencies:["drizzle-kit"],projectDir:o}):t==="prisma"&&b({dependencies:["@prisma/client"],devDependencies:["prisma"],projectDir:o}))}catch(i){throw n.stop(ge.red("Failed to set up database")),i instanceof Error&&Nt.error(ge.red(i.message)),i}}import N from"node:path";import I from"fs-extra";async function we(e,a){let t=N.join(e,"apps/server"),r=N.join(t,".env"),n="";if(await I.pathExists(r)&&(n=await I.readFile(r,"utf8")),n.includes("CORS_ORIGIN")||(n+=`
|
|
83
|
+
CORS_ORIGIN=http://localhost:3001`),a.auth&&(n.includes("BETTER_AUTH_SECRET")||(n+=`
|
|
84
|
+
BETTER_AUTH_SECRET=${pe()}`),n.includes("BETTER_AUTH_URL")||(n+=`
|
|
85
|
+
BETTER_AUTH_URL=http://localhost:3000`)),a.database!=="none"){if(a.orm==="prisma"&&!n.includes("DATABASE_URL")){let o=a.database==="sqlite"?"":`
|
|
86
|
+
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/mydb?schema=public"`;n+=o}a.database==="sqlite"&&!a.turso&&(n.includes("TURSO_CONNECTION_URL")||(n+=`
|
|
87
|
+
TURSO_CONNECTION_URL=http://127.0.0.1:8080`))}if(a.examples?.includes("ai")&&!n.includes("GOOGLE_GENERATIVE_AI_API_KEY")&&(n+=`
|
|
88
|
+
GOOGLE_GENERATIVE_AI_API_KEY=`),await I.writeFile(r,n.trim()),a.frontend.includes("web")){let o=N.join(e,"apps/web"),i=N.join(o,".env"),s="";await I.pathExists(i)&&(s=await I.readFile(i,"utf8")),s.includes("VITE_SERVER_URL")||(s+=`VITE_SERVER_URL=http://localhost:3000
|
|
89
|
+
`),await I.writeFile(i,s.trim())}if(a.frontend.includes("native")){let o=N.join(e,"apps/native"),i=N.join(o,".env"),s="";await I.pathExists(i)&&(s=await I.readFile(i,"utf8")),s.includes("EXPO_PUBLIC_SERVER_URL")||(s+=`EXPO_PUBLIC_SERVER_URL=http://localhost:3000
|
|
90
|
+
`),await I.writeFile(i,s.trim())}}import k from"node:path";import f from"fs-extra";async function ye(e,a,t,r,n,o=["web"]){let i=o.includes("web"),s=await f.pathExists(k.join(e,"apps/web"));a.includes("todo")&&i&&s?await Gt(e,t,r):await Jt(e,t),a.includes("ai")&&n==="hono"&&i&&s&&await zt(e)}async function zt(e){let a=k.join(x,"template/examples/ai");if(await f.pathExists(a)){await f.copy(a,e),await Ut(e);let t=k.join(e,"apps/web");b({dependencies:["ai"],projectDir:t});let r=k.join(e,"apps/server");b({dependencies:["ai","@ai-sdk/google"],projectDir:r}),await Mt(e)}}async function Mt(e){let a=k.join(e,"apps/server/src/index.ts");if(await f.pathExists(a)){let t=await f.readFile(a,"utf8");if(t.includes("hono")){let n=`import { streamText } from "ai";
|
|
91
91
|
import { google } from "@ai-sdk/google";
|
|
92
|
-
import { stream } from "hono/streaming";`,
|
|
92
|
+
import { stream } from "hono/streaming";`,o=`
|
|
93
93
|
app.post("/ai", async (c) => {
|
|
94
94
|
const body = await c.req.json();
|
|
95
95
|
const messages = body.messages || [];
|
|
@@ -105,62 +105,63 @@ app.post("/ai", async (c) => {
|
|
|
105
105
|
return stream(c, (stream) => stream.pipe(result.toDataStream()));
|
|
106
106
|
});`;if(t.includes("import {")){let s=t.lastIndexOf("import"),c=t.indexOf(`
|
|
107
107
|
`,s);t=`${t.substring(0,c+1)}
|
|
108
|
-
${
|
|
109
|
-
${t.substring(c+1)}`}else t=`${
|
|
108
|
+
${n}
|
|
109
|
+
${t.substring(c+1)}`}else t=`${n}
|
|
110
110
|
|
|
111
|
-
${t}`;let i=t.indexOf('app.use("/trpc"')||t.indexOf("app.use(trpc(");if(i!==-1)t=`${t.substring(0,i)}${
|
|
111
|
+
${t}`;let i=t.indexOf('app.use("/trpc"')||t.indexOf("app.use(trpc(");if(i!==-1)t=`${t.substring(0,i)}${o}
|
|
112
112
|
|
|
113
|
-
${t.substring(i)}`;else{let s=t.indexOf("export default");s!==-1?t=`${t.substring(0,s)}${
|
|
113
|
+
${t.substring(i)}`;else{let s=t.indexOf("export default");s!==-1?t=`${t.substring(0,s)}${o}
|
|
114
114
|
|
|
115
115
|
${t.substring(s)}`:t=`${t}
|
|
116
116
|
|
|
117
|
-
${
|
|
117
|
+
${o}`}await f.writeFile(a,t)}}}async function Ut(e){let a=k.join(e,"apps/web/src/components/header.tsx");if(await f.pathExists(a)){let t=await f.readFile(a,"utf8");t.includes('{ to: "/todos"')?t=t.replace(/{ to: "\/todos", label: "Todos" },/,`{ to: "/todos", label: "Todos" },
|
|
118
118
|
{ to: "/ai", label: "AI Chat" },`):t.includes('{ to: "/dashboard"')?t=t.replace(/{ to: "\/dashboard", label: "Dashboard" },/,`{ to: "/dashboard", label: "Dashboard" },
|
|
119
119
|
{ to: "/ai", label: "AI Chat" },`):t=t.replace(/const links = \[\s*{ to: "\/", label: "Home" },/,`const links = [
|
|
120
120
|
{ to: "/", label: "Home" },
|
|
121
|
-
{ to: "/ai", label: "AI Chat" },`),await
|
|
121
|
+
{ to: "/ai", label: "AI Chat" },`),await f.writeFile(a,t)}}async function Gt(e,a,t){let r=k.join(x,"template/examples/todo");if(await f.pathExists(r)){let n=k.join(r,"apps/web/src/routes"),o=k.join(e,"apps/web/src/routes");if(await f.copy(n,o,{overwrite:!0}),a!=="none"){let i=k.join(r,`apps/server/src/routers/with-${a}-todo.ts`),s=k.join(e,"apps/server/src/routers/todo.ts");await f.pathExists(i)&&await f.copy(i,s,{overwrite:!0})}await qt(e,t),await Wt(e)}}async function qt(e,a){let t=k.join(e,"apps/web/src/components/header.tsx");if(await f.pathExists(t)){let r=await f.readFile(t,"utf8");a?r=r.replace(/const links = \[\s*{ to: "\/", label: "Home" },\s*{ to: "\/dashboard", label: "Dashboard" },/,`const links = [
|
|
122
122
|
{ to: "/", label: "Home" },
|
|
123
123
|
{ to: "/dashboard", label: "Dashboard" },
|
|
124
|
-
{ to: "/todos", label: "Todos" },`):
|
|
124
|
+
{ to: "/todos", label: "Todos" },`):r=r.replace(/const links = \[\s*{ to: "\/", label: "Home" },/,`const links = [
|
|
125
125
|
{ to: "/", label: "Home" },
|
|
126
|
-
{ to: "/todos", label: "Todos" },`),await
|
|
126
|
+
{ to: "/todos", label: "Todos" },`),await f.writeFile(t,r)}}async function Jt(e,a){if(a==="drizzle"){let r=k.join(e,"apps/server/src/db/schema/todo.ts");await f.pathExists(r)&&await f.remove(r)}else if(a==="prisma"){let r=k.join(e,"apps/server/prisma/schema/todo.prisma");await f.pathExists(r)&&await f.remove(r)}let t=k.join(e,"apps/server/src/routers/todo.ts");await f.pathExists(t)&&await f.remove(t),await Vt(e)}async function Vt(e){let a=k.join(e,"apps/server/src/routers/index.ts");if(await f.pathExists(a)){let t=await f.readFile(a,"utf8");t=t.replace(/import { todoRouter } from ".\/todo";/,""),t=t.replace(/todo: todoRouter,/,""),await f.writeFile(a,t)}}async function Wt(e){let a=k.join(e,"apps/web/src/routes/index.tsx");if(await f.pathExists(a)){let t=await f.readFile(a,"utf8");t=t.replace(/<div id="buttons"><\/div>/,`<div id="buttons" className="mt-4 flex flex-col gap-4 sm:flex-row sm:items-center">
|
|
127
127
|
<Button asChild>
|
|
128
128
|
<Link to="/todos" className="flex items-center">
|
|
129
129
|
View Todo Demo
|
|
130
130
|
<ArrowRight className="ml-1 h-4 w-4" />
|
|
131
131
|
</Link>
|
|
132
132
|
</Button>
|
|
133
|
-
</div>`),await
|
|
134
|
-
${
|
|
135
|
-
`}${
|
|
136
|
-
|
|
137
|
-
${
|
|
138
|
-
${st?`${_?`${
|
|
139
|
-
`:""}`:`${
|
|
140
|
-
`}${
|
|
141
|
-
${
|
|
142
|
-
${
|
|
143
|
-
${
|
|
144
|
-
${
|
|
145
|
-
${
|
|
133
|
+
</div>`),await f.writeFile(a,t)}}import{log as Pe,spinner as je}from"@clack/prompts";import{$ as ve}from"execa";import V from"picocolors";async function ke({projectDir:e,packageManager:a,addons:t=[]}){let r=je();try{r.start(`Running ${a} install...`),await ve({cwd:e,stderr:"inherit"})`${a} install`,r.stop("Dependencies installed successfully"),(t.includes("biome")||t.includes("husky"))&&await Ht(e,a)}catch(n){throw r.stop(V.red("Failed to install dependencies")),n instanceof Error&&Pe.error(V.red(`Installation error: ${n.message}`)),n}}async function Ht(e,a){let t=je();try{t.start("Running Biome format check..."),await ve({cwd:e,stderr:"inherit"})`${a} biome check --write .`,t.stop("Biome check completed successfully")}catch{t.stop(V.yellow("Biome check encountered issues")),Pe.warn(V.yellow("Some files may need manual formatting"))}}import{note as Qt}from"@clack/prompts";import y from"picocolors";function xe(e,a,t,r,n,o,i,s){let c=t==="npm"?"npm run":t,w=`cd ${a}`,P=o?.includes("husky")||o?.includes("biome"),v=e!=="none"?Yt(e,n,c,i):"",g=o?.includes("tauri")?Zt(c):"",C=P?Xt(c):"",M=s?.includes("native")?Kt():"",_=s?.includes("web"),it=s?.includes("native"),st=_||it;Qt(`${y.cyan("1.")} ${w}
|
|
134
|
+
${r?"":`${y.cyan("2.")} ${t} install
|
|
135
|
+
`}${y.cyan(r?"2.":"3.")} ${c} dev
|
|
136
|
+
|
|
137
|
+
${y.bold("Your project will be available at:")}
|
|
138
|
+
${st?`${_?`${y.cyan("\u2022")} Frontend: http://localhost:3001
|
|
139
|
+
`:""}`:`${y.yellow("NOTE:")} You are creating a backend-only app (no frontend selected)
|
|
140
|
+
`}${y.cyan("\u2022")} API: http://localhost:3000
|
|
141
|
+
${M?`
|
|
142
|
+
${M.trim()}`:""}${v?`
|
|
143
|
+
${v.trim()}`:""}${g?`
|
|
144
|
+
${g.trim()}`:""}${C?`
|
|
145
|
+
${C.trim()}`:""}`,"Next steps")}function Kt(){return`${y.yellow("NOTE:")} For Expo connectivity issues, update apps/native/.env
|
|
146
|
+
with your local IP:
|
|
146
147
|
EXPO_PUBLIC_SERVER_URL=http://192.168.0.103:3000
|
|
147
|
-
`}function
|
|
148
|
+
`}function Xt(e){return`${y.bold(`
|
|
148
149
|
Linting and formatting:`)}
|
|
149
|
-
${
|
|
150
|
+
${y.cyan("\u2022")} Format and lint fix: ${`${e} check`}
|
|
150
151
|
|
|
151
|
-
`}function
|
|
152
|
-
${
|
|
152
|
+
`}function Yt(e,a,t,r){let n=[];return a==="prisma"?(e==="sqlite"&&n.push(`${y.yellow("NOTE:")} Turso support with Prisma is in Early Access and requires additional setup.`,"Learn more at: https://www.prisma.io/docs/orm/overview/databases/turso"),r==="bun"&&n.push(`${y.yellow("NOTE:")} Prisma with Bun may require additional configuration. If you encounter errors, follow the guidance provided in the error messages`),n.push(`${y.cyan("\u2022")} Apply schema: ${`${t} db:push`}`),n.push(`${y.cyan("\u2022")} Database UI: ${`${t} db:studio`}`)):a==="drizzle"&&(e==="sqlite"&&n.push(`${y.cyan("\u2022")} Start local DB: ${`cd apps/server && ${t} db:local`}`),n.push(`${y.cyan("\u2022")} Apply schema: ${`${t} db:push`}`),n.push(`${y.cyan("\u2022")} Database UI: ${`${t} db:studio`}`)),n.length?`${y.bold("Database commands:")}
|
|
153
|
+
${n.join(`
|
|
153
154
|
`)}
|
|
154
155
|
|
|
155
|
-
`:""}function
|
|
156
|
-
${
|
|
157
|
-
${
|
|
158
|
-
${
|
|
156
|
+
`:""}function Zt(e){return`${y.bold("Desktop app with Tauri:")}
|
|
157
|
+
${y.cyan("\u2022")} Start desktop app: ${`cd apps/web && ${e} desktop:dev`}
|
|
158
|
+
${y.cyan("\u2022")} Build desktop app: ${`cd apps/web && ${e} desktop:build`}
|
|
159
|
+
${y.yellow("NOTE:")} Tauri requires Rust and platform-specific dependencies. See: https://v2.tauri.app/start/prerequisites/
|
|
159
160
|
|
|
160
|
-
`}import
|
|
161
|
+
`}import W from"node:path";import{$ as ea,execa as ta}from"execa";import F from"fs-extra";async function Te(e,a){await aa(e,a),await ra(e,a)}async function aa(e,a){let t=W.join(e,"package.json");if(await F.pathExists(t)){let r=await F.readJson(t);r.name=a.projectName;let{stdout:n}=await ta(a.packageManager,["-v"],{cwd:e});if(r.packageManager=`${a.packageManager}@${n.trim()}`,await F.writeJson(t,r,{spaces:2}),a.packageManager==="pnpm"){let o=W.join(x,"template/with-pnpm/pnpm-workspace.yaml"),i=W.join(e,"pnpm-workspace.yaml");await F.pathExists(o)&&await F.copy(o,i)}}}async function ra(e,a){let t=W.join(e,"apps/server/package.json");if(await F.pathExists(t)){let r=await F.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 F.writeJson(t,r,{spaces:2})}}async function Ee(e,a){a&&await ea({cwd:e})`git init`}import H from"node:path";import D from"fs-extra";async function $e(e,a,t){let r=H.join(e,"apps/server"),n=H.join(r,"src/index.ts"),o=await D.readFile(n,"utf-8");a==="bun"?await na(r,n,o,t):a==="node"&&await oa(r,n,o,t)}async function na(e,a,t,r){let n=H.join(e,"package.json"),o=await D.readJson(n);if(o.scripts={...o.scripts,dev:"bun run --hot src/index.ts",start:"bun run dist/src/index.js"},await D.writeJson(n,o,{spaces:2}),b({devDependencies:["@types/bun"],projectDir:e}),r==="hono"){let i=`${t}
|
|
161
162
|
|
|
162
163
|
export default app;
|
|
163
|
-
`;await D.writeFile(a,i)}}async function
|
|
164
|
+
`;await D.writeFile(a,i)}}async function oa(e,a,t,r){let n=H.join(e,"package.json"),o=await D.readJson(n);if(o.scripts={...o.scripts,dev:"tsx watch src/index.ts",start:"node dist/src/index.js"},await D.writeJson(n,o,{spaces:2}),b({devDependencies:["tsx","@types/node"],projectDir:e}),r==="hono"){b({dependencies:["@hono/node-server"],projectDir:e});let i=`import { serve } from "@hono/node-server";
|
|
164
165
|
`,s=`
|
|
165
166
|
serve(
|
|
166
167
|
{
|
|
@@ -171,11 +172,11 @@ serve(
|
|
|
171
172
|
console.log(\`Server is running on http://localhost:\${info.port}\`);
|
|
172
173
|
},
|
|
173
174
|
);
|
|
174
|
-
`;if(!t.includes("@hono/node-server")){let c=t.lastIndexOf("import"),
|
|
175
|
+
`;if(!t.includes("@hono/node-server")){let c=t.lastIndexOf("import"),w=t.substring(0,c),P=t.substring(c),v=w+i+P+s;await D.writeFile(a,v)}}else if(r==="elysia"&&(b({dependencies:["@elysiajs/node"],projectDir:e}),!t.includes("@elysiajs/node"))){let i=`import { node } from "@elysiajs/node";
|
|
175
176
|
`,s=t.indexOf(`
|
|
176
|
-
`,t.indexOf("import")),c=t.substring(0,s+1),
|
|
177
|
-
`);else{let t=d.join(e,"apps/native");await f.pathExists(t)&&await f.remove(t)}}async function Ee(e,a){let t=d.join(P,`template/with-${a}`);await f.pathExists(t)&&await f.copy(t,e,{overwrite:!0})}async function $e(e,a,t,o){if(a==="none"||t==="none")return;let r=d.join(P,na(a,t));if(await f.pathExists(r)&&(await f.copy(r,e,{overwrite:!0}),!o)){if(a==="prisma"){let n=d.join(e,"apps/server/prisma/schema/auth.prisma");await f.pathExists(n)&&await f.remove(n)}else if(a==="drizzle"){let n=d.join(e,"apps/server/src/db/schema/auth.ts");await f.pathExists(n)&&await f.remove(n)}}}async function Ce(e,a,t,o,r){if(!a)return;let n=d.join(P,"template/with-auth");if(await f.pathExists(n)){let i=d.join(n,"apps/web"),s=d.join(e,"apps/web");await f.copy(i,s,{overwrite:!0});let c=d.join(n,"apps/server/src"),g=d.join(e,"apps/server/src");await f.copy(d.join(c,"lib/trpc.ts"),d.join(g,"lib/trpc.ts"),{overwrite:!0}),await f.copy(d.join(c,"routers/index.ts"),d.join(g,"routers/index.ts"),{overwrite:!0});let w=`with-${t}-context.ts`;await f.copy(d.join(c,"lib",w),d.join(g,"lib/context.ts"),{overwrite:!0});let k=`with-${t}-index.ts`;await f.copy(d.join(c,k),d.join(g,"index.ts"),{overwrite:!0});let O=ia(o,r),T=d.join(c,O);if(await f.pathExists(T)){let U=await f.readdir(T);for(let _ of U)await f.copy(d.join(T,_),d.join(g,"lib",_),{overwrite:!0})}}}async function Oe(e){let a=[d.join(e,"_gitignore"),d.join(e,"apps/web/_gitignore"),d.join(e,"apps/native/_gitignore"),d.join(e,"apps/server/_gitignore")];for(let t of a)if(await f.pathExists(t)){let o=d.join(d.dirname(t),".gitignore");await f.move(t,o)}}function na(e,a){return e==="drizzle"?a==="sqlite"?"template/with-drizzle-sqlite":"template/with-drizzle-postgres":e==="prisma"?a==="sqlite"?"template/with-prisma-sqlite":"template/with-prisma-postgres":"template/base"}function ia(e,a){if(e==="drizzle")return a==="sqlite"?"with-drizzle-sqlite-lib":"with-drizzle-postgres-lib";if(e==="prisma")return a==="sqlite"?"with-prisma-sqlite-lib":"with-prisma-postgres-lib";throw new Error("Invalid ORM or database configuration for auth setup")}async function Ae(e){let a=pa(),t=sa.resolve(process.cwd(),e.projectName);try{return await la.ensureDir(t),await xe(t),await Te(t,e.frontend),await Oe(t),await Ee(t,e.backend),await de(t,e.backend,e.runtime),await $e(t,e.orm,e.database,e.auth),await be(t,e.database,e.orm,e.turso??e.database==="sqlite"),await Ce(t,e.auth,e.backend,e.orm,e.database),await le(t,e.auth),await ke(t,e.runtime,e.backend),await ye(t,e.examples,e.orm,e.auth,e.backend,e.frontend),await we(t,e),await ve(t,e.git),e.addons.length>0&&await ne(t,e.addons,e.packageManager,e.frontend),await je(t,e),await ue(t,e),Pe(e.database,e.projectName,e.packageManager,!e.noInstall,e.orm,e.addons,e.runtime,e.frontend),t}catch(o){throw a.message(Ie.red("Failed")),o instanceof Error&&(ca(Ie.red(`Error during project creation: ${o.message}`)),process.exit(1)),o}}import{log as De,spinner as Fe}from"@clack/prompts";import{$ as Re}from"execa";import H from"picocolors";async function Se({projectDir:e,packageManager:a,addons:t=[]}){let o=Fe();try{o.start(`Running ${a} install...`),await Re({cwd:e,stderr:"inherit"})`${a} install`,o.stop("Dependencies installed successfully"),(t.includes("biome")||t.includes("husky"))&&await da(e,a)}catch(r){throw o.stop(H.red("Failed to install dependencies")),r instanceof Error&&De.error(H.red(`Installation error: ${r.message}`)),r}}async function da(e,a){let t=Fe();try{t.start("Running Biome format check..."),await Re({cwd:e,stderr:"inherit"})`${a} biome check --write .`,t.stop("Biome check completed successfully")}catch{t.stop(H.yellow("Biome check encountered issues")),De.warn(H.yellow("Some files may need manual formatting"))}}import{cancel as lo,group as uo}from"@clack/prompts";import mo from"picocolors";import{cancel as ua,isCancel as ma,multiselect as fa}from"@clack/prompts";import ha from"picocolors";async function Le(e,a){if(e!==void 0)return e;let t=a?.includes("web"),o=[{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)"}],n=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"}],...o]:o,i=u.addons.filter(c=>t||c!=="pwa"&&c!=="tauri"),s=await fa({message:"Which Addons would you like to add?",options:n,initialValues:i,required:!1});return ma(s)&&(ua(ha.red("Operation cancelled")),process.exit(0)),s.includes("husky")&&!s.includes("biome")&&s.push("biome"),s}import{cancel as ga,confirm as ba,isCancel as wa,log as ya}from"@clack/prompts";import Ne from"picocolors";async function _e(e,a,t){if(!a)return!1;let o=t?.includes("native"),r=t?.includes("web");if(o&&ya.warn(Ne.yellow("Note: Authentication is not yet available with native")),!r)return!1;if(e!==void 0)return e;let n=await ba({message:"Would you like to add authentication with Better-Auth?",initialValue:u.auth});return wa(n)&&(ga(Ne.red("Operation cancelled")),process.exit(0)),n}import{cancel as Pa,isCancel as ja,select as va}from"@clack/prompts";import ka from"picocolors";async function Be(e){if(e!==void 0)return e;let a=await va({message:"Which backend framework would you like to use?",options:[{value:"hono",label:"Hono",hint:"Lightweight, ultrafast web framework"},{value:"elysia",label:"Elysia",hint:"TypeScript framework with end-to-end type safety)"}],initialValue:u.backend});return ja(a)&&(Pa(ka.red("Operation cancelled")),process.exit(0)),a}import{cancel as xa,isCancel as Ta,select as Ea}from"@clack/prompts";import $a from"picocolors";async function ze(e){if(e!==void 0)return e;let a=await Ea({message:"Which database would you like to use?",options:[{value:"none",label:"None",hint:"No database setup"},{value:"sqlite",label:"SQLite",hint:"by Turso"},{value:"postgres",label:"PostgreSQL",hint:"Traditional relational database"}],initialValue:u.database});return Ta(a)&&(xa($a.red("Operation cancelled")),process.exit(0)),a}import{cancel as Ca,isCancel as Oa,multiselect as Ue}from"@clack/prompts";import Ia from"picocolors";async function Me(e,a,t,o){if(e!==void 0)return e;if(a==="none")return[];if(!t?.includes("web"))return[];let n=[];return o==="elysia"&&(n=await Ue({message:"Which examples would you like to include?",options:[{value:"todo",label:"Todo App",hint:"A simple CRUD example app"}],required:!1,initialValues:u.examples})),o==="hono"&&(n=await Ue({message:"Which examples would you like to include?",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:u.examples})),Oa(n)&&(Ca(Ia.red("Operation cancelled")),process.exit(0)),n}import{cancel as Aa,isCancel as Da,multiselect as Fa}from"@clack/prompts";import Ra from"picocolors";async function Ge(e){if(e!==void 0)return e;let a=await Fa({message:"Which frontend applications would you like to create?",options:[{value:"web",label:"Web App",hint:"React + TanStack Router web application"},{value:"native",label:"Native App",hint:"React Native + Expo application"}],initialValues:u.frontend,required:!1});return Da(a)&&(Aa(Ra.red("Operation cancelled")),process.exit(0)),a}import{cancel as Sa,confirm as La,isCancel as Na}from"@clack/prompts";import _a from"picocolors";async function Je(e){if(e!==void 0)return e;let a=await La({message:"Initialize a new git repository?",initialValue:u.git});return Na(a)&&(Sa(_a.red("Operation cancelled")),process.exit(0)),a}import{cancel as Ba,confirm as za,isCancel as Ua}from"@clack/prompts";import Ma from"picocolors";async function Ve(e){if(e!==void 0)return e;let a=await za({message:"Do you want to install project dependencies?",initialValue:!u.noInstall});return Ua(a)&&(Ba(Ma.red("Operation cancelled")),process.exit(0)),!a}import{cancel as Ga,isCancel as Ja,select as Va}from"@clack/prompts";import qa from"picocolors";async function qe(e,a){if(!a)return"none";if(e!==void 0)return e;let t=await Va({message:"Which ORM would you like to use?",options:[{value:"drizzle",label:"Drizzle",hint:"Type-safe, lightweight ORM"},{value:"prisma",label:"Prisma",hint:"Powerful, feature-rich ORM"}],initialValue:u.orm});return Ja(t)&&(Ga(qa.red("Operation cancelled")),process.exit(0)),t}import{cancel as Wa,isCancel as Ha,select as Ka}from"@clack/prompts";import Qa from"picocolors";async function We(e){if(e!==void 0)return e;let a=M(),t=await Ka({message:"Which package manager do you want to use?",options:[{value:"npm",label:"npm",hint:"Node Package Manager"},{value:"bun",label:"bun",hint:"All-in-one JavaScript runtime & toolkit"},{value:"pnpm",label:"pnpm",hint:"Fast, disk space efficient package manager"}],initialValue:a});return Ha(t)&&(Wa(Qa.red("Operation cancelled")),process.exit(0)),t}import z from"node:path";import{cancel as Xa,isCancel as Ya,text as Za}from"@clack/prompts";import R from"fs-extra";import eo from"picocolors";var to=["<",">",":",'"',"|","?","*"],He=255;function Ke(e){if(e!=="."){if(!e)return"Project name cannot be empty";if(e.length>He)return`Project name must be less than ${He} characters`;if(to.some(a=>e.includes(a)))return"Project name contains invalid characters";if(e.startsWith(".")||e.startsWith("-"))return"Project name cannot start with a dot or dash";if(e.toLowerCase()==="node_modules"||e.toLowerCase()==="favicon.ico")return"Project name is reserved"}}async function Qe(e){if(e)if(e==="."){let n=process.cwd();if(R.readdirSync(n).length===0)return e}else{let n=z.basename(e);if(!Ke(n)){let s=z.resolve(process.cwd(),e);if(!R.pathExistsSync(s)||R.readdirSync(s).length===0)return e}}let a=!1,t="",o=u.projectName,r=1;for(;R.pathExistsSync(z.resolve(process.cwd(),o));)o=`${u.projectName}-${r}`,r++;for(;!a;){let n=await Za({message:"Enter your project name or path (relative to current directory)",placeholder:o,initialValue:e,defaultValue:o,validate:i=>{let s=i.trim()||o;if(s==="."){if(R.readdirSync(process.cwd()).length>0)return"Current directory is not empty. Please choose a different directory.";a=!0;return}let c=z.resolve(process.cwd(),s),g=z.basename(c),w=Ke(g);if(w)return w;if(!c.startsWith(process.cwd()))return"Project path must be within current directory";if(R.pathExistsSync(c)&&R.readdirSync(c).length>0)return`Directory "${s}" already exists and is not empty. Please choose a different name or path.`;a=!0}});Ya(n)&&(Xa(eo.red("Operation cancelled.")),process.exit(0)),t=n||o}return t}import{cancel as ao,isCancel as oo,select as ro}from"@clack/prompts";import no from"picocolors";async function Xe(e){if(e!==void 0)return e;let a=await ro({message:"Which runtime would you like to use?",options:[{value:"bun",label:"Bun",hint:"Fast all-in-one JavaScript runtime"},{value:"node",label:"Node.js",hint:"Traditional Node.js runtime"}],initialValue:u.runtime});return oo(a)&&(ao(no.red("Operation cancelled")),process.exit(0)),a}import{cancel as io,confirm as so,isCancel as co}from"@clack/prompts";import po from"picocolors";async function Ye(e){if(e!==void 0)return e;let a=await so({message:"Set up a Turso database for this project?",initialValue:u.turso});return co(a)&&(io(po.red("Operation cancelled")),process.exit(0)),a}async function Ze(e){let a=await uo({projectName:async()=>Qe(e.projectName),frontend:()=>Ge(e.frontend),backend:()=>Be(e.backend),runtime:()=>Xe(e.runtime),database:()=>ze(e.database),orm:({results:t})=>qe(e.orm,t.database!=="none"),auth:({results:t})=>_e(e.auth,t.database!=="none",t.frontend),turso:({results:t})=>t.database==="sqlite"&&t.orm!=="prisma"?Ye(e.turso):Promise.resolve(!1),addons:({results:t})=>Le(e.addons,t.frontend),examples:({results:t})=>Me(e.examples,t.database,t.frontend,t.backend),git:()=>Je(e.git),packageManager:()=>We(e.packageManager),noInstall:()=>Ve(e.noInstall)},{onCancel:()=>{lo(mo.red("Operation cancelled")),process.exit(0)}});return{projectName:a.projectName,frontend:a.frontend,database:a.database,orm:a.orm,auth:a.auth,addons:a.addons,examples:a.examples,git:a.git,packageManager:a.packageManager,noInstall:a.noInstall,turso:a.turso,backend:a.backend,runtime:a.runtime}}import x from"picocolors";function Z(e){let a=[];if(e.projectName&&a.push(`${x.blue("Project Name:")} ${e.projectName}`),e.frontend!==void 0){let t=e.frontend.length>0?e.frontend.join(", "):"none";a.push(`${x.blue("Frontend:")} ${t}`)}if(e.backend!==void 0&&a.push(`${x.blue("Backend Framework:")} ${e.backend}`),e.runtime!==void 0&&a.push(`${x.blue("Runtime:")} ${e.runtime}`),e.database!==void 0&&a.push(`${x.blue("Database:")} ${e.database}`),e.orm!==void 0&&a.push(`${x.blue("ORM:")} ${e.orm}`),e.auth!==void 0&&a.push(`${x.blue("Authentication:")} ${e.auth}`),e.addons!==void 0){let t=e.addons.length>0?e.addons.join(", "):"none";a.push(`${x.blue("Addons:")} ${t}`)}if(e.examples!==void 0){let t=e.examples.length>0?e.examples.join(", "):"none";a.push(`${x.blue("Examples:")} ${t}`)}return e.git!==void 0&&a.push(`${x.blue("Git Init:")} ${e.git}`),e.packageManager!==void 0&&a.push(`${x.blue("Package Manager:")} ${e.packageManager}`),e.noInstall!==void 0&&a.push(`${x.blue("Skip Install:")} ${e.noInstall}`),e.turso!==void 0&&a.push(`${x.blue("Turso Setup:")} ${e.turso}`),a.join(`
|
|
178
|
-
`)}function et(e){let a=[];e.database==="none"?a.push("--database none"):(a.push(`--database ${e.database}`),e.orm&&a.push(`--orm ${e.orm}`),e.database==="sqlite"&&a.push(e.turso?"--turso":"--no-turso")),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("
|
|
177
|
+
`,t.indexOf("import")),c=t.substring(0,s+1),w=t.substring(s+1),P=c+i+w;P=P.replace(/const app = new Elysia\([^)]*\)/,"const app = new Elysia({ adapter: node() })"),await D.writeFile(a,P)}}import l from"node:path";import h from"fs-extra";async function Ce(e){let a=l.join(x,"template/base");if(!await h.pathExists(a))throw new Error(`Template directory not found: ${a}`);await h.copy(a,e)}async function Ae(e,a){if(!a.includes("web")){let t=l.join(e,"apps/web");await h.pathExists(t)&&await h.remove(t)}if(a.includes("native"))await h.writeFile(l.join(e,".npmrc"),`node-linker=hoisted
|
|
178
|
+
`);else{let t=l.join(e,"apps/native");await h.pathExists(t)&&await h.remove(t)}}async function Oe(e,a){let t=l.join(x,`template/with-${a}`);await h.pathExists(t)&&await h.copy(t,e,{overwrite:!0})}async function Ie(e,a,t,r){if(a==="none"||t==="none")return;let n=l.join(x,ia(a,t));if(await h.pathExists(n)&&(await h.copy(n,e,{overwrite:!0}),!r)){if(a==="prisma"){let o=l.join(e,"apps/server/prisma/schema/auth.prisma");await h.pathExists(o)&&await h.remove(o)}else if(a==="drizzle"){let o=l.join(e,"apps/server/src/db/schema/auth.ts");await h.pathExists(o)&&await h.remove(o)}}}async function Fe(e,a,t,r,n){if(!a)return;let o=l.join(x,"template/with-auth");if(await h.pathExists(o)){let i=l.join(o,"apps/web"),s=l.join(e,"apps/web");await h.copy(i,s,{overwrite:!0});let c=l.join(o,"apps/server/src"),w=l.join(e,"apps/server/src");await h.copy(l.join(c,"lib/trpc.ts"),l.join(w,"lib/trpc.ts"),{overwrite:!0}),await h.copy(l.join(c,"routers/index.ts"),l.join(w,"routers/index.ts"),{overwrite:!0});let P=`with-${t}-context.ts`;await h.copy(l.join(c,"lib",P),l.join(w,"lib/context.ts"),{overwrite:!0});let v=`with-${t}-index.ts`;await h.copy(l.join(c,v),l.join(w,"index.ts"),{overwrite:!0});let g=sa(r,n),C=l.join(c,g);if(await h.pathExists(C)){let M=await h.readdir(C);for(let _ of M)await h.copy(l.join(C,_),l.join(w,"lib",_),{overwrite:!0})}}}async function De(e){let a=[l.join(e,"_gitignore"),l.join(e,"apps/web/_gitignore"),l.join(e,"apps/native/_gitignore"),l.join(e,"apps/server/_gitignore")];for(let t of a)if(await h.pathExists(t)){let r=l.join(l.dirname(t),".gitignore");await h.move(t,r)}}function ia(e,a){return e==="drizzle"?a==="sqlite"?"template/with-drizzle-sqlite":"template/with-drizzle-postgres":e==="prisma"?a==="sqlite"?"template/with-prisma-sqlite":"template/with-prisma-postgres":"template/base"}function sa(e,a){if(e==="drizzle")return a==="sqlite"?"with-drizzle-sqlite-lib":"with-drizzle-postgres-lib";if(e==="prisma")return a==="sqlite"?"with-prisma-sqlite-lib":"with-prisma-postgres-lib";throw new Error("Invalid ORM or database configuration for auth setup")}async function Re(e){let a=da(),t=ca.resolve(process.cwd(),e.projectName);try{return await la.ensureDir(t),await Ce(t),await Ae(t,e.frontend),await De(t),await Oe(t,e.backend),await le(t,e.backend,e.runtime),await Ie(t,e.orm,e.database,e.auth),await be(t,e.database,e.orm,e.turso??e.database==="sqlite"),await Fe(t,e.auth,e.backend,e.orm,e.database),await de(t,e.auth),await $e(t,e.runtime,e.backend),await ye(t,e.examples,e.orm,e.auth,e.backend,e.frontend),await we(t,e),await Ee(t,e.git),e.addons.length>0&&await oe(t,e.addons,e.packageManager,e.frontend),await Te(t,e),await ue(t,e),e.noInstall||await ke({projectDir:t,packageManager:e.packageManager,addons:e.addons}),xe(e.database,e.projectName,e.packageManager,!e.noInstall,e.orm,e.addons,e.runtime,e.frontend),t}catch(r){throw a.message(Se.red("Failed")),r instanceof Error&&(pa(Se.red(`Error during project creation: ${r.message}`)),process.exit(1)),r}}import{cancel as dr,group as lr}from"@clack/prompts";import ur from"picocolors";import{cancel as ua,isCancel as ma,multiselect as fa}from"@clack/prompts";import ha from"picocolors";async function Le(e,a){if(e!==void 0)return e;let t=a?.includes("web"),r=[{value:"biome",label:"Biome",hint:"Add Biome for linting and formatting"},{value:"husky",label:"Husky",hint:"Add Git hooks with Husky, lint-staged (requires Biome)"}],o=t?[...[{value:"pwa",label:"PWA (Progressive Web App)",hint:"Make your app installable and work offline"},{value:"tauri",label:"Tauri Desktop App",hint:"Build native desktop apps from your web frontend"}],...r]:r,i=m.addons.filter(c=>t||c!=="pwa"&&c!=="tauri"),s=await fa({message:"Which Addons would you like to add?",options:o,initialValues:i,required:!1});return ma(s)&&(ua(ha.red("Operation cancelled")),process.exit(0)),s.includes("husky")&&!s.includes("biome")&&s.push("biome"),s}import{cancel as ga,confirm as ba,isCancel as wa,log as ya}from"@clack/prompts";import Ne from"picocolors";async function _e(e,a,t){if(!a)return!1;let r=t?.includes("native"),n=t?.includes("web");if(r&&ya.warn(Ne.yellow("Note: Authentication is not yet available with native")),!n)return!1;if(e!==void 0)return e;let o=await ba({message:"Would you like to add authentication with Better-Auth?",initialValue:m.auth});return wa(o)&&(ga(Ne.red("Operation cancelled")),process.exit(0)),o}import{cancel as Pa,isCancel as ja,select as va}from"@clack/prompts";import ka from"picocolors";async function Be(e){if(e!==void 0)return e;let a=await va({message:"Which backend framework would you like to use?",options:[{value:"hono",label:"Hono",hint:"Lightweight, ultrafast web framework"},{value:"elysia",label:"Elysia",hint:"TypeScript framework with end-to-end type safety)"}],initialValue:m.backend});return ja(a)&&(Pa(ka.red("Operation cancelled")),process.exit(0)),a}import{cancel as xa,isCancel as Ta,select as Ea}from"@clack/prompts";import $a from"picocolors";async function ze(e){if(e!==void 0)return e;let a=await Ea({message:"Which database would you like to use?",options:[{value:"none",label:"None",hint:"No database setup"},{value:"sqlite",label:"SQLite",hint:"by Turso"},{value:"postgres",label:"PostgreSQL",hint:"Traditional relational database"}],initialValue:m.database});return Ta(a)&&(xa($a.red("Operation cancelled")),process.exit(0)),a}import{cancel as Ca,isCancel as Aa,multiselect as Me}from"@clack/prompts";import Oa from"picocolors";async function Ue(e,a,t,r){if(e!==void 0)return e;if(a==="none")return[];if(!t?.includes("web"))return[];let o=[];return r==="elysia"&&(o=await Me({message:"Which examples would you like to include?",options:[{value:"todo",label:"Todo App",hint:"A simple CRUD example app"}],required:!1,initialValues:m.examples})),r==="hono"&&(o=await Me({message:"Which examples would you like to include?",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:m.examples})),Aa(o)&&(Ca(Oa.red("Operation cancelled")),process.exit(0)),o}import{cancel as Ia,isCancel as Fa,multiselect as Da}from"@clack/prompts";import Sa from"picocolors";async function Ge(e){if(e!==void 0)return e;let a=await Da({message:"Which frontend applications would you like to create?",options:[{value:"web",label:"Web App",hint:"React + TanStack Router web application"},{value:"native",label:"Native App",hint:"React Native + Expo application"}],initialValues:m.frontend,required:!1});return Fa(a)&&(Ia(Sa.red("Operation cancelled")),process.exit(0)),a}import{cancel as Ra,confirm as La,isCancel as Na}from"@clack/prompts";import _a from"picocolors";async function qe(e){if(e!==void 0)return e;let a=await La({message:"Initialize a new git repository?",initialValue:m.git});return Na(a)&&(Ra(_a.red("Operation cancelled")),process.exit(0)),a}import{cancel as Ba,confirm as za,isCancel as Ma}from"@clack/prompts";import Ua from"picocolors";async function Je(e){if(e!==void 0)return e;let a=await za({message:"Do you want to install project dependencies?",initialValue:!m.noInstall});return Ma(a)&&(Ba(Ua.red("Operation cancelled")),process.exit(0)),!a}import{cancel as Ga,isCancel as qa,select as Ja}from"@clack/prompts";import Va from"picocolors";async function Ve(e,a){if(!a)return"none";if(e!==void 0)return e;let t=await Ja({message:"Which ORM would you like to use?",options:[{value:"drizzle",label:"Drizzle",hint:"Type-safe, lightweight ORM"},{value:"prisma",label:"Prisma",hint:"Powerful, feature-rich ORM"}],initialValue:m.orm});return qa(t)&&(Ga(Va.red("Operation cancelled")),process.exit(0)),t}import{cancel as Wa,isCancel as Ha,select as Qa}from"@clack/prompts";import Ka from"picocolors";async function We(e){if(e!==void 0)return e;let a=U(),t=await Qa({message:"Which package manager do you want to use?",options:[{value:"npm",label:"npm",hint:"Node Package Manager"},{value:"bun",label:"bun",hint:"All-in-one JavaScript runtime & toolkit"},{value:"pnpm",label:"pnpm",hint:"Fast, disk space efficient package manager"}],initialValue:a});return Ha(t)&&(Wa(Ka.red("Operation cancelled")),process.exit(0)),t}import z from"node:path";import{cancel as Xa,isCancel as Ya,text as Za}from"@clack/prompts";import R from"fs-extra";import er from"picocolors";var tr=["<",">",":",'"',"|","?","*"],He=255;function Qe(e){if(e!=="."){if(!e)return"Project name cannot be empty";if(e.length>He)return`Project name must be less than ${He} characters`;if(tr.some(a=>e.includes(a)))return"Project name contains invalid characters";if(e.startsWith(".")||e.startsWith("-"))return"Project name cannot start with a dot or dash";if(e.toLowerCase()==="node_modules"||e.toLowerCase()==="favicon.ico")return"Project name is reserved"}}async function Ke(e){if(e)if(e==="."){let o=process.cwd();if(R.readdirSync(o).length===0)return e}else{let o=z.basename(e);if(!Qe(o)){let s=z.resolve(process.cwd(),e);if(!R.pathExistsSync(s)||R.readdirSync(s).length===0)return e}}let a=!1,t="",r=m.projectName,n=1;for(;R.pathExistsSync(z.resolve(process.cwd(),r));)r=`${m.projectName}-${n}`,n++;for(;!a;){let o=await Za({message:"Enter your project name or path (relative to current directory)",placeholder:r,initialValue:e,defaultValue:r,validate:i=>{let s=i.trim()||r;if(s==="."){if(R.readdirSync(process.cwd()).length>0)return"Current directory is not empty. Please choose a different directory.";a=!0;return}let c=z.resolve(process.cwd(),s),w=z.basename(c),P=Qe(w);if(P)return P;if(!c.startsWith(process.cwd()))return"Project path must be within current directory";if(R.pathExistsSync(c)&&R.readdirSync(c).length>0)return`Directory "${s}" already exists and is not empty. Please choose a different name or path.`;a=!0}});Ya(o)&&(Xa(er.red("Operation cancelled.")),process.exit(0)),t=o||r}return t}import{cancel as ar,isCancel as rr,select as nr}from"@clack/prompts";import or from"picocolors";async function Xe(e){if(e!==void 0)return e;let a=await nr({message:"Which runtime would you like to use?",options:[{value:"bun",label:"Bun",hint:"Fast all-in-one JavaScript runtime"},{value:"node",label:"Node.js",hint:"Traditional Node.js runtime"}],initialValue:m.runtime});return rr(a)&&(ar(or.red("Operation cancelled")),process.exit(0)),a}import{cancel as ir,confirm as sr,isCancel as cr}from"@clack/prompts";import pr from"picocolors";async function Ye(e){if(e!==void 0)return e;let a=await sr({message:"Set up a Turso database for this project?",initialValue:m.turso});return cr(a)&&(ir(pr.red("Operation cancelled")),process.exit(0)),a}async function Ze(e){let a=await lr({projectName:async()=>Ke(e.projectName),frontend:()=>Ge(e.frontend),backend:()=>Be(e.backend),runtime:()=>Xe(e.runtime),database:()=>ze(e.database),orm:({results:t})=>Ve(e.orm,t.database!=="none"),auth:({results:t})=>_e(e.auth,t.database!=="none",t.frontend),turso:({results:t})=>t.database==="sqlite"&&t.orm!=="prisma"?Ye(e.turso):Promise.resolve(!1),addons:({results:t})=>Le(e.addons,t.frontend),examples:({results:t})=>Ue(e.examples,t.database,t.frontend,t.backend),git:()=>qe(e.git),packageManager:()=>We(e.packageManager),noInstall:()=>Je(e.noInstall)},{onCancel:()=>{dr(ur.red("Operation cancelled")),process.exit(0)}});return{projectName:a.projectName,frontend:a.frontend,database:a.database,orm:a.orm,auth:a.auth,addons:a.addons,examples:a.examples,git:a.git,packageManager:a.packageManager,noInstall:a.noInstall,turso:a.turso,backend:a.backend,runtime:a.runtime}}import $ from"picocolors";function Z(e){let a=[];if(e.projectName&&a.push(`${$.blue("Project Name:")} ${e.projectName}`),e.frontend!==void 0){let t=e.frontend.length>0?e.frontend.join(", "):"none";a.push(`${$.blue("Frontend:")} ${t}`)}if(e.backend!==void 0&&a.push(`${$.blue("Backend Framework:")} ${e.backend}`),e.runtime!==void 0&&a.push(`${$.blue("Runtime:")} ${e.runtime}`),e.database!==void 0&&a.push(`${$.blue("Database:")} ${e.database}`),e.orm!==void 0&&a.push(`${$.blue("ORM:")} ${e.orm}`),e.auth!==void 0&&a.push(`${$.blue("Authentication:")} ${e.auth}`),e.addons!==void 0){let t=e.addons.length>0?e.addons.join(", "):"none";a.push(`${$.blue("Addons:")} ${t}`)}if(e.examples!==void 0){let t=e.examples.length>0?e.examples.join(", "):"none";a.push(`${$.blue("Examples:")} ${t}`)}return e.git!==void 0&&a.push(`${$.blue("Git Init:")} ${e.git}`),e.packageManager!==void 0&&a.push(`${$.blue("Package Manager:")} ${e.packageManager}`),e.noInstall!==void 0&&a.push(`${$.blue("Skip Install:")} ${e.noInstall}`),e.turso!==void 0&&a.push(`${$.blue("Turso Setup:")} ${e.turso}`),a.join(`
|
|
179
|
+
`)}function et(e){let a=[];e.database==="none"?a.push("--database none"):(a.push(`--database ${e.database}`),e.orm&&a.push(`--orm ${e.orm}`),e.database==="sqlite"&&a.push(e.turso?"--turso":"--no-turso")),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("--no-addons"),e.examples&&e.examples.length>0?a.push(`--examples ${e.examples.join(" ")}`):a.push("--no-examples"),e.packageManager&&a.push(`--package-manager ${e.packageManager}`);let t="",r=e.packageManager;r==="npm"?t="npm 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 mr from"node:path";import fr from"fs-extra";var tt=()=>{let e=mr.join(x,"package.json");return fr.readJSONSync(e).version??"1.0.0"};import at from"gradient-string";var rt=`
|
|
179
180
|
\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
|
|
180
181
|
\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
|
|
181
182
|
\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
|
|
@@ -189,10 +190,10 @@ serve(
|
|
|
189
190
|
\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
|
|
190
191
|
\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
|
|
191
192
|
\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
|
|
192
|
-
`,
|
|
193
|
-
`),t=Math.max(...a.map(
|
|
193
|
+
`,nt={pink:"#F5C2E7",mauve:"#CBA6F7",red:"#F38BA8",maroon:"#E78284",peach:"#FAB387",yellow:"#F9E2AF",green:"#A6E3A1",teal:"#94E2D5",sky:"#89DCEB",sapphire:"#74C7EC",lavender:"#B4BEFE"},ot=()=>{let e=process.stdout.columns||80,a=rt.split(`
|
|
194
|
+
`),t=Math.max(...a.map(r=>r.length));e<t?console.log(at(Object.values(nt)).multiline(`
|
|
194
195
|
\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557
|
|
195
196
|
\u2551 Better T-Stack \u2551
|
|
196
197
|
\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D
|
|
197
|
-
`)):console.log(at(Object.values(
|
|
198
|
-
${
|
|
198
|
+
`)):console.log(at(Object.values(nt)).multiline(rt))};process.on("SIGINT",()=>{E.error(u.red("Operation cancelled")),process.exit(0)});var ee=new wr;async function yr(){let e=Date.now();ee.name("create-better-t-stack").description("Create a new Better-T Stack project").version(tt()).argument("[project-directory]","Project name/directory").option("-y, --yes","Use default configuration").option("--database <type>","Database type (none, sqlite, postgres)").option("--orm <type>","ORM type (none, drizzle, prisma)").option("--auth","Include authentication").option("--no-auth","Exclude authentication").option("--frontend <types...>","Frontend types (web, native, none)").option("--addons <types...>","Additional addons (pwa, tauri, biome, husky)").option("--no-addons","Skip all additional addons").option("--examples <types...>","Examples to include (todo, ai)").option("--no-examples","Skip all examples").option("--git","Initialize git repository").option("--no-git","Skip git initialization").option("--package-manager <pm>","Package manager (npm, pnpm, bun)").option("--install","Install dependencies").option("--no-install","Skip installing dependencies").option("--turso","Set up Turso for SQLite database").option("--no-turso","Skip Turso setup").option("--backend <framework>","Backend framework (hono, elysia)").option("--runtime <runtime>","Runtime (bun, node)").parse();let a=br();try{ot(),hr(u.magenta("Creating a new Better-T-Stack project"));let t=ee.opts(),r=ee.args[0];Pr(t);let n=jr(t,r);!t.yes&&Object.keys(n).length>0&&(E.info(u.yellow("Using these pre-selected options:")),E.message(Z(n)),E.message(""));let o=t.yes?{...m,projectName:r??m.projectName,...n}:await Ze(n);t.yes&&(E.info(u.yellow("Using these default options:")),E.message(Z(o)),E.message("")),await Re(o),E.success(u.blue(`You can reproduce this setup with the following command:
|
|
199
|
+
${u.white(et(o))}`));let i=((Date.now()-e)/1e3).toFixed(2);gr(u.magenta(`Project created successfully in ${u.bold(i)} seconds!`))}catch(t){a.stop(u.red("Failed")),t instanceof Error&&(j(u.red(`An unexpected error occurred: ${t.message}`)),process.exit(1))}}function Pr(e){if(e.database&&!["none","sqlite","postgres"].includes(e.database)&&(j(u.red(`Invalid database type: ${e.database}. Must be none, sqlite, or postgres.`)),process.exit(1)),e.orm&&!["none","drizzle","prisma"].includes(e.orm)&&(j(u.red(`Invalid ORM type: ${e.orm}. Must be none, drizzle, or prisma.`)),process.exit(1)),e.database==="none"&&(e.auth===!0&&(j(u.red("Authentication requires a database. Cannot use --auth with --database none.")),process.exit(1)),e.orm&&e.orm!=="none"&&(j(u.red(`Cannot use ORM with no database. Cannot use --orm ${e.orm} with --database none.`)),process.exit(1)),"turso"in e&&e.turso===!0&&(j(u.red("Turso setup requires a SQLite database. Cannot use --turso with --database none.")),process.exit(1))),"turso"in e&&e.turso===!0&&e.database&&e.database!=="sqlite"&&(j(u.red(`Turso setup requires a SQLite database. Cannot use --turso with --database ${e.database}`)),process.exit(1)),"turso"in e&&e.turso===!0&&e.orm==="prisma"&&(j(u.red("Turso setup is not compatible with Prisma. Cannot use --turso with --orm prisma")),process.exit(1)),e.packageManager&&!["npm","pnpm","bun"].includes(e.packageManager)&&(j(u.red(`Invalid package manager: ${e.packageManager}. Must be npm, pnpm, or bun.`)),process.exit(1)),e.backend&&!["hono","elysia"].includes(e.backend)&&(j(u.red(`Invalid backend framework: ${e.backend}. Must be hono or elysia.`)),process.exit(1)),e.runtime&&!["bun","node"].includes(e.runtime)&&(j(u.red(`Invalid runtime: ${e.runtime}. Must be bun or node.`)),process.exit(1)),e.examples&&Array.isArray(e.examples)&&e.examples.length>0){let a=["todo","ai"],t=e.examples.filter(r=>!a.includes(r));t.length>0&&(j(u.red(`Invalid example(s): ${t.join(", ")}. Valid options are: ${a.join(", ")}.`)),process.exit(1)),e.examples.includes("ai")&&e.backend==="elysia"&&(j(u.red("AI example is only compatible with Hono backend. Cannot use --examples ai with --backend elysia")),process.exit(1)),e.frontend&&!e.frontend.includes("web")&&!e.frontend.includes("none")&&(j(u.red("Examples require a web frontend. Cannot use --examples with --frontend native only")),process.exit(1))}if(e.frontend&&e.frontend.length>0){let a=["web","native","none"],t=e.frontend.filter(r=>!a.includes(r));t.length>0&&(j(u.red(`Invalid frontend(s): ${t.join(", ")}. Valid options are: ${a.join(", ")}.`)),process.exit(1)),e.frontend.includes("none")&&e.frontend.length>1&&(j(u.red("Cannot combine 'none' with other frontend options.")),process.exit(1))}if(e.addons&&e.addons.length>0){let a=["pwa","tauri","biome","husky"],t=e.addons.filter(o=>!a.includes(o));t.length>0&&(j(u.red(`Invalid addon(s): ${t.join(", ")}. Valid options are: ${a.join(", ")}.`)),process.exit(1));let r=["pwa","tauri"];e.addons.some(o=>r.includes(o))&&e.frontend&&!e.frontend.includes("web")&&!e.frontend.includes("none")&&(j(u.red(`PWA and Tauri addons require a web frontend. Cannot use --addons ${e.addons.filter(o=>r.includes(o)).join(", ")} with --frontend native only`)),process.exit(1))}}function jr(e,a){let t;e.frontend&&(e.frontend.includes("none")?t=[]:t=e.frontend.filter(g=>g==="web"||g==="native"));let r=e.database,n;e.orm&&(n=e.orm);let o="auth"in e?e.auth:void 0,i="turso"in e?e.turso:void 0;r==="none"&&(n="none",o=!1,i=!1);let s;"examples"in e&&(e.examples===!1?s=[]:Array.isArray(e.examples)&&(s=e.examples.filter(g=>g==="todo"||g==="ai"),t&&t.length>0&&!t.includes("web")&&(s=[],E.warn(u.yellow("Examples require web frontend - ignoring examples flag"))),s.includes("ai")&&e.backend==="elysia"&&(s=s.filter(g=>g!=="ai"),E.warn(u.yellow("AI example is not compatible with Elysia - removing AI example")))));let c;"addons"in e&&(e.addons===void 0?c=[]:e.addons&&(c=e.addons.filter(g=>g==="pwa"||g==="tauri"||g==="biome"||g==="husky"),t&&t.length>0&&!t.includes("web")&&(c=c.filter(g=>!["pwa","tauri"].includes(g)),c.length!==e.addons.length&&E.warn(u.yellow("PWA and Tauri addons require web frontend - removing these addons"))),c.includes("husky")&&!c.includes("biome")&&c.push("biome")));let w=e.backend,P=e.runtime,v=e.packageManager;return{...a&&{projectName:a},...r!==void 0&&{database:r},...n!==void 0&&{orm:n},...o!==void 0&&{auth:o},...v&&{packageManager:v},..."git"in e&&{git:e.git},..."install"in e&&{noInstall:!e.install},...i!==void 0&&{turso:i},...w&&{backend:w},...P&&{runtime:P},...t!==void 0&&{frontend:t},...c!==void 0&&{addons:c},...s!==void 0&&{examples:s}}}yr().catch(e=>{E.error("Aborting installation..."),e instanceof Error?E.error(e.message):(E.error("An unknown error has occurred. Please open an issue on GitHub with the below:"),console.log(e)),process.exit(1)});
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
export const NAV_THEME = {
|
|
2
2
|
light: {
|
|
3
|
-
background: "hsl(0 0% 100%)",
|
|
4
|
-
border: "hsl(240 5.9% 90%)",
|
|
5
|
-
card: "hsl(0 0% 100%)",
|
|
6
|
-
notification: "hsl(0 84.2% 60.2%)",
|
|
7
|
-
primary: "hsl(240 5.9% 10%)",
|
|
8
|
-
text: "hsl(240 10% 3.9%)",
|
|
3
|
+
background: "hsl(0 0% 100%)",
|
|
4
|
+
border: "hsl(240 5.9% 90%)",
|
|
5
|
+
card: "hsl(0 0% 100%)",
|
|
6
|
+
notification: "hsl(0 84.2% 60.2%)",
|
|
7
|
+
primary: "hsl(240 5.9% 10%)",
|
|
8
|
+
text: "hsl(240 10% 3.9%)",
|
|
9
9
|
},
|
|
10
10
|
dark: {
|
|
11
|
-
background: "hsl(240 10% 3.9%)",
|
|
12
|
-
border: "hsl(240 3.7% 15.9%)",
|
|
13
|
-
card: "hsl(240 10% 3.9%)",
|
|
14
|
-
notification: "hsl(0 72% 51%)",
|
|
15
|
-
primary: "hsl(0 0% 98%)",
|
|
16
|
-
text: "hsl(0 0% 98%)",
|
|
11
|
+
background: "hsl(240 10% 3.9%)",
|
|
12
|
+
border: "hsl(240 3.7% 15.9%)",
|
|
13
|
+
card: "hsl(240 10% 3.9%)",
|
|
14
|
+
notification: "hsl(0 72% 51%)",
|
|
15
|
+
primary: "hsl(0 0% 98%)",
|
|
16
|
+
text: "hsl(0 0% 98%)",
|
|
17
17
|
},
|
|
18
18
|
};
|
|
@@ -19,9 +19,8 @@ const app = new Elysia()
|
|
|
19
19
|
const { request } = context;
|
|
20
20
|
if (["POST", "GET"].includes(request.method)) {
|
|
21
21
|
return auth.handler(request);
|
|
22
|
-
} else {
|
|
23
|
-
context.error(405);
|
|
24
22
|
}
|
|
23
|
+
context.error(405);
|
|
25
24
|
})
|
|
26
25
|
.all("/trpc/*", async (context) => {
|
|
27
26
|
const res = await fetchRequestHandler({
|
|
@@ -34,5 +33,5 @@ const app = new Elysia()
|
|
|
34
33
|
})
|
|
35
34
|
.get("/", () => "OK")
|
|
36
35
|
.listen(3000, () => {
|
|
37
|
-
console.log(
|
|
36
|
+
console.log("Server is running on http://localhost:3000");
|
|
38
37
|
});
|