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: [],
|
features: [],
|
||||||
git: true,
|
git: true,
|
||||||
packageManager: "npm",
|
packageManager: "npm",
|
||||||
|
orm: "drizzle",
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import type {
|
|||||||
ProjectConfig,
|
ProjectConfig,
|
||||||
ProjectDatabase,
|
ProjectDatabase,
|
||||||
ProjectFeature,
|
ProjectFeature,
|
||||||
|
ProjectORM,
|
||||||
} from "./types";
|
} from "./types";
|
||||||
import { generateReproducibleCommand } from "./utils/generate-reproducible-command";
|
import { generateReproducibleCommand } from "./utils/generate-reproducible-command";
|
||||||
import { getUserPkgManager } from "./utils/get-package-manager";
|
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: () =>
|
auth: () =>
|
||||||
flags.auth !== undefined
|
flags.auth !== undefined
|
||||||
? Promise.resolve(flags.auth)
|
? Promise.resolve(flags.auth)
|
||||||
@@ -186,6 +206,7 @@ async function gatherConfig(
|
|||||||
return {
|
return {
|
||||||
projectName: result.projectName ?? DEFAULT_CONFIG.projectName,
|
projectName: result.projectName ?? DEFAULT_CONFIG.projectName,
|
||||||
database: result.database ?? DEFAULT_CONFIG.database,
|
database: result.database ?? DEFAULT_CONFIG.database,
|
||||||
|
orm: result.orm ?? DEFAULT_CONFIG.orm,
|
||||||
auth: result.auth ?? DEFAULT_CONFIG.auth,
|
auth: result.auth ?? DEFAULT_CONFIG.auth,
|
||||||
features: result.features ?? DEFAULT_CONFIG.features,
|
features: result.features ?? DEFAULT_CONFIG.features,
|
||||||
git: result.git ?? DEFAULT_CONFIG.git,
|
git: result.git ?? DEFAULT_CONFIG.git,
|
||||||
@@ -202,6 +223,9 @@ function displayConfig(config: Partial<ProjectConfig>) {
|
|||||||
if (config.database) {
|
if (config.database) {
|
||||||
configDisplay.push(`${pc.blue("Database:")} ${config.database}`);
|
configDisplay.push(`${pc.blue("Database:")} ${config.database}`);
|
||||||
}
|
}
|
||||||
|
if (config.orm) {
|
||||||
|
configDisplay.push(`${pc.blue("ORM:")} ${config.orm}`);
|
||||||
|
}
|
||||||
if (config.auth !== undefined) {
|
if (config.auth !== undefined) {
|
||||||
configDisplay.push(`${pc.blue("Authentication:")} ${config.auth}`);
|
configDisplay.push(`${pc.blue("Authentication:")} ${config.auth}`);
|
||||||
}
|
}
|
||||||
@@ -245,6 +269,8 @@ async function main() {
|
|||||||
.option("--pnpm", "Use pnpm package manager")
|
.option("--pnpm", "Use pnpm package manager")
|
||||||
.option("--yarn", "Use yarn package manager")
|
.option("--yarn", "Use yarn package manager")
|
||||||
.option("--bun", "Use bun package manager")
|
.option("--bun", "Use bun package manager")
|
||||||
|
.option("--drizzle", "Use Drizzle ORM")
|
||||||
|
.option("--prisma", "Use Prisma ORM (coming soon)")
|
||||||
.parse();
|
.parse();
|
||||||
|
|
||||||
const options = program.opts();
|
const options = program.opts();
|
||||||
@@ -257,6 +283,7 @@ async function main() {
|
|||||||
: options.postgres
|
: options.postgres
|
||||||
? "postgres"
|
? "postgres"
|
||||||
: undefined,
|
: undefined,
|
||||||
|
orm: options.drizzle ? "drizzle" : options.prisma ? "prisma" : undefined,
|
||||||
auth: "auth" in options ? options.auth : undefined,
|
auth: "auth" in options ? options.auth : undefined,
|
||||||
packageManager: options.npm
|
packageManager: options.npm
|
||||||
? "npm"
|
? "npm"
|
||||||
@@ -293,6 +320,11 @@ async function main() {
|
|||||||
yes: true,
|
yes: true,
|
||||||
projectName: projectDirectory ?? DEFAULT_CONFIG.projectName,
|
projectName: projectDirectory ?? DEFAULT_CONFIG.projectName,
|
||||||
database: options.database ?? DEFAULT_CONFIG.database,
|
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,
|
auth: options.auth ?? DEFAULT_CONFIG.auth,
|
||||||
git: options.git ?? DEFAULT_CONFIG.git,
|
git: options.git ?? DEFAULT_CONFIG.git,
|
||||||
packageManager:
|
packageManager:
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ export type ProjectDatabase = "sqlite" | "postgres";
|
|||||||
|
|
||||||
export type PackageManager = "npm" | "yarn" | "pnpm" | "bun";
|
export type PackageManager = "npm" | "yarn" | "pnpm" | "bun";
|
||||||
|
|
||||||
|
export type ProjectORM = "drizzle" | "prisma";
|
||||||
|
|
||||||
export type ProjectConfig = {
|
export type ProjectConfig = {
|
||||||
yes?: boolean;
|
yes?: boolean;
|
||||||
projectName: string;
|
projectName: string;
|
||||||
@@ -12,4 +14,5 @@ export type ProjectConfig = {
|
|||||||
auth: boolean;
|
auth: boolean;
|
||||||
packageManager: PackageManager;
|
packageManager: PackageManager;
|
||||||
features: ProjectFeature[];
|
features: ProjectFeature[];
|
||||||
|
orm: ProjectORM;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -18,6 +18,10 @@ export function generateReproducibleCommand(config: ProjectConfig): string {
|
|||||||
flags.push(config.database === "sqlite" ? "--sqlite" : "--postgres");
|
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) {
|
if (config.auth !== DEFAULT_CONFIG.auth) {
|
||||||
flags.push("--no-auth");
|
flags.push("--no-auth");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user