nose-pluto/nose/bin/ls.ts
Chris Wanstrath 8f7fc5d36b getState
2025-09-21 12:37:21 -07:00

27 lines
731 B
TypeScript

import { readdirSync } from "fs"
import { NOSE_WWW } from "@/config"
import { getState } from "@/state"
import { appPath } from "@/webapp"
export default function () {
const state = getState()
if (!state) return { error: "no state" }
const project = state.project
if (!project) return { error: "no project loaded" }
const root = appPath(project)
if (!root) return { error: "error loading project" }
let files: string[] = []
for (const file of readdirSync(root, { withFileTypes: true })) {
files.push(file.name)
}
if (root === NOSE_WWW) {
files = files.filter(file => file.endsWith(`${project}.ts`) || file.endsWith(`${project}.tsx`))
}
return files.join(" ")
}