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

17 lines
513 B
TypeScript

// Create an empty text file.
import { join } from "path"
import { readdirSync } from "fs"
import { projectDir } from "@/project"
import { getState } from "@/session"
export default async function (path: string) {
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) throw `${path} exists`
await Bun.write(join(root, path), "")
return `${path} created`
}