├── README.md └── mod.ts /README.md: -------------------------------------------------------------------------------- 1 | # Rhinoder 2 | 3 | This program reloads a deno program automatically when a file in the current working directory is created, deleted or modified. 4 | 5 | ## Usage 6 | 7 | the following code runs `deno --allow-net example.ts` which is located in `/some/work/dir/example.ts` on start and whenever a file in the folder `/some/work/dir` changes. 8 | 9 | 10 | ```bash 11 | /some/work/dir$ deno run --allow-run --allow-read https://deno.land/x/rhinoder@v1.2.0/mod.ts --allow-net example.ts 12 | ``` 13 | 14 | ## Thanks to 15 | 16 | Thanks to [samuelgozi](https://github.com/samuelgozi) who posted the base for this code in [this GitHub issue](https://github.com/denoland/deno/issues/4830). 17 | -------------------------------------------------------------------------------- /mod.ts: -------------------------------------------------------------------------------- 1 | function startProcess(args: string[] = []): Deno.Process { 2 | return Deno.run({ cmd: ['deno', 'run', ...args] }); 3 | } 4 | 5 | const throttle = 500; 6 | let app: Deno.Process = startProcess(Deno.args); 7 | let timeout: number|null = null; 8 | 9 | function runApp() { 10 | app && app.close(); 11 | app = startProcess(Deno.args); 12 | } 13 | 14 | for await (const event of Deno.watchFs('.')) { 15 | if (event.kind !== "access") { 16 | if (timeout) clearTimeout(timeout); 17 | timeout = setTimeout(runApp, throttle); 18 | } 19 | } 20 | --------------------------------------------------------------------------------