create-better-t-stack 1.3.3 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +69 -37
- package/package.json +2 -2
- package/template/base/apps/native/metro.config.js +1 -1
- package/template/base/apps/web/src/routes/__root.tsx +5 -3
- package/template/examples/ai/apps/web/src/routes/ai.tsx +69 -0
- package/template/with-auth/apps/web/src/components/sign-in-form.tsx +1 -1
- package/template/with-auth/apps/web/src/components/sign-up-form.tsx +1 -1
- package/template/with-auth/apps/web/src/routes/login.tsx +10 -3
- package/template/with-drizzle-sqlite/apps/server/src/db/index.ts +6 -6
- package/template/with-auth/apps/web/src/components/auth-forms.tsx +0 -13
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{cancel as
|
|
2
|
+
import{cancel as S,intro as go,log as C,outro as bo,spinner as wo}from"@clack/prompts";import{Command as yo}from"commander";import v from"picocolors";import te from"node:path";import{fileURLToPath as ct}from"node:url";var M=()=>{let e=process.env.npm_config_user_agent;return e?.startsWith("pnpm")?"pnpm":e?.startsWith("bun")?"bun":"npm"};var pt=ct(import.meta.url),lt=te.dirname(pt),P=te.join(lt,"../"),m={projectName:"my-better-t-app",frontend:["web"],database:"sqlite",orm:"drizzle",auth:!0,addons:[],examples:[],git:!0,packageManager:M(),noInstall:!1,turso:!1,backend:"hono",runtime:"bun"},K={"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 sa from"node:path";import{cancel as ca,spinner as pa}from"@clack/prompts";import la from"fs-extra";import Ae from"picocolors";import F from"node:path";import j from"fs-extra";import dt from"node:path";import ae from"fs-extra";var g=e=>{let{dependencies:a=[],devDependencies:t=[],projectDir:o}=e,r=dt.join(o,"package.json"),n=ae.readJSONSync(r);n.dependencies||(n.dependencies={}),n.devDependencies||(n.devDependencies={});for(let i of a){let s=K[i];n.dependencies[i]=s}for(let i of t){let s=K[i];n.devDependencies[i]=s}ae.writeJSONSync(r,n,{spaces:2})};import G from"node:path";import{log as ut,spinner as mt}from"@clack/prompts";import{execa as ft}from"execa";import J from"fs-extra";import oe from"picocolors";async function re(e,a){let t=mt(),o=G.join(e,"apps/web");if(await J.pathExists(o))try{t.start("Setting up Tauri desktop app support..."),g({devDependencies:["@tauri-apps/cli"],projectDir:o});let r=G.join(o,"package.json");if(await J.pathExists(r)){let s=await J.readJson(r);s.scripts={...s.scripts,tauri:"tauri","desktop:dev":"tauri dev","desktop:build":"tauri build"},await J.writeJson(r,s,{spaces:2})}let n,i;switch(a){case"npm":n="npx",i=["@tauri-apps/cli@latest"];break;case"pnpm":n="pnpm",i=["dlx","@tauri-apps/cli@latest"];break;case"bun":n="bunx",i=["@tauri-apps/cli@latest"];break;default:n="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(n,i,{cwd:o,env:{CI:"true"}}),t.stop("Tauri desktop app support configured successfully!")}catch(r){throw t.stop(oe.red("Failed to set up Tauri")),r instanceof Error&&ut.error(oe.red(r.message)),r}}async function ne(e,a,t,o){let r=o.includes("web");a.includes("pwa")&&r&&await bt(e),a.includes("tauri")&&r&&await re(e,t),a.includes("biome")&&await ht(e),a.includes("husky")&&await gt(e)}async function ht(e){let a=F.join(P,"template/with-biome");await j.pathExists(a)&&await j.copy(a,e,{overwrite:!0}),g({devDependencies:["@biomejs/biome"],projectDir:e});let t=F.join(e,"package.json");if(await j.pathExists(t)){let o=await j.readJson(t);o.scripts={...o.scripts,check:"biome check --write ."},await j.writeJson(t,o,{spaces:2})}}async function gt(e){let a=F.join(P,"template/with-husky");await j.pathExists(a)&&await j.copy(a,e,{overwrite:!0}),g({devDependencies:["husky","lint-staged"],projectDir:e});let t=F.join(e,"package.json");if(await j.pathExists(t)){let o=await j.readJson(t);o.scripts={...o.scripts,prepare:"husky"},o["lint-staged"]={"*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json,jsonc}":["biome check --write ."]},await j.writeJson(t,o,{spaces:2})}}async function bt(e){let a=F.join(P,"template/with-pwa");await j.pathExists(a)&&await j.copy(a,e,{overwrite:!0});let t=F.join(e,"apps/web");if(!await j.pathExists(t))return;g({dependencies:["vite-plugin-pwa"],devDependencies:["@vite-pwa/assets-generator"],projectDir:t});let o=F.join(t,"package.json");if(await j.pathExists(o)){let r=await j.readJson(o);r.scripts={...r.scripts,"generate-pwa-assets":"pwa-assets-generator"},await j.writeJson(o,r,{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="",o=a.length;for(let r=0;r<e;r++)t+=a.charAt(Math.floor(Math.random()*o));return t}async function le(e,a){if(!a)return;let t=ie.join(e,"apps/server"),o=ie.join(e,"apps/web");try{g({dependencies:["better-auth"],projectDir:t}),g({dependencies:["better-auth"],projectDir:o})}catch(r){throw se.error(ce.red("Failed to configure authentication")),r instanceof Error&&se.error(ce.red(r.message)),r}}import wt from"node:path";async function de(e,a,t){let o=wt.join(e,"apps/server"),r=[],n=[];a==="hono"?(r.push("hono","@hono/trpc-server"),t==="node"&&(r.push("@hono/node-server"),n.push("tsx","@types/node"))):a==="elysia"&&(r.push("elysia","@elysiajs/cors","@elysiajs/trpc"),t==="node"&&(r.push("@elysiajs/node"),n.push("tsx","@types/node"))),t==="bun"&&n.push("@types/bun"),g({dependencies:r,devDependencies:n,projectDir:o})}import yt from"node:path";import Pt from"fs-extra";async function ue(e,a){let t=yt.join(e,"README.md"),o=jt(a);try{await Pt.writeFile(t,o)}catch(r){console.error("Failed to create README.md file:",r)}}function jt(e){let{projectName:a,packageManager:t,database:o,auth:r,addons:n=[],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
|
-
${
|
|
8
|
+
${vt(o,r,n,i,s)}
|
|
9
9
|
|
|
10
10
|
## Getting Started
|
|
11
11
|
|
|
@@ -15,12 +15,12 @@ First, install the dependencies:
|
|
|
15
15
|
${t} install
|
|
16
16
|
\`\`\`
|
|
17
17
|
|
|
18
|
-
${kt(o,r,
|
|
18
|
+
${kt(o,r,c,i)}
|
|
19
19
|
|
|
20
20
|
Then, run the development server:
|
|
21
21
|
|
|
22
22
|
\`\`\`bash
|
|
23
|
-
${
|
|
23
|
+
${c} dev
|
|
24
24
|
\`\`\`
|
|
25
25
|
|
|
26
26
|
Open [http://localhost:3001](http://localhost:3001) in your browser to see the web application.
|
|
@@ -37,8 +37,8 @@ ${a}/
|
|
|
37
37
|
|
|
38
38
|
## Available Scripts
|
|
39
39
|
|
|
40
|
-
${
|
|
41
|
-
`}function
|
|
40
|
+
${xt(c,o,i,r)}
|
|
41
|
+
`}function vt(e,a,t,o,r){let n=["- **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",`- **${r==="bun"?"Bun":"Node.js"}** - Runtime environment`];e!=="none"&&n.push(`- **${o==="drizzle"?"Drizzle":"Prisma"}** - TypeScript-first ORM`,`- **${e==="sqlite"?"SQLite/Turso":"PostgreSQL"}** - Database engine`),a&&n.push("- **Authentication** - Email & password authentication with Better Auth");for(let i of t)i==="pwa"?n.push("- **PWA** - Progressive Web App support"):i==="tauri"?n.push("- **Tauri** - Build native desktop applications"):i==="biome"?n.push("- **Biome** - Linting and formatting"):i==="husky"&&n.push("- **Husky** - Git hooks for code quality");return n.join(`
|
|
42
42
|
`)}function kt(e,a,t,o){if(e==="none")return"";let r=`## Database Setup
|
|
43
43
|
|
|
44
44
|
`;return e==="sqlite"?r+=`This project uses SQLite${o==="drizzle"?" with Drizzle ORM":" with Prisma"}.
|
|
@@ -61,17 +61,17 @@ ${t} db:push
|
|
|
61
61
|
\`\`\`bash
|
|
62
62
|
${t} db:push
|
|
63
63
|
\`\`\``}
|
|
64
|
-
`,r}function
|
|
64
|
+
`,r}function xt(e,a,t,o){let r=`- \`${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
68
|
- \`${e} check-types\`: Check TypeScript types across all apps`;return a!=="none"&&(r+=`
|
|
69
69
|
- \`${e} db:push\`: Push schema changes to database
|
|
70
70
|
- \`${e} db:studio\`: Open database studio UI`,a==="sqlite"&&t==="drizzle"&&(r+=`
|
|
71
|
-
- \`cd apps/server && ${e} db:local\`: Start the local SQLite database`)),r}import he from"node:path";import{log as
|
|
72
|
-
`);return a.length<=1?[]:a.slice(1).map(o=>{let[r,n,i,s]=o.trim().split(/\s{2,}/);return{name:r,locations:n,version:i,status:s}})}catch(e){return console.error("Error fetching Turso groups:",e),[]}}async function
|
|
71
|
+
- \`cd apps/server && ${e} db:local\`: Start the local SQLite database`)),r}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 Et from"node:os";import me from"node:path";import{cancel as Q,confirm as Tt,isCancel as X,log as L,select as $t,spinner as Y,text as Ct}from"@clack/prompts";import{$}from"execa";import Ot from"fs-extra";import T from"picocolors";async function At(){try{return(await $`turso --version`).exitCode===0}catch{return!1}}async function It(){try{return!(await $`turso auth whoami`).stdout.includes("You are not logged in")}catch{return!1}}async function Dt(){let e=Y();try{return e.start("Logging in to Turso..."),await $`turso auth login`,e.stop("Logged in to Turso successfully!"),!0}catch(a){throw e.stop(T.red("Failed to log in to Turso")),a}}async function Ft(e){let a=Y();try{if(a.start("Installing Turso CLI..."),e)await $`brew install tursodatabase/tap/turso`;else{let{stdout:t}=await $`curl -sSfL https://get.tur.so/install.sh`;await $`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(T.yellow("Turso CLI installation cancelled by user")),new Error("Installation cancelled")):(a.stop(T.red("Failed to install Turso CLI")),t)}}async function Rt(){try{let{stdout:e}=await $`turso group list`,a=e.trim().split(`
|
|
72
|
+
`);return a.length<=1?[]:a.slice(1).map(o=>{let[r,n,i,s]=o.trim().split(/\s{2,}/);return{name:r,locations:n,version:i,status:s}})}catch(e){return console.error("Error fetching Turso groups:",e),[]}}async function St(){let e=await Rt();if(e.length===0)return null;if(e.length===1)return e[0].name;let a=e.map(o=>({value:o.name,label:`${o.name} (${o.locations})`})),t=await $t({message:"Select a Turso database group:",options:a});return X(t)&&(Q(T.red("Operation cancelled")),process.exit(0)),t}async function Lt(e,a){try{a?await $`turso db create ${e} --group ${a}`:await $`turso db create ${e}`}catch(r){throw r instanceof Error&&r.message.includes("already exists")?new Error("DATABASE_EXISTS"):r}let{stdout:t}=await $`turso db show ${e} --url`,{stdout:o}=await $`turso db tokens create ${e}`;return{dbUrl:t.trim(),authToken:o.trim()}}async function B(e,a){let t=me.join(e,"apps/server",".env"),o=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 Ot.writeFile(t,o)}function V(){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,56 +79,88 @@ TURSO_AUTH_TOKEN=`;await $t.writeFile(t,o)}function J(){I.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
|
|
82
|
+
TURSO_AUTH_TOKEN=your_auth_token`)}async function fe(e,a){if(!a){await B(e),L.info(T.blue("Skipping Turso setup. Setting up empty configuration.")),V();return}let t=Et.platform(),o=t==="darwin";if(!(t!=="win32")){L.warn(T.yellow("Automatic Turso setup is not supported on Windows.")),await B(e),V();return}try{if(!await At()){let k=await Tt({message:"Would you like to install Turso CLI?",initialValue:!0});if(X(k)&&(Q(T.red("Operation cancelled")),process.exit(0)),!k){await B(e),V();return}await Ft(o)}await It()||await Dt();let s=await St(),c=!1,b="",w=me.basename(e);for(;!c;){let k=await Ct({message:"Enter a name for your database:",defaultValue:w,initialValue:w,placeholder:w});X(k)&&(Q(T.red("Operation cancelled")),process.exit(0)),b=k;let O=Y();try{O.start(`Creating Turso database "${b}"${s?` in group "${s}"`:""}...`);let E=await Lt(b,s);await B(e,E),O.stop("Turso database configured successfully!"),c=!0}catch(E){if(E instanceof Error&&E.message==="DATABASE_EXISTS")O.stop(T.yellow(`Database "${T.red(b)}" already exists`)),w=`${b}-${Math.floor(Math.random()*1e3)}`;else throw O.stop(T.red("Failed to create Turso database")),E}}}catch(n){L.error(T.red(`Error during Turso setup: ${n}`)),await B(e),V(),L.success("Setup completed with manual configuration required.")}}async function be(e,a,t,o=!0){let r=_t(),n=he.join(e,"apps/server");if(a==="none"){await Bt.remove(he.join(n,"src/db"));return}try{a==="sqlite"?(t==="drizzle"?g({dependencies:["drizzle-orm","@libsql/client"],devDependencies:["drizzle-kit"],projectDir:n}):t==="prisma"&&g({dependencies:["@prisma/client"],devDependencies:["prisma"],projectDir:n}),o&&await fe(e,!0)):a==="postgres"&&(t==="drizzle"?g({dependencies:["drizzle-orm","postgres"],devDependencies:["drizzle-kit"],projectDir:n}):t==="prisma"&&g({dependencies:["@prisma/client"],devDependencies:["prisma"],projectDir:n}))}catch(i){throw r.stop(ge.red("Failed to set up database")),i instanceof Error&&Nt.error(ge.red(i.message)),i}}import N from"node:path";import A from"fs-extra";async function we(e,a){let t=N.join(e,"apps/server"),o=N.join(t,".env"),r="";if(await A.pathExists(o)&&(r=await A.readFile(o,"utf8")),r.includes("CORS_ORIGIN")||(r+=`
|
|
83
83
|
CORS_ORIGIN=http://localhost:3001`),a.auth&&(r.includes("BETTER_AUTH_SECRET")||(r+=`
|
|
84
84
|
BETTER_AUTH_SECRET=${pe()}`),r.includes("BETTER_AUTH_URL")||(r+=`
|
|
85
85
|
BETTER_AUTH_URL=http://localhost:3000`)),a.database!=="none"){if(a.orm==="prisma"&&!r.includes("DATABASE_URL")){let n=a.database==="sqlite"?"":`
|
|
86
86
|
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/mydb?schema=public"`;r+=n}a.database==="sqlite"&&!a.turso&&(r.includes("TURSO_CONNECTION_URL")||(r+=`
|
|
87
|
-
TURSO_CONNECTION_URL=http://127.0.0.1:8080`))}if(
|
|
88
|
-
|
|
89
|
-
`),await
|
|
87
|
+
TURSO_CONNECTION_URL=http://127.0.0.1:8080`))}if(a.examples?.includes("ai")&&!r.includes("GOOGLE_GENERATIVE_AI_API_KEY")&&(r+=`
|
|
88
|
+
GOOGLE_GENERATIVE_AI_API_KEY=`),await A.writeFile(o,r.trim()),a.frontend.includes("web")){let n=N.join(e,"apps/web"),i=N.join(n,".env"),s="";await A.pathExists(i)&&(s=await A.readFile(i,"utf8")),s.includes("VITE_SERVER_URL")||(s+=`VITE_SERVER_URL=http://localhost:3000
|
|
89
|
+
`),await A.writeFile(i,s.trim())}if(a.frontend.includes("native")){let n=N.join(e,"apps/native"),i=N.join(n,".env"),s="";await A.pathExists(i)&&(s=await A.readFile(i,"utf8")),s.includes("EXPO_PUBLIC_SERVER_URL")||(s+=`EXPO_PUBLIC_SERVER_URL=http://localhost:3000
|
|
90
|
+
`),await A.writeFile(i,s.trim())}}import y from"node:path";import f from"fs-extra";async function ye(e,a,t,o,r,n=["web"]){console.log("EXAMPLEs:",a);let i=n.includes("web"),s=await f.pathExists(y.join(e,"apps/web"));a.includes("todo")&&i&&s?await Gt(e,t,o):await Vt(e,t),a.includes("ai")&&r==="hono"&&i&&s&&await zt(e)}async function zt(e){let a=y.join(P,"template/examples/ai");if(await f.pathExists(a)){await f.copy(a,e),await Mt(e);let t=y.join(e,"apps/web");g({dependencies:["ai"],projectDir:t});let o=y.join(e,"apps/server");g({dependencies:["ai","@ai-sdk/google"],projectDir:o}),await Ut(e)}}async function Ut(e){let a=y.join(e,"apps/server/src/index.ts");if(await f.pathExists(a)){let t=await f.readFile(a,"utf8");if(t.includes("hono")){let r=`import { streamText } from "ai";
|
|
91
|
+
import { google } from "@ai-sdk/google";
|
|
92
|
+
import { stream } from "hono/streaming";`,n=`
|
|
93
|
+
app.post("/ai", async (c) => {
|
|
94
|
+
const body = await c.req.json();
|
|
95
|
+
const messages = body.messages || [];
|
|
96
|
+
|
|
97
|
+
const result = streamText({
|
|
98
|
+
model: google("gemini-2.0-flash-exp"),
|
|
99
|
+
messages,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
c.header("X-Vercel-AI-Data-Stream", "v1");
|
|
103
|
+
c.header("Content-Type", "text/plain; charset=utf-8");
|
|
104
|
+
|
|
105
|
+
return stream(c, (stream) => stream.pipe(result.toDataStream()));
|
|
106
|
+
});`;if(t.includes("import {")){let s=t.lastIndexOf("import"),c=t.indexOf(`
|
|
107
|
+
`,s);t=`${t.substring(0,c+1)}
|
|
108
|
+
${r}
|
|
109
|
+
${t.substring(c+1)}`}else t=`${r}
|
|
110
|
+
|
|
111
|
+
${t}`;let i=t.indexOf('app.use("/trpc"')||t.indexOf("app.use(trpc(");if(i!==-1)t=`${t.substring(0,i)}${n}
|
|
112
|
+
|
|
113
|
+
${t.substring(i)}`;else{let s=t.indexOf("export default");s!==-1?t=`${t.substring(0,s)}${n}
|
|
114
|
+
|
|
115
|
+
${t.substring(s)}`:t=`${t}
|
|
116
|
+
|
|
117
|
+
${n}`}await f.writeFile(a,t)}}}async function Mt(e){let a=y.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
|
+
{ to: "/ai", label: "AI Chat" },`):t.includes('{ to: "/dashboard"')?t=t.replace(/{ to: "\/dashboard", label: "Dashboard" },/,`{ to: "/dashboard", label: "Dashboard" },
|
|
119
|
+
{ to: "/ai", label: "AI Chat" },`):t=t.replace(/const links = \[\s*{ to: "\/", label: "Home" },/,`const links = [
|
|
120
|
+
{ to: "/", label: "Home" },
|
|
121
|
+
{ to: "/ai", label: "AI Chat" },`),await f.writeFile(a,t)}}async function Gt(e,a,t){let o=y.join(P,"template/examples/todo");if(await f.pathExists(o)){let r=y.join(o,"apps/web/src/routes"),n=y.join(e,"apps/web/src/routes");if(await f.copy(r,n,{overwrite:!0}),a!=="none"){let i=y.join(o,`apps/server/src/routers/with-${a}-todo.ts`),s=y.join(e,"apps/server/src/routers/todo.ts");await f.pathExists(i)&&await f.copy(i,s,{overwrite:!0})}await Jt(e,t),await Wt(e)}}async function Jt(e,a){let t=y.join(e,"apps/web/src/components/header.tsx");if(await f.pathExists(t)){let o=await f.readFile(t,"utf8");a?o=o.replace(/const links = \[\s*{ to: "\/", label: "Home" },\s*{ to: "\/dashboard", label: "Dashboard" },/,`const links = [
|
|
90
122
|
{ to: "/", label: "Home" },
|
|
91
123
|
{ to: "/dashboard", label: "Dashboard" },
|
|
92
124
|
{ to: "/todos", label: "Todos" },`):o=o.replace(/const links = \[\s*{ to: "\/", label: "Home" },/,`const links = [
|
|
93
125
|
{ to: "/", label: "Home" },
|
|
94
|
-
{ to: "/todos", label: "Todos" },`),await
|
|
126
|
+
{ to: "/todos", label: "Todos" },`),await f.writeFile(t,o)}}async function Vt(e,a){if(a==="drizzle"){let o=y.join(e,"apps/server/src/db/schema/todo.ts");await f.pathExists(o)&&await f.remove(o)}else if(a==="prisma"){let o=y.join(e,"apps/server/prisma/schema/todo.prisma");await f.pathExists(o)&&await f.remove(o)}let t=y.join(e,"apps/server/src/routers/todo.ts");await f.pathExists(t)&&await f.remove(t),await qt(e)}async function qt(e){let a=y.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=y.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">
|
|
95
127
|
<Button asChild>
|
|
96
128
|
<Link to="/todos" className="flex items-center">
|
|
97
129
|
View Todo Demo
|
|
98
130
|
<ArrowRight className="ml-1 h-4 w-4" />
|
|
99
131
|
</Link>
|
|
100
132
|
</Button>
|
|
101
|
-
</div>`),await
|
|
102
|
-
${d.cyan("1.")} ${
|
|
133
|
+
</div>`),await f.writeFile(a,t)}}import{log as Ht}from"@clack/prompts";import d from"picocolors";function Pe(e,a,t,o,r,n,i,s){let c=t==="npm"?"npm run":t,b=`cd ${a}`,w=n?.includes("husky")||n?.includes("biome"),k=e!=="none"?Xt(e,r,c,i):"",O=n?.includes("tauri")?Yt(c):"",E=w?Qt(c):"",U=s?.includes("native")?Kt():"",_=s?.includes("web"),it=s?.includes("native"),st=_||it;Ht.info(`${d.bold("Next steps:")}
|
|
134
|
+
${d.cyan("1.")} ${b}
|
|
103
135
|
${o?"":`${d.cyan("2.")} ${t} install
|
|
104
|
-
`}${d.cyan(o?"2.":"3.")} ${
|
|
136
|
+
`}${d.cyan(o?"2.":"3.")} ${c} dev
|
|
105
137
|
|
|
106
138
|
${d.bold("Your project will be available at:")}
|
|
107
|
-
${
|
|
139
|
+
${st?`${_?`${d.cyan("\u2022")} Frontend: http://localhost:3001
|
|
108
140
|
`:""}`:`${d.yellow("NOTE:")} You are creating a backend-only app (no frontend selected)
|
|
109
141
|
`}${d.cyan("\u2022")} API: http://localhost:3000
|
|
110
|
-
${
|
|
111
|
-
${
|
|
112
|
-
${k.trim()}`:""}${
|
|
113
|
-
${
|
|
114
|
-
${
|
|
142
|
+
${U?`
|
|
143
|
+
${U.trim()}`:""}${k?`
|
|
144
|
+
${k.trim()}`:""}${O?`
|
|
145
|
+
${O.trim()}`:""}${E?`
|
|
146
|
+
${E.trim()}`:""}`)}function Kt(){return`${d.yellow("NOTE:")} If the Expo app cannot connect to the server, update the EXPO_PUBLIC_SERVER_URL in apps/native/.env to use your local IP address instead of localhost:
|
|
115
147
|
${d.dim("EXPO_PUBLIC_SERVER_URL=http://192.168.0.103:3000")}
|
|
116
|
-
`}function
|
|
148
|
+
`}function Qt(e){return`${d.bold("Linting and formatting:")}
|
|
117
149
|
${d.cyan("\u2022")} Format and lint fix: ${d.dim(`${e} check`)}
|
|
118
150
|
|
|
119
|
-
`}function
|
|
151
|
+
`}function Xt(e,a,t,o){let r=[];return a==="prisma"?(e==="sqlite"&&r.push(`${d.yellow("NOTE:")} Turso support with Prisma is in Early Access and requires additional setup.`,`${d.dim("Learn more at: https://www.prisma.io/docs/orm/overview/databases/turso")}`),o==="bun"&&r.push(`${d.yellow("NOTE:")} Prisma with Bun may require additional configuration. If you encounter errors, follow the guidance provided in the error messages`),r.push(`${d.cyan("\u2022")} Apply schema: ${d.dim(`${t} db:push`)}`),r.push(`${d.cyan("\u2022")} Database UI: ${d.dim(`${t} db:studio`)}`)):a==="drizzle"&&(e==="sqlite"&&r.push(`${d.cyan("\u2022")} Start local DB: ${d.dim(`cd apps/server && ${t} db:local`)}`),r.push(`${d.cyan("\u2022")} Apply schema: ${d.dim(`${t} db:push`)}`),r.push(`${d.cyan("\u2022")} Database UI: ${d.dim(`${t} db:studio`)}`)),r.length?`${d.bold("Database commands:")}
|
|
120
152
|
${r.join(`
|
|
121
153
|
`)}
|
|
122
154
|
|
|
123
|
-
`:""}function
|
|
155
|
+
`:""}function Yt(e){return`${d.bold("Desktop app with Tauri:")}
|
|
124
156
|
${d.cyan("\u2022")} Start desktop app: ${d.dim(`cd apps/web && ${e} desktop:dev`)}
|
|
125
157
|
${d.cyan("\u2022")} Build desktop app: ${d.dim(`cd apps/web && ${e} desktop:build`)}
|
|
126
158
|
${d.yellow("NOTE:")} Tauri requires Rust and platform-specific dependencies. See: ${d.dim("https://v2.tauri.app/start/prerequisites/")}
|
|
127
159
|
|
|
128
|
-
`}import q from"node:path";import{$ as
|
|
160
|
+
`}import q from"node:path";import{$ as Zt,execa as ea}from"execa";import I from"fs-extra";async function je(e,a){await ta(e,a),await aa(e,a)}async function ta(e,a){let t=q.join(e,"package.json");if(await I.pathExists(t)){let o=await I.readJson(t);o.name=a.projectName;let{stdout:r}=await ea(a.packageManager,["-v"],{cwd:e});if(o.packageManager=`${a.packageManager}@${r.trim()}`,await I.writeJson(t,o,{spaces:2}),a.packageManager==="pnpm"){let n=q.join(P,"template/with-pnpm/pnpm-workspace.yaml"),i=q.join(e,"pnpm-workspace.yaml");await I.pathExists(n)&&await I.copy(n,i)}}}async function aa(e,a){let t=q.join(e,"apps/server/package.json");if(await I.pathExists(t)){let o=await I.readJson(t);a.database!=="none"&&(a.database==="sqlite"&&(o.scripts["db:local"]="turso dev --db-file local.db"),a.orm==="prisma"?(o.scripts["db:push"]="prisma db push --schema ./prisma/schema",o.scripts["db:studio"]="prisma studio"):a.orm==="drizzle"&&(o.scripts["db:push"]="drizzle-kit push",o.scripts["db:studio"]="drizzle-kit studio")),await I.writeJson(t,o,{spaces:2})}}async function ve(e,a){a&&await Zt({cwd:e})`git init`}import W from"node:path";import D from"fs-extra";async function ke(e,a,t){let o=W.join(e,"apps/server"),r=W.join(o,"src/index.ts"),n=await D.readFile(r,"utf-8");a==="bun"?await oa(o,r,n,t):a==="node"&&await ra(o,r,n,t)}async function oa(e,a,t,o){let r=W.join(e,"package.json"),n=await D.readJson(r);if(n.scripts={...n.scripts,dev:"bun run --hot src/index.ts",start:"bun run dist/src/index.js"},await D.writeJson(r,n,{spaces:2}),g({devDependencies:["@types/bun"],projectDir:e}),o==="hono"){let i=`${t}
|
|
129
161
|
|
|
130
162
|
export default app;
|
|
131
|
-
`;await D.writeFile(a,i)}}async function
|
|
163
|
+
`;await D.writeFile(a,i)}}async function ra(e,a,t,o){let r=W.join(e,"package.json"),n=await D.readJson(r);if(n.scripts={...n.scripts,dev:"tsx watch src/index.ts",start:"node dist/src/index.js"},await D.writeJson(r,n,{spaces:2}),g({devDependencies:["tsx","@types/node"],projectDir:e}),o==="hono"){g({dependencies:["@hono/node-server"],projectDir:e});let i=`import { serve } from "@hono/node-server";
|
|
132
164
|
`,s=`
|
|
133
165
|
serve(
|
|
134
166
|
{
|
|
@@ -139,11 +171,11 @@ serve(
|
|
|
139
171
|
console.log(\`Server is running on http://localhost:\${info.port}\`);
|
|
140
172
|
},
|
|
141
173
|
);
|
|
142
|
-
`;if(!t.includes("@hono/node-server")){let
|
|
174
|
+
`;if(!t.includes("@hono/node-server")){let c=t.lastIndexOf("import"),b=t.substring(0,c),w=t.substring(c),k=b+i+w+s;await D.writeFile(a,k)}}else if(o==="elysia"&&(g({dependencies:["@elysiajs/node"],projectDir:e}),!t.includes("@elysiajs/node"))){let i=`import { node } from "@elysiajs/node";
|
|
143
175
|
`,s=t.indexOf(`
|
|
144
|
-
`,t.indexOf("import")),
|
|
145
|
-
`);else{let t=m.join(e,"apps/native");await f.pathExists(t)&&await f.remove(t)}}async function Ee(e,a){let t=m.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=m.join(P,ea(a,t));if(await f.pathExists(r)&&(await f.copy(r,e,{overwrite:!0}),!o)){if(a==="prisma"){let n=m.join(e,"apps/server/prisma/schema/auth.prisma");await f.pathExists(n)&&await f.remove(n)}else if(a==="drizzle"){let n=m.join(e,"apps/server/src/db/schema/auth.ts");await f.pathExists(n)&&await f.remove(n)}}}async function Fe(e,a,t,o,r){if(!a)return;let n=m.join(P,"template/with-auth");if(await f.pathExists(n)){let i=m.join(n,"apps/web"),s=m.join(e,"apps/web");await f.copy(i,s,{overwrite:!0});let u=m.join(n,"apps/server/src"),h=m.join(e,"apps/server/src");await f.copy(m.join(u,"lib/trpc.ts"),m.join(h,"lib/trpc.ts"),{overwrite:!0}),await f.copy(m.join(u,"routers/index.ts"),m.join(h,"routers/index.ts"),{overwrite:!0});let b=`with-${t}-context.ts`;await f.copy(m.join(u,"lib",b),m.join(h,"lib/context.ts"),{overwrite:!0});let k=`with-${t}-index.ts`;await f.copy(m.join(u,k),m.join(h,"index.ts"),{overwrite:!0});let C=ta(o,r),j=m.join(u,C);if(await f.pathExists(j)){let z=await f.readdir(j);for(let N of z)await f.copy(m.join(j,N),m.join(h,"lib",N),{overwrite:!0})}}}async function Ce(e){let a=[m.join(e,"_gitignore"),m.join(e,"apps/web/_gitignore"),m.join(e,"apps/native/_gitignore"),m.join(e,"apps/server/_gitignore")];for(let t of a)if(await f.pathExists(t)){let o=m.join(m.dirname(t),".gitignore");await f.move(t,o)}}function ea(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 ta(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 Se(e){let a=ra(),t=aa.resolve(process.cwd(),e.projectName);try{return await na.ensureDir(t),await xe(t),await Te(t,e.frontend),await Ce(t),await Ee(t,e.backendFramework),await de(t,e.backendFramework,e.runtime),await $e(t,e.orm,e.database,e.auth),await ge(t,e.database,e.orm,e.turso??e.database==="sqlite"),await Fe(t,e.auth,e.backendFramework,e.orm,e.database),await le(t,e.auth),await je(t,e.runtime,e.backendFramework),await ye(t,e.examples,e.orm,e.auth,e.frontend),await be(t,e),await ve(t,e.git),e.addons.length>0&&await ne(t,e.addons,e.packageManager,e.frontend),await ke(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(Oe.red("Failed")),o instanceof Error&&(oa(Oe.red(`Error during project creation: ${o.message}`)),process.exit(1)),o}}import{log as De,spinner as Ae}from"@clack/prompts";import{$ as Y}from"execa";import W from"picocolors";async function Re({projectDir:e,packageManager:a,addons:t=[]}){let o=Ae();try{switch(o.start(`Running ${a} install...`),a){case"npm":await Y({cwd:e,stderr:"inherit"})`${a} install`;break;case"pnpm":case"bun":await Y({cwd:e})`${a} install`;break}o.stop("Dependencies installed successfully"),(t.includes("biome")||t.includes("husky"))&&await ia(e,a)}catch(r){throw o.stop(W.red("Failed to install dependencies")),r instanceof Error&&De.error(W.red(`Installation error: ${r.message}`)),r}}async function ia(e,a){let t=Ae();try{t.start("Running Biome format check..."),await Y({cwd:e})`${a} biome check --write .`,t.stop("Biome check completed successfully")}catch{t.stop(W.yellow("Biome check encountered issues")),De.warn(W.yellow("Some files may need manual formatting"))}}import{cancel as io,group as so}from"@clack/prompts";import co from"picocolors";import{cancel as sa,isCancel as ca,multiselect as pa}from"@clack/prompts";import la from"picocolors";async function Ie(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=c.addons.filter(u=>t||u!=="pwa"&&u!=="tauri"),s=await pa({message:"Which Addons would you like to add?",options:n,initialValues:i,required:!1});return ca(s)&&(sa(la.red("Operation cancelled")),process.exit(0)),s.includes("husky")&&!s.includes("biome")&&s.push("biome"),s}import{cancel as da,confirm as ua,isCancel as ma,log as fa}from"@clack/prompts";import Le from"picocolors";async function Ne(e,a,t){if(!a)return!1;let o=t?.includes("native"),r=t?.includes("web");if(o&&fa.warn(Le.yellow("Note: Authentication is not yet available with native")),!r)return!1;if(e!==void 0)return e;let n=await ua({message:"Would you like to add authentication with Better-Auth?",initialValue:c.auth});return ma(n)&&(da(Le.red("Operation cancelled")),process.exit(0)),n}import{cancel as ha,isCancel as wa,select as ga}from"@clack/prompts";import ba from"picocolors";async function _e(e){if(e!==void 0)return e;let a=await ga({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:c.backendFramework});return wa(a)&&(ha(ba.red("Operation cancelled")),process.exit(0)),a}import{cancel as ya,isCancel as Pa,select as ka}from"@clack/prompts";import va from"picocolors";async function Ue(e){if(e!==void 0)return e;let a=await ka({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:c.database});return Pa(a)&&(ya(va.red("Operation cancelled")),process.exit(0)),a}import{cancel as ja,isCancel as xa,multiselect as Ta}from"@clack/prompts";import Ea from"picocolors";async function ze(e,a,t){if(e!==void 0)return e;if(a==="none")return[];if(!t?.includes("web"))return[];let r=await Ta({message:"Which examples would you like to include?",options:[{value:"todo",label:"Todo App",hint:"A simple CRUD example app"}],required:!1,initialValues:c.examples});return xa(r)&&(ja(Ea.red("Operation cancelled")),process.exit(0)),r}import{cancel as $a,isCancel as Fa,multiselect as Ca}from"@clack/prompts";import Oa from"picocolors";async function Be(e){if(e!==void 0)return e;let a=await Ca({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:c.frontend,required:!1});return Fa(a)&&($a(Oa.red("Operation cancelled")),process.exit(0)),a}import{cancel as Sa,confirm as Da,isCancel as Aa}from"@clack/prompts";import Ra from"picocolors";async function Me(e){if(e!==void 0)return e;let a=await Da({message:"Initialize a new git repository?",initialValue:c.git});return Aa(a)&&(Sa(Ra.red("Operation cancelled")),process.exit(0)),a}import{cancel as Ia,confirm as La,isCancel as Na}from"@clack/prompts";import _a from"picocolors";async function Ge(e){if(e!==void 0)return e;let a=await La({message:"Do you want to install project dependencies?",initialValue:!c.noInstall});return Na(a)&&(Ia(_a.red("Operation cancelled")),process.exit(0)),!a}import{cancel as Ua,isCancel as za,select as Ba}from"@clack/prompts";import Ma from"picocolors";async function Je(e,a){if(!a)return"none";if(e!==void 0)return e;let t=await Ba({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:c.orm});return za(t)&&(Ua(Ma.red("Operation cancelled")),process.exit(0)),t}import{cancel as Ga,isCancel as Ja,select as qa}from"@clack/prompts";import Va from"picocolors";async function qe(e){if(e!==void 0)return e;let a=B(),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 Ja(t)&&(Ga(Va.red("Operation cancelled")),process.exit(0)),t}import U from"node:path";import{cancel as Wa,isCancel as Ha,text as Qa}from"@clack/prompts";import R from"fs-extra";import Ka from"picocolors";var Xa=["<",">",":",'"',"|","?","*"],Ve=255;function We(e){if(e!=="."){if(!e)return"Project name cannot be empty";if(e.length>Ve)return`Project name must be less than ${Ve} characters`;if(Xa.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 He(e){if(e)if(e==="."){let n=process.cwd();if(R.readdirSync(n).length===0)return e}else{let n=U.basename(e);if(!We(n)){let s=U.resolve(process.cwd(),e);if(!R.pathExistsSync(s)||R.readdirSync(s).length===0)return e}}let a=!1,t="",o=c.projectName,r=1;for(;R.pathExistsSync(U.resolve(process.cwd(),o));)o=`${c.projectName}-${r}`,r++;for(;!a;){let n=await Qa({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 u=U.resolve(process.cwd(),s),h=U.basename(u),b=We(h);if(b)return b;if(!u.startsWith(process.cwd()))return"Project path must be within current directory";if(R.pathExistsSync(u)&&R.readdirSync(u).length>0)return`Directory "${s}" already exists and is not empty. Please choose a different name or path.`;a=!0}});Ha(n)&&(Wa(Ka.red("Operation cancelled.")),process.exit(0)),t=n||o}return t}import{cancel as Ya,isCancel as Za,select as eo}from"@clack/prompts";import to from"picocolors";async function Qe(e){if(e!==void 0)return e;let a=await eo({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:c.runtime});return Za(a)&&(Ya(to.red("Operation cancelled")),process.exit(0)),a}import{cancel as ao,confirm as oo,isCancel as ro}from"@clack/prompts";import no from"picocolors";async function Ke(e){if(e!==void 0)return e;let a=await oo({message:"Set up a Turso database for this project?",initialValue:c.turso});return ro(a)&&(ao(no.red("Operation cancelled")),process.exit(0)),a}async function Xe(e){let a=await so({projectName:async()=>He(e.projectName),frontend:()=>Be(e.frontend),backendFramework:()=>_e(e.backendFramework),runtime:()=>Qe(e.runtime),database:()=>Ue(e.database),orm:({results:t})=>Je(e.orm,t.database!=="none"),auth:({results:t})=>Ne(e.auth,t.database!=="none",t.frontend),turso:({results:t})=>t.database==="sqlite"&&t.orm!=="prisma"?Ke(e.turso):Promise.resolve(!1),addons:({results:t})=>Ie(e.addons,t.frontend),examples:({results:t})=>ze(e.examples,t.database,t.frontend),git:()=>Me(e.git),packageManager:()=>qe(e.packageManager),noInstall:()=>Ge(e.noInstall)},{onCancel:()=>{io(co.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,backendFramework:a.backendFramework,runtime:a.runtime}}import v from"picocolors";function Z(e){let a=[];if(e.projectName&&a.push(`${v.blue("Project Name:")} ${e.projectName}`),e.frontend!==void 0){let t=e.frontend.length>0?e.frontend.join(", "):"none";a.push(`${v.blue("Frontend:")} ${t}`)}if(e.backendFramework!==void 0&&a.push(`${v.blue("Backend Framework:")} ${e.backendFramework}`),e.runtime!==void 0&&a.push(`${v.blue("Runtime:")} ${e.runtime}`),e.database!==void 0&&a.push(`${v.blue("Database:")} ${e.database}`),e.orm!==void 0&&a.push(`${v.blue("ORM:")} ${e.orm}`),e.auth!==void 0&&a.push(`${v.blue("Authentication:")} ${e.auth}`),e.addons!==void 0){let t=e.addons.length>0?e.addons.join(", "):"none";a.push(`${v.blue("Addons:")} ${t}`)}if(e.examples!==void 0){let t=e.examples.length>0?e.examples.join(", "):"none";a.push(`${v.blue("Examples:")} ${t}`)}return e.git!==void 0&&a.push(`${v.blue("Git Init:")} ${e.git}`),e.packageManager!==void 0&&a.push(`${v.blue("Package Manager:")} ${e.packageManager}`),e.noInstall!==void 0&&a.push(`${v.blue("Skip Install:")} ${e.noInstall}`),e.turso!==void 0&&a.push(`${v.blue("Turso Setup:")} ${e.turso}`),a.join(`
|
|
146
|
-
`)}function
|
|
176
|
+
`,t.indexOf("import")),c=t.substring(0,s+1),b=t.substring(s+1),w=c+i+b;w=w.replace(/const app = new Elysia\([^)]*\)/,"const app = new Elysia({ adapter: node() })"),await D.writeFile(a,w)}}import u from"node:path";import h from"fs-extra";async function xe(e){let a=u.join(P,"template/base");if(!await h.pathExists(a))throw new Error(`Template directory not found: ${a}`);await h.copy(a,e)}async function Ee(e,a){if(!a.includes("web")){let t=u.join(e,"apps/web");await h.pathExists(t)&&await h.remove(t)}if(a.includes("native"))await h.writeFile(u.join(e,".npmrc"),`node-linker=hoisted
|
|
177
|
+
`);else{let t=u.join(e,"apps/native");await h.pathExists(t)&&await h.remove(t)}}async function Te(e,a){let t=u.join(P,`template/with-${a}`);await h.pathExists(t)&&await h.copy(t,e,{overwrite:!0})}async function $e(e,a,t,o){if(a==="none"||t==="none")return;let r=u.join(P,na(a,t));if(await h.pathExists(r)&&(await h.copy(r,e,{overwrite:!0}),!o)){if(a==="prisma"){let n=u.join(e,"apps/server/prisma/schema/auth.prisma");await h.pathExists(n)&&await h.remove(n)}else if(a==="drizzle"){let n=u.join(e,"apps/server/src/db/schema/auth.ts");await h.pathExists(n)&&await h.remove(n)}}}async function Ce(e,a,t,o,r){if(!a)return;let n=u.join(P,"template/with-auth");if(await h.pathExists(n)){let i=u.join(n,"apps/web"),s=u.join(e,"apps/web");await h.copy(i,s,{overwrite:!0});let c=u.join(n,"apps/server/src"),b=u.join(e,"apps/server/src");await h.copy(u.join(c,"lib/trpc.ts"),u.join(b,"lib/trpc.ts"),{overwrite:!0}),await h.copy(u.join(c,"routers/index.ts"),u.join(b,"routers/index.ts"),{overwrite:!0});let w=`with-${t}-context.ts`;await h.copy(u.join(c,"lib",w),u.join(b,"lib/context.ts"),{overwrite:!0});let k=`with-${t}-index.ts`;await h.copy(u.join(c,k),u.join(b,"index.ts"),{overwrite:!0});let O=ia(o,r),E=u.join(c,O);if(await h.pathExists(E)){let U=await h.readdir(E);for(let _ of U)await h.copy(u.join(E,_),u.join(b,"lib",_),{overwrite:!0})}}}async function Oe(e){let a=[u.join(e,"_gitignore"),u.join(e,"apps/web/_gitignore"),u.join(e,"apps/native/_gitignore"),u.join(e,"apps/server/_gitignore")];for(let t of a)if(await h.pathExists(t)){let o=u.join(u.dirname(t),".gitignore");await h.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 Ie(e){let a=pa(),t=sa.resolve(process.cwd(),e.projectName);try{return await la.ensureDir(t),await xe(t),await Ee(t,e.frontend),await Oe(t),await Te(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(Ae.red("Failed")),o instanceof Error&&(ca(Ae.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=m.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:m.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:m.backend});return ja(a)&&(Pa(ka.red("Operation cancelled")),process.exit(0)),a}import{cancel as xa,isCancel as Ea,select as Ta}from"@clack/prompts";import $a from"picocolors";async function ze(e){if(e!==void 0)return e;let a=await Ta({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 Ea(a)&&(xa($a.red("Operation cancelled")),process.exit(0)),a}import{cancel as Ca,isCancel as Oa,multiselect as Ue}from"@clack/prompts";import Aa 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:m.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:m.examples})),Oa(n)&&(Ca(Aa.red("Operation cancelled")),process.exit(0)),n}import{cancel as Ia,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:m.frontend,required:!1});return Da(a)&&(Ia(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:m.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:!m.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:m.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=m.projectName,r=1;for(;R.pathExistsSync(z.resolve(process.cwd(),o));)o=`${m.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),b=z.basename(c),w=Ke(b);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:m.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:m.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(",")}`),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="",o=e.packageManager;o==="npm"?t="npm create better-t-stack@latest":o==="pnpm"?t="pnpm create better-t-stack@latest":o==="bun"&&(t="bun create better-t-stack@latest");let r=e.projectName?` ${e.projectName}`:"";return`${t}${r} ${a.join(" ")}`}import fo from"node:path";import ho from"fs-extra";var tt=()=>{let e=fo.join(P,"package.json");return ho.readJSONSync(e).version??"1.0.0"};import at from"gradient-string";var ot=`
|
|
147
179
|
\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
|
|
148
180
|
\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
|
|
149
181
|
\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
|
|
@@ -157,10 +189,10 @@ serve(
|
|
|
157
189
|
\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
|
|
158
190
|
\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
|
|
159
191
|
\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
|
|
160
|
-
`,
|
|
161
|
-
`),t=Math.max(...a.map(o=>o.length));e<t?console.log(
|
|
192
|
+
`,rt={pink:"#F5C2E7",mauve:"#CBA6F7",red:"#F38BA8",maroon:"#E78284",peach:"#FAB387",yellow:"#F9E2AF",green:"#A6E3A1",teal:"#94E2D5",sky:"#89DCEB",sapphire:"#74C7EC",lavender:"#B4BEFE"},nt=()=>{let e=process.stdout.columns||80,a=ot.split(`
|
|
193
|
+
`),t=Math.max(...a.map(o=>o.length));e<t?console.log(at(Object.values(rt)).multiline(`
|
|
162
194
|
\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557
|
|
163
195
|
\u2551 Better T-Stack \u2551
|
|
164
196
|
\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D
|
|
165
|
-
`)):console.log(
|
|
166
|
-
${
|
|
197
|
+
`)):console.log(at(Object.values(rt)).multiline(ot))};process.on("SIGINT",()=>{C.error(v.red("Operation cancelled")),process.exit(0)});var ee=new yo;async function Po(){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 or both)",t=>t.split(",")).option("--addons <types>","Additional addons (pwa,tauri,biome,husky)",t=>t.split(",")).option("--no-addons","Skip all additional addons").option("--examples <types>","Examples to include (todo,ai)",t=>t.split(",")).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=wo();try{nt(),go(v.magenta("Creating a new Better-T-Stack project"));let t=ee.opts(),o=ee.args[0];if(t.database&&!["none","sqlite","postgres"].includes(t.database)&&(S(v.red(`Invalid database type: ${t.database}. Must be none, sqlite, or postgres.`)),process.exit(1)),t.orm&&!["none","drizzle","prisma"].includes(t.orm)&&(S(v.red(`Invalid ORM type: ${t.orm}. Must be none, drizzle, or prisma.`)),process.exit(1)),t.packageManager&&!["npm","pnpm","bun"].includes(t.packageManager)&&(S(v.red(`Invalid package manager: ${t.packageManager}. Must be npm, pnpm, or bun.`)),process.exit(1)),t.backend&&!["hono","elysia"].includes(t.backend)&&(S(v.red(`Invalid backend framework: ${t.backend}. Must be hono or elysia.`)),process.exit(1)),t.runtime&&!["bun","node"].includes(t.runtime)&&(S(v.red(`Invalid runtime: ${t.runtime}. Must be bun or node.`)),process.exit(1)),t.examples&&t.examples.length>0){let c=["todo","ai"],b=t.examples.filter(w=>!c.includes(w));b.length>0&&(S(v.red(`Invalid example(s): ${b.join(", ")}. Valid options are: ${c.join(", ")}.`)),process.exit(1))}let r={...o&&{projectName:o},...t.database&&{database:t.database},...t.orm&&{orm:t.orm},..."auth"in t&&{auth:t.auth},...t.packageManager&&{packageManager:t.packageManager},..."git"in t&&{git:t.git},..."install"in t&&{noInstall:!t.install},..."turso"in t&&{turso:t.turso},...t.backend&&{backend:t.backend},...t.runtime&&{runtime:t.runtime},...t.frontend&&{frontend:t.frontend},...(t.addons||t.addons===!1)&&{addons:t.addons===!1?[]:t.addons},...(t.examples||t.examples===!1)&&{examples:t.examples===!1?[]:t.examples}};!t.yes&&Object.keys(r).length>0&&(C.info(v.yellow("Using these pre-selected options:")),C.message(Z(r)),C.message(""));let n=t.yes?{...m,projectName:o??m.projectName,...r}:await Ze(r);t.yes&&(C.info(v.yellow("Using these default options:")),C.message(Z(n)),C.message(""));let i=await Ie(n);n.noInstall||await Se({projectDir:i,packageManager:n.packageManager,addons:n.addons}),C.success(v.blue(`You can reproduce this setup with the following command:
|
|
198
|
+
${v.white(et(n))}`));let s=((Date.now()-e)/1e3).toFixed(2);bo(v.magenta(`Project created successfully in ${v.bold(s)} seconds!`))}catch(t){a.stop(v.red("Failed")),t instanceof Error&&(S(v.red(`An unexpected error occurred: ${t.message}`)),process.exit(1))}}Po().catch(e=>{C.error("Aborting installation..."),e instanceof Error?C.error(e.message):(C.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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-better-t-stack",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "CLI tool
|
|
3
|
+
"version": "1.4.0",
|
|
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
7
|
"bin": {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
const { getDefaultConfig } = require("expo/metro-config");
|
|
3
3
|
const { FileStore } = require("metro-cache");
|
|
4
4
|
const { withNativeWind } = require("nativewind/metro");
|
|
5
|
-
const path = require("path");
|
|
5
|
+
const path = require("node:path");
|
|
6
6
|
|
|
7
7
|
const config = withTurborepoManagedCache(
|
|
8
8
|
withMonorepoPaths(
|
|
@@ -46,9 +46,11 @@ function RootComponent() {
|
|
|
46
46
|
<>
|
|
47
47
|
<HeadContent />
|
|
48
48
|
<ThemeProvider defaultTheme="dark" storageKey="vite-ui-theme">
|
|
49
|
-
<
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
<div className="grid grid-rows-[auto_1fr] h-svh">
|
|
50
|
+
<Header />
|
|
51
|
+
{isFetching && <Loader />}
|
|
52
|
+
<Outlet />
|
|
53
|
+
</div>
|
|
52
54
|
<Toaster richColors />
|
|
53
55
|
</ThemeProvider>
|
|
54
56
|
<TanStackRouterDevtools position="bottom-left" />
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { createFileRoute } from "@tanstack/react-router";
|
|
2
|
+
import { useChat } from "@ai-sdk/react";
|
|
3
|
+
import { Input } from "@/components/ui/input";
|
|
4
|
+
import { Button } from "@/components/ui/button";
|
|
5
|
+
import { Send } from "lucide-react";
|
|
6
|
+
import { useRef, useEffect } from "react";
|
|
7
|
+
|
|
8
|
+
export const Route = createFileRoute("/ai")({
|
|
9
|
+
component: RouteComponent,
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
function RouteComponent() {
|
|
13
|
+
const { messages, input, handleInputChange, handleSubmit } = useChat({
|
|
14
|
+
api: `${import.meta.env.VITE_SERVER_URL}/ai`,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const messagesEndRef = useRef<HTMLDivElement>(null);
|
|
18
|
+
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
|
|
21
|
+
}, [messages]);
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<div className="grid grid-rows-[1fr_auto] overflow-hidden w-full mx-auto p-4">
|
|
25
|
+
<div className="overflow-y-auto space-y-4 pb-4">
|
|
26
|
+
{messages.length === 0 ? (
|
|
27
|
+
<div className="text-center text-muted-foreground mt-8">
|
|
28
|
+
Ask me anything to get started!
|
|
29
|
+
</div>
|
|
30
|
+
) : (
|
|
31
|
+
messages.map((message) => (
|
|
32
|
+
<div
|
|
33
|
+
key={message.id}
|
|
34
|
+
className={`p-3 rounded-lg ${
|
|
35
|
+
message.role === "user"
|
|
36
|
+
? "bg-primary/10 ml-8"
|
|
37
|
+
: "bg-secondary/20 mr-8"
|
|
38
|
+
}`}
|
|
39
|
+
>
|
|
40
|
+
<p className="text-sm font-semibold mb-1">
|
|
41
|
+
{message.role === "user" ? "You" : "AI Assistant"}
|
|
42
|
+
</p>
|
|
43
|
+
<div className="whitespace-pre-wrap">{message.content}</div>
|
|
44
|
+
</div>
|
|
45
|
+
))
|
|
46
|
+
)}
|
|
47
|
+
<div ref={messagesEndRef} />
|
|
48
|
+
</div>
|
|
49
|
+
|
|
50
|
+
<form
|
|
51
|
+
onSubmit={handleSubmit}
|
|
52
|
+
className="w-full flex items-center space-x-2 pt-2 border-t"
|
|
53
|
+
>
|
|
54
|
+
<Input
|
|
55
|
+
name="prompt"
|
|
56
|
+
value={input}
|
|
57
|
+
onChange={handleInputChange}
|
|
58
|
+
placeholder="Type your message..."
|
|
59
|
+
className="flex-1"
|
|
60
|
+
autoComplete="off"
|
|
61
|
+
autoFocus
|
|
62
|
+
/>
|
|
63
|
+
<Button type="submit" size="icon">
|
|
64
|
+
<Send size={18} />
|
|
65
|
+
</Button>
|
|
66
|
+
</form>
|
|
67
|
+
</div>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
@@ -1,11 +1,18 @@
|
|
|
1
|
+
import SignInForm from "@/components/sign-in-form";
|
|
2
|
+
import SignUpForm from "@/components/sign-up-form";
|
|
1
3
|
import { createFileRoute } from "@tanstack/react-router";
|
|
2
|
-
import
|
|
4
|
+
import { useState } from "react";
|
|
3
5
|
|
|
4
6
|
export const Route = createFileRoute("/login")({
|
|
5
7
|
component: RouteComponent,
|
|
6
8
|
});
|
|
7
9
|
|
|
8
10
|
function RouteComponent() {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
const [showSignIn, setShowSignIn] = useState(false);
|
|
12
|
+
|
|
13
|
+
return showSignIn ? (
|
|
14
|
+
<SignInForm onSwitchToSignUp={() => setShowSignIn(false)} />
|
|
15
|
+
) : (
|
|
16
|
+
<SignUpForm onSwitchToSignIn={() => setShowSignIn(true)} />
|
|
17
|
+
);
|
|
11
18
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { drizzle } from "drizzle-orm/libsql";
|
|
2
|
+
import { createClient } from "@libsql/client";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
authToken: process.env.TURSO_AUTH_TOKEN,
|
|
7
|
-
},
|
|
8
|
-
// logger: true,
|
|
4
|
+
const client = createClient({
|
|
5
|
+
url: process.env.TURSO_CONNECTION_URL || "",
|
|
6
|
+
authToken: process.env.TURSO_AUTH_TOKEN,
|
|
9
7
|
});
|
|
8
|
+
|
|
9
|
+
export const db = drizzle({ client });
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { useState } from "react";
|
|
2
|
-
import SignInForm from "./sign-in-form";
|
|
3
|
-
import SignUpForm from "./sign-up-form";
|
|
4
|
-
|
|
5
|
-
export default function AuthForms() {
|
|
6
|
-
const [showSignIn, setShowSignIn] = useState(false);
|
|
7
|
-
|
|
8
|
-
return showSignIn ? (
|
|
9
|
-
<SignInForm onSwitchToSignUp={() => setShowSignIn(false)} />
|
|
10
|
-
) : (
|
|
11
|
-
<SignUpForm onSwitchToSignIn={() => setShowSignIn(true)} />
|
|
12
|
-
);
|
|
13
|
-
}
|