-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ts
27 lines (21 loc) · 882 Bytes
/
build.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
import { encodeBase64 } from "@std/encoding";
// Init rust project
// wasm-pack build --target deno --out-dir ../wasm
const command = new Deno.Command("wasm-pack", {
args: ["build", "--target", "web", "--out-dir", "../wasm"],
cwd: "./rust",
stdout: "inherit",
stderr: "inherit",
});
await command.output();
// Copy files
await Deno.copyFile("./wasm/librsync_rust_bg.wasm", "./src/librsync.wasm");
await Deno.copyFile("./wasm/librsync_rust.d.ts", "./src/initLibrsync.d.ts");
await Deno.copyFile("./wasm/librsync_rust.js", "./src/initLibrsync.js");
const wasmFile = await Deno.readFile("./src/librsync.wasm");
const base64 = encodeBase64(wasmFile);
const modelFile = await Deno.readTextFile("./mod.model.ts");
const modFile = modelFile
.replace("BASE64_ENCODED_WASM_BINARY", base64)
.replace("mod.ts", "mod.model.ts");
await Deno.writeTextFile("./mod.ts", modFile);