Works, easy :D

This commit is contained in:
Sebastian Seedorf
2020-04-20 18:19:42 +02:00
commit 331a08620e
2 changed files with 35 additions and 0 deletions

12
README.md Normal file
View File

@@ -0,0 +1,12 @@
# Rhinoder
This program reloads a deno program automatically when a file in the current working directory is created, deleted or modified.
## Usage
the following code runs `deno --allow-net example.ts` which is located in `/some/work/dir/example.ts` on start an whenever a file in the folder `/some/work/dir` changes.
```bash
/some/work/dir$ deno --allow-run --allow-read https://raw.githubusercontent.com/Caesar2011/rhinoder/master/mod.ts --allow-net example.ts
```

23
mod.ts Normal file
View File

@@ -0,0 +1,23 @@
function startProcess(args: string[] = []): Deno.Process {
return Deno.run({ cmd: ['deno', ...args] });
}
const throttle = 500;
let app: Deno.Process = startProcess(Deno.args);
let appInitTime: number = Date.now();
let timeout: number|null = null;
function runApp() {
appInitTime = Date.now();
app && app.close();
app = startProcess(Deno.args);
}
runApp();
for await (const event of Deno.fsEvents('.')) {
if (event.kind !== "access") {
if (timeout) clearTimeout(timeout);
timeout = setTimeout(runApp, throttle);
}
}