mirror of
https://github.com/loro-dev/loro.git
synced 2025-02-06 12:25:03 +00:00
chore(ci): fix build script in ci
This commit is contained in:
parent
1400804fb1
commit
2903a47ddb
1 changed files with 21 additions and 7 deletions
|
@ -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`,
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue