Add consola errors, update to better-auth v1.2.6

This commit is contained in:
Aman Varshney
2025-04-13 14:36:14 +05:30
parent 3dd2147a98
commit 1e67949e4f
16 changed files with 184 additions and 123 deletions

View File

@@ -1,5 +1,5 @@
import path from "node:path";
import { log } from "@clack/prompts";
import consola from "consola";
import pc from "picocolors";
import type { ProjectFrontend } from "../types";
import { addPackageDependency } from "../utils/add-package-deps";
@@ -54,9 +54,9 @@ export async function setupAuth(
});
}
} catch (error) {
log.error(pc.red("Failed to configure authentication"));
consola.error(pc.red("Failed to configure authentication"));
if (error instanceof Error) {
log.error(pc.red(error.message));
consola.error(pc.red(error.message));
}
throw error;
}

View File

@@ -1,4 +1,5 @@
import path from "node:path";
import consola from "consola";
import fs from "fs-extra";
import type {
ProjectAddons,
@@ -16,7 +17,7 @@ export async function createReadme(projectDir: string, options: ProjectConfig) {
try {
await fs.writeFile(readmePath, content);
} catch (error) {
console.error("Failed to create README.md file:", error);
consola.error("Failed to create README.md file:", error);
}
}
@@ -30,24 +31,33 @@ function generateReadmeContent(options: ProjectConfig): string {
orm = "drizzle",
runtime = "bun",
frontend = ["tanstack-router"],
backend = "hono",
} = options;
const hasReactRouter = frontend.includes("react-router");
const hasTanstackRouter = frontend.includes("tanstack-router");
const hasNative = frontend.includes("native");
const hasNext = frontend.includes("next");
const hasTanstackStart = frontend.includes("tanstack-start");
const packageManagerRunCmd =
packageManager === "npm" ? "npm run" : packageManager;
const port = hasReactRouter ? "5173" : "3001";
// Determine the web port based on the frontend framework
let webPort = "3001"; // Default for TanStack Router and TanStack Start
if (hasReactRouter) {
webPort = "5173";
} else if (hasNext) {
webPort = "3000";
}
return `# ${projectName}
This project was created with [Better-T-Stack](https://github.com/AmanVarshney01/create-better-t-stack), a modern TypeScript stack that combines React, ${hasTanstackRouter ? "TanStack Router" : "React Router"}, Hono, tRPC, and more.
This project was created with [Better-T-Stack](https://github.com/AmanVarshney01/create-better-t-stack), a modern TypeScript stack that combines React, ${hasTanstackRouter ? "TanStack Router" : hasReactRouter ? "React Router" : hasNext ? "Next.js" : hasTanstackStart ? "TanStack Start" : ""}, ${backend[0].toUpperCase() + backend.slice(1)}, tRPC, and more.
## Features
${generateFeaturesList(database, auth, addons, orm, runtime, frontend)}
${generateFeaturesList(database, auth, addons, orm, runtime, frontend, backend)}
## Getting Started
@@ -66,8 +76,8 @@ ${packageManagerRunCmd} dev
\`\`\`
${
hasTanstackRouter || hasReactRouter
? `Open [http://localhost:${port}](http://localhost:${port}) in your browser to see the web application.`
hasTanstackRouter || hasReactRouter || hasNext || hasTanstackStart
? `Open [http://localhost:${webPort}](http://localhost:${webPort}) in your browser to see the web application.`
: ""
}
${hasNative ? "Use the Expo Go app to run the mobile application.\n" : ""}
@@ -84,12 +94,12 @@ ${
\`\`\`
${projectName}/
├── apps/
${hasTanstackRouter || hasReactRouter ? `│ ├── web/ # Frontend application (React, ${hasTanstackRouter ? "TanStack Router" : "React Router"})\n` : ""}${hasNative ? "│ ├── native/ # Mobile application (React Native, Expo)\n" : ""}│ └── server/ # Backend API (Hono, tRPC)
${hasTanstackRouter || hasReactRouter || hasNext || hasTanstackStart ? `│ ├── web/ # Frontend application (${hasTanstackRouter ? "React + TanStack Router" : hasReactRouter ? "React + React Router" : hasNext ? "Next.js" : "React + TanStack Start"})\n` : ""}${hasNative ? "│ ├── native/ # Mobile application (React Native, Expo)\n" : ""}${addons.includes("starlight") ? "│ ├── docs/ # Documentation site (Astro Starlight)\n" : ""}│ └── server/ # Backend API (${backend[0].toUpperCase() + backend.slice(1)}, tRPC)
\`\`\`
## Available Scripts
${generateScriptsList(packageManagerRunCmd, database, orm, auth, hasNative)}
${generateScriptsList(packageManagerRunCmd, database, orm, auth, hasNative, addons, backend)}
`;
}
@@ -100,10 +110,13 @@ function generateFeaturesList(
orm: ProjectOrm,
runtime: ProjectRuntime,
frontend: ProjectFrontend[],
backend: string,
): string {
const hasTanstackRouter = frontend.includes("tanstack-router");
const hasReactRouter = frontend.includes("react-router");
const hasNative = frontend.includes("native");
const hasNext = frontend.includes("next");
const hasTanstackStart = frontend.includes("tanstack-start");
const addonsList = [
"- **TypeScript** - For type safety and improved developer experience",
@@ -115,6 +128,12 @@ function generateFeaturesList(
);
} else if (hasReactRouter) {
addonsList.push("- **React Router** - Declarative routing for React");
} else if (hasNext) {
addonsList.push("- **Next.js** - Full-stack React framework");
} else if (hasTanstackStart) {
addonsList.push(
"- **TanStack Start** - SSR framework with TanStack Router",
);
}
if (hasNative) {
@@ -125,7 +144,19 @@ function generateFeaturesList(
addonsList.push(
"- **TailwindCSS** - Utility-first CSS for rapid UI development",
"- **shadcn/ui** - Reusable UI components",
"- **Hono** - Lightweight, performant server framework",
);
if (backend === "hono") {
addonsList.push("- **Hono** - Lightweight, performant server framework");
} else if (backend === "express") {
addonsList.push("- **Express** - Fast, unopinionated web framework");
} else if (backend === "elysia") {
addonsList.push("- **Elysia** - Type-safe, high-performance framework");
} else if (backend === "next") {
addonsList.push("- **Next.js** - Full-stack React framework");
}
addonsList.push(
"- **tRPC** - End-to-end type-safe APIs",
`- **${runtime === "bun" ? "Bun" : "Node.js"}** - Runtime environment`,
);
@@ -133,7 +164,7 @@ function generateFeaturesList(
if (database !== "none") {
addonsList.push(
`- **${orm === "drizzle" ? "Drizzle" : "Prisma"}** - TypeScript-first ORM`,
`- **${database === "sqlite" ? "SQLite/Turso" : "PostgreSQL"}** - Database engine`,
`- **${database === "sqlite" ? "SQLite/Turso" : database === "postgres" ? "PostgreSQL" : database === "mysql" ? "MySQL" : "MongoDB"}** - Database engine`,
);
}
@@ -152,6 +183,8 @@ function generateFeaturesList(
addonsList.push("- **Biome** - Linting and formatting");
} else if (addon === "husky") {
addonsList.push("- **Husky** - Git hooks for code quality");
} else if (addon === "starlight") {
addonsList.push("- **Starlight** - Documentation site with Astro");
}
}
@@ -185,11 +218,23 @@ cd apps/server && ${packageManagerRunCmd} db:local
1. Make sure you have a PostgreSQL database set up.
2. Update your \`apps/server/.env\` file with your PostgreSQL connection details.
`;
} else if (database === "mysql") {
setup += `This project uses MySQL${orm === "drizzle" ? " with Drizzle ORM" : " with Prisma"}.
1. Make sure you have a MySQL database set up.
2. Update your \`apps/server/.env\` file with your MySQL connection details.
`;
} else if (database === "mongodb") {
setup += `This project uses MongoDB with Prisma ORM.
1. Make sure you have MongoDB set up.
2. Update your \`apps/server/.env\` file with your MongoDB connection URI.
`;
}
setup += `
${auth ? "4" : "3"}. ${
${auth ? "3" : "3"}. ${
orm === "prisma"
? `Generate the Prisma client and push the schema:
\`\`\`bash
@@ -211,9 +256,11 @@ function generateScriptsList(
orm: ProjectOrm,
auth: boolean,
hasNative: boolean,
addons: ProjectAddons[],
backend: string,
): string {
let scripts = `- \`${packageManagerRunCmd} dev\`: Start both web and server in development mode
- \`${packageManagerRunCmd} build\`: Build both web and server
let scripts = `- \`${packageManagerRunCmd} dev\`: Start all applications in development mode
- \`${packageManagerRunCmd} build\`: Build all applications
- \`${packageManagerRunCmd} dev:web\`: Start only the web application
- \`${packageManagerRunCmd} dev:server\`: Start only the server
- \`${packageManagerRunCmd} check-types\`: Check TypeScript types across all apps`;
@@ -229,9 +276,32 @@ function generateScriptsList(
- \`${packageManagerRunCmd} db:studio\`: Open database studio UI`;
if (database === "sqlite" && orm === "drizzle") {
scripts += `\n- \`cd apps/server && ${packageManagerRunCmd} db:local\`: Start the local SQLite database`;
scripts += `
- \`cd apps/server && ${packageManagerRunCmd} db:local\`: Start the local SQLite database`;
}
}
if (addons.includes("biome")) {
scripts += `
- \`${packageManagerRunCmd} check\`: Run Biome formatting and linting`;
}
if (addons.includes("pwa")) {
scripts += `
- \`cd apps/web && ${packageManagerRunCmd} generate-pwa-assets\`: Generate PWA assets`;
}
if (addons.includes("tauri")) {
scripts += `
- \`cd apps/web && ${packageManagerRunCmd} desktop:dev\`: Start Tauri desktop app in development
- \`cd apps/web && ${packageManagerRunCmd} desktop:build\`: Build Tauri desktop app`;
}
if (addons.includes("starlight")) {
scripts += `
- \`cd apps/docs && ${packageManagerRunCmd} dev\`: Start documentation site
- \`cd apps/docs && ${packageManagerRunCmd} build\`: Build documentation site`;
}
return scripts;
}

View File

@@ -1,5 +1,6 @@
import path from "node:path";
import { log, spinner } from "@clack/prompts";
import consola from "consola";
import fs from "fs-extra";
import pc from "picocolors";
import type {
@@ -74,7 +75,7 @@ export async function setupDatabase(
} catch (error) {
s.stop(pc.red("Failed to set up database"));
if (error instanceof Error) {
log.error(pc.red(error.message));
consola.error(pc.red(error.message));
}
throw error;
}

View File

@@ -1,4 +1,5 @@
import { log, spinner } from "@clack/prompts";
import consola from "consola";
import { $ } from "execa";
import pc from "picocolors";
import type { ProjectAddons, ProjectPackageManager } from "../types";
@@ -30,7 +31,7 @@ export async function installDependencies({
} catch (error) {
s.stop(pc.red("Failed to install dependencies"));
if (error instanceof Error) {
log.error(pc.red(`Installation error: ${error.message}`));
consola.error(pc.red(`Installation error: ${error.message}`));
}
throw error;
}

View File

@@ -1,5 +1,6 @@
import path from "node:path";
import { cancel, isCancel, log, spinner, text } from "@clack/prompts";
import consola from "consola";
import { execa } from "execa";
import fs from "fs-extra";
import pc from "picocolors";
@@ -34,7 +35,7 @@ async function initMongoDBAtlas(
const hasAtlas = await checkAtlasCLI();
if (!hasAtlas) {
log.error(pc.red("MongoDB Atlas CLI not found."));
consola.error(pc.red("MongoDB Atlas CLI not found."));
log.info(
pc.yellow(
"Please install it from: https://www.mongodb.com/docs/atlas/cli/current/install-atlas-cli/",
@@ -74,7 +75,7 @@ async function initMongoDBAtlas(
};
} catch (error) {
if (error instanceof Error) {
log.error(pc.red(error.message));
consola.error(pc.red(error.message));
}
return null;
}
@@ -105,7 +106,7 @@ async function writeEnvFile(projectDir: string, config?: MongoDBConfig) {
await fs.writeFile(envPath, envContent.trim());
} catch (error) {
log.error("Failed to update environment configuration");
consola.error("Failed to update environment configuration");
throw error;
}
}
@@ -154,7 +155,7 @@ export async function setupMongoDBAtlas(projectDir: string) {
}
} catch (error) {
mainSpinner.stop(pc.red("MongoDB Atlas setup failed"));
log.error(
consola.error(
pc.red(
`Error during MongoDB Atlas setup: ${error instanceof Error ? error.message : String(error)}`,
),

View File

@@ -1,5 +1,6 @@
import path from "node:path";
import { cancel, isCancel, log, spinner, text } from "@clack/prompts";
import { consola } from "consola";
import { execa } from "execa";
import fs from "fs-extra";
import pc from "picocolors";
@@ -82,7 +83,7 @@ async function authenticateWithNeon(packageManager: string) {
log.success("Authenticated with Neon successfully!");
return true;
} catch (error) {
log.error(pc.red("Failed to authenticate with Neon"));
consola.error(pc.red("Failed to authenticate with Neon"));
throw error;
}
}
@@ -116,10 +117,12 @@ async function createNeonProject(
roleName: params.role,
};
}
log.error(pc.red("Failed to extract connection information from response"));
consola.error(
pc.red("Failed to extract connection information from response"),
);
return null;
} catch (error) {
log.error(pc.red("Failed to create Neon project"));
consola.error(pc.red("Failed to create Neon project"));
throw error;
}
}
@@ -198,7 +201,7 @@ export async function setupNeonPostgres(
setupSpinner.stop(pc.red("Neon PostgreSQL setup failed"));
if (error instanceof Error) {
log.error(pc.red(error.message));
consola.error(pc.red(error.message));
}
await writeEnvFile(projectDir);

View File

@@ -1,4 +1,4 @@
import { note } from "@clack/prompts";
import { consola } from "consola";
import pc from "picocolors";
import type {
ProjectAddons,
@@ -57,8 +57,8 @@ export function displayPostInstallInstructions(
const webPort = hasReactRouter ? "5173" : "3001";
note(
`${pc.cyan("1.")} ${cdCmd}
consola.box(
`${pc.bold("Next steps")}\n${pc.cyan("1.")} ${cdCmd}
${!depsInstalled ? `${pc.cyan("2.")} ${packageManager} install\n` : ""}${pc.cyan(depsInstalled ? "2." : "3.")} ${runCmd} dev
${pc.bold("Your project will be available at:")}
@@ -68,9 +68,9 @@ ${
: `${pc.yellow("NOTE:")} You are creating a backend-only app (no frontend selected)\n`
}${pc.cyan("•")} API: http://localhost:3000
${addons?.includes("starlight") ? `${pc.cyan("•")} Docs: http://localhost:4321\n` : ""}${nativeInstructions ? `\n${nativeInstructions.trim()}` : ""}${databaseInstructions ? `\n${databaseInstructions.trim()}` : ""}${tauriInstructions ? `\n${tauriInstructions.trim()}` : ""}${lintingInstructions ? `\n${lintingInstructions.trim()}` : ""}${pwaInstructions ? `\n${pwaInstructions.trim()}` : ""}${starlightInstructions ? `\n${starlightInstructions.trim()}` : ""}
\n${pc.bold("Like Better-T Stack?")} Please consider giving us a star on GitHub:
${pc.bold("Like Better-T Stack?")} Please consider giving us a star on GitHub:
${pc.cyan("https://github.com/AmanVarshney01/create-better-t-stack")}`,
"Next steps",
);
}

View File

@@ -1,5 +1,6 @@
import path from "node:path";
import { cancel, isCancel, log, password, spinner } from "@clack/prompts";
import { consola } from "consola";
import { execa } from "execa";
import fs from "fs-extra";
import pc from "picocolors";
@@ -62,7 +63,7 @@ async function initPrismaDatabase(
} catch (error) {
s.stop(pc.red("Failed to initialize Prisma PostgreSQL"));
if (error instanceof Error) {
log.error(error.message);
consola.error(error.message);
}
return null;
}
@@ -93,7 +94,7 @@ async function writeEnvFile(projectDir: string, config?: PrismaConfig) {
await fs.writeFile(envPath, envContent.trim());
} catch (error) {
log.error("Failed to update environment configuration");
consola.error("Failed to update environment configuration");
throw error;
}
}
@@ -181,7 +182,7 @@ export async function setupPrismaPostgres(
}
} catch (error) {
s.stop(pc.red("Prisma PostgreSQL setup failed"));
log.error(
consola.error(
pc.red(
`Error during Prisma PostgreSQL setup: ${error instanceof Error ? error.message : String(error)}`,
),

View File

@@ -1,5 +1,6 @@
import path from "node:path";
import { log, spinner } from "@clack/prompts";
import consola from "consola";
import { execa } from "execa";
import pc from "picocolors";
import type { ProjectPackageManager } from "../types";
@@ -57,7 +58,7 @@ export async function setupStarlight(
} catch (error) {
s.stop(pc.red("Failed to set up Starlight documentation site"));
if (error instanceof Error) {
log.error(pc.red(error.message));
consola.error(pc.red(error.message));
}
throw error;
}

View File

@@ -1,5 +1,6 @@
import path from "node:path";
import { log, spinner } from "@clack/prompts";
import { consola } from "consola";
import { execa } from "execa";
import fs from "fs-extra";
import pc from "picocolors";
@@ -88,7 +89,7 @@ export async function setupTauri(
} catch (error) {
s.stop(pc.red("Failed to set up Tauri"));
if (error instanceof Error) {
log.error(pc.red(error.message));
consola.error(pc.red(error.message));
}
throw error;
}

View File

@@ -9,6 +9,7 @@ import {
spinner,
text,
} from "@clack/prompts";
import consola from "consola";
import { $ } from "execa";
import fs from "fs-extra";
import pc from "picocolors";
@@ -301,7 +302,7 @@ export async function setupTurso(
}
} catch (error) {
setupSpinner.stop(pc.red("Failed to set up Turso database"));
log.error(
consola.error(
pc.red(
`Error during Turso setup: ${error instanceof Error ? error.message : String(error)}`,
),