-
Notifications
You must be signed in to change notification settings - Fork 169
/
dev.ts
37 lines (33 loc) · 886 Bytes
/
dev.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { fromFileUrl } from "std/path/mod.ts";
import dev, { createWatchFsEmitter } from "aleph/dev";
const emitter = createWatchFsEmitter();
emitter.on("modify", ({ specifier }) => {
if (specifier.endsWith(".rs")) {
// rebuild the yew app then restart the dev server
start();
}
});
let buildProc: Deno.Process | null = null;
// build the yew app then start the dev server
async function start() {
const cwd = fromFileUrl(new URL(".", import.meta.url));
if (buildProc) {
buildProc.kill("SIGTERM");
buildProc.close();
}
buildProc = Deno.run({
cmd: ["wasm-pack", "build", "--target", "web"],
stdout: "inherit",
stderr: "inherit",
cwd,
});
try {
await buildProc.status();
buildProc.close();
await Deno.remove(`${cwd}/pkg/.gitignore`);
dev({ baseUrl: import.meta.url });
} finally {
buildProc = null;
}
}
start();