Initial project creation panel
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { z } from "zod";
|
||||
|
||||
export const projectNameSchema = z
|
||||
.string()
|
||||
.trim()
|
||||
.min(1, "Enter a project name.")
|
||||
.max(64, "Project names must be 64 characters or fewer.")
|
||||
.regex(
|
||||
/^[a-zA-Z0-9][a-zA-Z0-9 _-]*$/,
|
||||
"Use letters, numbers, spaces, hyphens, or underscores.",
|
||||
)
|
||||
.refine((name) => !name.includes(".."), "Project names cannot contain '..'.");
|
||||
|
||||
export function getProjectsRoot() {
|
||||
return path.resolve(process.env.PROJECTS_ROOT || path.join(os.homedir(), "projects"));
|
||||
}
|
||||
|
||||
export function getProjectPath(name: string) {
|
||||
const root = getProjectsRoot();
|
||||
const projectPath = path.resolve(root, name);
|
||||
|
||||
if (projectPath === root || !projectPath.startsWith(`${root}${path.sep}`)) {
|
||||
throw new Error("The project path must remain inside the projects directory.");
|
||||
}
|
||||
|
||||
return projectPath;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { type ClassValue, clsx } from "clsx";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs));
|
||||
}
|
||||
Reference in New Issue
Block a user