feat(cli): add alchemy and improve cli tooling and structure (#520)

This commit is contained in:
Aman Varshney
2025-08-20 23:43:58 +05:30
committed by GitHub
parent c5430ae4fd
commit 5788876c47
152 changed files with 5804 additions and 2264 deletions

View File

@@ -0,0 +1,47 @@
import path from "node:path";
import { ProjectNameSchema } from "../types";
import { exitWithError } from "./errors";
export function validateProjectName(name: string): void {
const result = ProjectNameSchema.safeParse(name);
if (!result.success) {
exitWithError(
`Invalid project name: ${
result.error.issues[0]?.message || "Invalid project name"
}`,
);
}
}
export function validateProjectNameThrow(name: string): void {
const result = ProjectNameSchema.safeParse(name);
if (!result.success) {
throw new Error(`Invalid project name: ${result.error.issues[0]?.message}`);
}
}
export function extractAndValidateProjectName(
projectName?: string,
projectDirectory?: string,
throwOnError = false,
): string {
const derivedName =
projectName ||
(projectDirectory
? path.basename(path.resolve(process.cwd(), projectDirectory))
: "");
if (!derivedName) {
return "";
}
const nameToValidate = projectName ? path.basename(projectName) : derivedName;
if (throwOnError) {
validateProjectNameThrow(nameToValidate);
} else {
validateProjectName(nameToValidate);
}
return projectName || derivedName;
}