async function* cleanWatch(dir: string) { let lastPath = null; let lastKind = null; for await ( const { kind, paths } of Deno.watchFs(dir, { recursive: true, }) ) { for (const path of paths) { if (lastPath != path || lastKind != kind) { lastPath = path; lastKind = kind; yield { kind, path }; } } } } const color: Record = { "any": "color: grey", "create": "color: lightgreen", "modify": "color: yellow", "remove": "color: red", "access": "color: cyan", }; const prefix: Record = { "any": "?", "create": "+", "modify": "~", "remove": "-", "access": ".", }; let lastTime = new Date(0); for await ( const event of cleanWatch(Deno.args[0]) ) { let time = new Date(); if (time.valueOf() - lastTime.valueOf() > 5000) console.log(time); lastTime = time; console.log(`%c${prefix[event.kind]} ${event.path}`, color[event.kind]); } export {};