feat(cli): add vibe rules addon (#481)

This commit is contained in:
Aman Varshney
2025-08-09 12:06:23 +05:30
committed by GitHub
parent 9005a432cf
commit 6cf476a21e
42 changed files with 429 additions and 302 deletions

View File

@@ -1,5 +1,4 @@
import path from "node:path";
import { consola } from "consola";
import {
type Addons,
type API,
@@ -27,6 +26,7 @@ import {
validateWebDeployRequiresWebFrontend,
validateWorkersCompatibility,
} from "./utils/compatibility-rules";
import { exitWithError } from "./utils/errors";
export function processAndValidateFlags(
options: CLIInput,
@@ -43,10 +43,9 @@ export function processAndValidateFlags(
!(options.examples.length === 1 && options.examples[0] === "none") &&
options.backend !== "convex"
) {
consola.fatal(
exitWithError(
"Cannot use '--examples' when '--api' is set to 'none'. Please remove the --examples flag or choose an API type.",
);
process.exit(1);
}
}
}
@@ -62,10 +61,9 @@ export function processAndValidateFlags(
config.backend !== "none"
) {
if (providedFlags.has("runtime") && options.runtime === "none") {
consola.fatal(
exitWithError(
`'--runtime none' is only supported with '--backend convex' or '--backend none'. Please choose 'bun', 'node', or remove the --runtime flag.`,
);
process.exit(1);
}
}
@@ -101,12 +99,11 @@ export function processAndValidateFlags(
if (projectName) {
const result = ProjectNameSchema.safeParse(path.basename(projectName));
if (!result.success) {
consola.fatal(
exitWithError(
`Invalid project name: ${
result.error.issues[0]?.message || "Invalid project name"
}`,
);
process.exit(1);
}
config.projectName = projectName;
} else if (options.projectDirectory) {
@@ -115,12 +112,11 @@ export function processAndValidateFlags(
);
const result = ProjectNameSchema.safeParse(baseName);
if (!result.success) {
consola.fatal(
exitWithError(
`Invalid project name: ${
result.error.issues[0]?.message || "Invalid project name"
}`,
);
process.exit(1);
}
config.projectName = baseName;
}
@@ -128,8 +124,7 @@ export function processAndValidateFlags(
if (options.frontend && options.frontend.length > 0) {
if (options.frontend.includes("none")) {
if (options.frontend.length > 1) {
consola.fatal(`Cannot combine 'none' with other frontend options.`);
process.exit(1);
exitWithError(`Cannot combine 'none' with other frontend options.`);
}
config.frontend = [];
} else {
@@ -153,8 +148,7 @@ export function processAndValidateFlags(
if (options.addons && options.addons.length > 0) {
if (options.addons.includes("none")) {
if (options.addons.length > 1) {
consola.fatal(`Cannot combine 'none' with other addons.`);
process.exit(1);
exitWithError(`Cannot combine 'none' with other addons.`);
}
config.addons = [];
} else {
@@ -166,8 +160,7 @@ export function processAndValidateFlags(
if (options.examples && options.examples.length > 0) {
if (options.examples.includes("none")) {
if (options.examples.length > 1) {
consola.fatal("Cannot combine 'none' with other examples.");
process.exit(1);
exitWithError("Cannot combine 'none' with other examples.");
}
config.examples = [];
} else {
@@ -187,12 +180,11 @@ export function processAndValidateFlags(
options,
);
if (incompatibleFlags.length > 0) {
consola.fatal(
exitWithError(
`The following flags are incompatible with '--backend ${config.backend}': ${incompatibleFlags.join(
", ",
)}. Please remove them.`,
);
process.exit(1);
}
if (
@@ -204,12 +196,11 @@ export function processAndValidateFlags(
(f) => f === "solid",
);
if (incompatibleFrontends.length > 0) {
consola.fatal(
exitWithError(
`The following frontends are not compatible with '--backend convex': ${incompatibleFrontends.join(
", ",
)}. Please choose a different frontend or backend.`,
);
process.exit(1);
}
}
@@ -222,10 +213,9 @@ export function processAndValidateFlags(
config.orm === "mongoose" &&
config.database !== "mongodb"
) {
consola.fatal(
exitWithError(
"Mongoose ORM requires MongoDB database. Please use '--database mongodb' or choose a different ORM.",
);
process.exit(1);
}
if (
@@ -236,10 +226,9 @@ export function processAndValidateFlags(
config.orm !== "mongoose" &&
config.orm !== "prisma"
) {
consola.fatal(
exitWithError(
"MongoDB database requires Mongoose or Prisma ORM. Please use '--orm mongoose' or '--orm prisma' or choose a different database.",
);
process.exit(1);
}
if (
@@ -248,10 +237,9 @@ export function processAndValidateFlags(
config.orm === "drizzle" &&
config.database === "mongodb"
) {
consola.fatal(
exitWithError(
"Drizzle ORM does not support MongoDB. Please use '--orm mongoose' or '--orm prisma' or choose a different database.",
);
process.exit(1);
}
if (
@@ -261,10 +249,9 @@ export function processAndValidateFlags(
config.database !== "none" &&
config.orm === "none"
) {
consola.fatal(
exitWithError(
"Database selection requires an ORM. Please choose '--orm drizzle', '--orm prisma', or '--orm mongoose'.",
);
process.exit(1);
}
if (
@@ -274,10 +261,9 @@ export function processAndValidateFlags(
config.orm !== "none" &&
config.database === "none"
) {
consola.fatal(
exitWithError(
"ORM selection requires a database. Please choose a database or set '--orm none'.",
);
process.exit(1);
}
if (
@@ -286,10 +272,9 @@ export function processAndValidateFlags(
config.auth &&
config.database === "none"
) {
consola.fatal(
exitWithError(
"Authentication requires a database. Please choose a database or set '--no-auth'.",
);
process.exit(1);
}
if (
@@ -299,10 +284,9 @@ export function processAndValidateFlags(
config.dbSetup !== "none" &&
config.database === "none"
) {
consola.fatal(
exitWithError(
"Database setup requires a database. Please choose a database or set '--db-setup none'.",
);
process.exit(1);
}
if (
@@ -311,10 +295,9 @@ export function processAndValidateFlags(
config.dbSetup === "turso" &&
config.database !== "sqlite"
) {
consola.fatal(
exitWithError(
"Turso setup requires SQLite database. Please use '--database sqlite' or choose a different setup.",
);
process.exit(1);
}
if (
@@ -323,10 +306,9 @@ export function processAndValidateFlags(
config.dbSetup === "neon" &&
config.database !== "postgres"
) {
consola.fatal(
exitWithError(
"Neon setup requires PostgreSQL database. Please use '--database postgres' or choose a different setup.",
);
process.exit(1);
}
if (
@@ -335,10 +317,9 @@ export function processAndValidateFlags(
config.dbSetup === "prisma-postgres" &&
config.database !== "postgres"
) {
consola.fatal(
exitWithError(
"Prisma PostgreSQL setup requires PostgreSQL database. Please use '--database postgres' or choose a different setup.",
);
process.exit(1);
}
if (
@@ -347,10 +328,9 @@ export function processAndValidateFlags(
config.dbSetup === "mongodb-atlas" &&
config.database !== "mongodb"
) {
consola.fatal(
exitWithError(
"MongoDB Atlas setup requires MongoDB database. Please use '--database mongodb' or choose a different setup.",
);
process.exit(1);
}
if (
@@ -359,10 +339,9 @@ export function processAndValidateFlags(
config.dbSetup === "supabase" &&
config.database !== "postgres"
) {
consola.fatal(
exitWithError(
"Supabase setup requires PostgreSQL database. Please use '--database postgres' or choose a different setup.",
);
process.exit(1);
}
if (config.dbSetup === "d1") {
@@ -371,10 +350,9 @@ export function processAndValidateFlags(
(providedFlags.has("dbSetup") && !config.database)
) {
if (config.database !== "sqlite") {
consola.fatal(
exitWithError(
"Cloudflare D1 setup requires SQLite database. Please use '--database sqlite' or choose a different setup.",
);
process.exit(1);
}
}
@@ -383,10 +361,9 @@ export function processAndValidateFlags(
(providedFlags.has("dbSetup") && !config.runtime)
) {
if (config.runtime !== "workers") {
consola.fatal(
exitWithError(
"Cloudflare D1 setup requires the Cloudflare Workers runtime. Please use '--runtime workers' or choose a different setup.",
);
process.exit(1);
}
}
}
@@ -397,10 +374,9 @@ export function processAndValidateFlags(
config.dbSetup === "docker" &&
config.database === "sqlite"
) {
consola.fatal(
exitWithError(
"Docker setup is not compatible with SQLite database. SQLite is file-based and doesn't require Docker. Please use '--database postgres', '--database mysql', '--database mongodb', or choose a different setup.",
);
process.exit(1);
}
if (
@@ -409,10 +385,9 @@ export function processAndValidateFlags(
config.dbSetup === "docker" &&
config.runtime === "workers"
) {
consola.fatal(
exitWithError(
"Docker setup is not compatible with Cloudflare Workers runtime. Workers runtime uses serverless databases (D1) and doesn't support local Docker containers. Please use '--db-setup d1' for SQLite or choose a different runtime.",
);
process.exit(1);
}
validateWorkersCompatibility(providedFlags, options, config);