Skip to content

Commit d8875f0

Browse files
bug fixes
1 parent 83a5e1e commit d8875f0

File tree

5 files changed

+225
-178
lines changed

5 files changed

+225
-178
lines changed

.changeset/tasty-points-kneel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-better-t-stack": patch
3+
---
4+
5+
bug fixes

.zed/settings.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
{
2-
"language_servers": ["typescript-language-server", "!vtsls", "biome", "..."]
2+
"language_servers": ["typescript-language-server", "!vtsls", "biome", "..."],
3+
"formatter": {
4+
"language_server": {
5+
"name": "biome"
6+
}
7+
},
8+
"code_actions_on_format": {
9+
"source.fixAll.biome": true,
10+
"source.organizeImports.biome": true
11+
}
312
}

apps/cli/src/helpers/create-project.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export async function createProject(options: ProjectConfig) {
1212
let shouldInstallDeps = false;
1313

1414
try {
15-
await tasks([
15+
const tasksList = [
1616
{
1717
title: "Creating project directory",
1818
task: async () => {
@@ -33,15 +33,22 @@ export async function createProject(options: ProjectConfig) {
3333
}
3434
},
3535
},
36-
{
36+
];
37+
38+
if (options.git) {
39+
tasksList.push({
3740
title: "Initializing git repository",
3841
task: async () => {
39-
if (options.git) {
40-
await $`git init ${projectDir}`;
41-
}
42+
await $`git init ${projectDir}`;
4243
},
43-
},
44-
]);
44+
});
45+
}
46+
47+
await tasks(tasksList);
48+
49+
if (options.database === "libsql") {
50+
await setupTurso(projectDir);
51+
}
4552

4653
const installDepsResponse = await confirm({
4754
message: `📦 Install dependencies using ${options.packageManager}?`,
@@ -71,10 +78,6 @@ export async function createProject(options: ProjectConfig) {
7178
}
7279
}
7380

74-
if (options.database === "libsql") {
75-
await setupTurso(projectDir);
76-
}
77-
7881
log.success("✨ Project created successfully!\n");
7982
log.info(chalk.dim("Next steps:"));
8083
log.info(` cd ${options.projectName}`);

apps/cli/src/helpers/db-setup.ts

Lines changed: 75 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
import os from "node:os";
22
import path from "node:path";
3-
import * as p from "@clack/prompts";
3+
import {
4+
cancel,
5+
confirm,
6+
group,
7+
intro,
8+
isCancel,
9+
log,
10+
multiselect,
11+
outro,
12+
select,
13+
spinner,
14+
tasks,
15+
text,
16+
} from "@clack/prompts";
417
import { $ } from "execa";
518
import fs from "fs-extra";
619
import { isTursoInstalled, isTursoLoggedIn } from "../utils/turso-cli";
@@ -11,21 +24,21 @@ interface TursoConfig {
1124
}
1225

1326
async function loginToTurso() {
14-
const spinner = p.spinner();
27+
const s = spinner();
1528
try {
16-
spinner.start("Logging in to Turso...");
29+
s.start("Logging in to Turso...");
1730
await $`turso auth login`;
18-
spinner.stop("Logged in to Turso successfully!");
31+
s.stop("Logged in to Turso successfully!");
1932
} catch (error) {
20-
spinner.stop("Failed to log in to Turso");
33+
s.stop("Failed to log in to Turso");
2134
throw error;
2235
}
2336
}
2437

2538
async function installTursoCLI(isMac: boolean) {
26-
const spinner = p.spinner();
39+
const s = spinner();
2740
try {
28-
spinner.start("Installing Turso CLI...");
41+
s.start("Installing Turso CLI...");
2942

3043
if (isMac) {
3144
await $`brew install tursodatabase/tap/turso`;
@@ -35,14 +48,14 @@ async function installTursoCLI(isMac: boolean) {
3548
await $`bash -c '${installScript}'`;
3649
}
3750

38-
spinner.stop("Turso CLI installed successfully!");
51+
s.stop("Turso CLI installed successfully!");
3952
} catch (error) {
4053
if (error instanceof Error && error.message.includes("User force closed")) {
41-
spinner.stop();
42-
p.log.warn("Turso CLI installation cancelled by user");
54+
s.stop();
55+
log.warn("Turso CLI installation cancelled by user");
4356
throw new Error("Installation cancelled");
4457
}
45-
spinner.stop("Failed to install Turso CLI");
58+
s.stop("Failed to install Turso CLI");
4659
throw error;
4760
}
4861
}
@@ -78,42 +91,38 @@ TURSO_AUTH_TOKEN=`;
7891
}
7992

8093
function displayManualSetupInstructions() {
81-
p.log.info("📝 Manual Turso Setup Instructions:");
82-
p.log.info("1. Visit https://turso.tech and create an account");
83-
p.log.info("2. Create a new database from the dashboard");
84-
p.log.info("3. Get your database URL and authentication token");
85-
p.log.info(
86-
"4. Add these credentials to the .env file in packages/server/.env",
87-
);
88-
p.log.info("\nThe .env file has been created with placeholder variables:");
89-
p.log.info("TURSO_DATABASE_URL=your_database_url");
90-
p.log.info("TURSO_AUTH_TOKEN=your_auth_token");
94+
log.info("📝 Manual Turso Setup Instructions:");
95+
log.info("1. Visit https://turso.tech and create an account");
96+
log.info("2. Create a new database from the dashboard");
97+
log.info("3. Get your database URL and authentication token");
98+
log.info("4. Add these credentials to the .env file in packages/server/.env");
99+
log.info("\nThe .env file has been created with placeholder variables:");
100+
log.info("TURSO_DATABASE_URL=your_database_url");
101+
log.info("TURSO_AUTH_TOKEN=your_auth_token");
91102
}
92103

93104
export async function setupTurso(projectDir: string) {
94-
p.intro("Setting up Turso...");
95-
96105
const platform = os.platform();
97106
const isMac = platform === "darwin";
98107
const canInstallCLI = platform !== "win32";
99108

100-
try {
101-
if (!canInstallCLI) {
102-
p.log.warn("Automatic Turso setup is not supported on Windows.");
103-
await writeEnvFile(projectDir);
104-
displayManualSetupInstructions();
105-
return;
106-
}
109+
if (!canInstallCLI) {
110+
log.warn("Automatic Turso setup is not supported on Windows.");
111+
await writeEnvFile(projectDir);
112+
displayManualSetupInstructions();
113+
return;
114+
}
107115

116+
try {
108117
const isCliInstalled = await isTursoInstalled();
109118

110119
if (!isCliInstalled) {
111-
const shouldInstall = await p.confirm({
120+
const shouldInstall = await confirm({
112121
message: "Would you like to install Turso CLI?",
113122
});
114123

115-
if (p.isCancel(shouldInstall)) {
116-
p.cancel("Operation cancelled");
124+
if (isCancel(shouldInstall)) {
125+
cancel("Operation cancelled");
117126
process.exit(0);
118127
}
119128

@@ -123,53 +132,73 @@ export async function setupTurso(projectDir: string) {
123132
return;
124133
}
125134

126-
await installTursoCLI(isMac);
135+
const s = spinner();
136+
s.start("Installing Turso CLI...");
137+
try {
138+
if (isMac) {
139+
await $`brew install tursodatabase/tap/turso`;
140+
} else {
141+
const { stdout: installScript } =
142+
await $`curl -sSfL https://get.tur.so/install.sh`;
143+
await $`bash -c '${installScript}'`;
144+
}
145+
s.stop("Turso CLI installed successfully!");
146+
} catch (error) {
147+
s.stop("Failed to install Turso CLI");
148+
throw error;
149+
}
127150
}
128151

129152
const isLoggedIn = await isTursoLoggedIn();
130153
if (!isLoggedIn) {
131-
await loginToTurso();
154+
const s = spinner();
155+
s.start("Logging in to Turso...");
156+
try {
157+
await $`turso auth login`;
158+
s.stop("Logged in to Turso successfully!");
159+
} catch (error) {
160+
s.stop("Failed to log in to Turso");
161+
throw error;
162+
}
132163
}
133164

134165
let success = false;
135166
let dbName = "";
136167
let suggestedName = path.basename(projectDir);
137168

138169
while (!success) {
139-
const dbNameResponse = await p.text({
170+
const dbNameResponse = await text({
140171
message: "Enter database name:",
141172
defaultValue: suggestedName,
142173
});
143174

144-
if (p.isCancel(dbNameResponse)) {
145-
p.cancel("Operation cancelled");
175+
if (isCancel(dbNameResponse)) {
176+
cancel("Operation cancelled");
146177
process.exit(0);
147178
}
148179

149180
dbName = dbNameResponse as string;
150-
const spinner = p.spinner();
181+
const s = spinner();
151182

152183
try {
153-
spinner.start(`Creating Turso database "${dbName}"...`);
184+
s.start(`Creating Turso database "${dbName}"...`);
154185
const config = await createTursoDatabase(dbName);
155186
await writeEnvFile(projectDir, config);
156-
spinner.stop("Turso database configured successfully!");
187+
s.stop("Turso database configured successfully!");
157188
success = true;
158189
} catch (error) {
159190
if (error instanceof Error && error.message === "DATABASE_EXISTS") {
160-
spinner.stop(`Database "${dbName}" already exists`);
191+
s.stop(`Database "${dbName}" already exists`);
161192
suggestedName = `${dbName}-${Math.floor(Math.random() * 1000)}`;
162193
} else {
163194
throw error;
164195
}
165196
}
166197
}
167-
168-
p.outro("Turso setup completed successfully!");
169198
} catch (error) {
170-
p.log.error(`Error during Turso setup: ${error}`);
199+
log.error(`Error during Turso setup: ${error}`);
171200
await writeEnvFile(projectDir);
172201
displayManualSetupInstructions();
173-
p.outro("Setup completed with manual configuration required.");
202+
outro("Setup completed with manual configuration required.");
174203
}
175204
}

0 commit comments

Comments
 (0)