nose-pluto/app/nose/bin/rmdir.ts

24 lines
578 B
TypeScript

import { rmdirSync } from "fs"
import { join } from "path"
import { projectDir, projectFiles } from "@/project"
export default function (path: string) {
let target = ""
if (path.endsWith("/")) path = path.slice(0, path.length - 1)
for (const file of projectFiles()) {
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(projectDir(), path), { recursive: true })
return `${path} removed`
}