mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
better log message in db setups
This commit is contained in:
5
.changeset/odd-trees-chew.md
Normal file
5
.changeset/odd-trees-chew.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"create-better-t-stack": patch
|
||||
---
|
||||
|
||||
update database setup log messages
|
||||
@@ -17,7 +17,7 @@ type MongoDBConfig = {
|
||||
|
||||
async function checkAtlasCLI(): Promise<boolean> {
|
||||
const s = spinner();
|
||||
s.start("Checking for MongoDB Atlas CLI");
|
||||
s.start("Checking for MongoDB Atlas CLI...");
|
||||
|
||||
try {
|
||||
const exists = await commandExists("atlas");
|
||||
@@ -28,7 +28,7 @@ async function checkAtlasCLI(): Promise<boolean> {
|
||||
);
|
||||
return exists;
|
||||
} catch (_error) {
|
||||
s.stop(pc.red("Error checking for MongoDB Atlas CLI"));
|
||||
s.stop(pc.red("Error checking MongoDB Atlas CLI"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,7 @@ async function initMongoDBAtlas(
|
||||
stdio: "inherit",
|
||||
});
|
||||
|
||||
log.info(pc.green("Atlas setup complete!"));
|
||||
log.info(pc.green("MongoDB Atlas deployment ready"));
|
||||
|
||||
const connectionString = await text({
|
||||
message: "Enter your MongoDB connection string:",
|
||||
@@ -127,13 +127,13 @@ ${pc.green("MongoDB Atlas Manual Setup Instructions:")}
|
||||
export async function setupMongoDBAtlas(config: ProjectConfig) {
|
||||
const { projectDir } = config;
|
||||
const mainSpinner = spinner();
|
||||
mainSpinner.start("Setting up MongoDB Atlas");
|
||||
mainSpinner.start("Setting up MongoDB Atlas...");
|
||||
|
||||
const serverDir = path.join(projectDir, "apps/server");
|
||||
try {
|
||||
await fs.ensureDir(serverDir);
|
||||
|
||||
mainSpinner.stop("Starting MongoDB Atlas setup");
|
||||
mainSpinner.stop("MongoDB Atlas setup ready");
|
||||
|
||||
const config = await initMongoDBAtlas(serverDir);
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { consola } from "consola";
|
||||
import { execa } from "execa";
|
||||
import fs from "fs-extra";
|
||||
import pc from "picocolors";
|
||||
import type { PackageManager } from "../../types";
|
||||
import type { PackageManager, ProjectConfig } from "../../types";
|
||||
import { getPackageExecutionCommand } from "../../utils/get-package-execution-command";
|
||||
import {
|
||||
type EnvVariable,
|
||||
@@ -47,10 +47,13 @@ async function executeNeonCommand(
|
||||
|
||||
if (spinnerText) s.start(spinnerText);
|
||||
const result = await execa(fullCommand, { shell: true });
|
||||
if (spinnerText) s.stop(pc.green("Completed"));
|
||||
if (spinnerText)
|
||||
s.stop(
|
||||
pc.green(spinnerText.replace("...", "").replace("ing ", "ed ").trim()),
|
||||
);
|
||||
return result;
|
||||
} catch (error) {
|
||||
if (s) s.stop(pc.red(`Failed: ${spinnerText}`));
|
||||
if (s) s.stop(pc.red(`Failed: ${spinnerText || "Command execution"}`));
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -75,7 +78,6 @@ async function authenticateWithNeon(packageManager: PackageManager) {
|
||||
"neonctl auth",
|
||||
"Authenticating with Neon...",
|
||||
);
|
||||
log.success("Authenticated with Neon successfully!");
|
||||
return true;
|
||||
} catch (_error) {
|
||||
consola.error(pc.red("Failed to authenticate with Neon"));
|
||||
@@ -149,17 +151,15 @@ function displayManualSetupInstructions() {
|
||||
DATABASE_URL="your_connection_string"`);
|
||||
}
|
||||
|
||||
import type { ProjectConfig } from "../../types";
|
||||
|
||||
export async function setupNeonPostgres(config: ProjectConfig): Promise<void> {
|
||||
const { packageManager, projectDir } = config;
|
||||
const setupSpinner = spinner();
|
||||
setupSpinner.start("Setting up Neon PostgreSQL");
|
||||
setupSpinner.start("Checking Neon authentication...");
|
||||
|
||||
try {
|
||||
const isAuthenticated = await isNeonAuthenticated(packageManager);
|
||||
|
||||
setupSpinner.stop("Setting up Neon PostgreSQL");
|
||||
setupSpinner.stop("Neon authentication checked");
|
||||
|
||||
if (!isAuthenticated) {
|
||||
log.info("Please authenticate with Neon to continue:");
|
||||
@@ -202,9 +202,9 @@ export async function setupNeonPostgres(config: ProjectConfig): Promise<void> {
|
||||
await fs.ensureDir(path.join(projectDir, "apps/server"));
|
||||
await writeEnvFile(projectDir, config);
|
||||
|
||||
finalSpinner.stop("Neon database configured successfully!");
|
||||
finalSpinner.stop("Neon database configured!");
|
||||
} catch (error) {
|
||||
setupSpinner.stop(pc.red("Neon PostgreSQL setup failed"));
|
||||
setupSpinner.stop(pc.red("Neon authentication check failed"));
|
||||
|
||||
if (error instanceof Error) {
|
||||
consola.error(pc.red(error.message));
|
||||
|
||||
@@ -22,12 +22,12 @@ async function initPrismaDatabase(
|
||||
): Promise<PrismaConfig | null> {
|
||||
const s = spinner();
|
||||
try {
|
||||
s.start("Initializing Prisma PostgreSQL");
|
||||
s.start("Initializing Prisma PostgreSQL...");
|
||||
|
||||
const prismaDir = path.join(serverDir, "prisma");
|
||||
await fs.ensureDir(prismaDir);
|
||||
|
||||
s.stop("Initializing Prisma. Follow the prompts below:");
|
||||
s.stop("Prisma PostgreSQL initialized. Follow the prompts below:");
|
||||
|
||||
const prismaInitCommand = getPackageExecutionCommand(
|
||||
packageManager,
|
||||
@@ -65,7 +65,7 @@ async function initPrismaDatabase(
|
||||
databaseUrl: databaseUrl as string,
|
||||
};
|
||||
} catch (error) {
|
||||
s.stop(pc.red("Failed to initialize Prisma PostgreSQL"));
|
||||
s.stop(pc.red("Prisma PostgreSQL initialization failed"));
|
||||
if (error instanceof Error) {
|
||||
consola.error(error.message);
|
||||
}
|
||||
@@ -150,12 +150,12 @@ export async function setupPrismaPostgres(config: ProjectConfig) {
|
||||
const { packageManager, projectDir } = config;
|
||||
const serverDir = path.join(projectDir, "apps/server");
|
||||
const s = spinner();
|
||||
s.start("Setting up Prisma PostgreSQL");
|
||||
s.start("Setting up Prisma PostgreSQL...");
|
||||
|
||||
try {
|
||||
await fs.ensureDir(serverDir);
|
||||
|
||||
s.stop("Starting Prisma setup");
|
||||
s.stop("Prisma PostgreSQL setup ready");
|
||||
|
||||
const config = await initPrismaDatabase(serverDir, packageManager);
|
||||
|
||||
@@ -172,9 +172,9 @@ export async function setupPrismaPostgres(config: ProjectConfig) {
|
||||
);
|
||||
} else {
|
||||
const fallbackSpinner = spinner();
|
||||
fallbackSpinner.start("Setting up fallback configuration");
|
||||
fallbackSpinner.start("Setting up fallback configuration...");
|
||||
await writeEnvFile(projectDir);
|
||||
fallbackSpinner.stop("Manual setup required");
|
||||
fallbackSpinner.stop("Fallback configuration ready");
|
||||
displayManualSetupInstructions();
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -66,7 +66,7 @@ async function initializeSupabase(
|
||||
stdio: "inherit",
|
||||
shell: true,
|
||||
});
|
||||
log.success("Supabase project initialized successfully.");
|
||||
log.success("Supabase project initialized");
|
||||
return true;
|
||||
} catch (error) {
|
||||
consola.error(pc.red("Failed to initialize Supabase project."));
|
||||
@@ -183,7 +183,7 @@ export async function setupSupabase(config: ProjectConfig) {
|
||||
const envUpdated = await writeSupabaseEnvFile(projectDir, dbUrl);
|
||||
|
||||
if (envUpdated) {
|
||||
log.success(pc.green("Supabase local development setup complete!"));
|
||||
log.success(pc.green("Supabase local development setup ready!"));
|
||||
} else {
|
||||
log.error(
|
||||
pc.red(
|
||||
|
||||
@@ -49,7 +49,7 @@ async function loginToTurso() {
|
||||
try {
|
||||
s.start("Logging in to Turso...");
|
||||
await $`turso auth login`;
|
||||
s.stop("Logged in to Turso successfully!");
|
||||
s.stop("Logged into Turso");
|
||||
return true;
|
||||
} catch (_error) {
|
||||
s.stop(pc.red("Failed to log in to Turso"));
|
||||
@@ -69,7 +69,7 @@ async function installTursoCLI(isMac: boolean) {
|
||||
await $`bash -c '${installScript}'`;
|
||||
}
|
||||
|
||||
s.stop("Turso CLI installed successfully!");
|
||||
s.stop("Turso CLI installed");
|
||||
return true;
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.message.includes("User force closed")) {
|
||||
@@ -153,7 +153,7 @@ async function createTursoDatabase(dbName: string, groupName: string | null) {
|
||||
await $`turso db create ${dbName}`;
|
||||
}
|
||||
|
||||
s.stop(`Created database "${dbName}"`);
|
||||
s.stop(`Turso database "${dbName}" created`);
|
||||
} catch (error) {
|
||||
s.stop(pc.red(`Failed to create database "${dbName}"`));
|
||||
if (error instanceof Error && error.message.includes("already exists")) {
|
||||
@@ -166,7 +166,7 @@ async function createTursoDatabase(dbName: string, groupName: string | null) {
|
||||
const { stdout: dbUrl } = await $`turso db show ${dbName} --url`;
|
||||
const { stdout: authToken } = await $`turso db tokens create ${dbName}`;
|
||||
|
||||
s.stop("Retrieved database connection details");
|
||||
s.stop("Database connection details retrieved");
|
||||
|
||||
return {
|
||||
dbUrl: dbUrl.trim(),
|
||||
@@ -210,7 +210,7 @@ export async function setupTurso(config: ProjectConfig): Promise<void> {
|
||||
const { orm, projectDir } = config;
|
||||
const _isDrizzle = orm === "drizzle";
|
||||
const setupSpinner = spinner();
|
||||
setupSpinner.start("Setting up Turso database");
|
||||
setupSpinner.start("Checking Turso CLI availability...");
|
||||
|
||||
try {
|
||||
const platform = os.platform();
|
||||
@@ -226,7 +226,7 @@ export async function setupTurso(config: ProjectConfig): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
setupSpinner.stop("Checking Turso CLI");
|
||||
setupSpinner.stop("Turso CLI availability checked");
|
||||
|
||||
const isCliInstalled = await isTursoInstalled();
|
||||
|
||||
@@ -278,23 +278,21 @@ export async function setupTurso(config: ProjectConfig): Promise<void> {
|
||||
|
||||
try {
|
||||
const config = await createTursoDatabase(dbName, selectedGroup);
|
||||
|
||||
const finalSpinner = spinner();
|
||||
finalSpinner.start("Writing configuration to .env file");
|
||||
await writeEnvFile(projectDir, config);
|
||||
finalSpinner.stop("Turso database configured successfully!");
|
||||
|
||||
success = true;
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.message === "DATABASE_EXISTS") {
|
||||
log.warn(pc.yellow(`Database "${pc.red(dbName)}" already exists`));
|
||||
suggestedName = `${dbName}-${Math.floor(Math.random() * 1000)}`;
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.success("Turso database setup completed successfully!");
|
||||
} catch (error) {
|
||||
setupSpinner.stop(pc.red("Failed to set up Turso database"));
|
||||
setupSpinner.stop(pc.red("Turso CLI availability check failed"));
|
||||
consola.error(
|
||||
pc.red(
|
||||
`Error during Turso setup: ${
|
||||
|
||||
Reference in New Issue
Block a user