From 2903a47ddbcf839094b7ed342f24726fdcd2a05a Mon Sep 17 00:00:00 2001 From: Zixuan Chen Date: Fri, 9 Dec 2022 12:03:45 +0800 Subject: [PATCH] chore(ci): fix build script in ci --- crates/loro-wasm/scripts/build.ts | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/crates/loro-wasm/scripts/build.ts b/crates/loro-wasm/scripts/build.ts index 535db847..dcba9f78 100644 --- a/crates/loro-wasm/scripts/build.ts +++ b/crates/loro-wasm/scripts/build.ts @@ -1,14 +1,20 @@ +import __ from "https://deno.land/x/dirname@1.1.2/mod.ts"; +import { resolve } from "https://deno.land/std@0.105.0/path/mod.ts"; +const { __dirname } = __(import.meta); + // deno run -A build.ts debug // deno run -A build.ts release // deno run -A build.ts release web // deno run -A build.ts release nodejs -let profile = "dev" +let profile = "dev"; if (Deno.args[0] == "release") { - profile = "release" + profile = "release"; } const TARGETS = ["bundler", "web", "nodejs"]; const startTime = performance.now(); +const LoroWasmDir = resolve(__dirname, ".."); +console.log(LoroWasmDir); async function build() { await cargoBuild(); if (Deno.args[1] != null) { @@ -20,7 +26,7 @@ async function build() { return; } - await Promise.all(TARGETS.map(target => { + await Promise.all(TARGETS.map((target) => { return buildTarget(target); })); @@ -36,6 +42,7 @@ async function cargoBuild() { const status = await Deno.run({ cmd: `cargo build --target wasm32-unknown-unknown --profile release` .split(" "), + cwd: LoroWasmDir, }).status(); if (!status.success) { console.log( @@ -50,18 +57,25 @@ async function cargoBuild() { async function buildTarget(target: string) { console.log("🏗️ Building target", `[${target}]`); + const targetDirPath = resolve(LoroWasmDir, target); + try { + await Deno.remove(targetDirPath, { recursive: true }); + console.log("Clear directory " + targetDirPath); + } catch (e) {} + for (const cmd of genCommands(target)) { console.log(">", cmd); - await Deno.run({ cmd: cmd.split(" ") }).status(); + await Deno.run({ cmd: cmd.split(" "), cwd: LoroWasmDir }).status(); } - console.log() + console.log(); } function genCommands(target: string): string[] { return [ - `rm -rf ./${target}`, `wasm-bindgen --weak-refs --target ${target} --out-dir ${target} ../../target/wasm32-unknown-unknown/release/loro_wasm.wasm`, - ...(profile == "dev" ? [] : [`wasm-opt -O4 ${target}/loro_wasm_bg.wasm -o ${target}/loro_wasm_bg.wasm`]), + ...(profile == "dev" ? [] : [ + `wasm-opt -O4 ${target}/loro_wasm_bg.wasm -o ${target}/loro_wasm_bg.wasm`, + ]), ]; }