import { exec, OutputMode } from "https://deno.land/x/exec@0.0.5/mod.ts"; import { ensureFile } from "https://deno.land/std@0.95.0/fs/mod.ts"; const entry = 'https://scrapbox.io/api/code/deno-ja/最速でWeb_Assemblyを使ったweb_pageを試す'; // 必要なファイルをdownloadする { const filename = 'lib.rs'; await ensureFile(`./src/${filename}`); const res = await fetch(`${entry}/${filename}`); await Deno.writeTextFile(`./src/${filename}`, await res.text()); } { const filename = 'Cargo.toml'; await ensureFile(filename); const res = await fetch(`${entry}/${filename}`); await Deno.writeTextFile(filename, await res.text()); } { const filename = 'index.js'; await ensureFile(filename); const res = await fetch(`${entry}/${filename}`); await Deno.writeTextFile(filename, await res.text()); } // compileを実行する await exec('wasm-pack build --target web --release', {output: OutputMode.Capture, verbose: true}); // 予めUint8Arrayにしておく const wasm = await Deno.readFile("./pkg/web_page_demo_bg.wasm"); await Deno.writeTextFile("./pkg/web_page_demo_bg.wasm.js", `export const wasm = new Uint8Array([${wasm.join(",")}]);`);