From 2d688e71e65e106e7caa9050c08891f1d0ed9c22 Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Sat, 1 Apr 2023 10:27:24 -0400 Subject: [PATCH] only monitor transpileable files --- server.tsx | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/server.tsx b/server.tsx index b9fa4c0..e4444d5 100644 --- a/server.tsx +++ b/server.tsx @@ -256,25 +256,36 @@ const SocketsBroadcast =(inData:string)=>{ for (const socket of Sockets){ socket const FilesChanged:Map = new Map(); const ProcessFiles =debounce(async()=> { - console.log("Files changed...") - for await (const [file, action] of FilesChanged) + console.log("Processing Files...", FilesChanged); + for await (const [path, action] of FilesChanged) { - const pathname = file.substring(Deno.cwd().length).replaceAll("\\", "/"); - console.log(pathname, action); - if(Transpileable(pathname)) + const key = path.substring(Deno.cwd().length).replaceAll("\\", "/"); + console.log(key, action); + + if(action != "remove") { - if(action !== "remove") - { - await TranspileFS(file, pathname, false); - console.log(` ...cached "${pathname}"`); - SocketsBroadcast(pathname); - } + await TranspileFS(path, key, false); + console.log(` ...cached "${key}"`); + SocketsBroadcast(key); + } + else + { + Transpiled.delete(key) } } FilesChanged.clear(); }, 1000); for await (const event of Deno.watchFs(Deno.cwd())) { - event.paths.forEach( path => FilesChanged.set(path, event.kind) ); - ProcessFiles(); + event.paths.forEach( path => + { + if(Transpileable(path)) + { + FilesChanged.set(path, event.kind); + } + }); + if(FilesChanged.size) + { + ProcessFiles(); + } } \ No newline at end of file