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

24 lines
571 B
TypeScript

import { unlinkSync } 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.isDirectory())
return { error: "Use `rmdir` to remove directory" }
target = file.name
break
}
}
if (!target)
return { error: `${path} not found` }
unlinkSync(join(projectDir(), path))
return `${path} removed`
}