Add spinner feedback to database setup workflows

This commit is contained in:
Aman Varshney
2025-04-11 15:45:41 +05:30
parent 37217f4e18
commit 30efd64fc1
6 changed files with 258 additions and 125 deletions

View File

@@ -47,7 +47,7 @@ async function executeNeonCommand(
if (s) s.start(spinnerText);
const result = await execa(cmd, cmdArgs);
if (s) s.stop();
if (s) s.stop(spinnerText);
return result;
} catch (error) {
@@ -58,11 +58,15 @@ async function executeNeonCommand(
async function isNeonAuthenticated(packageManager: string) {
try {
const { stdout } = await executeNeonCommand(packageManager, [
const { cmd, cmdArgs } = buildNeonCommand(packageManager, [
"projects",
"list",
]);
return !stdout.includes("not authenticated") && !stdout.includes("error");
const result = await execa(cmd, cmdArgs);
return (
!result.stdout.includes("not authenticated") &&
!result.stdout.includes("error")
);
} catch {
return false;
}
@@ -147,11 +151,14 @@ export async function setupNeonPostgres(
projectDir: string,
packageManager: ProjectPackageManager,
) {
const s = spinner();
const setupSpinner = spinner();
setupSpinner.start("Setting up Neon PostgreSQL");
try {
const isAuthenticated = await isNeonAuthenticated(packageManager);
setupSpinner.stop("Setting up Neon PostgreSQL");
if (!isAuthenticated) {
log.info("Please authenticate with Neon to continue:");
await authenticateWithNeon(packageManager);
@@ -180,14 +187,20 @@ export async function setupNeonPostgres(
);
}
const finalSpinner = spinner();
finalSpinner.start("Configuring database connection");
await fs.ensureDir(path.join(projectDir, "apps/server"));
await writeEnvFile(projectDir, config);
log.success("Neon database configured successfully!");
finalSpinner.stop("Neon database configured successfully!");
} catch (error) {
s.stop(pc.red("Neon PostgreSQL setup failed"));
setupSpinner.stop(pc.red("Neon PostgreSQL setup failed"));
if (error instanceof Error) {
log.error(pc.red(error.message));
}
await writeEnvFile(projectDir);
displayManualSetupInstructions();
}