-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjust.ts
executable file
·80 lines (72 loc) · 2.51 KB
/
just.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env -S deno run --allow-all
import $ from "@david/dax";
import { Command, EnumType } from "@cliffy/command";
const envEnum = new EnumType(["linux", "windows", "macos", "macos"]);
interface Env {
binary: string;
}
async function installLinuxDeps() {
// TODO: check if Ubuntu
await $`sudo apt-get update`;
await $`sudo apt-get install --no-install-recommends pkg-config libx11-dev libasound2-dev libudev-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev clang mold libwayland-dev libxkbcommon-dev`;
}
async function installWasmDeps() {
await Promise.all([
$`rustup component add rustc-codegen-cranelift-preview --toolchain nightly`,
$`cargo install wasm-bindgen-cli --version 0.2.95`,
$`cargo install wasm-opt`,
]);
}
async function buildWasm() {
await $`cargo build --release --target wasm32-unknown-unknown`;
}
async function prepareWasmPackage(env: Env = { binary: "dinosaur-game" }) {
// Gen JS
await $`wasm-bindgen --out-name ${env.binary} --out-dir wasm --target web target/wasm32-unknown-unknown/release/${env.binary}.wasm`;
// Optimize Wasm
await $`wasm-opt -O wasm/${env.binary}_bg.wasm -o ${env.binary}.wasm`;
// Compress Wasm using brotli
await $`brotli wasm/${env.binary}_bg.wasm -o web/${env.binary}_bg.wasm`;
await $`mv wasm/${env.binary}.js web/`;
// Copy assets
await $`cp -r crates/game/assets web/`;
// Check assets folder exists under web
if (!(await $`test -d web/assets`)) {
throw new Error("Assets folder not copied");
}
}
async function buildRelease() {
await $`cargo b --release`;
}
// TODO: Migrate All workflow script to this file
await new Command()
.name("just")
.description("Command used to build whole project")
.version("0.1.0")
.type("env", envEnum)
.globalOption("--env <level:env>", "Environment to build", {
default: "linux",
})
.description("Script for the dinosaur game").action(async () => {
await buildRelease();
})
.command("install-linux-deps", "Install dependencies").action(async () => {
await installLinuxDeps();
})
.command("install-wasm-deps", "Install wasm dependencies").action(
async () => {
await installWasmDeps();
},
)
.command("build-wasm", "Build wasm").action(async () => {
await buildWasm();
})
.command("prepare-wasm-package", "Prepare wasm package").action(async () => {
await prepareWasmPackage();
})
.command("web", "Web build").action(async () => {
await installWasmDeps();
await buildWasm();
await prepareWasmPackage();
})
.parse(Deno.args);