create-better-t-stack 0.1.0 → 1.0.1

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.
Files changed (87) hide show
  1. package/README.md +59 -49
  2. package/dist/index.js +128 -305
  3. package/package.json +19 -11
  4. package/template/base/_gitignore +2 -0
  5. package/template/base/package.json +18 -0
  6. package/template/base/packages/client/_gitignore +23 -0
  7. package/template/base/packages/client/components.json +21 -0
  8. package/template/base/packages/client/index.html +12 -0
  9. package/template/base/packages/client/package.json +49 -0
  10. package/template/base/packages/client/src/components/header.tsx +31 -0
  11. package/template/base/packages/client/src/components/loader.tsx +9 -0
  12. package/template/base/packages/client/src/components/mode-toggle.tsx +37 -0
  13. package/template/base/packages/client/src/components/theme-provider.tsx +73 -0
  14. package/template/base/packages/client/src/components/ui/button.tsx +57 -0
  15. package/template/base/packages/client/src/components/ui/card.tsx +92 -0
  16. package/template/base/packages/client/src/components/ui/checkbox.tsx +30 -0
  17. package/template/base/packages/client/src/components/ui/dropdown-menu.tsx +199 -0
  18. package/template/base/packages/client/src/components/ui/input.tsx +22 -0
  19. package/template/base/packages/client/src/components/ui/label.tsx +24 -0
  20. package/template/base/packages/client/src/components/ui/skeleton.tsx +15 -0
  21. package/template/base/packages/client/src/components/ui/sonner.tsx +29 -0
  22. package/template/base/packages/client/src/index.css +119 -0
  23. package/template/base/packages/client/src/lib/utils.ts +6 -0
  24. package/template/base/packages/client/src/main.tsx +72 -0
  25. package/template/base/packages/client/src/routes/__root.tsx +58 -0
  26. package/template/base/packages/client/src/routes/index.tsx +97 -0
  27. package/template/base/packages/client/src/utils/trpc.ts +4 -0
  28. package/template/base/packages/client/tsconfig.json +18 -0
  29. package/template/base/packages/client/vite.config.ts +14 -0
  30. package/template/base/packages/server/_gitignore +36 -0
  31. package/template/base/packages/server/package.json +27 -0
  32. package/template/base/packages/server/src/index.ts +41 -0
  33. package/template/base/packages/server/src/lib/context.ts +13 -0
  34. package/template/base/packages/server/src/lib/trpc.ts +8 -0
  35. package/template/base/packages/server/src/routers/index.ts +11 -0
  36. package/template/base/packages/server/tsconfig.json +18 -0
  37. package/template/base/turbo.json +27 -0
  38. package/template/examples/todo/packages/client/src/routes/todos.tsx +128 -0
  39. package/template/examples/todo/packages/server/src/routers/with-drizzle-todo.ts +44 -0
  40. package/template/examples/todo/packages/server/src/routers/with-prisma-todo.ts +55 -0
  41. package/template/with-auth/packages/client/src/components/auth-forms.tsx +13 -0
  42. package/template/with-auth/packages/client/src/components/header.tsx +34 -0
  43. package/template/with-auth/packages/client/src/components/sign-in-form.tsx +139 -0
  44. package/template/with-auth/packages/client/src/components/sign-up-form.tsx +164 -0
  45. package/template/with-auth/packages/client/src/components/user-menu.tsx +62 -0
  46. package/template/with-auth/packages/client/src/lib/auth-client.ts +5 -0
  47. package/template/with-auth/packages/client/src/main.tsx +78 -0
  48. package/template/with-auth/packages/client/src/routes/dashboard.tsx +36 -0
  49. package/template/with-auth/packages/client/src/routes/index.tsx +97 -0
  50. package/template/with-auth/packages/client/src/routes/login.tsx +11 -0
  51. package/template/with-auth/packages/server/src/index.ts +46 -0
  52. package/template/with-auth/packages/server/src/lib/trpc.ts +24 -0
  53. package/template/with-auth/packages/server/src/routers/index.ts +19 -0
  54. package/template/with-biome/biome.json +42 -0
  55. package/template/with-drizzle-postgres/packages/server/drizzle.config.ts +10 -0
  56. package/template/with-drizzle-postgres/packages/server/src/db/index.ts +5 -0
  57. package/template/with-drizzle-postgres/packages/server/src/db/schema/auth.ts +47 -0
  58. package/template/with-drizzle-postgres/packages/server/src/db/schema/todo.ts +7 -0
  59. package/template/with-drizzle-postgres/packages/server/src/routers/todo.ts +44 -0
  60. package/template/with-drizzle-postgres/packages/server/src/with-auth-lib/auth.ts +15 -0
  61. package/template/with-drizzle-postgres/packages/server/src/with-auth-lib/context.ts +18 -0
  62. package/template/with-drizzle-postgres/packages/server/src/with-auth-lib/trpc.ts +24 -0
  63. package/template/with-drizzle-sqlite/packages/server/drizzle.config.ts +11 -0
  64. package/template/with-drizzle-sqlite/packages/server/src/db/index.ts +9 -0
  65. package/template/with-drizzle-sqlite/packages/server/src/db/schema/auth.ts +61 -0
  66. package/template/with-drizzle-sqlite/packages/server/src/db/schema/todo.ts +7 -0
  67. package/template/with-drizzle-sqlite/packages/server/src/with-auth-lib/auth.ts +15 -0
  68. package/template/with-drizzle-sqlite/packages/server/src/with-auth-lib/context.ts +18 -0
  69. package/template/with-drizzle-sqlite/packages/server/src/with-auth-lib/trpc.ts +24 -0
  70. package/template/with-husky/.husky/pre-commit +1 -0
  71. package/template/with-prisma-postgres/packages/server/prisma/index.ts +5 -0
  72. package/template/with-prisma-postgres/packages/server/prisma/schema/auth.prisma +59 -0
  73. package/template/with-prisma-postgres/packages/server/prisma/schema/schema.prisma +9 -0
  74. package/template/with-prisma-postgres/packages/server/prisma/schema/todo.prisma +7 -0
  75. package/template/with-prisma-postgres/packages/server/src/with-auth-lib/auth.ts +17 -0
  76. package/template/with-prisma-postgres/packages/server/src/with-auth-lib/context.ts +18 -0
  77. package/template/with-prisma-postgres/packages/server/src/with-auth-lib/trpc.ts +24 -0
  78. package/template/with-prisma-sqlite/packages/server/prisma/index.ts +5 -0
  79. package/template/with-prisma-sqlite/packages/server/prisma/schema/auth.prisma +59 -0
  80. package/template/with-prisma-sqlite/packages/server/prisma/schema/schema.prisma +8 -0
  81. package/template/with-prisma-sqlite/packages/server/prisma/schema/todo.prisma +7 -0
  82. package/template/with-prisma-sqlite/packages/server/src/with-auth-lib/auth.ts +17 -0
  83. package/template/with-prisma-sqlite/packages/server/src/with-auth-lib/context.ts +18 -0
  84. package/template/with-prisma-sqlite/packages/server/src/with-auth-lib/trpc.ts +24 -0
  85. package/template/with-pwa/packages/client/public/logo.png +0 -0
  86. package/template/with-pwa/packages/client/pwa-assets.config.ts +12 -0
  87. package/template/with-pwa/packages/client/vite.config.ts +35 -0
