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

@@ -3,6 +3,7 @@ import { Command } from "commander";
import pc from "picocolors";
import { DEFAULT_CONFIG } from "./constants";
import { createProject } from "./helpers/create-project";
import { installDependencies } from "./helpers/install-dependencies";
import { gatherConfig } from "./prompts/config-prompts";
import type { ProjectConfig, ProjectFeature } from "./types";
import { displayConfig } from "./utils/display-config";
@@ -37,6 +38,7 @@ async function main() {
.option("--docker", "Include Docker setup")
.option("--github-actions", "Include GitHub Actions")
.option("--seo", "Include SEO setup")
.option("--no-features", "Skip all additional features")
.option("--git", "Include git setup")
.option("--no-git", "Skip git initialization")
.option("--npm", "Use npm package manager")
@@ -45,6 +47,10 @@ async function main() {
.option("--bun", "Use bun package manager")
.option("--drizzle", "Use Drizzle ORM")
.option("--prisma", "Use Prisma ORM (coming soon)")
.option("--install", "Install dependencies")
.option("--no-install", "Skip installing dependencies")
.option("--turso", "Set up Turso for SQLite database")
.option("--no-turso", "Skip Turso setup for SQLite database")
.parse();
const options = program.opts();
@@ -63,12 +69,20 @@ async function main() {
...(options.yarn && { packageManager: "yarn" }),
...(options.bun && { packageManager: "bun" }),
...("git" in options && { git: options.git }),
...((options.docker || options.githubActions || options.seo) && {
features: [
...(options.docker ? ["docker"] : []),
...(options.githubActions ? ["github-actions"] : []),
...(options.seo ? ["SEO"] : []),
] as ProjectFeature[],
...("install" in options && { noInstall: !options.install }),
...("turso" in options && { turso: options.turso }),
...((options.docker ||
options.githubActions ||
options.seo ||
options.features === false) && {
features:
options.features === false
? []
: ([
...(options.docker ? ["docker"] : []),
...(options.githubActions ? ["github-actions"] : []),
...(options.seo ? ["SEO"] : []),
] as ProjectFeature[]),
}),
};
@@ -96,11 +110,21 @@ async function main() {
: DEFAULT_CONFIG.orm,
auth: options.auth ?? DEFAULT_CONFIG.auth,
git: options.git ?? DEFAULT_CONFIG.git,
noInstall:
"noInstall" in options
? options.noInstall
: DEFAULT_CONFIG.noInstall,
packageManager:
flagConfig.packageManager ?? DEFAULT_CONFIG.packageManager,
features: flagConfig.features?.length
? flagConfig.features
: DEFAULT_CONFIG.features,
turso:
"turso" in options
? options.turso
: flagConfig.database === "sqlite"
? DEFAULT_CONFIG.turso
: false,
}
: await gatherConfig(flagConfig);
@@ -110,7 +134,14 @@ async function main() {
log.message("");
}
await createProject(config);
const projectDir = await createProject(config);
if (!config.noInstall) {
await installDependencies({
projectDir,
packageManager: config.packageManager,
});
}
log.success(
pc.blue(
@@ -124,10 +155,21 @@ async function main() {
} catch (error) {
s.stop(pc.red("Failed"));
if (error instanceof Error) {
cancel(pc.red("An unexpected error occurred"));
cancel(pc.red(`An unexpected error occurred: ${error.message}`));
process.exit(1);
}
}
}
main();
main().catch((err) => {
log.error("Aborting installation...");
if (err instanceof Error) {
log.error(err.message);
} else {
log.error(
"An unknown error has occurred. Please open an issue on GitHub with the below:",
);
console.log(err);
}
process.exit(1);
});