mirror of
https://github.com/ParkerTenBroeck/automata.git
synced 2026-06-06 21:24:06 -04:00
moved to deno to bundle website
This commit is contained in:
parent
c35d7a9192
commit
7629bdab6d
28 changed files with 1534 additions and 41961 deletions
44
web/tools/build.ts
Normal file
44
web/tools/build.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import * as sass from "sass";
|
||||
|
||||
// tools/build.ts
|
||||
const ROOT = new URL("../root/", import.meta.url);
|
||||
const WASM = new URL("../wasm/", import.meta.url);
|
||||
const DIST = new URL("../dist/", import.meta.url);
|
||||
|
||||
async function run(cmd: string[], cwd?: string) {
|
||||
const p = new Deno.Command(cmd[0], { args: cmd.slice(1), cwd });
|
||||
const out = await p.output();
|
||||
if (!out.success) {
|
||||
console.error(new TextDecoder().decode(out.stderr));
|
||||
Deno.exit(out.code);
|
||||
}
|
||||
}
|
||||
|
||||
// Clean dist
|
||||
await Deno.remove(DIST, { recursive: true }).catch(() => {});
|
||||
await Deno.mkdir(DIST, { recursive: true });
|
||||
|
||||
|
||||
console.log("compiling scss...");
|
||||
|
||||
const result = sass.compile(String(new URL("style/style.scss", ROOT).pathname), {
|
||||
style: "compressed",
|
||||
});
|
||||
await Deno.writeTextFile(new URL("style.css", DIST), result.css);
|
||||
|
||||
console.log("Compiling wasm lib...");
|
||||
await run(["wasm-pack", "build", "--target", "web", "--release", "--out-dir", "wasm"], "");
|
||||
await Deno.copyFile(new URL("automata_web_bg.wasm", WASM), new URL("automata_web_bg.wasm", DIST));
|
||||
|
||||
|
||||
console.log("Compiling bundle...");
|
||||
const bundle = new Deno.Command(Deno.execPath(), {
|
||||
args: ["bundle", "--platform=browser", "--outdir", "dist", "root/index.html", "--minify",],
|
||||
});
|
||||
const bundleRes = await bundle.output();
|
||||
if (!bundleRes.success) {
|
||||
console.error(new TextDecoder().decode(bundleRes.stderr));
|
||||
Deno.exit(bundleRes.code);
|
||||
}
|
||||
|
||||
console.log("Build complete: dist/");
|
||||
58
web/tools/dev.ts
Normal file
58
web/tools/dev.ts
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
// tools/dev.ts
|
||||
const BUILD_CMD = ["deno", "run", "-A", "tools/build.ts"];
|
||||
const SERVE_CMD = [
|
||||
"deno",
|
||||
"run",
|
||||
"--allow-net",
|
||||
"--allow-read",
|
||||
"--allow-sys",
|
||||
"jsr:@std/http/file-server",
|
||||
"dist",
|
||||
];
|
||||
|
||||
let building = false;
|
||||
let server: Deno.ChildProcess | null = null;
|
||||
|
||||
async function runBuild() {
|
||||
if (building) return;
|
||||
building = true;
|
||||
|
||||
console.log("🔨 building…");
|
||||
const p = new Deno.Command(BUILD_CMD[0], {
|
||||
args: BUILD_CMD.slice(1),
|
||||
});
|
||||
const r = await p.output();
|
||||
if (!r.success) {
|
||||
console.error(new TextDecoder().decode(r.stderr));
|
||||
} else {
|
||||
console.log("✅ build complete");
|
||||
}
|
||||
|
||||
building = false;
|
||||
}
|
||||
|
||||
async function startServer() {
|
||||
if (server) return;
|
||||
const p = new Deno.Command(SERVE_CMD[0], {
|
||||
args: SERVE_CMD.slice(1),
|
||||
stdout: "inherit",
|
||||
stderr: "inherit",
|
||||
});
|
||||
server = p.spawn();
|
||||
}
|
||||
|
||||
await runBuild();
|
||||
await startServer();
|
||||
|
||||
console.log("👀 watching for changes…");
|
||||
|
||||
const watcher = Deno.watchFs(["root", "../src"]);
|
||||
for await (const event of watcher) {
|
||||
if (
|
||||
event.kind === "modify" ||
|
||||
event.kind === "create" ||
|
||||
event.kind === "remove"
|
||||
) {
|
||||
await runBuild();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue