nose-pluto/app/nose/bin/rmdir.ts
2025-09-28 15:53:45 -07:00

25 lines
675 B
TypeScript

import { rmdirSync, readdirSync } from "fs"
import { join } from "path"
import { projectDir } from "@/project"
import { getState } from "@/session"
export default function (path: string) {
let target = ""
if (path.endsWith("/")) path = path.slice(0, path.length - 1)
const root = getState("cwd") || projectDir()
for (const file of readdirSync(root, { withFileTypes: true }))
if (file.name === path) {
if (file.isFile())
return { error: "Use `rm` to remove files" }
target = file.name
break
}
if (!target)
return { error: `${path} not found` }
rmdirSync(join(root, path), { recursive: true })
return `${path} removed`
}