import { Glob } from "bun" import { watch } from "fs" import { sendAll } from "./websocket" import { expectDir } from "./utils" import { NOSE_SYS_BIN, NOSE_BIN } from "./config" const sysCmdWatcher = watch(NOSE_SYS_BIN, async (event, filename) => sendAll({ type: "commands", data: await commands() }) ) expectDir(NOSE_BIN) const usrCmdWatcher = watch(NOSE_BIN, async (event, filename) => { sendAll({ type: "commands", data: await commands() }) }) export async function commands(): Promise { return (await findCommands(NOSE_SYS_BIN)).concat(await findCommands(NOSE_BIN)) } export async function findCommands(path: string): Promise { const glob = new Glob("**/*.{ts,tsx}") let list: string[] = [] for await (const file of glob.scan(path)) { list.push(file.replace(".ts", "").replace(".tsx", "")) } return list }