create-better-t-stack 1.3.0 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +27 -27
- package/package.json +1 -1
- package/template/base/apps/web/package.json +1 -0
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{cancel as uo,intro as mo,log as $,outro as fo,spinner as ho}from"@clack/prompts";import{Command as
|
|
2
|
+
import{cancel as uo,intro as mo,log as $,outro as fo,spinner as ho}from"@clack/prompts";import{Command as wo}from"commander";import F from"picocolors";import te from"node:path";import{fileURLToPath as it}from"node:url";var B=()=>{let e=process.env.npm_config_user_agent;return e?.startsWith("pnpm")?"pnpm":e?.startsWith("bun")?"bun":"npm"};var st=it(import.meta.url),ct=te.dirname(st),P=te.join(ct,"../"),c={projectName:"my-better-t-app",frontend:["web"],database:"sqlite",orm:"drizzle",auth:!0,addons:[],examples:[],git:!0,packageManager:B(),noInstall:!1,turso:!1,backendFramework:"hono",runtime:"bun"},H={"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"};import aa from"node:path";import{cancel as oa,spinner as ra}from"@clack/prompts";import na from"fs-extra";import Oe from"picocolors";import A from"node:path";import y from"fs-extra";import pt from"node:path";import ae from"fs-extra";var w=e=>{let{dependencies:a=[],devDependencies:t=[],projectDir:o}=e,r=pt.join(o,"package.json"),n=ae.readJSONSync(r);n.dependencies||(n.dependencies={}),n.devDependencies||(n.devDependencies={});for(let i of a){let s=H[i];n.dependencies[i]=s}for(let i of t){let s=H[i];n.devDependencies[i]=s}ae.writeJSONSync(r,n,{spaces:2})};import M from"node:path";import{log as lt,spinner as dt}from"@clack/prompts";import{execa as ut}from"execa";import G from"fs-extra";import oe from"picocolors";async function re(e,a){let t=dt(),o=M.join(e,"apps/web");if(await G.pathExists(o))try{t.start("Setting up Tauri desktop app support..."),w({devDependencies:["@tauri-apps/cli"],projectDir:o});let r=M.join(o,"package.json");if(await G.pathExists(r)){let s=await G.readJson(r);s.scripts={...s.scripts,tauri:"tauri","desktop:dev":"tauri dev","desktop:build":"tauri build"},await G.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=${M.basename(e)}`,`--window-title=${M.basename(e)}`,"--frontend-dist=dist","--dev-url=http://localhost:3001",`--before-dev-command=${a} run dev`,`--before-build-command=${a} run build`],await ut(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&<.error(oe.red(r.message)),r}}async function ne(e,a,t,o){let r=o.includes("web");a.includes("pwa")&&r&&await ht(e),a.includes("tauri")&&r&&await re(e,t),a.includes("biome")&&await mt(e),a.includes("husky")&&await ft(e)}async function mt(e){let a=A.join(P,"template/with-biome");await y.pathExists(a)&&await y.copy(a,e,{overwrite:!0}),w({devDependencies:["@biomejs/biome"],projectDir:e});let t=A.join(e,"package.json");if(await y.pathExists(t)){let o=await y.readJson(t);o.scripts={...o.scripts,check:"biome check --write ."},await y.writeJson(t,o,{spaces:2})}}async function ft(e){let a=A.join(P,"template/with-husky");await y.pathExists(a)&&await y.copy(a,e,{overwrite:!0}),w({devDependencies:["husky","lint-staged"],projectDir:e});let t=A.join(e,"package.json");if(await y.pathExists(t)){let o=await y.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 y.writeJson(t,o,{spaces:2})}}async function ht(e){let a=A.join(P,"template/with-pwa");await y.pathExists(a)&&await y.copy(a,e,{overwrite:!0});let t=A.join(e,"apps/web");if(!await y.pathExists(t))return;w({dependencies:["vite-plugin-pwa"],devDependencies:["@vite-pwa/assets-generator"],projectDir:t});let o=A.join(t,"package.json");if(await y.pathExists(o)){let r=await y.readJson(o);r.scripts={...r.scripts,"generate-pwa-assets":"pwa-assets-generator"},await y.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{w({dependencies:["better-auth"],projectDir:t}),w({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"),w({dependencies:r,devDependencies:n,projectDir:o})}import gt from"node:path";import bt from"fs-extra";async function ue(e,a){let t=gt.join(e,"README.md"),o=yt(a);try{await bt.writeFile(t,o)}catch(r){console.error("Failed to create README.md file:",r)}}function yt(e){let{projectName:a,packageManager:t,database:o,auth:r,addons:n=[],orm:i="drizzle",runtime:s="bun"}=e,u=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
|
+
${Pt(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
|
-
${
|
|
18
|
+
${kt(o,r,u,i)}
|
|
19
19
|
|
|
20
20
|
Then, run the development server:
|
|
21
21
|
|
|
22
22
|
\`\`\`bash
|
|
23
|
-
${
|
|
23
|
+
${u} dev
|
|
24
24
|
\`\`\`
|
|
25
25
|
|
|
26
26
|
Open [http://localhost:3001](http://localhost:3001) in your browser to see the web application.
|
|
@@ -37,9 +37,9 @@ ${a}/
|
|
|
37
37
|
|
|
38
38
|
## Available Scripts
|
|
39
39
|
|
|
40
|
-
${vt(
|
|
41
|
-
`}function
|
|
42
|
-
`)}function
|
|
40
|
+
${vt(u,o,i,r)}
|
|
41
|
+
`}function Pt(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
|
+
`)}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"}.
|
|
45
45
|
|
|
@@ -68,10 +68,10 @@ ${t} db:push
|
|
|
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 It,spinner as Lt}from"@clack/prompts";import Nt from"fs-extra";import we from"picocolors";import jt from"node:os";import me from"node:path";import{cancel as Q,confirm as xt,isCancel as K,log as I,select as Tt,spinner as X,text as Et}from"@clack/prompts";import{$ as E}from"execa";import $t from"fs-extra";import x from"picocolors";async function Ft(){try{return(await E`turso --version`).exitCode===0}catch{return!1}}async function Ct(){try{return!(await E`turso auth whoami`).stdout.includes("You are not logged in")}catch{return!1}}async function Ot(){let e=X();try{return e.start("Logging in to Turso..."),await E`turso auth login`,e.stop("Logged in to Turso successfully!"),!0}catch(a){throw e.stop(x.red("Failed to log in to Turso")),a}}async function St(e){let a=X();try{if(a.start("Installing Turso CLI..."),e)await E`brew install tursodatabase/tap/turso`;else{let{stdout:t}=await E`curl -sSfL https://get.tur.so/install.sh`;await E`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(x.yellow("Turso CLI installation cancelled by user")),new Error("Installation cancelled")):(a.stop(x.red("Failed to install Turso CLI")),t)}}async function Dt(){try{let{stdout:e}=await E`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 At(){let e=await Dt();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 Tt({message:"Select a Turso database group:",options:a});return K(t)&&(Q(x.red("Operation cancelled")),process.exit(0)),t}async function Rt(e,a){try{a?await E`turso db create ${e} --group ${a}`:await E`turso db create ${e}`}catch(r){throw r instanceof Error&&r.message.includes("already exists")?new Error("DATABASE_EXISTS"):r}let{stdout:t}=await E`turso db show ${e} --url`,{stdout:o}=await E`turso db tokens create ${e}`;return{dbUrl:t.trim(),authToken:o.trim()}}async function _(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 $t.writeFile(t,o)}function
|
|
74
|
+
TURSO_AUTH_TOKEN=`;await $t.writeFile(t,o)}function J(){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,39 +79,39 @@ TURSO_AUTH_TOKEN=`;await $t.writeFile(t,o)}function G(){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 fe(e,a){if(!a){await _(e),
|
|
82
|
+
TURSO_AUTH_TOKEN=your_auth_token`)}async function fe(e,a){if(!a){await _(e),I.info(x.blue("Skipping Turso setup. Setting up empty configuration.")),J();return}let t=jt.platform(),o=t==="darwin";if(!(t!=="win32")){I.warn(x.yellow("Automatic Turso setup is not supported on Windows.")),await _(e),J();return}try{if(!await Ft()){let k=await xt({message:"Would you like to install Turso CLI?",initialValue:!0});if(K(k)&&(Q(x.red("Operation cancelled")),process.exit(0)),!k){await _(e),J();return}await St(o)}await Ct()||await Ot();let s=await At(),u=!1,h="",b=me.basename(e);for(;!u;){let k=await Et({message:"Enter a name for your database:",defaultValue:b,initialValue:b,placeholder:b});K(k)&&(Q(x.red("Operation cancelled")),process.exit(0)),h=k;let C=X();try{C.start(`Creating Turso database "${h}"${s?` in group "${s}"`:""}...`);let j=await Rt(h,s);await _(e,j),C.stop("Turso database configured successfully!"),u=!0}catch(j){if(j instanceof Error&&j.message==="DATABASE_EXISTS")C.stop(x.yellow(`Database "${x.red(h)}" already exists`)),b=`${h}-${Math.floor(Math.random()*1e3)}`;else throw C.stop(x.red("Failed to create Turso database")),j}}}catch(n){I.error(x.red(`Error during Turso setup: ${n}`)),await _(e),J(),I.success("Setup completed with manual configuration required.")}}async function ge(e,a,t,o=!0){let r=Lt(),n=he.join(e,"apps/server");if(a==="none"){await Nt.remove(he.join(n,"src/db"));return}try{a==="sqlite"?(t==="drizzle"?w({dependencies:["drizzle-orm","@libsql/client"],devDependencies:["drizzle-kit"],projectDir:n}):t==="prisma"&&w({dependencies:["@prisma/client"],devDependencies:["prisma"],projectDir:n}),o&&await fe(e,!0)):a==="postgres"&&(t==="drizzle"?w({dependencies:["drizzle-orm","postgres"],devDependencies:["drizzle-kit"],projectDir:n}):t==="prisma"&&w({dependencies:["@prisma/client"],devDependencies:["prisma"],projectDir:n}))}catch(i){throw r.stop(we.red("Failed to set up database")),i instanceof Error&&It.error(we.red(i.message)),i}}import L from"node:path";import O from"fs-extra";async function be(e,a){let t=L.join(e,"apps/server"),o=L.join(t,".env"),r="";if(await O.pathExists(o)&&(r=await O.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
87
|
TURSO_CONNECTION_URL=http://127.0.0.1:8080`))}if(await O.writeFile(o,r.trim()),a.frontend.includes("web")){let n=L.join(e,"apps/web"),i=L.join(n,".env"),s="";await O.pathExists(i)&&(s=await O.readFile(i,"utf8")),s.includes("VITE_SERVER_URL")||(s+=`VITE_SERVER_URL=http://localhost:3000
|
|
88
88
|
`),await O.writeFile(i,s.trim())}if(a.frontend.includes("native")){let n=L.join(e,"apps/native"),i=L.join(n,".env"),s="";await O.pathExists(i)&&(s=await O.readFile(i,"utf8")),s.includes("EXPO_PUBLIC_SERVER_URL")||(s+=`EXPO_PUBLIC_SERVER_URL=http://localhost:3000
|
|
89
|
-
`),await O.writeFile(i,s.trim())}}import
|
|
89
|
+
`),await O.writeFile(i,s.trim())}}import T from"node:path";import g from"fs-extra";async function ye(e,a,t,o,r=["web"]){let n=r.includes("web"),i=await g.pathExists(T.join(e,"apps/web"));a.includes("todo")&&n&&i?await _t(e,t,o):await zt(e,t)}async function _t(e,a,t){let o=T.join(P,"template/examples/todo");if(await g.pathExists(o)){let r=T.join(o,"apps/web/src/routes"),n=T.join(e,"apps/web/src/routes");if(await g.copy(r,n,{overwrite:!0}),a!=="none"){let i=T.join(o,`apps/server/src/routers/with-${a}-todo.ts`),s=T.join(e,"apps/server/src/routers/todo.ts");await g.pathExists(i)&&await g.copy(i,s,{overwrite:!0})}await Ut(e,t),await Mt(e)}}async function Ut(e,a){let t=T.join(e,"apps/web/src/components/header.tsx");if(await g.pathExists(t)){let o=await g.readFile(t,"utf8");a?o=o.replace(/const links = \[\s*{ to: "\/", label: "Home" },\s*{ to: "\/dashboard", label: "Dashboard" },/,`const links = [
|
|
90
90
|
{ to: "/", label: "Home" },
|
|
91
91
|
{ to: "/dashboard", label: "Dashboard" },
|
|
92
92
|
{ to: "/todos", label: "Todos" },`):o=o.replace(/const links = \[\s*{ to: "\/", label: "Home" },/,`const links = [
|
|
93
93
|
{ to: "/", label: "Home" },
|
|
94
|
-
{ to: "/todos", label: "Todos" },`),await
|
|
94
|
+
{ to: "/todos", label: "Todos" },`),await g.writeFile(t,o)}}async function zt(e,a){if(a==="drizzle"){let o=T.join(e,"apps/server/src/db/schema/todo.ts");await g.pathExists(o)&&await g.remove(o)}else if(a==="prisma"){let o=T.join(e,"apps/server/prisma/schema/todo.prisma");await g.pathExists(o)&&await g.remove(o)}let t=T.join(e,"apps/server/src/routers/todo.ts");await g.pathExists(t)&&await g.remove(t),await Bt(e)}async function Bt(e){let a=T.join(e,"apps/server/src/routers/index.ts");if(await g.pathExists(a)){let t=await g.readFile(a,"utf8");t=t.replace(/import { todoRouter } from ".\/todo";/,""),t=t.replace(/todo: todoRouter,/,""),await g.writeFile(a,t)}}async function Mt(e){let a=T.join(e,"apps/web/src/routes/index.tsx");if(await g.pathExists(a)){let t=await g.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
95
|
<Button asChild>
|
|
96
96
|
<Link to="/todos" className="flex items-center">
|
|
97
97
|
View Todo Demo
|
|
98
98
|
<ArrowRight className="ml-1 h-4 w-4" />
|
|
99
99
|
</Link>
|
|
100
100
|
</Button>
|
|
101
|
-
</div>`),await
|
|
101
|
+
</div>`),await g.writeFile(a,t)}}import{log as Gt}from"@clack/prompts";import d from"picocolors";function Pe(e,a,t,o,r,n,i,s){let u=t==="npm"?"npm run":t,h=`cd ${a}`,b=n?.includes("husky")||n?.includes("biome"),k=e!=="none"?Vt(e,r,u,i):"",C=n?.includes("tauri")?Wt(u):"",j=b?qt(u):"",z=s?.includes("native")?Jt():"",N=s?.includes("web"),rt=s?.includes("native"),nt=N||rt;Gt.info(`${d.bold("Next steps:")}
|
|
102
102
|
${d.cyan("1.")} ${h}
|
|
103
103
|
${o?"":`${d.cyan("2.")} ${t} install
|
|
104
|
-
`}${d.cyan(o?"2.":"3.")} ${
|
|
104
|
+
`}${d.cyan(o?"2.":"3.")} ${u} dev
|
|
105
105
|
|
|
106
106
|
${d.bold("Your project will be available at:")}
|
|
107
107
|
${nt?`${N?`${d.cyan("\u2022")} Frontend: http://localhost:3001
|
|
108
108
|
`:""}`:`${d.yellow("NOTE:")} You are creating a backend-only app (no frontend selected)
|
|
109
109
|
`}${d.cyan("\u2022")} API: http://localhost:3000
|
|
110
110
|
${z?`
|
|
111
|
-
${z.trim()}`:""}${
|
|
112
|
-
${
|
|
113
|
-
${C.trim()}`:""}${
|
|
114
|
-
${
|
|
111
|
+
${z.trim()}`:""}${k?`
|
|
112
|
+
${k.trim()}`:""}${C?`
|
|
113
|
+
${C.trim()}`:""}${j?`
|
|
114
|
+
${j.trim()}`:""}`)}function Jt(){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
115
|
${d.dim("EXPO_PUBLIC_SERVER_URL=http://192.168.0.103:3000")}
|
|
116
116
|
`}function qt(e){return`${d.bold("Linting and formatting:")}
|
|
117
117
|
${d.cyan("\u2022")} Format and lint fix: ${d.dim(`${e} check`)}
|
|
@@ -125,10 +125,10 @@ ${d.cyan("\u2022")} Start desktop app: ${d.dim(`cd apps/web && ${e} desktop:dev`
|
|
|
125
125
|
${d.cyan("\u2022")} Build desktop app: ${d.dim(`cd apps/web && ${e} desktop:build`)}
|
|
126
126
|
${d.yellow("NOTE:")} Tauri requires Rust and platform-specific dependencies. See: ${d.dim("https://v2.tauri.app/start/prerequisites/")}
|
|
127
127
|
|
|
128
|
-
`}import
|
|
128
|
+
`}import q from"node:path";import{$ as Ht,execa as Qt}from"execa";import S from"fs-extra";async function ke(e,a){await Kt(e,a),await Xt(e,a)}async function Kt(e,a){let t=q.join(e,"package.json");if(await S.pathExists(t)){let o=await S.readJson(t);o.name=a.projectName;let{stdout:r}=await Qt(a.packageManager,["-v"],{cwd:e});if(o.packageManager=`${a.packageManager}@${r.trim()}`,await S.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 S.pathExists(n)&&await S.copy(n,i)}}}async function Xt(e,a){let t=q.join(e,"apps/server/package.json");if(await S.pathExists(t)){let o=await S.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 S.writeJson(t,o,{spaces:2})}}async function ve(e,a){a&&await Ht({cwd:e})`git init`}import V from"node:path";import D from"fs-extra";async function je(e,a,t){let o=V.join(e,"apps/server"),r=V.join(o,"src/index.ts"),n=await D.readFile(r,"utf-8");a==="bun"?await Yt(o,r,n,t):a==="node"&&await Zt(o,r,n,t)}async function Yt(e,a,t,o){let r=V.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}),w({devDependencies:["@types/bun"],projectDir:e}),o==="hono"){let i=`${t}
|
|
129
129
|
|
|
130
130
|
export default app;
|
|
131
|
-
`;await D.writeFile(a,i)}}async function Zt(e,a,t,o){let r=
|
|
131
|
+
`;await D.writeFile(a,i)}}async function Zt(e,a,t,o){let r=V.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}),w({devDependencies:["tsx","@types/node"],projectDir:e}),o==="hono"){w({dependencies:["@hono/node-server"],projectDir:e});let i=`import { serve } from "@hono/node-server";
|
|
132
132
|
`,s=`
|
|
133
133
|
serve(
|
|
134
134
|
{
|
|
@@ -139,11 +139,11 @@ serve(
|
|
|
139
139
|
console.log(\`Server is running on http://localhost:\${info.port}\`);
|
|
140
140
|
},
|
|
141
141
|
);
|
|
142
|
-
`;if(!t.includes("@hono/node-server")){let
|
|
142
|
+
`;if(!t.includes("@hono/node-server")){let u=t.lastIndexOf("import"),h=t.substring(0,u),b=t.substring(u),k=h+i+b+s;await D.writeFile(a,k)}}else if(o==="elysia"&&(w({dependencies:["@elysiajs/node"],projectDir:e}),!t.includes("@elysiajs/node"))){let i=`import { node } from "@elysiajs/node";
|
|
143
143
|
`,s=t.indexOf(`
|
|
144
|
-
`,t.indexOf("import")),
|
|
145
|
-
`);else{let t=u.join(e,"apps/native");await f.pathExists(t)&&await f.remove(t)}}async function Ee(e,a){let t=u.join(y,`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=u.join(y,ea(a,t));if(await f.pathExists(r)&&(await f.copy(r,e,{overwrite:!0}),!o)){if(a==="prisma"){let n=u.join(e,"apps/server/prisma/schema/auth.prisma");await f.pathExists(n)&&await f.remove(n)}else if(a==="drizzle"){let n=u.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=u.join(y,"template/with-auth");if(await f.pathExists(n)){let i=u.join(n,"apps/web"),s=u.join(e,"apps/web");await f.copy(i,s,{overwrite:!0});let m=u.join(n,"apps/server/src"),h=u.join(e,"apps/server/src");await f.copy(u.join(m,"lib/trpc.ts"),u.join(h,"lib/trpc.ts"),{overwrite:!0}),await f.copy(u.join(m,"routers/index.ts"),u.join(h,"routers/index.ts"),{overwrite:!0});let b=`with-${t}-context.ts`;await f.copy(u.join(m,"lib",b),u.join(h,"lib/context.ts"),{overwrite:!0});let P=`with-${t}-index.ts`;await f.copy(u.join(m,P),u.join(h,"index.ts"),{overwrite:!0});let C=ta(o,r),v=u.join(m,C);if(await f.pathExists(v)){let z=await f.readdir(v);for(let N of z)await f.copy(u.join(v,N),u.join(h,"lib",N),{overwrite:!0})}}}async function Ce(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 f.pathExists(t)){let o=u.join(u.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 we(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),await be(t,e),await ve(t,e.git),e.addons.length>0&&await ne(t,e.addons,e.packageManager),await Pe(t,e),await ue(t,e),ke(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 Re}from"@clack/prompts";import{$ as Y}from"execa";import V from"picocolors";async function Ie({projectDir:e,packageManager:a,addons:t=[]}){let o=Re();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(V.red("Failed to install dependencies")),r instanceof Error&&De.error(V.red(`Installation error: ${r.message}`)),r}}async function ia(e,a){let t=Re();try{t.start("Running Biome format check..."),await Y({cwd:e})`${a} biome check --write .`,t.stop("Biome check completed successfully")}catch{t.stop(V.yellow("Biome check encountered issues")),De.warn(V.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 Ae(e){if(e!==void 0)return e;let a=await pa({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)"}],initialValues:c.addons,required:!1});return ca(a)&&(sa(la.red("Operation cancelled")),process.exit(0)),a.includes("husky")&&!a.includes("biome")&&a.push("biome"),a}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 ga,select as wa}from"@clack/prompts";import ba from"picocolors";async function _e(e){if(e!==void 0)return e;let a=await wa({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 ga(a)&&(ha(ba.red("Operation cancelled")),process.exit(0)),a}import{cancel as ya,isCancel as ka,select as Pa}from"@clack/prompts";import va from"picocolors";async function Ue(e){if(e!==void 0)return e;let a=await Pa({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 ka(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){if(e!==void 0)return e;if(a==="none")return[];let t=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(t)&&(ja(Ea.red("Operation cancelled")),process.exit(0)),t}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 Ra}from"@clack/prompts";import Ia 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 Ra(a)&&(Sa(Ia.red("Operation cancelled")),process.exit(0)),a}import{cancel as Aa,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)&&(Aa(_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 I 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(I.readdirSync(n).length===0)return e}else{let n=U.basename(e);if(!We(n)){let s=U.resolve(process.cwd(),e);if(!I.pathExistsSync(s)||I.readdirSync(s).length===0)return e}}let a=!1,t="",o=c.projectName,r=1;for(;I.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(I.readdirSync(process.cwd()).length>0)return"Current directory is not empty. Please choose a different directory.";a=!0;return}let m=U.resolve(process.cwd(),s),h=U.basename(m),b=We(h);if(b)return b;if(!m.startsWith(process.cwd()))return"Project path must be within current directory";if(I.pathExistsSync(m)&&I.readdirSync(m).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:()=>Ae(e.addons),examples:({results:t})=>ze(e.examples,t.database),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 x from"picocolors";function Z(e){let a=[];if(e.projectName&&a.push(`${x.blue("Project Name:")} ${e.projectName}`),e.backendFramework!==void 0&&a.push(`${x.blue("Backend Framework:")} ${e.backendFramework}`),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(`
|
|
146
|
-
`)}function Ye(e){let a=[];if(e.database==="none"?a.push("--no-database"):(a.push(`--${e.database}`),e.orm&&a.push(`--${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.packageManager&&a.push(`--${e.packageManager}`),e.backendFramework&&a.push(`--${e.backendFramework}`),e.runtime&&a.push(`--runtime ${e.runtime}`),e.frontend&&(e.frontend.includes("web")?a.push("--web"):a.push("--no-web"),e.frontend.includes("native")?a.push("--native"):a.push("--no-native")),e.addons.length>0)for(let r of e.addons)a.push(`--${r}`);else a.push("--no-addons");e.examples&&e.examples.length>0?a.push(`--examples ${e.examples.join(",")}`):a.push("--no-examples");let t="npx create-better-t-stack",o=e.projectName?` ${e.projectName}`:"";return`${t}${o} ${a.join(" ")}`}import po from"node:path";import lo from"fs-extra";var Ze=()=>{let e=po.join(
|
|
144
|
+
`,t.indexOf("import")),u=t.substring(0,s+1),h=t.substring(s+1),b=u+i+h;b=b.replace(/const app = new Elysia\([^)]*\)/,"const app = new Elysia({ adapter: node() })"),await D.writeFile(a,b)}}import m from"node:path";import f from"fs-extra";async function xe(e){let a=m.join(P,"template/base");if(!await f.pathExists(a))throw new Error(`Template directory not found: ${a}`);await f.copy(a,e)}async function Te(e,a){if(!a.includes("web")){let t=m.join(e,"apps/web");await f.pathExists(t)&&await f.remove(t)}if(a.includes("native"))await f.writeFile(m.join(e,".npmrc"),`node-linker=hoisted
|
|
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 Ye(e){let a=[];if(e.database==="none"?a.push("--no-database"):(a.push(`--${e.database}`),e.orm&&a.push(`--${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.packageManager&&a.push(`--${e.packageManager}`),e.backendFramework&&a.push(`--${e.backendFramework}`),e.runtime&&a.push(`--runtime ${e.runtime}`),e.frontend&&(e.frontend.includes("web")?a.push("--web"):a.push("--no-web"),e.frontend.includes("native")?a.push("--native"):a.push("--no-native")),e.addons.length>0)for(let r of e.addons)a.push(`--${r}`);else a.push("--no-addons");e.examples&&e.examples.length>0?a.push(`--examples ${e.examples.join(",")}`):a.push("--no-examples");let t="npx create-better-t-stack",o=e.projectName?` ${e.projectName}`:"";return`${t}${o} ${a.join(" ")}`}import po from"node:path";import lo from"fs-extra";var Ze=()=>{let e=po.join(P,"package.json");return lo.readJSONSync(e).version??"1.0.0"};import et from"gradient-string";var tt=`
|
|
147
147
|
\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
148
|
\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
149
|
\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
|
|
@@ -162,5 +162,5 @@ serve(
|
|
|
162
162
|
\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557
|
|
163
163
|
\u2551 Better T-Stack \u2551
|
|
164
164
|
\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D
|
|
165
|
-
`)):console.log(et(Object.values(at)).multiline(tt))};process.on("SIGINT",()=>{$.error(F.red("Operation cancelled")),process.exit(0)});var ee=new
|
|
166
|
-
${F.white(Ye(i))}`));let
|
|
165
|
+
`)):console.log(et(Object.values(at)).multiline(tt))};process.on("SIGINT",()=>{$.error(F.red("Operation cancelled")),process.exit(0)});var ee=new wo;async function go(){let e=Date.now();ee.name("create-better-t-stack").description("Create a new Better-T Stack project").version(Ze()).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("--elysia","Use Elysia backend framework").option("--runtime <runtime>","Specify runtime (bun or node)").option("--web","Include web frontend").option("--native","Include Expo frontend").option("--no-web","Exclude web frontend").option("--no-native","Exclude Expo frontend").parse();let a=ho();try{ot(),mo(F.magenta("Creating a new Better-T-Stack project"));let t=ee.opts(),o=ee.args[0],r;t.hono&&(r="hono"),t.elysia&&(r="elysia");let n={...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},...r&&{backendFramework:r},...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(h=>h==="todo"):[]},...(t.web!==void 0||t.native!==void 0)&&{frontend:[...t.web===!1?[]:["web"],...t.native===!1?[]:t.native===!0?["native"]:[]].filter(Boolean)}};!t.yes&&Object.keys(n).length>0&&($.info(F.yellow("Using these pre-selected options:")),$.message(Z(n)),$.message(""));let i=t.yes?{...c,projectName:o??c.projectName,database:t.database===!1?"none":t.sqlite?"sqlite":t.postgres?"postgres":c.database,orm:t.database===!1?"none":t.drizzle?"drizzle":t.prisma?"prisma":c.orm,auth:"auth"in t?t.auth:c.auth,git:"git"in t?t.git:c.git,noInstall:"install"in t?!t.install:c.noInstall,packageManager:n.packageManager??c.packageManager,addons:n.addons?.length?n.addons:c.addons,examples:n.examples?.length?n.examples:c.examples,turso:"turso"in t?t.turso:n.database==="sqlite"?c.turso:!1,backendFramework:r??c.backendFramework,runtime:t.runtime?t.runtime:c.runtime,frontend:t.web===!1||t.native===!0?[...t.web===!1?[]:["web"],...t.native?["native"]:[]]:c.frontend}:await Xe(n);t.yes&&($.info(F.yellow("Using these default options:")),$.message(Z(i)),$.message(""));let s=await Se(i);i.noInstall||await Re({projectDir:s,packageManager:i.packageManager,addons:i.addons}),$.success(F.blue(`You can reproduce this setup with the following command:
|
|
166
|
+
${F.white(Ye(i))}`));let u=((Date.now()-e)/1e3).toFixed(2);fo(F.magenta(`Project created successfully in ${F.bold(u)} seconds!`))}catch(t){a.stop(F.red("Failed")),t instanceof Error&&(uo(F.red(`An unexpected error occurred: ${t.message}`)),process.exit(1))}}go().catch(e=>{$.error("Aborting installation..."),e instanceof Error?$.error(e.message):($.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