package/dist/index.js CHANGED
@@ -1,316 +1,139 @@
1
1
  #!/usr/bin/env node
2
+ import{cancel as Ia,intro as Da,log as k,outro as za,spinner as Ra}from"@clack/prompts";import{Command as La}from"commander";import E from"picocolors";import Q from"node:path";import{fileURLToPath as Ve}from"node:url";var He=Ve(import.meta.url),We=Q.dirname(He),g=Q.join(We,"../"),u={projectName:"my-better-t-app",database:"sqlite",orm:"drizzle",auth:!0,addons:[],git:!0,packageManager:"npm",noInstall:!1,examples:["todo"]},F={"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"};import Rt from"node:path";import{cancel as Lt,spinner as Nt}from"@clack/prompts";import Ut from"fs-extra";import ke from"picocolors";import C from"node:path";import m from"fs-extra";import Qe from"node:path";import K from"fs-extra";var f=e=>{let{dependencies:t=[],devDependencies:a=[],projectDir:r}=e,o=Qe.join(r,"package.json"),s=K.readJSONSync(o);s.dependencies||(s.dependencies={}),s.devDependencies||(s.devDependencies={});for(let i of t){let n=F[i];s.dependencies[i]=n}for(let i of a){let n=F[i];s.devDependencies[i]=n}K.writeJSONSync(o,s,{spaces:2})};import N from"node:path";import{log as Ke,spinner as Xe}from"@clack/prompts";import{execa as Ye}from"execa";import B from"fs-extra";import X from"picocolors";async function Y(e,t){let a=Xe(),r=N.join(e,"packages/client");try{a.start("Setting up Tauri desktop app support..."),f({devDependencies:["@tauri-apps/cli"],projectDir:r});let o=N.join(r,"package.json");if(await B.pathExists(o)){let s=await B.readJson(o);s.scripts={...s.scripts,tauri:"tauri","desktop:dev":"tauri dev","desktop:build":"tauri build"},await B.writeJson(o,s,{spaces:2})}await Ye("npx",["@tauri-apps/cli@latest","init",`--app-name=${N.basename(e)}`,`--window-title=${N.basename(e)}`,"--frontend-dist=dist","--dev-url=http://localhost:3001",`--before-dev-command=${t} run dev`,`--before-build-command=${t} run build`],{cwd:r,env:{CI:"true"}}),a.stop("Tauri desktop app support configured successfully!")}catch(o){throw a.stop(X.red("Failed to set up Tauri")),o instanceof Error&&Ke.error(X.red(o.message)),o}}async function Z(e,t,a){t.includes("pwa")&&await tt(e),t.includes("tauri")&&await Y(e,a),t.includes("biome")&&await Ze(e),t.includes("husky")&&await et(e)}async function Ze(e){let t=C.join(g,"template/with-biome");await m.pathExists(t)&&await m.copy(t,e,{overwrite:!0}),f({devDependencies:["@biomejs/biome"],projectDir:e});let a=C.join(e,"package.json");if(await m.pathExists(a)){let r=await m.readJson(a);r.scripts={...r.scripts,check:"biome check --write ."},await m.writeJson(a,r,{spaces:2})}}async function et(e){let t=C.join(g,"template/with-husky");await m.pathExists(t)&&await m.copy(t,e,{overwrite:!0}),f({devDependencies:["husky","lint-staged"],projectDir:e});let a=C.join(e,"package.json");if(await m.pathExists(a)){let r=await m.readJson(a);r.scripts={...r.scripts,prepare:"husky"},r["lint-staged"]={"*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json,jsonc}":["biome check --write ."]},await m.writeJson(a,r,{spaces:2})}}async function tt(e){let t=C.join(g,"template/with-pwa");await m.pathExists(t)&&await m.copy(t,e,{overwrite:!0});let a=C.join(e,"packages/client");f({dependencies:["vite-plugin-pwa"],devDependencies:["@vite-pwa/assets-generator"],projectDir:a});let r=C.join(a,"package.json");if(await m.pathExists(r)){let o=await m.readJson(r);o.scripts={...o.scripts,"generate-pwa-assets":"pwa-assets-generator"},await m.writeJson(r,o,{spaces:2})}}import ee from"node:path";import{log as te}from"@clack/prompts";import ae from"picocolors";function re(e=32){let t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",a="",r=t.length;for(let o=0;o<e;o++)a+=t.charAt(Math.floor(Math.random()*r));return a}async function oe(e,t){if(!t)return;let a=ee.join(e,"packages/server"),r=ee.join(e,"packages/client");try{f({dependencies:["better-auth"],projectDir:a}),f({dependencies:["better-auth"],projectDir:r})}catch(o){throw te.error(ae.red("Failed to configure authentication")),o instanceof Error&&te.error(ae.red(o.message)),o}}import at from"node:path";import rt from"fs-extra";async function se(e,t){let a=at.join(e,"README.md"),r=ot(t);try{await rt.writeFile(a,r)}catch(o){console.error("Failed to create README.md file:",o)}}function ot(e){let{projectName:t,packageManager:a,database:r,auth:o,addons:s=[],orm:i="drizzle"}=e,n=a==="npm"?"npm run":a;return`# ${t}
2
3
 
3
- // src/index.ts
4
- import { checkbox, confirm as confirm2, input as input2, select } from "@inquirer/prompts";
5
- import chalk2 from "chalk";
6
- import { Command } from "commander";
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.
7
5
 
8
- // src/create-project.ts
9
- import path2 from "node:path";
10
- import { execa as execa2 } from "execa";
11
- import fs2 from "fs-extra";
12
- import ora2 from "ora";
6
+ ## Features
13
7
 
14
- // src/helpers/db-setup.ts
15
- import os from "node:os";
16
- import path from "node:path";
17
- import { confirm, input } from "@inquirer/prompts";
18
- import { execa } from "execa";
19
- import fs from "fs-extra";
20
- import ora from "ora";
8
+ ${st(r,o,s,i)}
21
9
 
22
- // src/utils/logger.ts
23
- import chalk from "chalk";
24
- var logger = {
25
- error(...args) {
26
- console.log(chalk.red(...args));
27
- },
28
- warn(...args) {
29
- console.log(chalk.yellow(...args));
30
- },
31
- info(...args) {
32
- console.log(chalk.cyan(...args));
33
- },
34
- success(...args) {
35
- console.log(chalk.green(...args));
36
- }
37
- };
10
+ ## Getting Started
38
11
 
39
- // src/helpers/db-setup.ts
40
- async function isTursoInstalled() {
41
- try {
42
- await execa("turso", ["--version"]);
43
- return true;
44
- } catch {
45
- return false;
46
- }
47
- }
48
- async function isTursoLoggedIn() {
49
- try {
50
- await execa("turso", ["auth", "whoami"]);
51
- return true;
52
- } catch {
53
- return false;
54
- }
55
- }
56
- async function installTursoCLI(isMac, spinner) {
57
- try {
58
- if (await isTursoLoggedIn()) {
59
- spinner.succeed("Turso CLI already logged in!");
60
- return;
61
- }
62
- spinner.start("Installing Turso CLI...");
63
- if (isMac) {
64
- await execa("brew", ["install", "tursodatabase/tap/turso"]);
65
- } else {
66
- const installScript = await execa("curl", [
67
- "-sSfL",
68
- "https://get.tur.so/install.sh"
69
- ]);
70
- await execa("bash", [], { input: installScript.stdout });
71
- }
72
- spinner.succeed("Turso CLI installed successfully!");
73
- spinner.start("Logging in to Turso...");
74
- await execa("turso", ["auth", "login"]);
75
- spinner.succeed("Logged in to Turso!");
76
- } catch (error) {
77
- if (error instanceof Error && error.message.includes("User force closed")) {
78
- spinner.stop();
79
- console.log("\n");
80
- logger.warn("Turso CLI installation cancelled by user");
81
- throw error;
82
- }
83
- logger.error("Error during Turso CLI installation:", error);
84
- spinner.fail(
85
- "Failed to install Turso CLI. Proceeding with manual setup..."
86
- );
87
- throw error;
88
- }
89
- }
90
- async function setupTurso(projectDir) {
91
- const spinner = ora();
92
- const platform = os.platform();
93
- const isMac = platform === "darwin";
94
- let canInstallCLI = platform !== "win32";
95
- let installTurso = true;
96
- const isCliInstalled = await isTursoInstalled();
97
- if (canInstallCLI && !isCliInstalled) {
98
- installTurso = await confirm({
99
- message: "Would you like to install Turso CLI?",
100
- default: true
101
- });
102
- }
103
- canInstallCLI = canInstallCLI && installTurso;
104
- if (canInstallCLI) {
105
- try {
106
- await installTursoCLI(isMac, spinner);
107
- const defaultDbName = path.basename(projectDir);
108
- const dbName = await input({
109
- message: `Enter database name (default: ${defaultDbName}):`,
110
- default: defaultDbName
111
- });
112
- spinner.start(`Creating Turso database "${dbName}"...`);
113
- await execa("turso", ["db", "create", dbName]);
114
- const { stdout: dbUrl } = await execa("turso", [
115
- "db",
116
- "show",
117
- dbName,
118
- "--url"
119
- ]);
120
- const { stdout: authToken } = await execa("turso", [
121
- "db",
122
- "tokens",
123
- "create",
124
- dbName
125
- ]);
126
- const envPath = path.join(projectDir, "packages/server", ".env");
127
- const envContent = `TURSO_DATABASE_URL="${dbUrl.trim()}"
128
- TURSO_AUTH_TOKEN="${authToken.trim()}"`;
129
- await fs.writeFile(envPath, envContent);
130
- spinner.succeed("Turso database configured successfully!");
131
- return;
132
- } catch (error) {
133
- logger.error("Error during Turso database creation:", error);
134
- spinner.fail(
135
- "Failed to install Turso CLI. Proceeding with manual setup..."
136
- );
137
- installTurso = false;
138
- }
139
- }
140
- if (!installTurso) {
141
- const envPath = path.join(projectDir, "packages/server", ".env");
142
- const envContent = `TURSO_DATABASE_URL=
143
- TURSO_AUTH_TOKEN=`;
144
- await fs.writeFile(envPath, envContent);
145
- logger.info("\n\u{1F4DD} Manual Turso Setup Instructions:");
146
- logger.info("1. Visit https://turso.tech and create an account");
147
- logger.info("2. Create a new database from the dashboard");
148
- logger.info("3. Get your database URL and authentication token");
149
- logger.info(
150
- "4. Add these credentials to the .env file in your project root"
151
- );
152
- logger.info("\nThe .env file has been created with placeholder variables:");
153
- logger.info("TURSO_DATABASE_URL=your_database_url");
154
- logger.info("TURSO_AUTH_TOKEN=your_auth_token");
155
- }
156
- }
12
+ First, install the dependencies:
157
13
 
158
- // src/create-project.ts
159
- async function createProject(options) {
160
- const spinner = ora2("Creating project directory...").start();
161
- const projectDir = path2.resolve(process.cwd(), options.projectName);
162
- try {
163
- await fs2.ensureDir(projectDir);
164
- spinner.succeed();
165
- spinner.start("Cloning template repository...");
166
- await execa2("npx", [
167
- "degit",
168
- "https://github.com/AmanVarshney01/Better-T-Stack.git",
169
- projectDir
170
- ]);
171
- spinner.succeed();
172
- if (options.git) {
173
- spinner.start("Initializing git repository...");
174
- await execa2("git", ["init"], { cwd: projectDir });
175
- spinner.succeed();
176
- }
177
- spinner.start("Installing dependencies...");
178
- await execa2("bun", ["install"], { cwd: projectDir });
179
- spinner.succeed();
180
- if (options.database === "libsql") {
181
- await setupTurso(projectDir);
182
- }
183
- logger.success("\n\u2728 Project created successfully!\n");
184
- logger.info("Next steps:");
185
- logger.info(` cd ${options.projectName}`);
186
- logger.info(" bun dev");
187
- } catch (error) {
188
- spinner.fail("Failed to create project");
189
- logger.error("Error during project creation:", error);
190
- process.exit(1);
191
- }
192
- }
14
+ \`\`\`bash
15
+ ${a} install
16
+ \`\`\`
193
17
 
194
- // src/render-title.ts
195
- import gradient from "gradient-string";
18
+ ${it(r,o,n,i)}
196
19
 
197
- // src/consts.ts
198
- var TITLE_TEXT = `
199
- \u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557
200
- \u2551 \u2551
201
- \u2551 \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 \u2551
202
- \u2551 \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 \u2551
203
- \u2551 \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 \u2551
204
- \u2551 \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u255D \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557 \u2551
205
- \u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2551 \u2551
206
- \u2551 \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D \u2551
207
- \u2551 \u2551
208
- \u2551 \u2588\u2588\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\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2557 \u2588\u2588\u2557 \u2551
209
- \u2551 \u255A\u2550\u2550\u2588\u2588\u2554\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u2550\u2588\u2588\u2554\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2551 \u2588\u2588\u2554\u255D \u2551
210
- \u2551 \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2554\u255D \u2551
211
- \u2551 \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 \u2551
212
- \u2551 \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 \u2551
213
- \u2551 \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 \u2551
214
- \u2551 \u2551
215
- \u2551 The Modern Full-Stack Framework \u2551
216
- \u2551 \u2551
217
- \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D
218
- `;
20
+ Then, run the development server:
219
21
 
220
- // src/render-title.ts
221
- var catppuccinTheme = {
222
- rosewater: "#F5E0DC",
223
- flamingo: "#F2CDCD",
224
- pink: "#F5C2E7",
225
- mauve: "#CBA6F7",
226
- red: "#F38BA8",
227
- maroon: "#E78284",
228
- peach: "#FAB387",
229
- yellow: "#F9E2AF",
230
- green: "#A6E3A1",
231
- teal: "#94E2D5",
232
- sky: "#89DCEB",
233
- sapphire: "#74C7EC",
234
- lavender: "#B4BEFE"
235
- };
236
- var renderTitle = () => {
237
- const catppuccinGradient = gradient(Object.values(catppuccinTheme));
238
- console.log(catppuccinGradient.multiline(TITLE_TEXT));
239
- };
22
+ \`\`\`bash
23
+ ${n} dev
24
+ \`\`\`
240
25
 
241
- // src/index.ts
242
- var program = new Command();
243
- async function main() {
244
- try {
245
- renderTitle();
246
- console.log(chalk2.bold("\n\u{1F680} Creating a new Better-T Stack project...\n"));
247
- const projectName = await input2({
248
- message: "Project name:",
249
- default: "my-better-t-app"
250
- });
251
- const database = await select({
252
- message: chalk2.cyan("Select database:"),
253
- choices: [
254
- {
255
- value: "libsql",
256
- name: "libSQL",
257
- description: chalk2.dim(
258
- "(Recommended) - Turso's embedded SQLite database"
259
- )
260
- },
261
- {
262
- value: "postgres",
263
- name: "PostgreSQL",
264
- description: chalk2.dim("Traditional relational database")
265
- }
266
- ]
267
- });
268
- const auth = await confirm2({
269
- message: "Add authentication with Better-Auth?",
270
- default: true
271
- });
272
- const features = await checkbox({
273
- message: chalk2.cyan("Select additional features:"),
274
- choices: [
275
- {
276
- value: "docker",
277
- name: "Docker setup",
278
- description: chalk2.dim("Containerize your application")
279
- },
280
- {
281
- value: "github-actions",
282
- name: "GitHub Actions",
283
- description: chalk2.dim("CI/CD workflows")
284
- },
285
- {
286
- value: "SEO",
287
- name: "Basic SEO setup",
288
- description: chalk2.dim("Search engine optimization configuration")
289
- }
290
- ]
291
- });
292
- const projectOptions = {
293
- projectName,
294
- git: true,
295
- database,
296
- auth,
297
- features
298
- };
299
- await createProject(projectOptions);
300
- } catch (error) {
301
- if (error instanceof Error && error.message.includes("User force closed")) {
302
- console.log("\n");
303
- logger.warn("Operation cancelled by user");
304
- process.exit(0);
305
- }
306
- logger.error("An unexpected error occurred:", error);
307
- process.exit(1);
308
- }
309
- }
310
- process.on("SIGINT", () => {
311
- console.log("\n");
312
- logger.warn("Operation cancelled by user");
313
- process.exit(0);
314
- });
315
- program.name("create-better-t-stack").description("Create a new Better-T Stack project").version("1.0.0").action(main);
316
- program.parse();
26
+ Open [http://localhost:3001](http://localhost:3001) in your browser to see the client application.
27
+ The API is running at [http://localhost:3000](http://localhost:3000).
28
+
29
+ ## Project Structure
30
+
31
+ \`\`\`
32
+ ${t}/
33
+ \u251C\u2500\u2500 packages/
34
+ \u2502 \u251C\u2500\u2500 client/ # Frontend application (React, TanStack Router)
35
+ \u2502 \u2514\u2500\u2500 server/ # Backend API (Hono, tRPC)
36
+ \`\`\`
37
+
38
+ ## Available Scripts
39
+
40
+ ${nt(n,r,i,o)}
41
+ `}function st(e,t,a,r){let o=["- **TypeScript** - For type safety and improved developer experience","- **TanStack Router** - File-based routing with full type safety","- **TailwindCSS** - Utility-first CSS for rapid UI development","- **shadcn/ui** - Reusable UI components","- **Hono** - Lightweight, performant server framework","- **tRPC** - End-to-end type-safe APIs"];e!=="none"&&o.push(`- **${r==="drizzle"?"Drizzle":"Prisma"}** - TypeScript-first ORM`,`- **${e==="sqlite"?"SQLite/Turso":"PostgreSQL"}** - Database engine`),t&&o.push("- **Authentication** - Email & password authentication with Better Auth");for(let s of a)s==="docker"&&o.push("- **Docker** - Containerized deployment");return o.join(`
42
+ `)}function it(e,t,a,r){if(e==="none")return"";let o=`## Database Setup
43
+
44
+ `;return e==="sqlite"?o+=`This project uses SQLite${r==="drizzle"?" with Drizzle ORM":" with Prisma"}.
45
+
46
+ 1. Start the local SQLite database:
47
+ \`\`\`bash
48
+ cd packages/server && ${a} db:local
49
+ \`\`\`
50
+
51
+ 2. Update your \`.env\` file in the \`packages/server\` directory with the appropriate connection details if needed.
52
+ `:e==="postgres"&&(o+=`This project uses PostgreSQL${r==="drizzle"?" with Drizzle ORM":" with Prisma"}.
53
+
54
+ 1. Make sure you have a PostgreSQL database set up.
55
+ 2. Update your \`packages/server/.env\` file with your PostgreSQL connection details.
56
+ `),o+=`
57
+ ${t?"4":"3"}. ${r==="prisma"?`Generate the Prisma client and push the schema:
58
+ \`\`\`bash
59
+ ${a} db:push
60
+ \`\`\``:`Apply the schema to your database:
61
+ \`\`\`bash
62
+ ${a} db:push
63
+ \`\`\``}
64
+ `,o}function nt(e,t,a,r){let o=`- \`${e} dev\`: Start both client and server in development mode
65
+ - \`${e} build\`: Build both client and server
66
+ - \`${e} dev:client\`: Start only the client
67
+ - \`${e} dev:server\`: Start only the server
68
+ - \`${e} check-types\`: Check TypeScript types across all packages`;return t!=="none"&&(o+=`
69
+ - \`${e} db:push\`: Push schema changes to database
70
+ - \`${e} db:studio\`: Open database studio UI`,t==="sqlite"&&a==="drizzle"&&(o+=`
71
+ - \`cd packages/server && ${e} db:local\`: Start the local SQLite database`)),o}import ce from"node:path";import{log as Pt,spinner as kt}from"@clack/prompts";import jt from"fs-extra";import pe from"picocolors";import ct from"node:os";import ie from"node:path";import{cancel as G,confirm as pt,isCancel as q,log as O,select as lt,spinner as J,text as ut}from"@clack/prompts";import{$ as y}from"execa";import dt from"fs-extra";import h from"picocolors";async function mt(){try{return(await y`turso --version`).exitCode===0}catch{return!1}}async function ft(){try{return!(await y`turso auth whoami`).stdout.includes("You are not logged in")}catch{return!1}}async function gt(){let e=J();try{return e.start("Logging in to Turso..."),await y`turso auth login`,e.stop("Logged in to Turso successfully!"),!0}catch(t){throw e.stop(h.red("Failed to log in to Turso")),t}}async function ht(e){let t=J();try{if(t.start("Installing Turso CLI..."),e)await y`brew install tursodatabase/tap/turso`;else{let{stdout:a}=await y`curl -sSfL https://get.tur.so/install.sh`;await y`bash -c '${a}'`}return t.stop("Turso CLI installed successfully!"),!0}catch(a){throw a instanceof Error&&a.message.includes("User force closed")?(t.stop(),O.warn(h.yellow("Turso CLI installation cancelled by user")),new Error("Installation cancelled")):(t.stop(h.red("Failed to install Turso CLI")),a)}}async function bt(){try{let{stdout:e}=await y`turso group list`,t=e.trim().split(`
72
+ `);return t.length<=1?[]:t.slice(1).map(r=>{let[o,s,i,n]=r.trim().split(/\s{2,}/);return{name:o,locations:s,version:i,status:n}})}catch(e){return console.error("Error fetching Turso groups:",e),[]}}async function wt(){let e=await bt();if(e.length===0)return null;if(e.length===1)return e[0].name;let t=e.map(r=>({value:r.name,label:`${r.name} (${r.locations})`})),a=await lt({message:"Select a Turso database group:",options:t});return q(a)&&(G(h.red("Operation cancelled")),process.exit(0)),a}async function yt(e,t){try{t?await y`turso db create ${e} --group ${t}`:await y`turso db create ${e}`}catch(o){throw o instanceof Error&&o.message.includes("already exists")?new Error("DATABASE_EXISTS"):o}let{stdout:a}=await y`turso db show ${e} --url`,{stdout:r}=await y`turso db tokens create ${e}`;return{dbUrl:a.trim(),authToken:r.trim()}}async function z(e,t){let a=ie.join(e,"packages/server",".env"),r=t?`TURSO_CONNECTION_URL="${t.dbUrl}"
73
+ TURSO_AUTH_TOKEN="${t.authToken}"`:`TURSO_CONNECTION_URL=
74
+ TURSO_AUTH_TOKEN=`;await dt.writeFile(a,r)}function U(){O.info(`Manual Turso Setup Instructions:
75
+
76
+ 1. Visit https://turso.tech and create an account
77
+ 2. Create a new database from the dashboard
78
+ 3. Get your database URL and authentication token
79
+ 4. Add these credentials to the .env file in packages/server/.env
80
+
81
+ TURSO_CONNECTION_URL=your_database_url
82
+ TURSO_AUTH_TOKEN=your_auth_token`)}async function ne(e,t){if(!t){await z(e),O.info(h.blue("Skipping Turso setup. Setting up empty configuration.")),U();return}let a=ct.platform(),r=a==="darwin";if(!(a!=="win32")){O.warn(h.yellow("Automatic Turso setup is not supported on Windows.")),await z(e),U();return}try{if(!await mt()){let T=await pt({message:"Would you like to install Turso CLI?",initialValue:!0});if(q(T)&&(G(h.red("Operation cancelled")),process.exit(0)),!T){await z(e),U();return}await ht(r)}await ft()||await gt();let n=await wt(),w=!1,j="",v=ie.basename(e);for(;!w;){let T=await ut({message:"Enter a name for your database:",defaultValue:v,initialValue:v,placeholder:v});q(T)&&(G(h.red("Operation cancelled")),process.exit(0)),j=T;let L=J();try{L.start(`Creating Turso database "${j}"${n?` in group "${n}"`:""}...`);let D=await yt(j,n);await z(e,D),L.stop("Turso database configured successfully!"),w=!0}catch(D){if(D instanceof Error&&D.message==="DATABASE_EXISTS")L.stop(h.yellow(`Database "${h.red(j)}" already exists`)),v=`${j}-${Math.floor(Math.random()*1e3)}`;else throw L.stop(h.red("Failed to create Turso database")),D}}}catch(s){O.error(h.red(`Error during Turso setup: ${s}`)),await z(e),U(),O.success("Setup completed with manual configuration required.")}}async function le(e,t,a,r=!0){let o=kt(),s=ce.join(e,"packages/server");if(t==="none"){await jt.remove(ce.join(s,"src/db"));return}try{t==="sqlite"?(a==="drizzle"?f({dependencies:["drizzle-orm","@libsql/client"],devDependencies:["drizzle-kit"],projectDir:s}):a==="prisma"&&f({dependencies:["@prisma/client"],devDependencies:["prisma"],projectDir:s}),r&&await ne(e,!0)):t==="postgres"&&(a==="drizzle"?f({dependencies:["drizzle-orm","postgres"],devDependencies:["drizzle-kit"],projectDir:s}):a==="prisma"&&f({dependencies:["@prisma/client"],devDependencies:["prisma"],projectDir:s}))}catch(i){throw o.stop(pe.red("Failed to set up database")),i instanceof Error&&Pt.error(pe.red(i.message)),i}}import M from"node:path";import A from"fs-extra";async function ue(e,t){let a=M.join(e,"packages/server"),r=M.join(e,"packages/client"),o=M.join(a,".env"),s="";if(await A.pathExists(o)&&(s=await A.readFile(o,"utf8")),s.includes("CORS_ORIGIN")||(s+=`
83
+ CORS_ORIGIN=http://localhost:3001`),t.auth&&(s.includes("BETTER_AUTH_SECRET")||(s+=`
84
+ BETTER_AUTH_SECRET=${re()}`),s.includes("BETTER_AUTH_URL")||(s+=`
85
+ BETTER_AUTH_URL=http://localhost:3000`)),t.database!=="none"){if(t.orm==="prisma"&&!s.includes("DATABASE_URL")){let w=t.database==="sqlite"?"":`
86
+ DATABASE_URL="postgresql://postgres:postgres@localhost:5432/mydb?schema=public"`;s+=w}t.database==="sqlite"&&!t.turso&&(s.includes("TURSO_CONNECTION_URL")||(s+=`
87
+ TURSO_CONNECTION_URL=http://127.0.0.1:8080`))}await A.writeFile(o,s.trim());let i=M.join(r,".env"),n="";await A.pathExists(i)&&(n=await A.readFile(i,"utf8")),n.includes("VITE_SERVER_URL")||(n+=`VITE_SERVER_URL=http://localhost:3000
88
+ `),await A.writeFile(i,n.trim())}import x from"node:path";import d from"fs-extra";async function de(e,t,a,r){t.includes("todo")?await vt(e,a,r):await xt(e,a)}async function vt(e,t,a){let r=x.join(g,"template/examples/todo");if(await d.pathExists(r)){let o=x.join(r,"packages/client/src/routes"),s=x.join(e,"packages/client/src/routes");if(await d.copy(o,s,{overwrite:!0}),t!=="none"){let i=x.join(r,`packages/server/src/routers/with-${t}-todo.ts`),n=x.join(e,"packages/server/src/routers/todo.ts");await d.pathExists(i)&&await d.copy(i,n,{overwrite:!0})}await Tt(e,a)}}async function Tt(e,t){let a=x.join(e,"packages/client/src/components/header.tsx");if(await d.pathExists(a)){let r=await d.readFile(a,"utf8");t?r=r.replace(/const links = \[\s*{ to: "\/", label: "Home" },\s*{ to: "\/dashboard", label: "Dashboard" },/,`const links = [
89
+ { to: "/", label: "Home" },
90
+ { to: "/dashboard", label: "Dashboard" },
91
+ { to: "/todos", label: "Todos" },`):r=r.replace(/const links = \[\s*{ to: "\/", label: "Home" },/,`const links = [
92
+ { to: "/", label: "Home" },
93
+ { to: "/todos", label: "Todos" },`),await d.writeFile(a,r)}}async function xt(e,t){if(t==="drizzle"){let r=x.join(e,"packages/server/src/db/schema/todo.ts");await d.pathExists(r)&&await d.remove(r)}else if(t==="prisma"){let r=x.join(e,"packages/server/prisma/schema/todo.prisma");await d.pathExists(r)&&await d.remove(r)}let a=x.join(e,"packages/server/src/routers/todo.ts");await d.pathExists(a)&&await d.remove(a),await $t(e)}async function $t(e){let t=x.join(e,"packages/server/src/routers/index.ts");if(await d.pathExists(t)){let a=await d.readFile(t,"utf8");a=a.replace(/import { todoRouter } from ".\/todo";/,""),a=a.replace(/todo: todoRouter,/,""),await d.writeFile(t,a)}}import{log as Et}from"@clack/prompts";import p from"picocolors";function me(e,t,a,r,o,s){let i=a==="npm"?"npm run":a,n=`cd ${t}`,w=s?.includes("husky")||s?.includes("biome"),j=e!=="none"?St(e,o,i):"",v=s?.includes("tauri")?Ot(i):"",T=w?Ct(i):"";Et.info(`${p.cyan("Project created successfully!")}
94
+
95
+ ${p.bold("Next steps:")}
96
+ ${p.cyan("1.")} ${n}
97
+ ${r?"":`${p.cyan("2.")} ${a} install
98
+ `}${p.cyan(r?"2.":"3.")} ${i} dev
99
+
100
+ ${p.bold("Your project will be available at:")}
101
+ ${p.cyan("\u2022")} Frontend: http://localhost:3001
102
+ ${p.cyan("\u2022")} API: http://localhost:3000
103
+ ${j?`
104
+ ${j.trim()}`:""}${v?`
105
+ ${v.trim()}`:""}${T?`
106
+ ${T.trim()}`:""}`)}function Ct(e){return`${p.bold("Linting and formatting:")}
107
+ ${p.cyan("\u2022")} Format and lint fix: ${p.dim(`${e} check`)}
108
+
109
+ `}function St(e,t,a){let r=[];return t==="prisma"?(e==="sqlite"&&r.push(`${p.yellow("NOTE:")} Turso support with Prisma is in Early Access and requires additional setup.`,`${p.dim("Learn more at: https://www.prisma.io/docs/orm/overview/databases/turso")}`),r.push(`${p.cyan("\u2022")} Apply schema: ${p.dim(`${a} db:push`)}`),r.push(`${p.cyan("\u2022")} Database UI: ${p.dim(`${a} db:studio`)}`)):t==="drizzle"&&(e==="sqlite"&&r.push(`${p.cyan("\u2022")} Start local DB: ${p.dim(`cd packages/server && ${a} db:local`)}`),r.push(`${p.cyan("\u2022")} Apply schema: ${p.dim(`${a} db:push`)}`),r.push(`${p.cyan("\u2022")} Database UI: ${p.dim(`${a} db:studio`)}`)),r.length?`${p.bold("Database commands:")}
110
+ ${r.join(`
111
+ `)}
112
+
113
+ `:""}function Ot(e){return`${p.bold("Desktop app with Tauri:")}
114
+ ${p.cyan("\u2022")} Start desktop app: ${p.dim(`cd packages/client && ${e} desktop:dev`)}
115
+ ${p.cyan("\u2022")} Build desktop app: ${p.dim(`cd packages/client && ${e} desktop:build`)}
116
+ ${p.yellow("NOTE:")} Tauri requires Rust and platform-specific dependencies. See: ${p.dim("https://v2.tauri.app/start/prerequisites/")}
117
+
118
+ `}import fe from"node:path";import{$ as At}from"execa";import I from"fs-extra";async function ge(e,t){await It(e,t),await Dt(e,t)}async function It(e,t){let a=fe.join(e,"package.json");if(await I.pathExists(a)){let r=await I.readJson(a);r.name=t.projectName,t.packageManager!=="bun"&&(r.packageManager=t.packageManager==="npm"?"npm@10.9.2":t.packageManager==="pnpm"?"pnpm@10.6.4":"bun@1.2.5"),await I.writeJson(a,r,{spaces:2})}}async function Dt(e,t){let a=fe.join(e,"packages/server/package.json");if(await I.pathExists(a)){let r=await I.readJson(a);t.database!=="none"&&(t.database==="sqlite"&&(r.scripts["db:local"]="turso dev --db-file local.db"),t.orm==="prisma"?(r.scripts["db:push"]="prisma db push --schema ./prisma/schema",r.scripts["db:studio"]="prisma studio"):t.orm==="drizzle"&&(r.scripts["db:push"]="drizzle-kit push",r.scripts["db:studio"]="drizzle-kit studio")),await I.writeJson(a,r,{spaces:2})}}async function he(e,t){t&&await At({cwd:e})`git init`}import P from"node:path";import b from"fs-extra";async function be(e){let t=P.join(g,"template/base");if(!await b.pathExists(t))throw new Error(`Template directory not found: ${t}`);await b.copy(t,e)}async function we(e,t){if(!t)return;let a=P.join(g,"template/with-auth");await b.pathExists(a)&&await b.copy(a,e,{overwrite:!0})}async function ye(e,t,a,r){if(t==="none"||a==="none")return;let o=P.join(g,zt(t,a));if(await b.pathExists(o)){await b.copy(o,e,{overwrite:!0});let s=P.join(e,"packages/server/src"),i=P.join(s,"lib"),n=P.join(s,"with-auth-lib");r?await b.pathExists(n)&&(await b.remove(i),await b.move(n,i)):await b.remove(n)}}async function Pe(e){let t=[P.join(e,"_gitignore"),P.join(e,"packages/client/_gitignore"),P.join(e,"packages/server/_gitignore")];for(let a of t)if(await b.pathExists(a)){let r=P.join(P.dirname(a),".gitignore");await b.move(a,r)}}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 je(e){let t=Nt(),a=Rt.resolve(process.cwd(),e.projectName);try{return await Ut.ensureDir(a),await be(a),await Pe(a),await we(a,e.auth),await ye(a,e.orm,e.database,e.auth),await de(a,e.examples,e.orm,e.auth),await le(a,e.database,e.orm,e.turso??e.database==="sqlite"),await oe(a,e.auth),await ue(a,e),await he(a,e.git),e.addons.length>0&&await Z(a,e.addons,e.packageManager),await ge(a,e),await se(a,e),me(e.database,e.projectName,e.packageManager,!e.noInstall,e.orm,e.addons),a}catch(r){throw t.message(ke.red("Failed")),r instanceof Error&&(Lt(ke.red(`Error during project creation: ${r.message}`)),process.exit(1)),r}}import{log as ve,spinner as Te}from"@clack/prompts";import{$ as V}from"execa";import _ from"picocolors";async function xe({projectDir:e,packageManager:t,addons:a=[]}){let r=Te();try{switch(r.start(`Running ${t} install...`),t){case"npm":await V({cwd:e,stderr:"inherit"})`${t} install`;break;case"pnpm":case"bun":await V({cwd:e})`${t} install`;break}r.stop("Dependencies installed successfully"),(a.includes("biome")||a.includes("husky"))&&await Mt(e,t)}catch(o){throw r.stop(_.red("Failed to install dependencies")),o instanceof Error&&ve.error(_.red(`Installation error: ${o.message}`)),o}}async function Mt(e,t){let a=Te();try{a.start("Running Biome format check..."),await V({cwd:e})`${t} biome check --write .`,a.stop("Biome check completed successfully")}catch{a.stop(_.yellow("Biome check encountered issues")),ve.warn(_.yellow("Some files may need manual formatting"))}}import{cancel as Ea,group as Ca}from"@clack/prompts";import Sa from"picocolors";import{cancel as _t,isCancel as Ft,multiselect as Bt}from"@clack/prompts";import Gt from"picocolors";async function $e(e){if(e!==void 0)return e;let t=await Bt({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 Ft(t)&&(_t(Gt.red("Operation cancelled")),process.exit(0)),t.includes("husky")&&!t.includes("biome")&&t.push("biome"),t}import{cancel as qt,confirm as Jt,isCancel as Vt}from"@clack/prompts";import Ht from"picocolors";async function Ee(e,t){if(!t)return!1;if(e!==void 0)return e;let a=await Jt({message:"Would you like to add authentication with Better-Auth?",initialValue:u.auth});return Vt(a)&&(qt(Ht.red("Operation cancelled")),process.exit(0)),a}import{cancel as Wt,isCancel as Qt,select as Kt}from"@clack/prompts";import Xt from"picocolors";async function Ce(e){if(e!==void 0)return e;let t=await Kt({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 Qt(t)&&(Wt(Xt.red("Operation cancelled")),process.exit(0)),t}import{cancel as Yt,isCancel as Zt,multiselect as ea}from"@clack/prompts";import ta from"picocolors";async function Se(e){if(e!==void 0)return e;let t=await ea({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 Zt(t)&&(Yt(ta.red("Operation cancelled")),process.exit(0)),t}import{cancel as aa,confirm as ra,isCancel as oa}from"@clack/prompts";import sa from"picocolors";async function Oe(e){if(e!==void 0)return e;let t=await ra({message:"Initialize a new git repository?",initialValue:u.git});return oa(t)&&(aa(sa.red("Operation cancelled")),process.exit(0)),t}import{cancel as ia,confirm as na,isCancel as ca}from"@clack/prompts";import pa from"picocolors";async function Ae(e){if(e!==void 0)return e;let t=await na({message:"Do you want to install project dependencies?",initialValue:!u.noInstall});return ca(t)&&(ia(pa.red("Operation cancelled")),process.exit(0)),!t}import{cancel as la,isCancel as ua,select as da}from"@clack/prompts";import ma from"picocolors";async function Ie(e,t){if(!t)return"none";if(e!==void 0)return e;let a=await da({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)&&(la(ma.red("Operation cancelled")),process.exit(0)),a}import{cancel as fa,isCancel as ga,select as ha}from"@clack/prompts";import ba from"picocolors";var De=()=>{let e=process.env.npm_config_user_agent;return e?.startsWith("pnpm")?"pnpm":e?.startsWith("bun")?"bun":"npm"};async function ze(e){if(e!==void 0)return e;let t=De(),a=await ha({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)&&(fa(ba.red("Operation cancelled")),process.exit(0)),a}import R from"node:path";import{cancel as wa,isCancel as ya,text as Pa}from"@clack/prompts";import S from"fs-extra";import ka from"picocolors";var ja=["<",">",":",'"',"|","?","*"],Re=255;function Le(e){if(e!=="."){if(!e)return"Project name cannot be empty";if(e.length>Re)return`Project name must be less than ${Re} characters`;if(ja.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(S.readdirSync(s).length===0)return e}else{let s=R.basename(e);if(!Le(s)){let n=R.resolve(process.cwd(),e);if(!S.pathExistsSync(n)||S.readdirSync(n).length===0)return e}}let t=!1,a="",r=u.projectName,o=1;for(;S.pathExistsSync(R.resolve(process.cwd(),r));)r=`${u.projectName}-${o}`,o++;for(;!t;){let s=await Pa({message:"Enter your project name or path (relative to current directory)",placeholder:r,initialValue:e,defaultValue:r,validate:i=>{let n=i.trim()||r;if(n==="."){if(S.readdirSync(process.cwd()).length>0)return"Current directory is not empty. Please choose a different directory.";t=!0;return}let w=R.resolve(process.cwd(),n),j=R.basename(w),v=Le(j);if(v)return v;if(!w.startsWith(process.cwd()))return"Project path must be within current directory";if(S.pathExistsSync(w)&&S.readdirSync(w).length>0)return`Directory "${n}" already exists and is not empty. Please choose a different name or path.`;t=!0}});ya(s)&&(wa(ka.red("Operation cancelled.")),process.exit(0)),a=s||r}return a}import{cancel as va,confirm as Ta,isCancel as xa}from"@clack/prompts";import $a from"picocolors";async function Ue(e){if(e!==void 0)return e;let t=await Ta({message:"Set up a Turso database for this project?",initialValue:!0});return xa(t)&&(va($a.red("Operation cancelled")),process.exit(0)),t}async function Me(e){let t=await Ca({projectName:async()=>Ne(e.projectName),database:()=>Ce(e.database),orm:({results:a})=>Ie(e.orm,a.database!=="none"),auth:({results:a})=>Ee(e.auth,a.database!=="none"),turso:({results:a})=>a.database==="sqlite"&&a.orm!=="prisma"?Ue(e.turso):Promise.resolve(!1),addons:()=>$e(e.addons),examples:()=>Se(e.examples),git:()=>Oe(e.git),packageManager:()=>ze(e.packageManager),noInstall:()=>Ae(e.noInstall)},{onCancel:()=>{Ea(Sa.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 $ from"picocolors";function H(e){let t=[];return e.projectName&&t.push(`${$.blue("Project Name:")} ${e.projectName}`),e.database&&t.push(`${$.blue("Database:")} ${e.database}`),e.orm&&t.push(`${$.blue("ORM:")} ${e.orm}`),e.auth!==void 0&&t.push(`${$.blue("Authentication:")} ${e.auth}`),e.addons?.length&&t.push(`${$.blue("Addons:")} ${e.addons.join(", ")}`),e.git!==void 0&&t.push(`${$.blue("Git Init:")} ${e.git}`),e.packageManager&&t.push(`${$.blue("Package Manager:")} ${e.packageManager}`),e.noInstall!==void 0&&t.push(`${$.blue("Skip Install:")} ${e.noInstall}`),e.turso!==void 0&&t.push(`${$.blue("Turso Setup:")} ${e.turso}`),t.join(`
119
+ `)}function _e(e){let t=[];if(e.database==="none"?t.push("--no-database"):e.database==="sqlite"?t.push("--sqlite"):e.database==="postgres"&&t.push("--postgres"),e.database!=="none"&&(e.orm==="drizzle"?t.push("--drizzle"):e.orm==="prisma"&&t.push("--prisma")),e.auth?t.push("--auth"):t.push("--no-auth"),e.git?t.push("--git"):t.push("--no-git"),e.noInstall?t.push("--no-install"):t.push("--install"),e.packageManager&&t.push(`--${e.packageManager}`),e.addons.length>0)for(let s of e.addons)t.push(`--${s}`);else t.push("--no-addons");e.examples&&e.examples.length>0?t.push(`--examples ${e.examples.join(",")}`):t.push("--no-examples"),e.database==="sqlite"&&(e.turso?t.push("--turso"):t.push("--no-turso"));let a="npx create-better-t-stack",r=e.projectName?` ${e.projectName}`:"",o=t.length>0?` ${t.join(" ")}`:"";return`${a}${r}${o}`}import Oa from"node:path";import Aa from"fs-extra";var Fe=()=>{let e=Oa.join(g,"package.json");return Aa.readJSONSync(e).version??"1.0.0"};import Be from"gradient-string";var Ge=`
120
+ \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
121
+ \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
122
+ \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
123
+ \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u255D \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557
124
+ \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2551
125
+ \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D
126
+
127
+ \u2588\u2588\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\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2557 \u2588\u2588\u2557
128
+ \u255A\u2550\u2550\u2588\u2588\u2554\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u2550\u2588\u2588\u2554\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2551 \u2588\u2588\u2554\u255D
129
+ \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2554\u255D
130
+ \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
131
+ \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
132
+ \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
133
+ `,qe={pink:"#F5C2E7",mauve:"#CBA6F7",red:"#F38BA8",maroon:"#E78284",peach:"#FAB387",yellow:"#F9E2AF",green:"#A6E3A1",teal:"#94E2D5",sky:"#89DCEB",sapphire:"#74C7EC",lavender:"#B4BEFE"},Je=()=>{let e=process.stdout.columns||80,t=Ge.split(`
134
+ `),a=Math.max(...t.map(r=>r.length));e<a?console.log(Be(Object.values(qe)).multiline(`
135
+ \u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557
136
+ \u2551 Better T-Stack \u2551
137
+ \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D
138
+ `)):console.log(Be(Object.values(qe)).multiline(Ge))};process.on("SIGINT",()=>{k.error(E.red("Operation cancelled")),process.exit(0)});var W=new La;async function Na(){W.name("create-better-t-stack").description("Create a new Better-T Stack project").version(Fe()).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").parse();let e=Ra();try{Je(),Da(E.magenta("Creating a new Better-T-Stack project"));let t=W.opts(),a=W.args[0],r={...a&&{projectName:a},...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.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(i=>i==="todo"):[]}};!t.yes&&Object.keys(r).length>0&&(k.info(E.yellow("Using these pre-selected options:")),k.message(H(r)),k.message(""));let o=t.yes?{...u,projectName:a??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}:await Me(r);t.yes&&(k.info(E.yellow("Using these default options:")),k.message(H(o)),k.message(""));let s=await je(o);o.noInstall||await xe({projectDir:s,packageManager:o.packageManager,addons:o.addons}),k.success(E.blue(`You can reproduce this setup with the following command:
139
+ ${E.white(_e(o))}`)),za(E.magenta("Project created successfully!"))}catch(t){e.stop(E.red("Failed")),t instanceof Error&&(Ia(E.red(`An unexpected error occurred: ${t.message}`)),process.exit(1))}}Na().catch(e=>{k.error("Aborting installation..."),e instanceof Error?k.error(e.message):(k.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,6 +1,6 @@
1
1
  {
2
2
  "name": "create-better-t-stack",
3
- "version": "0.1.0",
3
+ "version": "1.0.1",
4
4
  "description": "CLI tool to scaffold Better-T Stack projects",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -8,6 +8,12 @@
8
8
  "create-better-t-stack": "dist/index.js"
9
9
  },
10
10
  "keywords": [],
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/better-t-stack/create-better-t-stack.git",
14
+ "directory": "apps/cli"
15
+ },
16
+ "homepage": "https://better-t-stack.pages.dev/",
11
17
  "scripts": {
12
18
  "build": "tsup",
13
19
  "dev": "tsup --watch",
@@ -16,22 +22,24 @@
16
22
  "test": "vitest run",
17
23
  "prepublishOnly": "npm run build"
18
24
  },
19
- "files": ["dist", "templates"],
25
+ "files": [
26
+ "dist",
27
+ "template"
28
+ ],
20
29
  "dependencies": {
21
- "@inquirer/prompts": "^7.3.1",
22
- "chalk": "^5.3.0",
30
+ "@clack/prompts": "^0.10.0",
23
31
  "commander": "^13.1.0",
32
+ "degit": "^2.8.4",
24
33
  "execa": "^8.0.1",
25
- "fs-extra": "^11.2.0",
34
+ "fs-extra": "^11.3.0",
26
35
  "gradient-string": "^3.0.0",
27
- "ora": "^7.0.1"
36
+ "picocolors": "^1.1.1"
28
37
  },
29
38
  "devDependencies": {
39
+ "@types/degit": "^2.8.6",
30
40
  "@types/fs-extra": "^11.0.4",
31
- "@types/inquirer": "^9.0.7",
32
- "@types/node": "^20.10.5",
33
- "tsup": "^8.0.1",
34
- "typescript": "^5.3.3",
35
- "vitest": "^1.1.0"
41
+ "@types/node": "^20.17.19",
42
+ "tsup": "^8.4.0",
43
+ "typescript": "^5.7.3"
36
44
  }
37
45
  }
@@ -0,0 +1,2 @@
1
+ /node_modules/
2
+ .turbo
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "better-t-stack",
3
+ "private": true,
4
+ "workspaces": ["packages/*"],
5
+ "scripts": {
6
+ "dev": "turbo dev",
7
+ "build": "turbo build",
8
+ "check-types": "turbo check-types",
9
+ "dev:client": "turbo -F client dev",
10
+ "dev:server": "turbo -F server dev",
11
+ "db:push": "turbo -F server db:push",
12
+ "db:studio": "turbo -F server db:studio"
13
+ },
14
+ "packageManager": "bun@1.2.4",
15
+ "devDependencies": {
16
+ "turbo": "^2.4.2"
17
+ }
18
+ }
@@ -0,0 +1,23 @@
1
+ # Local
2
+ .DS_Store
3
+ *.local
4
+ *.log*
5
+
6
+ # Dist
7
+ node_modules
8
+ dist/
9
+ .vinxi
10
+ .output
11
+ .vercel
12
+ .netlify
13
+ .wrangler
14
+
15
+ # IDE
16
+ .vscode/*
17
+ !.vscode/extensions.json
18
+ .idea
19
+
20
+ *.env*
21
+ !.env.example
22
+
23
+ dev-dist
@@ -0,0 +1,21 @@
1
+ {
2
+ "$schema": "https://ui.shadcn.com/schema.json",
3
+ "style": "new-york",
4
+ "rsc": false,
5
+ "tsx": true,
6
+ "tailwind": {
7
+ "config": "tailwind.config.js",
8
+ "css": "src/index.css",
9
+ "baseColor": "neutral",
10
+ "cssVariables": true,
11
+ "prefix": ""
12
+ },
13
+ "aliases": {
14
+ "components": "@/components",
15
+ "utils": "@/lib/utils",
16
+ "ui": "@/components/ui",
17
+ "lib": "@/lib",
18
+ "hooks": "@/hooks"
19
+ },
20
+ "iconLibrary": "lucide"
21
+ }