// Create a new project.

import { mkdirSync, writeFileSync } from "fs"
import { join } from "path"
import { projects } from "@/project"
import { NOSE_DIR } from "@/config"

import load from "./load"

export default function (project: string) {
    if (!project) throw "usage: new <project name>"

    if (projects().includes(project)) throw `${project} already exists`

    const dir = join(NOSE_DIR, project)
    mkdirSync(dir, { recursive: true })
    writeFileSync(join(dir, `index.ts`), `export default (c: Context) =>\n  "Hello, world!"`)

    load(project)

    return `Created ${project}`
}