Initial project creation panel
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
import { mkdir, rm } from "node:fs/promises";
|
||||
import { execFile } from "node:child_process";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
import {
|
||||
getProjectPath,
|
||||
getProjectsRoot,
|
||||
projectNameSchema,
|
||||
} from "@/lib/projects";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
|
||||
export async function POST(request: Request) {
|
||||
let body: unknown;
|
||||
|
||||
try {
|
||||
body = await request.json();
|
||||
} catch {
|
||||
return NextResponse.json({ error: "The request body must be valid JSON." }, { status: 400 });
|
||||
}
|
||||
|
||||
const result = projectNameSchema.safeParse(
|
||||
typeof body === "object" && body !== null && "name" in body
|
||||
? (body as { name: unknown }).name
|
||||
: undefined,
|
||||
);
|
||||
|
||||
if (!result.success) {
|
||||
return NextResponse.json(
|
||||
{ error: result.error.issues[0]?.message || "Enter a valid project name." },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
|
||||
const name = result.data;
|
||||
const projectPath = getProjectPath(name);
|
||||
let directoryCreated = false;
|
||||
|
||||
try {
|
||||
await mkdir(getProjectsRoot(), { recursive: true });
|
||||
await mkdir(projectPath);
|
||||
directoryCreated = true;
|
||||
|
||||
await execFileAsync("git", ["init"], { cwd: projectPath });
|
||||
|
||||
return NextResponse.json(
|
||||
{ name, path: projectPath, gitInitialized: true },
|
||||
{ status: 201 },
|
||||
);
|
||||
} catch (error) {
|
||||
if (directoryCreated) {
|
||||
await rm(projectPath, { recursive: true, force: true }).catch(() => undefined);
|
||||
}
|
||||
|
||||
const code = error && typeof error === "object" && "code" in error
|
||||
? (error as { code?: string }).code
|
||||
: undefined;
|
||||
|
||||
if (code === "EEXIST") {
|
||||
return NextResponse.json(
|
||||
{ error: "A project with that name already exists." },
|
||||
{ status: 409 },
|
||||
);
|
||||
}
|
||||
|
||||
if (code === "ENOENT") {
|
||||
return NextResponse.json(
|
||||
{ error: "Git was not found. Install Git and try again." },
|
||||
{ status: 503 },
|
||||
);
|
||||
}
|
||||
|
||||
console.error("Project creation failed", error);
|
||||
return NextResponse.json(
|
||||
{ error: "The project could not be created. Check the server logs for details." },
|
||||
{ status: 500 },
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
:root {
|
||||
--font-geist-sans: Arial, Helvetica, sans-serif;
|
||||
--font-geist-mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
|
||||
--background: 36 33% 96%;
|
||||
--foreground: 225 24% 14%;
|
||||
--card: 40 33% 99%;
|
||||
--card-foreground: 225 24% 14%;
|
||||
--muted: 36 20% 91%;
|
||||
--muted-foreground: 225 10% 43%;
|
||||
--primary: 225 24% 14%;
|
||||
--primary-foreground: 36 33% 96%;
|
||||
--border: 35 18% 84%;
|
||||
--input: 35 18% 78%;
|
||||
--ring: 14 72% 53%;
|
||||
--radius: 0.65rem;
|
||||
}
|
||||
|
||||
* {
|
||||
border-color: hsl(var(--border));
|
||||
}
|
||||
|
||||
body {
|
||||
min-height: 100vh;
|
||||
background: hsl(var(--background));
|
||||
color: hsl(var(--foreground));
|
||||
}
|
||||
|
||||
::selection {
|
||||
background: hsl(14 72% 53% / 0.22);
|
||||
}
|
||||
|
||||
@layer utilities {
|
||||
.text-balance {
|
||||
text-wrap: balance;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import type { Metadata } from "next";
|
||||
|
||||
import "./globals.css";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Forge | Project workspace",
|
||||
description: "Create a local project workspace with Git initialized.",
|
||||
};
|
||||
|
||||
export default function RootLayout({
|
||||
children,
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<body>{children}</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import { FolderKanban } from "lucide-react";
|
||||
|
||||
import { ProjectCreator } from "@/components/project-creator";
|
||||
import { getProjectsRoot } from "@/lib/projects";
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<main className="relative min-h-screen overflow-hidden px-5 py-6 sm:px-8 lg:px-12">
|
||||
<div className="pointer-events-none absolute -right-36 -top-40 h-[30rem] w-[30rem] rounded-full bg-orange-200/40 blur-3xl" />
|
||||
<div className="pointer-events-none absolute -bottom-48 -left-36 h-[26rem] w-[26rem] rounded-full bg-stone-200/60 blur-3xl" />
|
||||
|
||||
<div className="relative mx-auto flex min-h-[calc(100vh-3rem)] max-w-7xl flex-col">
|
||||
<header className="flex items-center justify-between border-b border-stone-300/70 pb-5">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="flex h-9 w-9 items-center justify-center rounded-md bg-stone-950 text-orange-200 shadow-sm">
|
||||
<FolderKanban size={18} strokeWidth={2.2} />
|
||||
</div>
|
||||
<span className="font-mono text-sm font-semibold tracking-[0.18em] text-stone-950">
|
||||
FORGE
|
||||
</span>
|
||||
</div>
|
||||
<span className="font-mono text-[11px] uppercase tracking-[0.16em] text-stone-500">
|
||||
Local workspace utility
|
||||
</span>
|
||||
</header>
|
||||
|
||||
<div className="grid flex-1 items-center gap-14 py-14 lg:grid-cols-[1.05fr_0.95fr] lg:gap-24">
|
||||
<section>
|
||||
<p className="mb-6 font-mono text-xs font-medium uppercase tracking-[0.24em] text-orange-700">
|
||||
Project / 001
|
||||
</p>
|
||||
<h1 className="max-w-xl text-balance text-5xl font-semibold leading-[0.98] tracking-[-0.055em] text-stone-950 sm:text-7xl">
|
||||
Start with a clean slate.
|
||||
</h1>
|
||||
<p className="mt-7 max-w-lg text-lg leading-8 text-stone-600">
|
||||
Create a local project workspace and initialize its Git history in one deliberate step.
|
||||
</p>
|
||||
|
||||
<div className="mt-12 flex items-center gap-3 text-sm text-stone-500">
|
||||
<span className="h-2 w-2 rounded-full bg-emerald-500 shadow-[0_0_0_4px_rgba(16,185,129,0.12)]" />
|
||||
Ready to create
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<ProjectCreator projectsRoot={getProjectsRoot()} />
|
||||
</div>
|
||||
|
||||
<footer className="flex flex-col gap-2 border-t border-stone-300/70 pt-5 font-mono text-[11px] uppercase tracking-[0.14em] text-stone-500 sm:flex-row sm:items-center sm:justify-between">
|
||||
<span>Git initialization enabled</span>
|
||||
<span>v0.1 / Local only</span>
|
||||
</footer>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user