// Makes a directory inside the current directory.
//
// Essentially `mkdir -p`.

import { mkdirSync, readdirSync } from "fs"
import { join } from "path"
import { projectDir } from "@/project"
import { sessionGet } from "@/session"

export default async function (path: string) {
  if (path.endsWith("/")) path = path.slice(0, path.length - 1)

  const root = sessionGet("cwd") || projectDir()
  for (const file of readdirSync(root, { withFileTypes: true }))
    if (file.name === path) throw `${path} exists`

  mkdirSync(join(root, path), { recursive: true })
  return `${path} created`
}