From b5267e00a04cc7b30639faa579785bc49a57cdc2 Mon Sep 17 00:00:00 2001 From: Aman Varshney Date: Sun, 20 Apr 2025 20:19:10 +0530 Subject: [PATCH] Add setup warnings and handle no-ORM auth --- .changeset/stupid-cloths-pay.md | 5 ++++ apps/cli/src/helpers/post-installation.ts | 20 ++++++++++++++- apps/cli/src/helpers/template-manager.ts | 23 +++++++++++------ .../auth/server/base/src/lib/auth.ts.hbs | 25 ++++++++++++++----- 4 files changed, 59 insertions(+), 14 deletions(-) create mode 100644 .changeset/stupid-cloths-pay.md diff --git a/.changeset/stupid-cloths-pay.md b/.changeset/stupid-cloths-pay.md new file mode 100644 index 0000000..e265791 --- /dev/null +++ b/.changeset/stupid-cloths-pay.md @@ -0,0 +1,5 @@ +--- +"create-better-t-stack": patch +--- + +Add setup warnings and handle no-ORM auth diff --git a/apps/cli/src/helpers/post-installation.ts b/apps/cli/src/helpers/post-installation.ts index de71dd0..62019b0 100644 --- a/apps/cli/src/helpers/post-installation.ts +++ b/apps/cli/src/helpers/post-installation.ts @@ -43,6 +43,16 @@ export function displayPostInstallInstructions( const starlightInstructions = addons?.includes("starlight") ? getStarlightInstructions(runCmd) : ""; + const hasWeb = frontend?.some((f) => + ["tanstack-router", "react-router", "next", "tanstack-start"].includes(f), + ); + const hasNative = frontend?.includes("native"); + const bunWebNativeWarning = + packageManager === "bun" && hasNative && hasWeb + ? getBunWebNativeWarning() + : ""; + const noOrmWarning = + database !== "none" && orm === "none" ? getNoOrmWarning() : ""; const hasTanstackRouter = frontend?.includes("tanstack-router"); const hasTanstackStart = frontend?.includes("tanstack-start"); @@ -83,7 +93,7 @@ ${ lintingInstructions ? `\n${lintingInstructions.trim()}` : "" }${pwaInstructions ? `\n${pwaInstructions.trim()}` : ""}${ starlightInstructions ? `\n${starlightInstructions.trim()}` : "" -} +}${noOrmWarning ? `\n${noOrmWarning.trim()}` : ""}${bunWebNativeWarning ? `\n${bunWebNativeWarning.trim()}` : ""} ${pc.bold("Update all dependencies:\n")}${pc.cyan(tazeCommand)} @@ -165,3 +175,11 @@ function getStarlightInstructions(runCmd?: string): string { "•", )} Build docs site: ${`cd apps/docs && ${runCmd} build`}\n`; } + +function getNoOrmWarning(): string { + return `\n${pc.yellow("WARNING:")} Database selected without an ORM. Features requiring database access (e.g., examples, auth) need manual setup.\n`; +} + +function getBunWebNativeWarning(): string { + return `\n${pc.yellow("WARNING:")} 'bun' might cause issues with web + native apps in a monorepo. Use 'pnpm' if problems arise.\n`; +} diff --git a/apps/cli/src/helpers/template-manager.ts b/apps/cli/src/helpers/template-manager.ts index e1696e8..ff7fe11 100644 --- a/apps/cli/src/helpers/template-manager.ts +++ b/apps/cli/src/helpers/template-manager.ts @@ -519,14 +519,23 @@ export async function handleExtras( context: ProjectConfig, ): Promise { if (context.packageManager === "pnpm") { - const src = path.join(PKG_ROOT, "templates/extras/pnpm-workspace.yaml"); - const dest = path.join(projectDir, "pnpm-workspace.yaml"); - if (await fs.pathExists(src)) { - await fs.copy(src, dest); + const pnpmWorkspaceSrc = path.join( + PKG_ROOT, + "templates/extras/pnpm-workspace.yaml", + ); + const pnpmWorkspaceDest = path.join(projectDir, "pnpm-workspace.yaml"); + if (await fs.pathExists(pnpmWorkspaceSrc)) { + await fs.copy(pnpmWorkspaceSrc, pnpmWorkspaceDest); + } else { + } + } + + if (context.frontend.includes("native")) { + const npmrcSrc = path.join(PKG_ROOT, "templates/extras/.npmrc"); + const npmrcDest = path.join(projectDir, ".npmrc"); + if (await fs.pathExists(npmrcSrc)) { + await fs.copy(npmrcSrc, npmrcDest); } else { - consola.warn( - pc.yellow("Warning: pnpm-workspace.yaml template not found."), - ); } } } diff --git a/apps/cli/templates/auth/server/base/src/lib/auth.ts.hbs b/apps/cli/templates/auth/server/base/src/lib/auth.ts.hbs index c56ad52..489228a 100644 --- a/apps/cli/templates/auth/server/base/src/lib/auth.ts.hbs +++ b/apps/cli/templates/auth/server/base/src/lib/auth.ts.hbs @@ -1,25 +1,28 @@ -import { betterAuth } from "better-auth"; - {{#if (eq orm "prisma")}} +import { betterAuth } from "better-auth"; import { prismaAdapter } from "better-auth/adapters/prisma"; import prisma from "../../prisma"; export const auth = betterAuth({ database: prismaAdapter(prisma, { - provider: "{{database}}" + {{#if (eq database "postgres")}}provider: "postgresql"{{/if}} + {{#if (eq database "sqlite")}}provider: "sqlite"{{/if}} + {{#if (eq database "mysql")}}provider: "mysql"{{/if}} }), trustedOrigins: [process.env.CORS_ORIGIN || ""], emailAndPassword: { enabled: true } }); +{{/if}} -{{else if (eq orm "drizzle")}} +{{#if (eq orm "drizzle")}} +import { betterAuth } from "better-auth"; import { drizzleAdapter } from "better-auth/adapters/drizzle"; import { db } from "../db"; import * as schema from "../db/schema/auth"; export const auth = betterAuth({ database: drizzleAdapter(db, { - {{#if (eq database "postgresql")}}provider: "pg",{{/if}} + {{#if (eq database "postgres")}}provider: "pg",{{/if}} {{#if (eq database "sqlite")}}provider: "sqlite",{{/if}} {{#if (eq database "mysql")}}provider: "mysql",{{/if}} schema: schema @@ -27,4 +30,14 @@ export const auth = betterAuth({ trustedOrigins: [process.env.CORS_ORIGIN || ""], emailAndPassword: { enabled: true } }); -{{/if}} \ No newline at end of file +{{/if}} + +{{#if (eq orm "none")}} +import { betterAuth } from "better-auth"; + +export const auth = betterAuth({ + database: "", + trustedOrigins: [process.env.CORS_ORIGIN || ""], + emailAndPassword: { enabled: true } +}); +{{/if}}