mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
Refactor Prisma integration and improve project setup
- Move Prisma files to standard /prisma directory - Remove Turso adapter dependencies for Prisma - Fix auth configuration in templates - Update router devtools package name - Simplify post-installation instructions - Improve npm scripts with cleaner commands
This commit is contained in:
@@ -31,7 +31,6 @@ export const dependencyVersionMap = {
|
||||
|
||||
// Database - Prisma
|
||||
"@prisma/client": "^5.7.1",
|
||||
"@prisma/adapter-libsql": "^5.7.1",
|
||||
prisma: "^5.7.1",
|
||||
} as const;
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ services:
|
||||
- "3000:3000"
|
||||
environment:
|
||||
- NODE_ENV=production
|
||||
- TURSO_DATABASE_URL=\${TURSO_DATABASE_URL}
|
||||
- TURSO_CONNECTION_URL=\${TURSO_CONNECTION_URL}
|
||||
- TURSO_AUTH_TOKEN=\${TURSO_AUTH_TOKEN}
|
||||
- CORS_ORIGIN=\${CORS_ORIGIN}
|
||||
restart: always
|
||||
|
||||
@@ -89,7 +89,7 @@ export async function createProject(options: ProjectConfig): Promise<string> {
|
||||
const serverPackageJson = await fs.readJson(serverPackageJsonPath);
|
||||
|
||||
if (options.database !== "none") {
|
||||
if (options.database === "sqlite" && options.turso) {
|
||||
if (options.database === "sqlite") {
|
||||
serverPackageJson.scripts["db:local"] =
|
||||
"turso dev --db-file local.db";
|
||||
}
|
||||
@@ -99,19 +99,19 @@ export async function createProject(options: ProjectConfig): Promise<string> {
|
||||
"npx @better-auth/cli generate --output ./src/db/auth-schema.ts";
|
||||
|
||||
if (options.orm === "prisma") {
|
||||
serverPackageJson.scripts["db:push"] = "npx prisma db push";
|
||||
serverPackageJson.scripts["db:studio"] = "npx prisma studio";
|
||||
serverPackageJson.scripts["db:push"] = "prisma db push";
|
||||
serverPackageJson.scripts["db:studio"] = "prisma studio";
|
||||
} else if (options.orm === "drizzle") {
|
||||
serverPackageJson.scripts["db:push"] = "npx drizzle-kit push";
|
||||
serverPackageJson.scripts["db:studio"] = "npx drizzle-kit studio";
|
||||
serverPackageJson.scripts["db:push"] = "drizzle-kit push";
|
||||
serverPackageJson.scripts["db:studio"] = "drizzle-kit studio";
|
||||
}
|
||||
} else {
|
||||
if (options.orm === "prisma") {
|
||||
serverPackageJson.scripts["db:push"] = "npx prisma db push";
|
||||
serverPackageJson.scripts["db:studio"] = "npx prisma studio";
|
||||
serverPackageJson.scripts["db:push"] = "prisma db push";
|
||||
serverPackageJson.scripts["db:studio"] = "prisma studio";
|
||||
} else if (options.orm === "drizzle") {
|
||||
serverPackageJson.scripts["db:push"] = "npx drizzle-kit push";
|
||||
serverPackageJson.scripts["db:studio"] = "npx drizzle-kit studio";
|
||||
serverPackageJson.scripts["db:push"] = "drizzle-kit push";
|
||||
serverPackageJson.scripts["db:studio"] = "drizzle-kit studio";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -124,7 +124,6 @@ export async function createProject(options: ProjectConfig): Promise<string> {
|
||||
await createReadme(projectDir, options);
|
||||
|
||||
displayPostInstallInstructions(
|
||||
options.auth,
|
||||
options.database,
|
||||
options.projectName,
|
||||
options.packageManager,
|
||||
|
||||
@@ -32,11 +32,7 @@ export async function setupDatabase(
|
||||
}
|
||||
} else if (orm === "prisma") {
|
||||
addPackageDependency({
|
||||
dependencies: [
|
||||
"@prisma/client",
|
||||
"@prisma/adapter-libsql",
|
||||
"@libsql/client",
|
||||
],
|
||||
dependencies: ["@prisma/client"],
|
||||
devDependencies: false,
|
||||
projectDir: serverDir,
|
||||
});
|
||||
|
||||
@@ -10,7 +10,6 @@ export async function setupEnvironmentVariables(
|
||||
const serverDir = path.join(projectDir, "packages/server");
|
||||
const clientDir = path.join(projectDir, "packages/client");
|
||||
|
||||
// Set up server env variables
|
||||
const envPath = path.join(serverDir, ".env");
|
||||
let envContent = "";
|
||||
|
||||
@@ -18,7 +17,6 @@ export async function setupEnvironmentVariables(
|
||||
envContent = await fs.readFile(envPath, "utf8");
|
||||
}
|
||||
|
||||
// Auth environment variables
|
||||
if (options.auth) {
|
||||
if (!envContent.includes("BETTER_AUTH_SECRET")) {
|
||||
envContent += `\nBETTER_AUTH_SECRET=${generateAuthSecret()}`;
|
||||
@@ -33,12 +31,11 @@ export async function setupEnvironmentVariables(
|
||||
}
|
||||
}
|
||||
|
||||
// Database environment variables
|
||||
if (options.database !== "none") {
|
||||
if (options.orm === "prisma" && !envContent.includes("DATABASE_URL")) {
|
||||
const databaseUrlLine =
|
||||
options.database === "sqlite"
|
||||
? `\nDATABASE_URL="file:./dev.db"`
|
||||
? ""
|
||||
: `\nDATABASE_URL="postgresql://postgres:postgres@localhost:5432/mydb?schema=public"`;
|
||||
envContent += databaseUrlLine;
|
||||
}
|
||||
@@ -54,7 +51,6 @@ export async function setupEnvironmentVariables(
|
||||
|
||||
await fs.writeFile(envPath, envContent.trim());
|
||||
|
||||
// Set up client env variables
|
||||
if (options.auth) {
|
||||
const clientEnvPath = path.join(clientDir, ".env");
|
||||
if (!(await fs.pathExists(clientEnvPath))) {
|
||||
|
||||
@@ -2,7 +2,6 @@ import { log } from "@clack/prompts";
|
||||
import pc from "picocolors";
|
||||
|
||||
export function displayPostInstallInstructions(
|
||||
hasAuth: boolean,
|
||||
database: string,
|
||||
projectName: string,
|
||||
packageManager: string,
|
||||
@@ -12,52 +11,56 @@ export function displayPostInstallInstructions(
|
||||
const runCmd = packageManager === "npm" ? "npm run" : packageManager;
|
||||
const cdCmd = `cd ${projectName}`;
|
||||
|
||||
const steps = [];
|
||||
log.info(`${pc.cyan("Project created successfully!")}
|
||||
|
||||
if (!depsInstalled) {
|
||||
steps.push(`${pc.cyan(packageManager)} install`);
|
||||
}
|
||||
${pc.bold("Next steps:")}
|
||||
${pc.cyan("1.")} ${cdCmd}
|
||||
${!depsInstalled ? `${pc.cyan("2.")} ${packageManager} install\n` : ""}${pc.cyan(depsInstalled ? "2." : "3.")} ${runCmd} dev
|
||||
|
||||
if (hasAuth && database !== "none") {
|
||||
steps.push(`${pc.yellow("Database Setup:")}`);
|
||||
${pc.bold("Your project will be available at:")}
|
||||
${pc.cyan("•")} Frontend: http://localhost:3001
|
||||
${pc.cyan("•")} API: http://localhost:3000
|
||||
|
||||
if (orm === "prisma") {
|
||||
steps.push(
|
||||
`${pc.cyan("1.")} Generate Prisma client: ${pc.green(`${runCmd} prisma:generate`)}`,
|
||||
);
|
||||
steps.push(
|
||||
`${pc.cyan("2.")} Push schema to database: ${pc.green(`${runCmd} prisma:push`)}`,
|
||||
);
|
||||
} else if (orm === "drizzle") {
|
||||
steps.push(
|
||||
`${pc.cyan("1.")} Apply migrations: ${pc.green(`${runCmd} db:push`)}`,
|
||||
${database !== "none" ? getDatabaseInstructions(database, orm, runCmd) : ""}`);
|
||||
}
|
||||
|
||||
function getDatabaseInstructions(
|
||||
database: string,
|
||||
orm?: string,
|
||||
runCmd?: string,
|
||||
): string {
|
||||
const instructions = [];
|
||||
|
||||
if (orm === "prisma") {
|
||||
instructions.push(
|
||||
`${pc.cyan("•")} Apply schema: ${pc.dim(`${runCmd} db:push`)}`,
|
||||
);
|
||||
instructions.push(
|
||||
`${pc.cyan("•")} Database UI: ${pc.dim(`${runCmd} db:studio`)}`,
|
||||
);
|
||||
|
||||
if (database === "turso") {
|
||||
instructions.push(
|
||||
`${pc.yellow("NOTE:")} Turso support with Prisma is in Early Access and requires additional setup.`,
|
||||
`${pc.dim("Learn more at: https://www.prisma.io/docs/orm/overview/databases/turso")}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (database === "postgres") {
|
||||
steps.push(`${pc.yellow("PostgreSQL Configuration:")}`);
|
||||
steps.push(
|
||||
`Make sure to update ${pc.cyan("packages/server/.env")} with your PostgreSQL connection string.`,
|
||||
} else if (orm === "drizzle") {
|
||||
instructions.push(
|
||||
`${pc.cyan("•")} Apply schema: ${pc.dim(`${runCmd} db:push`)}`,
|
||||
);
|
||||
} else if (database === "sqlite") {
|
||||
steps.push(`${pc.yellow("Database Configuration:")}`);
|
||||
steps.push(
|
||||
`${pc.cyan("packages/server/.env")} contains your SQLite connection details. Update if needed.`,
|
||||
);
|
||||
steps.push(
|
||||
`Start the local SQLite database with: ${pc.green(`${runCmd} db:local`)}`,
|
||||
instructions.push(
|
||||
`${pc.cyan("•")} Database UI: ${pc.dim(`${runCmd} db:studio`)}`,
|
||||
);
|
||||
}
|
||||
|
||||
steps.push(`${pc.yellow("Start Development:")}`);
|
||||
steps.push(`${pc.green(`${runCmd} dev`)}`);
|
||||
if (database === "sqlite") {
|
||||
instructions.push(
|
||||
`${pc.cyan("•")} Start local DB: ${pc.dim(`cd packages/server && ${runCmd} db:local`)}`,
|
||||
);
|
||||
}
|
||||
|
||||
log.info(`${pc.cyan("Installation completed!")} Here are some next steps:
|
||||
|
||||
${cdCmd}
|
||||
${steps.join("\n")}
|
||||
|
||||
The client application will be available at ${pc.cyan("http://localhost:3001")}
|
||||
The API server will be running at ${pc.cyan("http://localhost:3000")}`);
|
||||
return instructions.length
|
||||
? `${pc.bold("Database commands:")}\n${instructions.join("\n")}\n\n`
|
||||
: "";
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ export async function gatherConfig(
|
||||
auth: ({ results }) =>
|
||||
getAuthChoice(flags.auth, results.database !== "none"),
|
||||
turso: ({ results }) =>
|
||||
results.database === "sqlite"
|
||||
results.database === "sqlite" && results.orm !== "prisma"
|
||||
? getTursoSetupChoice(flags.turso)
|
||||
: Promise.resolve(false),
|
||||
addons: () => getAddonsChoice(flags.addons),
|
||||
|
||||
Reference in New Issue
Block a user