mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
bug fixes
This commit is contained in:
@@ -12,7 +12,7 @@ export async function createProject(options: ProjectConfig) {
|
||||
let shouldInstallDeps = false;
|
||||
|
||||
try {
|
||||
await tasks([
|
||||
const tasksList = [
|
||||
{
|
||||
title: "Creating project directory",
|
||||
task: async () => {
|
||||
@@ -33,15 +33,22 @@ export async function createProject(options: ProjectConfig) {
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
];
|
||||
|
||||
if (options.git) {
|
||||
tasksList.push({
|
||||
title: "Initializing git repository",
|
||||
task: async () => {
|
||||
if (options.git) {
|
||||
await $`git init ${projectDir}`;
|
||||
}
|
||||
await $`git init ${projectDir}`;
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
await tasks(tasksList);
|
||||
|
||||
if (options.database === "libsql") {
|
||||
await setupTurso(projectDir);
|
||||
}
|
||||
|
||||
const installDepsResponse = await confirm({
|
||||
message: `📦 Install dependencies using ${options.packageManager}?`,
|
||||
@@ -71,10 +78,6 @@ export async function createProject(options: ProjectConfig) {
|
||||
}
|
||||
}
|
||||
|
||||
if (options.database === "libsql") {
|
||||
await setupTurso(projectDir);
|
||||
}
|
||||
|
||||
log.success("✨ Project created successfully!\n");
|
||||
log.info(chalk.dim("Next steps:"));
|
||||
log.info(` cd ${options.projectName}`);
|
||||
|
||||
@@ -1,6 +1,19 @@
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import * as p from "@clack/prompts";
|
||||
import {
|
||||
cancel,
|
||||
confirm,
|
||||
group,
|
||||
intro,
|
||||
isCancel,
|
||||
log,
|
||||
multiselect,
|
||||
outro,
|
||||
select,
|
||||
spinner,
|
||||
tasks,
|
||||
text,
|
||||
} from "@clack/prompts";
|
||||
import { $ } from "execa";
|
||||
import fs from "fs-extra";
|
||||
import { isTursoInstalled, isTursoLoggedIn } from "../utils/turso-cli";
|
||||
@@ -11,21 +24,21 @@ interface TursoConfig {
|
||||
}
|
||||
|
||||
async function loginToTurso() {
|
||||
const spinner = p.spinner();
|
||||
const s = spinner();
|
||||
try {
|
||||
spinner.start("Logging in to Turso...");
|
||||
s.start("Logging in to Turso...");
|
||||
await $`turso auth login`;
|
||||
spinner.stop("Logged in to Turso successfully!");
|
||||
s.stop("Logged in to Turso successfully!");
|
||||
} catch (error) {
|
||||
spinner.stop("Failed to log in to Turso");
|
||||
s.stop("Failed to log in to Turso");
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async function installTursoCLI(isMac: boolean) {
|
||||
const spinner = p.spinner();
|
||||
const s = spinner();
|
||||
try {
|
||||
spinner.start("Installing Turso CLI...");
|
||||
s.start("Installing Turso CLI...");
|
||||
|
||||
if (isMac) {
|
||||
await $`brew install tursodatabase/tap/turso`;
|
||||
@@ -35,14 +48,14 @@ async function installTursoCLI(isMac: boolean) {
|
||||
await $`bash -c '${installScript}'`;
|
||||
}
|
||||
|
||||
spinner.stop("Turso CLI installed successfully!");
|
||||
s.stop("Turso CLI installed successfully!");
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.message.includes("User force closed")) {
|
||||
spinner.stop();
|
||||
p.log.warn("Turso CLI installation cancelled by user");
|
||||
s.stop();
|
||||
log.warn("Turso CLI installation cancelled by user");
|
||||
throw new Error("Installation cancelled");
|
||||
}
|
||||
spinner.stop("Failed to install Turso CLI");
|
||||
s.stop("Failed to install Turso CLI");
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -78,42 +91,38 @@ TURSO_AUTH_TOKEN=`;
|
||||
}
|
||||
|
||||
function displayManualSetupInstructions() {
|
||||
p.log.info("📝 Manual Turso Setup Instructions:");
|
||||
p.log.info("1. Visit https://turso.tech and create an account");
|
||||
p.log.info("2. Create a new database from the dashboard");
|
||||
p.log.info("3. Get your database URL and authentication token");
|
||||
p.log.info(
|
||||
"4. Add these credentials to the .env file in packages/server/.env",
|
||||
);
|
||||
p.log.info("\nThe .env file has been created with placeholder variables:");
|
||||
p.log.info("TURSO_DATABASE_URL=your_database_url");
|
||||
p.log.info("TURSO_AUTH_TOKEN=your_auth_token");
|
||||
log.info("📝 Manual Turso Setup Instructions:");
|
||||
log.info("1. Visit https://turso.tech and create an account");
|
||||
log.info("2. Create a new database from the dashboard");
|
||||
log.info("3. Get your database URL and authentication token");
|
||||
log.info("4. Add these credentials to the .env file in packages/server/.env");
|
||||
log.info("\nThe .env file has been created with placeholder variables:");
|
||||
log.info("TURSO_DATABASE_URL=your_database_url");
|
||||
log.info("TURSO_AUTH_TOKEN=your_auth_token");
|
||||
}
|
||||
|
||||
export async function setupTurso(projectDir: string) {
|
||||
p.intro("Setting up Turso...");
|
||||
|
||||
const platform = os.platform();
|
||||
const isMac = platform === "darwin";
|
||||
const canInstallCLI = platform !== "win32";
|
||||
|
||||
try {
|
||||
if (!canInstallCLI) {
|
||||
p.log.warn("Automatic Turso setup is not supported on Windows.");
|
||||
await writeEnvFile(projectDir);
|
||||
displayManualSetupInstructions();
|
||||
return;
|
||||
}
|
||||
if (!canInstallCLI) {
|
||||
log.warn("Automatic Turso setup is not supported on Windows.");
|
||||
await writeEnvFile(projectDir);
|
||||
displayManualSetupInstructions();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const isCliInstalled = await isTursoInstalled();
|
||||
|
||||
if (!isCliInstalled) {
|
||||
const shouldInstall = await p.confirm({
|
||||
const shouldInstall = await confirm({
|
||||
message: "Would you like to install Turso CLI?",
|
||||
});
|
||||
|
||||
if (p.isCancel(shouldInstall)) {
|
||||
p.cancel("Operation cancelled");
|
||||
if (isCancel(shouldInstall)) {
|
||||
cancel("Operation cancelled");
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
@@ -123,12 +132,34 @@ export async function setupTurso(projectDir: string) {
|
||||
return;
|
||||
}
|
||||
|
||||
await installTursoCLI(isMac);
|
||||
const s = spinner();
|
||||
s.start("Installing Turso CLI...");
|
||||
try {
|
||||
if (isMac) {
|
||||
await $`brew install tursodatabase/tap/turso`;
|
||||
} else {
|
||||
const { stdout: installScript } =
|
||||
await $`curl -sSfL https://get.tur.so/install.sh`;
|
||||
await $`bash -c '${installScript}'`;
|
||||
}
|
||||
s.stop("Turso CLI installed successfully!");
|
||||
} catch (error) {
|
||||
s.stop("Failed to install Turso CLI");
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
const isLoggedIn = await isTursoLoggedIn();
|
||||
if (!isLoggedIn) {
|
||||
await loginToTurso();
|
||||
const s = spinner();
|
||||
s.start("Logging in to Turso...");
|
||||
try {
|
||||
await $`turso auth login`;
|
||||
s.stop("Logged in to Turso successfully!");
|
||||
} catch (error) {
|
||||
s.stop("Failed to log in to Turso");
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
let success = false;
|
||||
@@ -136,40 +167,38 @@ export async function setupTurso(projectDir: string) {
|
||||
let suggestedName = path.basename(projectDir);
|
||||
|
||||
while (!success) {
|
||||
const dbNameResponse = await p.text({
|
||||
const dbNameResponse = await text({
|
||||
message: "Enter database name:",
|
||||
defaultValue: suggestedName,
|
||||
});
|
||||
|
||||
if (p.isCancel(dbNameResponse)) {
|
||||
p.cancel("Operation cancelled");
|
||||
if (isCancel(dbNameResponse)) {
|
||||
cancel("Operation cancelled");
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
dbName = dbNameResponse as string;
|
||||
const spinner = p.spinner();
|
||||
const s = spinner();
|
||||
|
||||
try {
|
||||
spinner.start(`Creating Turso database "${dbName}"...`);
|
||||
s.start(`Creating Turso database "${dbName}"...`);
|
||||
const config = await createTursoDatabase(dbName);
|
||||
await writeEnvFile(projectDir, config);
|
||||
spinner.stop("Turso database configured successfully!");
|
||||
s.stop("Turso database configured successfully!");
|
||||
success = true;
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.message === "DATABASE_EXISTS") {
|
||||
spinner.stop(`Database "${dbName}" already exists`);
|
||||
s.stop(`Database "${dbName}" already exists`);
|
||||
suggestedName = `${dbName}-${Math.floor(Math.random() * 1000)}`;
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
p.outro("Turso setup completed successfully!");
|
||||
} catch (error) {
|
||||
p.log.error(`Error during Turso setup: ${error}`);
|
||||
log.error(`Error during Turso setup: ${error}`);
|
||||
await writeEnvFile(projectDir);
|
||||
displayManualSetupInstructions();
|
||||
p.outro("Setup completed with manual configuration required.");
|
||||
outro("Setup completed with manual configuration required.");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user