mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
61 lines
1.3 KiB
TypeScript
61 lines
1.3 KiB
TypeScript
import { cancel, isCancel, select } from "@clack/prompts";
|
|
import pc from "picocolors";
|
|
import { DEFAULT_CONFIG } from "../constants";
|
|
import type { Backend, Database, ORM, Runtime } from "../types";
|
|
|
|
const ormOptions = {
|
|
prisma: {
|
|
value: "prisma" as const,
|
|
label: "Prisma",
|
|
hint: "Powerful, feature-rich ORM",
|
|
},
|
|
mongoose: {
|
|
value: "mongoose" as const,
|
|
label: "Mongoose",
|
|
hint: "Elegant object modeling tool",
|
|
},
|
|
drizzle: {
|
|
value: "drizzle" as const,
|
|
label: "Drizzle",
|
|
hint: "Lightweight and performant TypeScript ORM",
|
|
},
|
|
};
|
|
|
|
export async function getORMChoice(
|
|
orm: ORM | undefined,
|
|
hasDatabase: boolean,
|
|
database?: Database,
|
|
backend?: Backend,
|
|
runtime?: Runtime,
|
|
): Promise<ORM> {
|
|
if (backend === "convex") {
|
|
return "none";
|
|
}
|
|
|
|
if (!hasDatabase) return "none";
|
|
if (orm !== undefined) return orm;
|
|
|
|
if (runtime === "workers") {
|
|
return "drizzle";
|
|
}
|
|
|
|
const options = [
|
|
...(database === "mongodb"
|
|
? [ormOptions.prisma, ormOptions.mongoose]
|
|
: [ormOptions.drizzle, ormOptions.prisma]),
|
|
];
|
|
|
|
const response = await select<ORM>({
|
|
message: "Select ORM",
|
|
options,
|
|
initialValue: database === "mongodb" ? "prisma" : DEFAULT_CONFIG.orm,
|
|
});
|
|
|
|
if (isCancel(response)) {
|
|
cancel(pc.red("Operation cancelled"));
|
|
process.exit(0);
|
|
}
|
|
|
|
return response;
|
|
}
|