mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
add flags and prompt for orm selection
This commit is contained in:
@@ -13,4 +13,5 @@ export const DEFAULT_CONFIG: ProjectConfig = {
|
||||
features: [],
|
||||
git: true,
|
||||
packageManager: "npm",
|
||||
orm: "drizzle",
|
||||
};
|
||||
|
||||
@@ -21,6 +21,7 @@ import type {
|
||||
ProjectConfig,
|
||||
ProjectDatabase,
|
||||
ProjectFeature,
|
||||
ProjectORM,
|
||||
} from "./types";
|
||||
import { generateReproducibleCommand } from "./utils/generate-reproducible-command";
|
||||
import { getUserPkgManager } from "./utils/get-package-manager";
|
||||
@@ -101,6 +102,25 @@ async function gatherConfig(
|
||||
},
|
||||
],
|
||||
}),
|
||||
orm: () =>
|
||||
flags.orm !== undefined
|
||||
? Promise.resolve(flags.orm)
|
||||
: select<ProjectORM>({
|
||||
message: "Which ORM would you like to use?",
|
||||
options: [
|
||||
{
|
||||
value: "drizzle",
|
||||
label: "Drizzle",
|
||||
hint: "Type-safe, lightweight ORM (recommended)",
|
||||
},
|
||||
// {
|
||||
// value: "prisma",
|
||||
// label: "Prisma (coming soon)",
|
||||
// hint: "Feature-rich ORM with great DX",
|
||||
// },
|
||||
],
|
||||
initialValue: "drizzle",
|
||||
}),
|
||||
auth: () =>
|
||||
flags.auth !== undefined
|
||||
? Promise.resolve(flags.auth)
|
||||
@@ -186,6 +206,7 @@ async function gatherConfig(
|
||||
return {
|
||||
projectName: result.projectName ?? DEFAULT_CONFIG.projectName,
|
||||
database: result.database ?? DEFAULT_CONFIG.database,
|
||||
orm: result.orm ?? DEFAULT_CONFIG.orm,
|
||||
auth: result.auth ?? DEFAULT_CONFIG.auth,
|
||||
features: result.features ?? DEFAULT_CONFIG.features,
|
||||
git: result.git ?? DEFAULT_CONFIG.git,
|
||||
@@ -202,6 +223,9 @@ function displayConfig(config: Partial<ProjectConfig>) {
|
||||
if (config.database) {
|
||||
configDisplay.push(`${pc.blue("Database:")} ${config.database}`);
|
||||
}
|
||||
if (config.orm) {
|
||||
configDisplay.push(`${pc.blue("ORM:")} ${config.orm}`);
|
||||
}
|
||||
if (config.auth !== undefined) {
|
||||
configDisplay.push(`${pc.blue("Authentication:")} ${config.auth}`);
|
||||
}
|
||||
@@ -245,6 +269,8 @@ async function main() {
|
||||
.option("--pnpm", "Use pnpm package manager")
|
||||
.option("--yarn", "Use yarn package manager")
|
||||
.option("--bun", "Use bun package manager")
|
||||
.option("--drizzle", "Use Drizzle ORM")
|
||||
.option("--prisma", "Use Prisma ORM (coming soon)")
|
||||
.parse();
|
||||
|
||||
const options = program.opts();
|
||||
@@ -257,6 +283,7 @@ async function main() {
|
||||
: options.postgres
|
||||
? "postgres"
|
||||
: undefined,
|
||||
orm: options.drizzle ? "drizzle" : options.prisma ? "prisma" : undefined,
|
||||
auth: "auth" in options ? options.auth : undefined,
|
||||
packageManager: options.npm
|
||||
? "npm"
|
||||
@@ -293,6 +320,11 @@ async function main() {
|
||||
yes: true,
|
||||
projectName: projectDirectory ?? DEFAULT_CONFIG.projectName,
|
||||
database: options.database ?? DEFAULT_CONFIG.database,
|
||||
orm: options.drizzle
|
||||
? "drizzle"
|
||||
: options.prisma
|
||||
? "prisma"
|
||||
: DEFAULT_CONFIG.orm, // Add this line
|
||||
auth: options.auth ?? DEFAULT_CONFIG.auth,
|
||||
git: options.git ?? DEFAULT_CONFIG.git,
|
||||
packageManager:
|
||||
|
||||
@@ -4,6 +4,8 @@ export type ProjectDatabase = "sqlite" | "postgres";
|
||||
|
||||
export type PackageManager = "npm" | "yarn" | "pnpm" | "bun";
|
||||
|
||||
export type ProjectORM = "drizzle" | "prisma";
|
||||
|
||||
export type ProjectConfig = {
|
||||
yes?: boolean;
|
||||
projectName: string;
|
||||
@@ -12,4 +14,5 @@ export type ProjectConfig = {
|
||||
auth: boolean;
|
||||
packageManager: PackageManager;
|
||||
features: ProjectFeature[];
|
||||
orm: ProjectORM;
|
||||
};
|
||||
|
||||
@@ -18,6 +18,10 @@ export function generateReproducibleCommand(config: ProjectConfig): string {
|
||||
flags.push(config.database === "sqlite" ? "--sqlite" : "--postgres");
|
||||
}
|
||||
|
||||
if (config.orm !== DEFAULT_CONFIG.orm) {
|
||||
flags.push(config.orm === "drizzle" ? "--drizzle" : "--prisma");
|
||||
}
|
||||
|
||||
if (config.auth !== DEFAULT_CONFIG.auth) {
|
||||
flags.push("--no-auth");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user