mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
implement auth add or remove logic
This commit is contained in:
@@ -5,7 +5,11 @@ import { $ } from "execa";
|
||||
import fs from "fs-extra";
|
||||
import pc from "picocolors";
|
||||
import type { ProjectConfig } from "../types";
|
||||
import { configureAuth } from "./auth-setup";
|
||||
import { createReadme } from "./create-readme";
|
||||
import { setupTurso } from "./db-setup";
|
||||
import { setupFeatures } from "./feature-setup";
|
||||
import { displayPostInstallInstructions } from "./post-installation";
|
||||
|
||||
export async function createProject(options: ProjectConfig) {
|
||||
const s = spinner();
|
||||
@@ -37,6 +41,29 @@ export async function createProject(options: ProjectConfig) {
|
||||
},
|
||||
];
|
||||
|
||||
if (options.database === "none") {
|
||||
tasksList.push({
|
||||
title: "Removing database configuration",
|
||||
task: async () => {
|
||||
await fs.remove(path.join(projectDir, "packages/server/src/db"));
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
tasksList.push({
|
||||
title: options.auth
|
||||
? "Setting up authentication"
|
||||
: "Removing authentication",
|
||||
task: async () => {
|
||||
await configureAuth(
|
||||
projectDir,
|
||||
options.auth,
|
||||
options.database !== "none",
|
||||
options,
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
if (options.git) {
|
||||
tasksList.push({
|
||||
title: "Initializing git repository",
|
||||
@@ -48,12 +75,25 @@ export async function createProject(options: ProjectConfig) {
|
||||
});
|
||||
}
|
||||
|
||||
if (options.features.length > 0) {
|
||||
tasksList.push({
|
||||
title: "Setting up additional features",
|
||||
task: async () => {
|
||||
await setupFeatures(projectDir, options.features);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
await tasks(tasksList);
|
||||
|
||||
if (options.database === "sqlite") {
|
||||
await setupTurso(projectDir);
|
||||
} else if (options.database === "postgres") {
|
||||
// Handle postgres setup
|
||||
log.info(
|
||||
pc.blue(
|
||||
"PostgreSQL setup is manual. You'll need to set up your own PostgreSQL database and update the connection details in .env",
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
const installDepsResponse = await confirm({
|
||||
@@ -83,9 +123,46 @@ export async function createProject(options: ProjectConfig) {
|
||||
}
|
||||
}
|
||||
|
||||
log.info(`${pc.dim("Next steps:")}
|
||||
${pc.cyan("cd")} ${options.projectName}${!shouldInstallDeps ? `\n${pc.cyan(options.packageManager)} install` : ""}
|
||||
${pc.cyan(options.packageManager === "npm" ? "npm run" : options.packageManager)} ${"dev"}`);
|
||||
const rootPackageJsonPath = path.join(projectDir, "package.json");
|
||||
if (await fs.pathExists(rootPackageJsonPath)) {
|
||||
const packageJson = await fs.readJson(rootPackageJsonPath);
|
||||
|
||||
if (options.auth && options.database !== "none") {
|
||||
packageJson.scripts["auth:generate"] =
|
||||
"cd packages/server && npx @better-auth/cli generate --output ./src/db/auth-schema.ts";
|
||||
|
||||
if (options.orm === "prisma") {
|
||||
packageJson.scripts["prisma:generate"] =
|
||||
"cd packages/server && npx prisma generate";
|
||||
packageJson.scripts["prisma:push"] =
|
||||
"cd packages/server && npx prisma db push";
|
||||
packageJson.scripts["prisma:studio"] =
|
||||
"cd packages/server && npx prisma studio";
|
||||
|
||||
packageJson.scripts["db:setup"] =
|
||||
"npm run auth:generate && npm run prisma:generate && npm run prisma:push";
|
||||
} else if (options.orm === "drizzle") {
|
||||
packageJson.scripts["drizzle:migrate"] =
|
||||
"cd packages/server && npx @better-auth/cli migrate";
|
||||
|
||||
packageJson.scripts["db:setup"] =
|
||||
"npm run auth:generate && npm run drizzle:migrate";
|
||||
}
|
||||
}
|
||||
|
||||
await fs.writeJson(rootPackageJsonPath, packageJson, { spaces: 2 });
|
||||
}
|
||||
|
||||
await createReadme(projectDir, options);
|
||||
|
||||
displayPostInstallInstructions(
|
||||
options.auth,
|
||||
options.database,
|
||||
options.projectName,
|
||||
options.packageManager,
|
||||
shouldInstallDeps,
|
||||
options.orm,
|
||||
);
|
||||
} catch (error) {
|
||||
s.stop(pc.red("Failed"));
|
||||
if (error instanceof Error) {
|
||||
|
||||
Reference in New Issue
Block a user