29 lines
855 B
TypeScript
29 lines
855 B
TypeScript
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<string[]> {
|
|
return (await findCommands(NOSE_SYS_BIN)).concat(await findCommands(NOSE_BIN))
|
|
}
|
|
|
|
export async function findCommands(path: string): Promise<string[]> {
|
|
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
|
|
} |