create-better-t-stack 1.0.9 → 1.1.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/README.md +7 -0
- package/dist/index.js +71 -57
- package/package.json +5 -7
- package/template/base/apps/server/package.json +1 -7
- package/template/base/apps/server/src/index.ts +13 -21
- package/template/base/package.json +0 -1
- package/template/with-auth/apps/client/src/components/sign-in-form.tsx +1 -1
- package/template/with-auth/apps/client/src/components/sign-up-form.tsx +142 -142
- package/template/with-auth/apps/server/src/index.ts +15 -23
- package/template/with-auth/apps/server/src/routers/index.ts +11 -13
package/README.md
CHANGED
|
@@ -19,6 +19,7 @@ Follow the prompts to configure your project.
|
|
|
19
19
|
- **Monorepo**: Turborepo for optimized build system and workspace management
|
|
20
20
|
- **Frontend**: React, TanStack Router, TanStack Query, Tailwind CSS with shadcn/ui components
|
|
21
21
|
- **Backend**: Hono, tRPC
|
|
22
|
+
- **Runtime Options**: Choose between Bun or Node.js for your server
|
|
22
23
|
- **Database Options**: SQLite (via Turso), PostgreSQL, or no database
|
|
23
24
|
- **ORM Selection**: Choose between Drizzle ORM or Prisma
|
|
24
25
|
- **Authentication**: Optional auth setup with Better-Auth
|
|
@@ -60,6 +61,7 @@ Options:
|
|
|
60
61
|
--no-install Skip installing dependencies
|
|
61
62
|
--turso Set up Turso for SQLite database (default with sqlite)
|
|
62
63
|
--no-turso Skip Turso setup for SQLite database
|
|
64
|
+
--runtime <runtime> Specify runtime (bun or node)
|
|
63
65
|
-h, --help Display help
|
|
64
66
|
```
|
|
65
67
|
|
|
@@ -75,6 +77,11 @@ Create a project with specific options:
|
|
|
75
77
|
npx create-better-t-stack my-app --postgres --prisma --auth --pwa --biome
|
|
76
78
|
```
|
|
77
79
|
|
|
80
|
+
Create a project with Node.js runtime:
|
|
81
|
+
```bash
|
|
82
|
+
npx create-better-t-stack my-app --runtime node
|
|
83
|
+
```
|
|
84
|
+
|
|
78
85
|
## License
|
|
79
86
|
|
|
80
87
|
MIT
|
package/dist/index.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{cancel as
|
|
2
|
+
import{cancel as qa,intro as Va,log as x,outro as Ha,spinner as Wa}from"@clack/prompts";import{Command as Qa}from"commander";import E from"picocolors";import Y from"node:path";import{fileURLToPath as Xe}from"node:url";var Ye=Xe(import.meta.url),Ze=Y.dirname(Ye),g=Y.join(Ze,"../"),u={projectName:"my-better-t-app",database:"sqlite",orm:"drizzle",auth:!0,addons:[],examples:[],git:!0,packageManager:"npm",noInstall:!1,turso:!1,backendFramework:"hono",runtime:"bun"},G={"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"};import Gt from"node:path";import{cancel as qt,spinner as Vt}from"@clack/prompts";import Ht from"fs-extra";import xe from"picocolors";import A from"node:path";import h from"fs-extra";import et from"node:path";import Z from"fs-extra";var f=e=>{let{dependencies:a=[],devDependencies:t=[],projectDir:o}=e,r=et.join(o,"package.json"),s=Z.readJSONSync(r);s.dependencies||(s.dependencies={}),s.devDependencies||(s.devDependencies={});for(let i of a){let n=G[i];s.dependencies[i]=n}for(let i of t){let n=G[i];s.devDependencies[i]=n}Z.writeJSONSync(r,s,{spaces:2})};import N from"node:path";import{log as tt,spinner as at}from"@clack/prompts";import{execa as ot}from"execa";import q from"fs-extra";import ee from"picocolors";async function te(e,a){let t=at(),o=N.join(e,"apps/client");try{t.start("Setting up Tauri desktop app support..."),f({devDependencies:["@tauri-apps/cli"],projectDir:o});let r=N.join(o,"package.json");if(await q.pathExists(r)){let n=await q.readJson(r);n.scripts={...n.scripts,tauri:"tauri","desktop:dev":"tauri dev","desktop:build":"tauri build"},await q.writeJson(r,n,{spaces:2})}let s,i;switch(a){case"npm":s="npx",i=["@tauri-apps/cli@latest"];break;case"pnpm":s="pnpm",i=["dlx","@tauri-apps/cli@latest"];break;case"bun":s="bunx",i=["@tauri-apps/cli@latest"];break;default:s="npx",i=["@tauri-apps/cli@latest"]}i=[...i,"init",`--app-name=${N.basename(e)}`,`--window-title=${N.basename(e)}`,"--frontend-dist=dist","--dev-url=http://localhost:3001",`--before-dev-command=${a} run dev`,`--before-build-command=${a} run build`],await ot(s,i,{cwd:o,env:{CI:"true"}}),t.stop("Tauri desktop app support configured successfully!")}catch(r){throw t.stop(ee.red("Failed to set up Tauri")),r instanceof Error&&tt.error(ee.red(r.message)),r}}async function ae(e,a,t){a.includes("pwa")&&await it(e),a.includes("tauri")&&await te(e,t),a.includes("biome")&&await rt(e),a.includes("husky")&&await st(e)}async function rt(e){let a=A.join(g,"template/with-biome");await h.pathExists(a)&&await h.copy(a,e,{overwrite:!0}),f({devDependencies:["@biomejs/biome"],projectDir:e});let t=A.join(e,"package.json");if(await h.pathExists(t)){let o=await h.readJson(t);o.scripts={...o.scripts,check:"biome check --write ."},await h.writeJson(t,o,{spaces:2})}}async function st(e){let a=A.join(g,"template/with-husky");await h.pathExists(a)&&await h.copy(a,e,{overwrite:!0}),f({devDependencies:["husky","lint-staged"],projectDir:e});let t=A.join(e,"package.json");if(await h.pathExists(t)){let o=await h.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 h.writeJson(t,o,{spaces:2})}}async function it(e){let a=A.join(g,"template/with-pwa");await h.pathExists(a)&&await h.copy(a,e,{overwrite:!0});let t=A.join(e,"apps/client");f({dependencies:["vite-plugin-pwa"],devDependencies:["@vite-pwa/assets-generator"],projectDir:t});let o=A.join(t,"package.json");if(await h.pathExists(o)){let r=await h.readJson(o);r.scripts={...r.scripts,"generate-pwa-assets":"pwa-assets-generator"},await h.writeJson(o,r,{spaces:2})}}import oe from"node:path";import{log as re}from"@clack/prompts";import se from"picocolors";function ie(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 ne(e,a){if(!a)return;let t=oe.join(e,"apps/server"),o=oe.join(e,"apps/client");try{f({dependencies:["better-auth"],projectDir:t}),f({dependencies:["better-auth"],projectDir:o})}catch(r){throw re.error(se.red("Failed to configure authentication")),r instanceof Error&&re.error(se.red(r.message)),r}}import nt from"node:path";import ct from"fs-extra";async function ce(e,a){let t=nt.join(e,"README.md"),o=pt(a);try{await ct.writeFile(t,o)}catch(r){console.error("Failed to create README.md file:",r)}}function pt(e){let{projectName:a,packageManager:t,database:o,auth:r,addons:s=[],orm:i="drizzle",runtime:n="bun"}=e,d=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
|
+
${lt(o,r,s,i,n)}
|
|
9
9
|
|
|
10
10
|
## Getting Started
|
|
11
11
|
|
|
12
12
|
First, install the dependencies:
|
|
13
13
|
|
|
14
14
|
\`\`\`bash
|
|
15
|
-
${
|
|
15
|
+
${t} install
|
|
16
16
|
\`\`\`
|
|
17
17
|
|
|
18
|
-
${
|
|
18
|
+
${ut(o,r,d,i)}
|
|
19
19
|
|
|
20
20
|
Then, run the development server:
|
|
21
21
|
|
|
22
22
|
\`\`\`bash
|
|
23
|
-
${
|
|
23
|
+
${d} dev
|
|
24
24
|
\`\`\`
|
|
25
25
|
|
|
26
26
|
Open [http://localhost:3001](http://localhost:3001) in your browser to see the client application.
|
|
@@ -29,7 +29,7 @@ The API is running at [http://localhost:3000](http://localhost:3000).
|
|
|
29
29
|
## Project Structure
|
|
30
30
|
|
|
31
31
|
\`\`\`
|
|
32
|
-
${
|
|
32
|
+
${a}/
|
|
33
33
|
\u251C\u2500\u2500 apps/
|
|
34
34
|
\u2502 \u251C\u2500\u2500 client/ # Frontend application (React, TanStack Router)
|
|
35
35
|
\u2502 \u2514\u2500\u2500 server/ # Backend API (Hono, tRPC)
|
|
@@ -37,15 +37,15 @@ ${t}/
|
|
|
37
37
|
|
|
38
38
|
## Available Scripts
|
|
39
39
|
|
|
40
|
-
${
|
|
41
|
-
`}function
|
|
42
|
-
`)}function
|
|
40
|
+
${dt(d,o,i,r)}
|
|
41
|
+
`}function lt(e,a,t,o,r){let s=["- **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"&&s.push(`- **${o==="drizzle"?"Drizzle":"Prisma"}** - TypeScript-first ORM`,`- **${e==="sqlite"?"SQLite/Turso":"PostgreSQL"}** - Database engine`),a&&s.push("- **Authentication** - Email & password authentication with Better Auth");for(let i of t)i==="pwa"?s.push("- **PWA** - Progressive Web App support"):i==="tauri"?s.push("- **Tauri** - Build native desktop applications"):i==="biome"?s.push("- **Biome** - Linting and formatting"):i==="husky"&&s.push("- **Husky** - Git hooks for code quality");return s.join(`
|
|
42
|
+
`)}function ut(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"}.
|
|
45
45
|
|
|
46
46
|
1. Start the local SQLite database:
|
|
47
47
|
\`\`\`bash
|
|
48
|
-
cd apps/server && ${
|
|
48
|
+
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.
|
|
@@ -54,24 +54,24 @@ cd apps/server && ${a} db:local
|
|
|
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
56
|
`),r+=`
|
|
57
|
-
${
|
|
57
|
+
${a?"4":"3"}. ${o==="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
|
-
`,r}function
|
|
64
|
+
`,r}function dt(e,a,t,o){let r=`- \`${e} dev\`: Start both client and server in development mode
|
|
65
65
|
- \`${e} build\`: Build both client and server
|
|
66
66
|
- \`${e} dev:client\`: Start only the client
|
|
67
67
|
- \`${e} dev:server\`: Start only the server
|
|
68
|
-
- \`${e} check-types\`: Check TypeScript types across all apps`;return
|
|
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
|
-
- \`${e} db:studio\`: Open database studio UI`,
|
|
71
|
-
- \`cd apps/server && ${e} db:local\`: Start the local SQLite database`)),r}import
|
|
72
|
-
`);return
|
|
73
|
-
TURSO_AUTH_TOKEN="${
|
|
74
|
-
TURSO_AUTH_TOKEN=`;await
|
|
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 ue from"node:path";import{log as Tt,spinner as $t}from"@clack/prompts";import Et from"fs-extra";import de from"picocolors";import mt from"node:os";import pe from"node:path";import{cancel as V,confirm as ft,isCancel as H,log as I,select as ht,spinner as W,text as gt}from"@clack/prompts";import{$ as k}from"execa";import wt from"fs-extra";import b from"picocolors";async function bt(){try{return(await k`turso --version`).exitCode===0}catch{return!1}}async function yt(){try{return!(await k`turso auth whoami`).stdout.includes("You are not logged in")}catch{return!1}}async function Pt(){let e=W();try{return e.start("Logging in to Turso..."),await k`turso auth login`,e.stop("Logged in to Turso successfully!"),!0}catch(a){throw e.stop(b.red("Failed to log in to Turso")),a}}async function kt(e){let a=W();try{if(a.start("Installing Turso CLI..."),e)await k`brew install tursodatabase/tap/turso`;else{let{stdout:t}=await k`curl -sSfL https://get.tur.so/install.sh`;await k`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(),I.warn(b.yellow("Turso CLI installation cancelled by user")),new Error("Installation cancelled")):(a.stop(b.red("Failed to install Turso CLI")),t)}}async function jt(){try{let{stdout:e}=await k`turso group list`,a=e.trim().split(`
|
|
72
|
+
`);return a.length<=1?[]:a.slice(1).map(o=>{let[r,s,i,n]=o.trim().split(/\s{2,}/);return{name:r,locations:s,version:i,status:n}})}catch(e){return console.error("Error fetching Turso groups:",e),[]}}async function vt(){let e=await jt();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 ht({message:"Select a Turso database group:",options:a});return H(t)&&(V(b.red("Operation cancelled")),process.exit(0)),t}async function xt(e,a){try{a?await k`turso db create ${e} --group ${a}`:await k`turso db create ${e}`}catch(r){throw r instanceof Error&&r.message.includes("already exists")?new Error("DATABASE_EXISTS"):r}let{stdout:t}=await k`turso db show ${e} --url`,{stdout:o}=await k`turso db tokens create ${e}`;return{dbUrl:t.trim(),authToken:o.trim()}}async function z(e,a){let t=pe.join(e,"apps/server",".env"),o=a?`TURSO_CONNECTION_URL="${a.dbUrl}"
|
|
73
|
+
TURSO_AUTH_TOKEN="${a.authToken}"`:`TURSO_CONNECTION_URL=
|
|
74
|
+
TURSO_AUTH_TOKEN=`;await wt.writeFile(t,o)}function U(){I.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,51 +79,65 @@ TURSO_AUTH_TOKEN=`;await ut.writeFile(a,o)}function F(){A.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
|
|
83
|
-
CORS_ORIGIN=http://localhost:3001`),
|
|
84
|
-
BETTER_AUTH_SECRET=${
|
|
85
|
-
BETTER_AUTH_URL=http://localhost:3000`)),
|
|
86
|
-
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/mydb?schema=public"`;s+=
|
|
87
|
-
TURSO_CONNECTION_URL=http://127.0.0.1:8080`))}await D.writeFile(r,s.trim());let i=
|
|
88
|
-
`),await D.writeFile(i,n.trim())}import
|
|
82
|
+
TURSO_AUTH_TOKEN=your_auth_token`)}async function le(e,a){if(!a){await z(e),I.info(b.blue("Skipping Turso setup. Setting up empty configuration.")),U();return}let t=mt.platform(),o=t==="darwin";if(!(t!=="win32")){I.warn(b.yellow("Automatic Turso setup is not supported on Windows.")),await z(e),U();return}try{if(!await bt()){let T=await ft({message:"Would you like to install Turso CLI?",initialValue:!0});if(H(T)&&(V(b.red("Operation cancelled")),process.exit(0)),!T){await z(e),U();return}await kt(o)}await yt()||await Pt();let n=await vt(),d=!1,P="",w=pe.basename(e);for(;!d;){let T=await gt({message:"Enter a name for your database:",defaultValue:w,initialValue:w,placeholder:w});H(T)&&(V(b.red("Operation cancelled")),process.exit(0)),P=T;let O=W();try{O.start(`Creating Turso database "${P}"${n?` in group "${n}"`:""}...`);let F=await xt(P,n);await z(e,F),O.stop("Turso database configured successfully!"),d=!0}catch(F){if(F instanceof Error&&F.message==="DATABASE_EXISTS")O.stop(b.yellow(`Database "${b.red(P)}" already exists`)),w=`${P}-${Math.floor(Math.random()*1e3)}`;else throw O.stop(b.red("Failed to create Turso database")),F}}}catch(s){I.error(b.red(`Error during Turso setup: ${s}`)),await z(e),U(),I.success("Setup completed with manual configuration required.")}}async function me(e,a,t,o=!0){let r=$t(),s=ue.join(e,"apps/server");if(a==="none"){await Et.remove(ue.join(s,"src/db"));return}try{a==="sqlite"?(t==="drizzle"?f({dependencies:["drizzle-orm","@libsql/client"],devDependencies:["drizzle-kit"],projectDir:s}):t==="prisma"&&f({dependencies:["@prisma/client"],devDependencies:["prisma"],projectDir:s}),o&&await le(e,!0)):a==="postgres"&&(t==="drizzle"?f({dependencies:["drizzle-orm","postgres"],devDependencies:["drizzle-kit"],projectDir:s}):t==="prisma"&&f({dependencies:["@prisma/client"],devDependencies:["prisma"],projectDir:s}))}catch(i){throw r.stop(de.red("Failed to set up database")),i instanceof Error&&Tt.error(de.red(i.message)),i}}import _ from"node:path";import D from"fs-extra";async function fe(e,a){let t=_.join(e,"apps/server"),o=_.join(e,"apps/client"),r=_.join(t,".env"),s="";if(await D.pathExists(r)&&(s=await D.readFile(r,"utf8")),s.includes("CORS_ORIGIN")||(s+=`
|
|
83
|
+
CORS_ORIGIN=http://localhost:3001`),a.auth&&(s.includes("BETTER_AUTH_SECRET")||(s+=`
|
|
84
|
+
BETTER_AUTH_SECRET=${ie()}`),s.includes("BETTER_AUTH_URL")||(s+=`
|
|
85
|
+
BETTER_AUTH_URL=http://localhost:3000`)),a.database!=="none"){if(a.orm==="prisma"&&!s.includes("DATABASE_URL")){let d=a.database==="sqlite"?"":`
|
|
86
|
+
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/mydb?schema=public"`;s+=d}a.database==="sqlite"&&!a.turso&&(s.includes("TURSO_CONNECTION_URL")||(s+=`
|
|
87
|
+
TURSO_CONNECTION_URL=http://127.0.0.1:8080`))}await D.writeFile(r,s.trim());let i=_.join(o,".env"),n="";await D.pathExists(i)&&(n=await D.readFile(i,"utf8")),n.includes("VITE_SERVER_URL")||(n+=`VITE_SERVER_URL=http://localhost:3000
|
|
88
|
+
`),await D.writeFile(i,n.trim())}import j from"node:path";import m from"fs-extra";async function he(e,a,t,o){a.includes("todo")?await Ct(e,t,o):await Ot(e,t)}async function Ct(e,a,t){let o=j.join(g,"template/examples/todo");if(await m.pathExists(o)){let r=j.join(o,"apps/client/src/routes"),s=j.join(e,"apps/client/src/routes");if(await m.copy(r,s,{overwrite:!0}),a!=="none"){let i=j.join(o,`apps/server/src/routers/with-${a}-todo.ts`),n=j.join(e,"apps/server/src/routers/todo.ts");await m.pathExists(i)&&await m.copy(i,n,{overwrite:!0})}await St(e,t),await Rt(e)}}async function St(e,a){let t=j.join(e,"apps/client/src/components/header.tsx");if(await m.pathExists(t)){let o=await m.readFile(t,"utf8");a?o=o.replace(/const links = \[\s*{ to: "\/", label: "Home" },\s*{ to: "\/dashboard", label: "Dashboard" },/,`const links = [
|
|
89
89
|
{ to: "/", label: "Home" },
|
|
90
90
|
{ to: "/dashboard", label: "Dashboard" },
|
|
91
91
|
{ to: "/todos", label: "Todos" },`):o=o.replace(/const links = \[\s*{ to: "\/", label: "Home" },/,`const links = [
|
|
92
92
|
{ to: "/", label: "Home" },
|
|
93
|
-
{ to: "/todos", label: "Todos" },`),await
|
|
93
|
+
{ to: "/todos", label: "Todos" },`),await m.writeFile(t,o)}}async function Ot(e,a){if(a==="drizzle"){let o=j.join(e,"apps/server/src/db/schema/todo.ts");await m.pathExists(o)&&await m.remove(o)}else if(a==="prisma"){let o=j.join(e,"apps/server/prisma/schema/todo.prisma");await m.pathExists(o)&&await m.remove(o)}let t=j.join(e,"apps/server/src/routers/todo.ts");await m.pathExists(t)&&await m.remove(t),await At(e)}async function At(e){let a=j.join(e,"apps/server/src/routers/index.ts");if(await m.pathExists(a)){let t=await m.readFile(a,"utf8");t=t.replace(/import { todoRouter } from ".\/todo";/,""),t=t.replace(/todo: todoRouter,/,""),await m.writeFile(a,t)}}async function Rt(e){let a=j.join(e,"apps/client/src/routes/index.tsx");if(await m.pathExists(a)){let t=await m.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">
|
|
94
94
|
<Button asChild>
|
|
95
95
|
<Link to="/todos" className="flex items-center">
|
|
96
96
|
View Todo Demo
|
|
97
97
|
<ArrowRight className="ml-1 h-4 w-4" />
|
|
98
98
|
</Link>
|
|
99
99
|
</Button>
|
|
100
|
-
</div>`),await
|
|
101
|
-
|
|
102
|
-
${
|
|
103
|
-
${
|
|
104
|
-
${o?"":`${
|
|
105
|
-
`}${
|
|
106
|
-
|
|
107
|
-
${
|
|
108
|
-
${
|
|
109
|
-
${
|
|
110
|
-
${
|
|
111
|
-
${
|
|
112
|
-
${T.trim()}`:""}${
|
|
113
|
-
${
|
|
114
|
-
${
|
|
115
|
-
|
|
116
|
-
`}function
|
|
117
|
-
${
|
|
100
|
+
</div>`),await m.writeFile(a,t)}}import{log as It}from"@clack/prompts";import l from"picocolors";function ge(e,a,t,o,r,s,i){let n=t==="npm"?"npm run":t,d=`cd ${a}`,P=s?.includes("husky")||s?.includes("biome"),w=e!=="none"?Ft(e,r,n,i):"",T=s?.includes("tauri")?zt(n):"",O=P?Dt(n):"";It.info(`${l.cyan("Project created successfully!")}
|
|
101
|
+
|
|
102
|
+
${l.bold("Next steps:")}
|
|
103
|
+
${l.cyan("1.")} ${d}
|
|
104
|
+
${o?"":`${l.cyan("2.")} ${t} install
|
|
105
|
+
`}${l.cyan(o?"2.":"3.")} ${n} dev
|
|
106
|
+
|
|
107
|
+
${l.bold("Your project will be available at:")}
|
|
108
|
+
${l.cyan("\u2022")} Frontend: http://localhost:3001
|
|
109
|
+
${l.cyan("\u2022")} API: http://localhost:3000
|
|
110
|
+
${w?`
|
|
111
|
+
${w.trim()}`:""}${T?`
|
|
112
|
+
${T.trim()}`:""}${O?`
|
|
113
|
+
${O.trim()}`:""}`)}function Dt(e){return`${l.bold("Linting and formatting:")}
|
|
114
|
+
${l.cyan("\u2022")} Format and lint fix: ${l.dim(`${e} check`)}
|
|
115
|
+
|
|
116
|
+
`}function Ft(e,a,t,o){let r=[];return a==="prisma"?(e==="sqlite"&&r.push(`${l.yellow("NOTE:")} Turso support with Prisma is in Early Access and requires additional setup.`,`${l.dim("Learn more at: https://www.prisma.io/docs/orm/overview/databases/turso")}`),o==="bun"&&r.push(`${l.yellow("NOTE:")} Prisma with Bun may require additional configuration. If you encounter errors, follow the guidance provided in the error messages`),r.push(`${l.cyan("\u2022")} Apply schema: ${l.dim(`${t} db:push`)}`),r.push(`${l.cyan("\u2022")} Database UI: ${l.dim(`${t} db:studio`)}`)):a==="drizzle"&&(e==="sqlite"&&r.push(`${l.cyan("\u2022")} Start local DB: ${l.dim(`cd apps/server && ${t} db:local`)}`),r.push(`${l.cyan("\u2022")} Apply schema: ${l.dim(`${t} db:push`)}`),r.push(`${l.cyan("\u2022")} Database UI: ${l.dim(`${t} db:studio`)}`)),r.length?`${l.bold("Database commands:")}
|
|
117
|
+
${r.join(`
|
|
118
118
|
`)}
|
|
119
119
|
|
|
120
|
-
`:""}function
|
|
121
|
-
${
|
|
122
|
-
${
|
|
123
|
-
${
|
|
124
|
-
|
|
125
|
-
`}import _ from"node:path";import{$ as Dt}from"execa";import C from"fs-extra";async function he(e,t){await It(e,t),await Rt(e,t)}async function It(e,t){let a=_.join(e,"package.json");if(await C.pathExists(a)){let o=await C.readJson(a);if(o.name=t.projectName,t.packageManager!=="bun"&&(o.packageManager=t.packageManager==="npm"?"npm@10.9.2":t.packageManager==="pnpm"?"pnpm@10.6.4":"bun@1.2.5"),await C.writeJson(a,o,{spaces:2}),t.packageManager==="pnpm"){let r=_.join(f,"template/with-pnpm/pnpm-workspace.yaml"),s=_.join(e,"pnpm-workspace.yaml");await C.pathExists(r)&&await C.copy(r,s)}}}async function Rt(e,t){let a=_.join(e,"apps/server/package.json");if(await C.pathExists(a)){let o=await C.readJson(a);t.database!=="none"&&(t.database==="sqlite"&&(o.scripts["db:local"]="turso dev --db-file local.db"),t.orm==="prisma"?(o.scripts["db:push"]="prisma db push --schema ./prisma/schema",o.scripts["db:studio"]="prisma studio"):t.orm==="drizzle"&&(o.scripts["db:push"]="drizzle-kit push",o.scripts["db:studio"]="drizzle-kit studio")),await C.writeJson(a,o,{spaces:2})}}async function ge(e,t){t&&await Dt({cwd:e})`git init`}import j from"node:path";import b from"fs-extra";async function we(e){let t=j.join(f,"template/base");if(!await b.pathExists(t))throw new Error(`Template directory not found: ${t}`);await b.copy(t,e)}async function be(e,t){if(!t)return;let a=j.join(f,"template/with-auth");await b.pathExists(a)&&await b.copy(a,e,{overwrite:!0})}async function ye(e,t,a,o){if(t==="none"||a==="none")return;let r=j.join(f,zt(t,a));if(await b.pathExists(r)){await b.copy(r,e,{overwrite:!0});let s=j.join(e,"apps/server/src"),i=j.join(s,"lib"),n=j.join(s,"with-auth-lib");o?await b.pathExists(n)&&(await b.remove(i),await b.move(n,i)):await b.remove(n)}}async function Pe(e){let t=[j.join(e,"_gitignore"),j.join(e,"apps/client/_gitignore"),j.join(e,"apps/server/_gitignore")];for(let a of t)if(await b.pathExists(a)){let o=j.join(j.dirname(a),".gitignore");await b.move(a,o)}}function zt(e,t){return e==="drizzle"?t==="sqlite"?"template/with-drizzle-sqlite":"template/with-drizzle-postgres":e==="prisma"?t==="sqlite"?"template/with-prisma-sqlite":"template/with-prisma-postgres":"template/base"}async function ke(e){let t=Ft(),a=Lt.resolve(process.cwd(),e.projectName);try{return await Ut.ensureDir(a),await we(a),await Pe(a),await be(a,e.auth),await ye(a,e.orm,e.database,e.auth),await me(a,e.examples,e.orm,e.auth),await de(a,e.database,e.orm,e.turso??e.database==="sqlite"),await se(a,e.auth),await ue(a,e),await ge(a,e.git),e.addons.length>0&&await ee(a,e.addons,e.packageManager),await he(a,e),await ie(a,e),fe(e.database,e.projectName,e.packageManager,!e.noInstall,e.orm,e.addons),a}catch(o){throw t.message(je.red("Failed")),o instanceof Error&&(Nt(je.red(`Error during project creation: ${o.message}`)),process.exit(1)),o}}import{log as ve,spinner as Te}from"@clack/prompts";import{$ as H}from"execa";import M from"picocolors";async function xe({projectDir:e,packageManager:t,addons:a=[]}){let o=Te();try{switch(o.start(`Running ${t} install...`),t){case"npm":await H({cwd:e,stderr:"inherit"})`${t} install`;break;case"pnpm":case"bun":await H({cwd:e})`${t} install`;break}o.stop("Dependencies installed successfully"),(a.includes("biome")||a.includes("husky"))&&await _t(e,t)}catch(r){throw o.stop(M.red("Failed to install dependencies")),r instanceof Error&&ve.error(M.red(`Installation error: ${r.message}`)),r}}async function _t(e,t){let a=Te();try{a.start("Running Biome format check..."),await H({cwd:e})`${t} biome check --write .`,a.stop("Biome check completed successfully")}catch{a.stop(M.yellow("Biome check encountered issues")),ve.warn(M.yellow("Some files may need manual formatting"))}}import{cancel as Ca,group as Sa}from"@clack/prompts";import Oa from"picocolors";import{cancel as Mt,isCancel as Bt,multiselect as Gt}from"@clack/prompts";import qt from"picocolors";async function $e(e){if(e!==void 0)return e;let t=await Gt({message:"Which Addons would you like to add?",options:[{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"},{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)"}],required:!1});return Bt(t)&&(Mt(qt.red("Operation cancelled")),process.exit(0)),t.includes("husky")&&!t.includes("biome")&&t.push("biome"),t}import{cancel as Jt,confirm as Vt,isCancel as Ht}from"@clack/prompts";import Wt from"picocolors";async function Ee(e,t){if(!t)return!1;if(e!==void 0)return e;let a=await Vt({message:"Would you like to add authentication with Better-Auth?",initialValue:d.auth});return Ht(a)&&(Jt(Wt.red("Operation cancelled")),process.exit(0)),a}import{cancel as Qt,isCancel as Kt,select as Xt}from"@clack/prompts";import Yt from"picocolors";async function Ce(e){if(e!==void 0)return e;let t=await Xt({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:"sqlite"});return Kt(t)&&(Qt(Yt.red("Operation cancelled")),process.exit(0)),t}import{cancel as Zt,isCancel as ea,multiselect as ta}from"@clack/prompts";import aa from"picocolors";async function Se(e,t){if(e!==void 0)return e;if(t==="none")return[];let a=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:d.examples});return ea(a)&&(Zt(aa.red("Operation cancelled")),process.exit(0)),a}import{cancel as oa,confirm as ra,isCancel as sa}from"@clack/prompts";import ia from"picocolors";async function Oe(e){if(e!==void 0)return e;let t=await ra({message:"Initialize a new git repository?",initialValue:d.git});return sa(t)&&(oa(ia.red("Operation cancelled")),process.exit(0)),t}import{cancel as na,confirm as ca,isCancel as pa}from"@clack/prompts";import la from"picocolors";async function Ae(e){if(e!==void 0)return e;let t=await ca({message:"Do you want to install project dependencies?",initialValue:!d.noInstall});return pa(t)&&(na(la.red("Operation cancelled")),process.exit(0)),!t}import{cancel as da,isCancel as ua,select as ma}from"@clack/prompts";import fa from"picocolors";async function De(e,t){if(!t)return"none";if(e!==void 0)return e;let a=await ma({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 with schema migrations"}],initialValue:"drizzle"});return ua(a)&&(da(fa.red("Operation cancelled")),process.exit(0)),a}import{cancel as ha,isCancel as ga,select as wa}from"@clack/prompts";import ba from"picocolors";var Ie=()=>{let e=process.env.npm_config_user_agent;return e?.startsWith("pnpm")?"pnpm":e?.startsWith("bun")?"bun":"npm"};async function Re(e){if(e!==void 0)return e;let t=Ie(),a=await wa({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:t});return ga(a)&&(ha(ba.red("Operation cancelled")),process.exit(0)),a}import z from"node:path";import{cancel as ya,isCancel as Pa,text as ja}from"@clack/prompts";import O from"fs-extra";import ka from"picocolors";var va=["<",">",":",'"',"|","?","*"],ze=255;function Le(e){if(e!=="."){if(!e)return"Project name cannot be empty";if(e.length>ze)return`Project name must be less than ${ze} characters`;if(va.some(t=>e.includes(t)))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 Ne(e){if(e)if(e==="."){let s=process.cwd();if(O.readdirSync(s).length===0)return e}else{let s=z.basename(e);if(!Le(s)){let n=z.resolve(process.cwd(),e);if(!O.pathExistsSync(n)||O.readdirSync(n).length===0)return e}}let t=!1,a="",o=d.projectName,r=1;for(;O.pathExistsSync(z.resolve(process.cwd(),o));)o=`${d.projectName}-${r}`,r++;for(;!t;){let s=await ja({message:"Enter your project name or path (relative to current directory)",placeholder:o,initialValue:e,defaultValue:o,validate:i=>{let n=i.trim()||o;if(n==="."){if(O.readdirSync(process.cwd()).length>0)return"Current directory is not empty. Please choose a different directory.";t=!0;return}let g=z.resolve(process.cwd(),n),v=z.basename(g),T=Le(v);if(T)return T;if(!g.startsWith(process.cwd()))return"Project path must be within current directory";if(O.pathExistsSync(g)&&O.readdirSync(g).length>0)return`Directory "${n}" already exists and is not empty. Please choose a different name or path.`;t=!0}});Pa(s)&&(ya(ka.red("Operation cancelled.")),process.exit(0)),a=s||o}return a}import{cancel as Ta,confirm as xa,isCancel as $a}from"@clack/prompts";import Ea from"picocolors";async function Fe(e){if(e!==void 0)return e;let t=await xa({message:"Set up a Turso database for this project?",initialValue:!0});return $a(t)&&(Ta(Ea.red("Operation cancelled")),process.exit(0)),t}async function Ue(e){let t=await Sa({projectName:async()=>Ne(e.projectName),database:()=>Ce(e.database),orm:({results:a})=>De(e.orm,a.database!=="none"),auth:({results:a})=>Ee(e.auth,a.database!=="none"),turso:({results:a})=>a.database==="sqlite"&&a.orm!=="prisma"?Fe(e.turso):Promise.resolve(!1),addons:()=>$e(e.addons),examples:({results:a})=>Se(e.examples,a.database),git:()=>Oe(e.git),packageManager:()=>Re(e.packageManager),noInstall:()=>Ae(e.noInstall)},{onCancel:()=>{Ca(Oa.red("Operation cancelled")),process.exit(0)}});return{projectName:t.projectName,database:t.database,orm:t.orm,auth:t.auth,addons:t.addons,examples:t.examples,git:t.git,packageManager:t.packageManager,noInstall:t.noInstall,turso:t.turso}}import E from"picocolors";function W(e){let t=[];return e.projectName&&t.push(`${E.blue("Project Name:")} ${e.projectName}`),e.database&&t.push(`${E.blue("Database:")} ${e.database}`),e.orm&&t.push(`${E.blue("ORM:")} ${e.orm}`),e.auth!==void 0&&t.push(`${E.blue("Authentication:")} ${e.auth}`),e.addons?.length&&t.push(`${E.blue("Addons:")} ${e.addons.join(", ")}`),e.git!==void 0&&t.push(`${E.blue("Git Init:")} ${e.git}`),e.packageManager&&t.push(`${E.blue("Package Manager:")} ${e.packageManager}`),e.noInstall!==void 0&&t.push(`${E.blue("Skip Install:")} ${e.noInstall}`),e.turso!==void 0&&t.push(`${E.blue("Turso Setup:")} ${e.turso}`),t.join(`
|
|
126
|
-
|
|
120
|
+
`:""}function zt(e){return`${l.bold("Desktop app with Tauri:")}
|
|
121
|
+
${l.cyan("\u2022")} Start desktop app: ${l.dim(`cd apps/client && ${e} desktop:dev`)}
|
|
122
|
+
${l.cyan("\u2022")} Build desktop app: ${l.dim(`cd apps/client && ${e} desktop:build`)}
|
|
123
|
+
${l.yellow("NOTE:")} Tauri requires Rust and platform-specific dependencies. See: ${l.dim("https://v2.tauri.app/start/prerequisites/")}
|
|
124
|
+
|
|
125
|
+
`}import M from"node:path";import{$ as Lt,execa as Nt}from"execa";import C from"fs-extra";async function we(e,a){await Ut(e,a),await _t(e,a)}async function Ut(e,a){let t=M.join(e,"package.json");if(await C.pathExists(t)){let o=await C.readJson(t);o.name=a.projectName;let{stdout:r}=await Nt(a.packageManager,["-v"],{cwd:e});if(o.packageManager=`${a.packageManager}@${r.trim()}`,await C.writeJson(t,o,{spaces:2}),a.packageManager==="pnpm"){let s=M.join(g,"template/with-pnpm/pnpm-workspace.yaml"),i=M.join(e,"pnpm-workspace.yaml");await C.pathExists(s)&&await C.copy(s,i)}}}async function _t(e,a){let t=M.join(e,"apps/server/package.json");if(await C.pathExists(t)){let o=await C.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 C.writeJson(t,o,{spaces:2})}}async function be(e,a){a&&await Lt({cwd:e})`git init`}import B from"node:path";import S from"fs-extra";async function ye(e,a){let t=B.join(e,"apps/server"),o=B.join(t,"src/index.ts"),r=await S.readFile(o,"utf-8");a==="bun"?await Mt(t,o,r):a==="node"&&await Bt(t,o,r)}async function Mt(e,a,t){let o=B.join(e,"package.json"),r=await S.readJson(o);if(r.scripts={...r.scripts,dev:"bun run --hot src/index.ts",start:"bun run dist/src/index.js"},await S.writeJson(o,r,{spaces:2}),f({devDependencies:["@types/bun"],projectDir:e}),!t.includes("export default app")){let s=`${t}
|
|
126
|
+
|
|
127
|
+
export default app;
|
|
128
|
+
`;await S.writeFile(a,s)}}async function Bt(e,a,t){f({dependencies:["@hono/node-server"],devDependencies:["tsx","@types/node"],projectDir:e});let o=B.join(e,"package.json"),r=await S.readJson(o);r.scripts={...r.scripts,dev:"tsx watch src/index.ts",start:"node dist/src/index.js"},await S.writeJson(o,r,{spaces:2});let s=`import { serve } from "@hono/node-server";
|
|
129
|
+
`,i=`
|
|
130
|
+
serve(
|
|
131
|
+
{
|
|
132
|
+
fetch: app.fetch,
|
|
133
|
+
port: 3000,
|
|
134
|
+
},
|
|
135
|
+
(info) => {
|
|
136
|
+
console.log(\`Server is running on http://localhost:\${info.port}\`);
|
|
137
|
+
},
|
|
138
|
+
);
|
|
139
|
+
`;if(t.includes("@hono/node-server")){if(!t.includes("serve(")){let n=t+i;await S.writeFile(a,n)}}else{let n=t.lastIndexOf("import"),d=t.substring(0,n),P=t.substring(n),w=d+s+P+i;await S.writeFile(a,w)}}import v from"node:path";import y from"fs-extra";async function Pe(e){let a=v.join(g,"template/base");if(!await y.pathExists(a))throw new Error(`Template directory not found: ${a}`);await y.copy(a,e)}async function ke(e,a){if(!a)return;let t=v.join(g,"template/with-auth");await y.pathExists(t)&&await y.copy(t,e,{overwrite:!0})}async function je(e,a,t,o){if(a==="none"||t==="none")return;let r=v.join(g,Jt(a,t));if(await y.pathExists(r)){await y.copy(r,e,{overwrite:!0});let s=v.join(e,"apps/server/src"),i=v.join(s,"lib"),n=v.join(s,"with-auth-lib");o?await y.pathExists(n)&&(await y.remove(i),await y.move(n,i)):await y.remove(n)}}async function ve(e){let a=[v.join(e,"_gitignore"),v.join(e,"apps/client/_gitignore"),v.join(e,"apps/server/_gitignore")];for(let t of a)if(await y.pathExists(t)){let o=v.join(v.dirname(t),".gitignore");await y.move(t,o)}}function Jt(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"}async function Te(e){let a=Vt(),t=Gt.resolve(process.cwd(),e.projectName);try{return await Ht.ensureDir(t),await Pe(t),await ve(t),await ke(t,e.auth),await je(t,e.orm,e.database,e.auth),await ye(t,e.runtime),await he(t,e.examples,e.orm,e.auth),await me(t,e.database,e.orm,e.turso??e.database==="sqlite"),await ne(t,e.auth),await fe(t,e),await be(t,e.git),e.addons.length>0&&await ae(t,e.addons,e.packageManager),await we(t,e),await ce(t,e),ge(e.database,e.projectName,e.packageManager,!e.noInstall,e.orm,e.addons,e.runtime),t}catch(o){throw a.message(xe.red("Failed")),o instanceof Error&&(qt(xe.red(`Error during project creation: ${o.message}`)),process.exit(1)),o}}import{log as $e,spinner as Ee}from"@clack/prompts";import{$ as Q}from"execa";import J from"picocolors";async function Ce({projectDir:e,packageManager:a,addons:t=[]}){let o=Ee();try{switch(o.start(`Running ${a} install...`),a){case"npm":await Q({cwd:e,stderr:"inherit"})`${a} install`;break;case"pnpm":case"bun":await Q({cwd:e})`${a} install`;break}o.stop("Dependencies installed successfully"),(t.includes("biome")||t.includes("husky"))&&await Wt(e,a)}catch(r){throw o.stop(J.red("Failed to install dependencies")),r instanceof Error&&$e.error(J.red(`Installation error: ${r.message}`)),r}}async function Wt(e,a){let t=Ee();try{t.start("Running Biome format check..."),await Q({cwd:e})`${a} biome check --write .`,t.stop("Biome check completed successfully")}catch{t.stop(J.yellow("Biome check encountered issues")),$e.warn(J.yellow("Some files may need manual formatting"))}}import{cancel as _a,group as Ma}from"@clack/prompts";import Ba from"picocolors";import{cancel as Qt,isCancel as Kt,multiselect as Xt}from"@clack/prompts";import Yt from"picocolors";async function Se(e){if(e!==void 0)return e;let a=await Xt({message:"Which Addons would you like to add?",options:[{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"},{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)"}],required:!1});return Kt(a)&&(Qt(Yt.red("Operation cancelled")),process.exit(0)),a.includes("husky")&&!a.includes("biome")&&a.push("biome"),a}import{cancel as Zt,confirm as ea,isCancel as ta}from"@clack/prompts";import aa from"picocolors";async function Oe(e,a){if(!a)return!1;if(e!==void 0)return e;let t=await ea({message:"Would you like to add authentication with Better-Auth?",initialValue:u.auth});return ta(t)&&(Zt(aa.red("Operation cancelled")),process.exit(0)),t}async function Ae(e){return e!==void 0?e:"hono"}import{cancel as oa,isCancel as ra,select as sa}from"@clack/prompts";import ia from"picocolors";async function Re(e){if(e!==void 0)return e;let a=await sa({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:"sqlite"});return ra(a)&&(oa(ia.red("Operation cancelled")),process.exit(0)),a}import{cancel as na,isCancel as ca,multiselect as pa}from"@clack/prompts";import la from"picocolors";async function Ie(e,a){if(e!==void 0)return e;if(a==="none")return[];let t=await pa({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});return ca(t)&&(na(la.red("Operation cancelled")),process.exit(0)),t}import{cancel as ua,confirm as da,isCancel as ma}from"@clack/prompts";import fa from"picocolors";async function De(e){if(e!==void 0)return e;let a=await da({message:"Initialize a new git repository?",initialValue:u.git});return ma(a)&&(ua(fa.red("Operation cancelled")),process.exit(0)),a}import{cancel as ha,confirm as ga,isCancel as wa}from"@clack/prompts";import ba from"picocolors";async function Fe(e){if(e!==void 0)return e;let a=await ga({message:"Do you want to install project dependencies?",initialValue:!u.noInstall});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 ja from"picocolors";async function ze(e,a){if(!a)return"none";if(e!==void 0)return e;let t=await ka({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 with schema migrations"}],initialValue:"drizzle"});return Pa(t)&&(ya(ja.red("Operation cancelled")),process.exit(0)),t}import{cancel as va,isCancel as xa,select as Ta}from"@clack/prompts";import $a from"picocolors";var Le=()=>{let e=process.env.npm_config_user_agent;return e?.startsWith("pnpm")?"pnpm":e?.startsWith("bun")?"bun":"npm"};async function Ne(e){if(e!==void 0)return e;let a=Le(),t=await Ta({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 xa(t)&&(va($a.red("Operation cancelled")),process.exit(0)),t}import L from"node:path";import{cancel as Ea,isCancel as Ca,text as Sa}from"@clack/prompts";import R from"fs-extra";import Oa from"picocolors";var Aa=["<",">",":",'"',"|","?","*"],Ue=255;function _e(e){if(e!=="."){if(!e)return"Project name cannot be empty";if(e.length>Ue)return`Project name must be less than ${Ue} characters`;if(Aa.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 Me(e){if(e)if(e==="."){let s=process.cwd();if(R.readdirSync(s).length===0)return e}else{let s=L.basename(e);if(!_e(s)){let n=L.resolve(process.cwd(),e);if(!R.pathExistsSync(n)||R.readdirSync(n).length===0)return e}}let a=!1,t="",o=u.projectName,r=1;for(;R.pathExistsSync(L.resolve(process.cwd(),o));)o=`${u.projectName}-${r}`,r++;for(;!a;){let s=await Sa({message:"Enter your project name or path (relative to current directory)",placeholder:o,initialValue:e,defaultValue:o,validate:i=>{let n=i.trim()||o;if(n==="."){if(R.readdirSync(process.cwd()).length>0)return"Current directory is not empty. Please choose a different directory.";a=!0;return}let d=L.resolve(process.cwd(),n),P=L.basename(d),w=_e(P);if(w)return w;if(!d.startsWith(process.cwd()))return"Project path must be within current directory";if(R.pathExistsSync(d)&&R.readdirSync(d).length>0)return`Directory "${n}" already exists and is not empty. Please choose a different name or path.`;a=!0}});Ca(s)&&(Ea(Oa.red("Operation cancelled.")),process.exit(0)),t=s||o}return t}import{cancel as Ra,isCancel as Ia,select as Da}from"@clack/prompts";import Fa from"picocolors";async function Be(e){if(e!==void 0)return e;let a=await Da({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:"bun"});return Ia(a)&&(Ra(Fa.red("Operation cancelled")),process.exit(0)),a}import{cancel as za,confirm as La,isCancel as Na}from"@clack/prompts";import Ua from"picocolors";async function Je(e){if(e!==void 0)return e;let a=await La({message:"Set up a Turso database for this project?",initialValue:!0});return Na(a)&&(za(Ua.red("Operation cancelled")),process.exit(0)),a}async function Ge(e){let a=await Ma({projectName:async()=>Me(e.projectName),runtime:()=>Be(e.runtime),backendFramework:()=>Ae(e.backendFramework),database:()=>Re(e.database),orm:({results:t})=>ze(e.orm,t.database!=="none"),auth:({results:t})=>Oe(e.auth,t.database!=="none"),turso:({results:t})=>t.database==="sqlite"&&t.orm!=="prisma"?Je(e.turso):Promise.resolve(!1),addons:()=>Se(e.addons),examples:({results:t})=>Ie(e.examples,t.database),git:()=>De(e.git),packageManager:()=>Ne(e.packageManager),noInstall:()=>Fe(e.noInstall)},{onCancel:()=>{_a(Ba.red("Operation cancelled")),process.exit(0)}});return{projectName:a.projectName,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 $ from"picocolors";function K(e){let a=[];return e.projectName&&a.push(`${$.blue("Project Name:")} ${e.projectName}`),e.database&&a.push(`${$.blue("Database:")} ${e.database}`),e.orm&&a.push(`${$.blue("ORM:")} ${e.orm}`),e.auth!==void 0&&a.push(`${$.blue("Authentication:")} ${e.auth}`),e.runtime&&a.push(`${$.blue("Runtime:")} ${e.runtime}`),e.addons?.length&&a.push(`${$.blue("Addons:")} ${e.addons.join(", ")}`),e.git!==void 0&&a.push(`${$.blue("Git Init:")} ${e.git}`),e.packageManager&&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(`
|
|
140
|
+
`)}function qe(e){let a=[];if(e.database==="none"?a.push("--no-database"):e.database==="sqlite"?a.push("--sqlite"):e.database==="postgres"&&a.push("--postgres"),e.database!=="none"&&(e.orm==="drizzle"?a.push("--drizzle"):e.orm==="prisma"&&a.push("--prisma")),e.auth?a.push("--auth"):a.push("--no-auth"),e.git?a.push("--git"):a.push("--no-git"),e.noInstall?a.push("--no-install"):a.push("--install"),e.packageManager&&a.push(`--${e.packageManager}`),e.addons.length>0)for(let s of e.addons)a.push(`--${s}`);else a.push("--no-addons");e.examples&&e.examples.length>0?a.push(`--examples ${e.examples.join(",")}`):a.push("--no-examples"),e.database==="sqlite"&&(e.turso?a.push("--turso"):a.push("--no-turso")),e.runtime&&a.push(`--runtime ${e.runtime}`);let t="npx create-better-t-stack",o=e.projectName?` ${e.projectName}`:"",r=a.length>0?` ${a.join(" ")}`:"";return`${t}${o}${r}`}import Ja from"node:path";import Ga from"fs-extra";var Ve=()=>{let e=Ja.join(g,"package.json");return Ga.readJSONSync(e).version??"1.0.0"};import He from"gradient-string";var We=`
|
|
127
141
|
\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
|
|
128
142
|
\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
|
|
129
143
|
\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
|
|
@@ -137,10 +151,10 @@ ${p.yellow("NOTE:")} Tauri requires Rust and platform-specific dependencies. See
|
|
|
137
151
|
\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
|
|
138
152
|
\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
|
|
139
153
|
\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
|
|
140
|
-
`,
|
|
141
|
-
`),
|
|
154
|
+
`,Qe={pink:"#F5C2E7",mauve:"#CBA6F7",red:"#F38BA8",maroon:"#E78284",peach:"#FAB387",yellow:"#F9E2AF",green:"#A6E3A1",teal:"#94E2D5",sky:"#89DCEB",sapphire:"#74C7EC",lavender:"#B4BEFE"},Ke=()=>{let e=process.stdout.columns||80,a=We.split(`
|
|
155
|
+
`),t=Math.max(...a.map(o=>o.length));e<t?console.log(He(Object.values(Qe)).multiline(`
|
|
142
156
|
\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557
|
|
143
157
|
\u2551 Better T-Stack \u2551
|
|
144
158
|
\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D
|
|
145
|
-
`)):console.log(
|
|
146
|
-
${
|
|
159
|
+
`)):console.log(He(Object.values(Qe)).multiline(We))};process.on("SIGINT",()=>{x.error(E.red("Operation cancelled")),process.exit(0)});var X=new Qa;async function Ka(){let e=Date.now();X.name("create-better-t-stack").description("Create a new Better-T Stack project").version(Ve()).argument("[project-directory]","Project name/directory").option("-y, --yes","Use default configuration").option("--no-database","Skip database setup").option("--sqlite","Use SQLite database").option("--postgres","Use PostgreSQL database").option("--auth","Include authentication").option("--no-auth","Exclude authentication").option("--pwa","Include Progressive Web App support").option("--tauri","Include Tauri desktop app support").option("--biome","Include Biome for linting and formatting").option("--husky","Include Husky, lint-staged for Git hooks").option("--no-addons","Skip all additional addons").option("--examples <examples>","Include specified examples").option("--no-examples","Skip all examples").option("--git","Include git setup").option("--no-git","Skip git initialization").option("--npm","Use npm package manager").option("--pnpm","Use pnpm package manager").option("--bun","Use bun package manager").option("--drizzle","Use Drizzle ORM").option("--prisma","Use Prisma ORM (coming soon)").option("--install","Install dependencies").option("--no-install","Skip installing dependencies").option("--turso","Set up Turso for SQLite database").option("--no-turso","Skip Turso setup for SQLite database").option("--hono","Use Hono backend framework").option("--runtime <runtime>","Specify runtime (bun or node)").parse();let a=Wa();try{Ke(),Va(E.magenta("Creating a new Better-T-Stack project"));let t=X.opts(),o=X.args[0],r={...o&&{projectName:o},...t.database===!1&&{database:"none"},...t.sqlite&&{database:"sqlite"},...t.postgres&&{database:"postgres"},...t.drizzle&&{orm:"drizzle"},...t.prisma&&{orm:"prisma"},..."auth"in t&&{auth:t.auth},...t.npm&&{packageManager:"npm"},...t.pnpm&&{packageManager:"pnpm"},...t.bun&&{packageManager:"bun"},..."git"in t&&{git:t.git},..."install"in t&&{noInstall:!t.install},..."turso"in t&&{turso:t.turso},...t.hono&&{backendFramework:"hono"},...t.runtime&&{runtime:t.runtime},...(t.pwa||t.tauri||t.biome||t.husky||t.addons===!1)&&{addons:t.addons===!1?[]:[...t.pwa?["pwa"]:[],...t.tauri?["tauri"]:[],...t.biome?["biome"]:[],...t.husky?["husky"]:[]]},...(t.examples||t.examples===!1)&&{examples:t.examples===!1?[]:typeof t.examples=="string"?t.examples.split(",").filter(d=>d==="todo"):[]}};!t.yes&&Object.keys(r).length>0&&(x.info(E.yellow("Using these pre-selected options:")),x.message(K(r)),x.message(""));let s=t.yes?{...u,projectName:o??u.projectName,database:t.database===!1?"none":t.database??u.database,orm:t.database===!1?"none":t.drizzle?"drizzle":t.prisma?"prisma":u.orm,auth:t.auth??u.auth,git:t.git??u.git,noInstall:"noInstall"in t?t.noInstall:u.noInstall,packageManager:r.packageManager??u.packageManager,addons:r.addons?.length?r.addons:u.addons,examples:r.examples?.length?r.examples:u.examples,turso:"turso"in t?t.turso:r.database==="sqlite"?u.turso:!1,backendFramework:t.hono?"hono":u.backendFramework,runtime:t.runtime?t.runtime:u.runtime}:await Ge(r);t.yes&&(x.info(E.yellow("Using these default options:")),x.message(K(s)),x.message(""));let i=await Te(s);s.noInstall||await Ce({projectDir:i,packageManager:s.packageManager,addons:s.addons}),x.success(E.blue(`You can reproduce this setup with the following command:
|
|
160
|
+
${E.white(qe(s))}`));let n=((Date.now()-e)/1e3).toFixed(2);Ha(E.magenta(`Project created successfully in ${E.bold(n)} seconds!`))}catch(t){a.stop(E.red("Failed")),t instanceof Error&&(qa(E.red(`An unexpected error occurred: ${t.message}`)),process.exit(1))}}Ka().catch(e=>{x.error("Aborting installation..."),e instanceof Error?x.error(e.message):(x.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,22 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-better-t-stack",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "CLI tool to scaffold Better-T Stack projects",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"bin": {
|
|
8
8
|
"create-better-t-stack": "dist/index.js"
|
|
9
9
|
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"template"
|
|
13
|
+
],
|
|
10
14
|
"keywords": [],
|
|
11
15
|
"repository": {
|
|
12
16
|
"type": "git",
|
|
13
17
|
"url": "git+https://github.com/better-t-stack/create-better-t-stack.git",
|
|
14
18
|
"directory": "apps/cli"
|
|
15
19
|
},
|
|
16
|
-
"files": [
|
|
17
|
-
"dist",
|
|
18
|
-
"template"
|
|
19
|
-
],
|
|
20
20
|
"homepage": "https://better-t-stack.pages.dev/",
|
|
21
21
|
"scripts": {
|
|
22
22
|
"build": "tsup",
|
|
@@ -29,14 +29,12 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@clack/prompts": "^0.10.0",
|
|
31
31
|
"commander": "^13.1.0",
|
|
32
|
-
"degit": "^2.8.4",
|
|
33
32
|
"execa": "^8.0.1",
|
|
34
33
|
"fs-extra": "^11.3.0",
|
|
35
34
|
"gradient-string": "^3.0.0",
|
|
36
35
|
"picocolors": "^1.1.1"
|
|
37
36
|
},
|
|
38
37
|
"devDependencies": {
|
|
39
|
-
"@types/degit": "^2.8.6",
|
|
40
38
|
"@types/fs-extra": "^11.0.4",
|
|
41
39
|
"@types/node": "^20.17.19",
|
|
42
40
|
"tsup": "^8.4.0",
|
|
@@ -3,15 +3,11 @@
|
|
|
3
3
|
"main": "src/index.ts",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"dev": "tsx watch src/index.ts",
|
|
7
|
-
"start": "node dist/src/index.js",
|
|
8
6
|
"build": "tsc && tsc-alias",
|
|
9
|
-
"dev:bun": "bun run --hot src/index.ts",
|
|
10
7
|
"check-types": "tsc --noEmit",
|
|
11
8
|
"compile": "bun build --compile --minify --sourcemap --bytecode ./src/index.ts --outfile server"
|
|
12
9
|
},
|
|
13
10
|
"dependencies": {
|
|
14
|
-
"@hono/node-server": "^1.14.0",
|
|
15
11
|
"@hono/trpc-server": "^0.3.4",
|
|
16
12
|
"@trpc/server": "^11.0.0",
|
|
17
13
|
"dotenv": "^16.4.7",
|
|
@@ -19,9 +15,7 @@
|
|
|
19
15
|
"zod": "^3.24.2"
|
|
20
16
|
},
|
|
21
17
|
"devDependencies": {
|
|
22
|
-
|
|
23
|
-
"tsx": "^4.19.2",
|
|
24
|
-
"@types/node": "^22.13.11",
|
|
18
|
+
"tsc-alias": "^1.8.11",
|
|
25
19
|
"typescript": "^5.8.2"
|
|
26
20
|
}
|
|
27
21
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { serve } from "@hono/node-server";
|
|
2
1
|
import { trpcServer } from "@hono/trpc-server";
|
|
3
2
|
import "dotenv/config";
|
|
4
3
|
import { Hono } from "hono";
|
|
@@ -12,30 +11,23 @@ const app = new Hono();
|
|
|
12
11
|
app.use(logger());
|
|
13
12
|
|
|
14
13
|
app.use(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
"/*",
|
|
15
|
+
cors({
|
|
16
|
+
origin: process.env.CORS_ORIGIN || "",
|
|
17
|
+
allowMethods: ["GET", "POST", "OPTIONS"],
|
|
18
|
+
}),
|
|
20
19
|
);
|
|
21
20
|
|
|
22
21
|
app.use(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
"/trpc/*",
|
|
23
|
+
trpcServer({
|
|
24
|
+
router: appRouter,
|
|
25
|
+
createContext: (_opts, hono) => {
|
|
26
|
+
return createContext({ hono });
|
|
27
|
+
},
|
|
28
|
+
}),
|
|
30
29
|
);
|
|
31
30
|
|
|
32
31
|
app.get("/", (c) => {
|
|
33
|
-
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
serve({
|
|
37
|
-
fetch: app.fetch,
|
|
38
|
-
port: 3000,
|
|
39
|
-
}, (info) => {
|
|
40
|
-
console.log(`Server is running on http://localhost:${info.port}`)
|
|
32
|
+
return c.text("OK");
|
|
41
33
|
});
|
|
@@ -31,10 +31,10 @@ export default function SignInForm({
|
|
|
31
31
|
},
|
|
32
32
|
{
|
|
33
33
|
onSuccess: () => {
|
|
34
|
-
toast.success("Sign in successful");
|
|
35
34
|
navigate({
|
|
36
35
|
to: "/dashboard",
|
|
37
36
|
});
|
|
37
|
+
toast.success("Sign in successful");
|
|
38
38
|
},
|
|
39
39
|
onError: (error) => {
|
|
40
40
|
toast.error(error.error.message);
|
|
@@ -9,156 +9,156 @@ import { Input } from "./ui/input";
|
|
|
9
9
|
import { Label } from "./ui/label";
|
|
10
10
|
|
|
11
11
|
export default function SignUpForm({
|
|
12
|
-
|
|
12
|
+
onSwitchToSignIn,
|
|
13
13
|
}: {
|
|
14
|
-
|
|
14
|
+
onSwitchToSignIn: () => void;
|
|
15
15
|
}) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
const navigate = useNavigate({
|
|
17
|
+
from: "/",
|
|
18
|
+
});
|
|
19
|
+
const { isPending } = authClient.useSession();
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
21
|
+
const form = useForm({
|
|
22
|
+
defaultValues: {
|
|
23
|
+
email: "",
|
|
24
|
+
password: "",
|
|
25
|
+
name: "",
|
|
26
|
+
},
|
|
27
|
+
onSubmit: async ({ value }) => {
|
|
28
|
+
await authClient.signUp.email(
|
|
29
|
+
{
|
|
30
|
+
email: value.email,
|
|
31
|
+
password: value.password,
|
|
32
|
+
name: value.name,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
onSuccess: () => {
|
|
36
|
+
navigate({
|
|
37
|
+
to: "/dashboard",
|
|
38
|
+
});
|
|
39
|
+
toast.success("Sign up successful");
|
|
40
|
+
},
|
|
41
|
+
onError: (error) => {
|
|
42
|
+
toast.error(error.error.message);
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
);
|
|
46
|
+
},
|
|
47
|
+
validators: {
|
|
48
|
+
onSubmit: z.object({
|
|
49
|
+
name: z.string().min(2, "Name must be at least 2 characters"),
|
|
50
|
+
email: z.string().email("Invalid email address"),
|
|
51
|
+
password: z.string().min(6, "Password must be at least 6 characters"),
|
|
52
|
+
}),
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
if (isPending) {
|
|
57
|
+
return <Loader />;
|
|
58
|
+
}
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
return (
|
|
61
|
+
<div className="mx-auto mt-10 max-w-md p-6">
|
|
62
|
+
<h1 className="mb-6 text-center text-3xl font-bold">Create Account</h1>
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
64
|
+
<form
|
|
65
|
+
onSubmit={(e) => {
|
|
66
|
+
e.preventDefault();
|
|
67
|
+
e.stopPropagation();
|
|
68
|
+
void form.handleSubmit();
|
|
69
|
+
}}
|
|
70
|
+
className="space-y-4"
|
|
71
|
+
>
|
|
72
|
+
<div>
|
|
73
|
+
<form.Field name="name">
|
|
74
|
+
{(field) => (
|
|
75
|
+
<div className="space-y-2">
|
|
76
|
+
<Label htmlFor={field.name}>Name</Label>
|
|
77
|
+
<Input
|
|
78
|
+
id={field.name}
|
|
79
|
+
name={field.name}
|
|
80
|
+
value={field.state.value}
|
|
81
|
+
onBlur={field.handleBlur}
|
|
82
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
83
|
+
/>
|
|
84
|
+
{field.state.meta.errors.map((error) => (
|
|
85
|
+
<p key={error?.message} className="text-red-500">
|
|
86
|
+
{error?.message}
|
|
87
|
+
</p>
|
|
88
|
+
))}
|
|
89
|
+
</div>
|
|
90
|
+
)}
|
|
91
|
+
</form.Field>
|
|
92
|
+
</div>
|
|
93
93
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
94
|
+
<div>
|
|
95
|
+
<form.Field name="email">
|
|
96
|
+
{(field) => (
|
|
97
|
+
<div className="space-y-2">
|
|
98
|
+
<Label htmlFor={field.name}>Email</Label>
|
|
99
|
+
<Input
|
|
100
|
+
id={field.name}
|
|
101
|
+
name={field.name}
|
|
102
|
+
type="email"
|
|
103
|
+
value={field.state.value}
|
|
104
|
+
onBlur={field.handleBlur}
|
|
105
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
106
|
+
/>
|
|
107
|
+
{field.state.meta.errors.map((error) => (
|
|
108
|
+
<p key={error?.message} className="text-red-500">
|
|
109
|
+
{error?.message}
|
|
110
|
+
</p>
|
|
111
|
+
))}
|
|
112
|
+
</div>
|
|
113
|
+
)}
|
|
114
|
+
</form.Field>
|
|
115
|
+
</div>
|
|
116
116
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
117
|
+
<div>
|
|
118
|
+
<form.Field name="password">
|
|
119
|
+
{(field) => (
|
|
120
|
+
<div className="space-y-2">
|
|
121
|
+
<Label htmlFor={field.name}>Password</Label>
|
|
122
|
+
<Input
|
|
123
|
+
id={field.name}
|
|
124
|
+
name={field.name}
|
|
125
|
+
type="password"
|
|
126
|
+
value={field.state.value}
|
|
127
|
+
onBlur={field.handleBlur}
|
|
128
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
129
|
+
/>
|
|
130
|
+
{field.state.meta.errors.map((error) => (
|
|
131
|
+
<p key={error?.message} className="text-red-500">
|
|
132
|
+
{error?.message}
|
|
133
|
+
</p>
|
|
134
|
+
))}
|
|
135
|
+
</div>
|
|
136
|
+
)}
|
|
137
|
+
</form.Field>
|
|
138
|
+
</div>
|
|
139
139
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
140
|
+
<form.Subscribe>
|
|
141
|
+
{(state) => (
|
|
142
|
+
<Button
|
|
143
|
+
type="submit"
|
|
144
|
+
className="w-full"
|
|
145
|
+
disabled={!state.canSubmit || state.isSubmitting}
|
|
146
|
+
>
|
|
147
|
+
{state.isSubmitting ? "Submitting..." : "Sign Up"}
|
|
148
|
+
</Button>
|
|
149
|
+
)}
|
|
150
|
+
</form.Subscribe>
|
|
151
|
+
</form>
|
|
152
152
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
153
|
+
<div className="mt-4 text-center">
|
|
154
|
+
<Button
|
|
155
|
+
variant="link"
|
|
156
|
+
onClick={onSwitchToSignIn}
|
|
157
|
+
className="text-indigo-600 hover:text-indigo-800"
|
|
158
|
+
>
|
|
159
|
+
Already have an account? Sign In
|
|
160
|
+
</Button>
|
|
161
|
+
</div>
|
|
162
|
+
</div>
|
|
163
|
+
);
|
|
164
164
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { serve } from "@hono/node-server";
|
|
2
1
|
import { trpcServer } from "@hono/trpc-server";
|
|
3
2
|
import "dotenv/config";
|
|
4
3
|
import { Hono } from "hono";
|
|
@@ -13,34 +12,27 @@ const app = new Hono();
|
|
|
13
12
|
app.use(logger());
|
|
14
13
|
|
|
15
14
|
app.use(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
"/*",
|
|
16
|
+
cors({
|
|
17
|
+
origin: process.env.CORS_ORIGIN || "",
|
|
18
|
+
allowMethods: ["GET", "POST", "OPTIONS"],
|
|
19
|
+
allowHeaders: ["Content-Type", "Authorization"],
|
|
20
|
+
credentials: true,
|
|
21
|
+
}),
|
|
23
22
|
);
|
|
24
23
|
|
|
25
24
|
app.on(["POST", "GET"], "/api/auth/**", (c) => auth.handler(c.req.raw));
|
|
26
25
|
|
|
27
26
|
app.use(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
"/trpc/*",
|
|
28
|
+
trpcServer({
|
|
29
|
+
router: appRouter,
|
|
30
|
+
createContext: (_opts, hono) => {
|
|
31
|
+
return createContext({ hono });
|
|
32
|
+
},
|
|
33
|
+
}),
|
|
35
34
|
);
|
|
36
35
|
|
|
37
36
|
app.get("/", (c) => {
|
|
38
|
-
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
serve({
|
|
42
|
-
fetch: app.fetch,
|
|
43
|
-
port: 3000,
|
|
44
|
-
}, (info) => {
|
|
45
|
-
console.log(`Server is running on http://localhost:${info.port}`)
|
|
37
|
+
return c.text("OK");
|
|
46
38
|
});
|
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
import { router, publicProcedure, protectedProcedure } from "../lib/trpc";
|
|
1
|
+
import { protectedProcedure, publicProcedure, router } from "../lib/trpc";
|
|
3
2
|
import { todoRouter } from "./todo";
|
|
4
3
|
|
|
5
|
-
|
|
6
4
|
export const appRouter = router({
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
5
|
+
healthCheck: publicProcedure.query(() => {
|
|
6
|
+
return "OK";
|
|
7
|
+
}),
|
|
8
|
+
privateData: protectedProcedure.query(({ ctx }) => {
|
|
9
|
+
return {
|
|
10
|
+
message: "This is private",
|
|
11
|
+
user: ctx.session.user,
|
|
12
|
+
};
|
|
13
|
+
}),
|
|
14
|
+
todo: todoRouter,
|
|
17
15
|
});
|
|
18
16
|
|
|
19
17
|
export type AppRouter = typeof appRouter;
|