Works, easy :D
This commit is contained in:
12
README.md
Normal file
12
README.md
Normal 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
23
mod.ts
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user