add auth, drizzle, prisma setup logic with template

This commit is contained in:
Aman Varshney
2025-03-04 09:33:31 +05:30
parent 54d63823bb
commit 792885b9c4
68 changed files with 2692 additions and 921 deletions

View File

@@ -5,24 +5,28 @@ import type {
ProjectConfig,
ProjectDatabase,
ProjectFeature,
ProjectORM,
ProjectOrm,
} from "../types";
import { getAuthChoice } from "./auth";
import { getDatabaseChoice } from "./database";
import { getFeaturesChoice } from "./features";
import { getGitChoice } from "./git";
import { getNoInstallChoice } from "./install";
import { getORMChoice } from "./orm";
import { getPackageManagerChoice } from "./package-manager";
import { getProjectName } from "./project-name";
import { getTursoSetupChoice } from "./turso";
interface PromptGroupResults {
projectName: string;
database: ProjectDatabase;
orm: ProjectORM;
orm: ProjectOrm;
auth: boolean;
features: ProjectFeature[];
git: boolean;
packageManager: PackageManager;
noInstall: boolean;
turso: boolean;
}
export async function gatherConfig(
@@ -38,9 +42,14 @@ export async function gatherConfig(
getORMChoice(flags.orm, results.database !== "none"),
auth: ({ results }) =>
getAuthChoice(flags.auth, results.database !== "none"),
turso: ({ results }) =>
results.database === "sqlite"
? getTursoSetupChoice(flags.turso)
: Promise.resolve(false),
features: () => getFeaturesChoice(flags.features),
git: () => getGitChoice(flags.git),
packageManager: () => getPackageManagerChoice(flags.packageManager),
noInstall: () => getNoInstallChoice(flags.noInstall),
},
{
onCancel: () => {
@@ -58,5 +67,7 @@ export async function gatherConfig(
features: result.features,
git: result.git,
packageManager: result.packageManager,
noInstall: result.noInstall,
turso: result.turso,
};
}

View File

@@ -0,0 +1,21 @@
import { cancel, confirm, isCancel } from "@clack/prompts";
import pc from "picocolors";
import { DEFAULT_CONFIG } from "../constants";
export async function getNoInstallChoice(
noInstall?: boolean,
): Promise<boolean> {
if (noInstall !== undefined) return noInstall;
const response = await confirm({
message: "Install dependencies after creating project?",
initialValue: !DEFAULT_CONFIG.noInstall,
});
if (isCancel(response)) {
cancel(pc.red("Operation cancelled"));
process.exit(0);
}
return !response;
}

View File

@@ -1,15 +1,15 @@
import { cancel, isCancel, select } from "@clack/prompts";
import pc from "picocolors";
import type { ProjectORM } from "../types";
import type { ProjectOrm } from "../types";
export async function getORMChoice(
orm: ProjectORM | undefined,
orm: ProjectOrm | undefined,
hasDatabase: boolean,
): Promise<ProjectORM> {
): Promise<ProjectOrm> {
if (!hasDatabase) return "none";
if (orm !== undefined) return orm;
const response = await select<ProjectORM>({
const response = await select<ProjectOrm>({
message: "Which ORM would you like to use?",
options: [
{

View File

@@ -0,0 +1,18 @@
import { cancel, confirm, isCancel } from "@clack/prompts";
import pc from "picocolors";
export async function getTursoSetupChoice(turso?: boolean): Promise<boolean> {
if (turso !== undefined) return turso;
const response = await confirm({
message: "Set up a Turso database for this project?",
initialValue: true,
});
if (isCancel(response)) {
cancel(pc.red("Operation cancelled"));
process.exit(0);
}
return response;
}