47 lines
969 B
TypeScript
47 lines
969 B
TypeScript
|
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<string, string> = {
|
||
|
"any": "color: grey",
|
||
|
"create": "color: lightgreen",
|
||
|
"modify": "color: yellow",
|
||
|
"remove": "color: red",
|
||
|
"access": "color: cyan",
|
||
|
};
|
||
|
|
||
|
const prefix: Record<string, string> = {
|
||
|
"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 {};
|