Skip to content

Commit 6b17d9e

Browse files
committed
refactor: repareWasmFiles.ts -> prepare-wasm-files.sh - no more need of nodeJS for this part
1 parent f167b78 commit 6b17d9e

File tree

4 files changed

+118
-96
lines changed

4 files changed

+118
-96
lines changed

justfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,11 @@ prepare-fixtures:
150150
cp -r fixtures/filesystem tmp
151151
mv tmp/filesystem/README.rust.md tmp/filesystem/README.md
152152
rm tmp/filesystem/README.browser.md
153+
154+
# Copy wasm files into /public/plugins of the web host - debug mode
155+
web-host-prepare-wasm-files-debug:
156+
./scripts/prepare-wasm-files.sh --mode debug
157+
158+
# Copy wasm files into /public/plugins of the web host - release mode
159+
web-host-prepare-wasm-files-release:
160+
./scripts/prepare-wasm-files.sh --mode release

packages/web-host/clis/prepareWasmFiles.ts

Lines changed: 0 additions & 92 deletions
This file was deleted.

packages/web-host/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,15 @@
66
"description": "Web host for Terminal REPL with plugin system (using WebAssembly Component Model)",
77
"scripts": {
88
"predev": "npm run prebuild",
9-
"predev:debug": "npm run wit-types && just build-plugins && just build-repl-logic-guest && npm run prepareWasmFiles:debug && npm run wasm:transpile",
9+
"predev:debug": "npm run wit-types && just build-plugins && just build-repl-logic-guest && just web-host-prepare-wasm-files-debug && npm run wasm:transpile",
1010
"dev": "vite --host",
1111
"dev:debug": "vite --host",
12-
"prebuild": "npm run wit-types && just build-plugins-release && just build-repl-logic-guest-release && npm run prepareWasmFiles:release && npm run wasm:transpile && npm run prepareVirtualFs",
12+
"prebuild": "npm run wit-types && just build-plugins-release && just build-repl-logic-guest-release && just web-host-prepare-wasm-files-release && npm run wasm:transpile && npm run prepareVirtualFs",
1313
"build": "tsc -b && vite build",
1414
"preview": "vite preview --host",
1515
"lint": "biome check .",
1616
"lint:fix": "biome check --write .",
1717
"typecheck": "tsc --noEmit -p tsconfig.app.json",
18-
"prepareWasmFiles:release": "node --experimental-strip-types --no-warnings ./clis/prepareWasmFiles.ts --mode release",
19-
"prepareWasmFiles:debug": "node --experimental-strip-types --no-warnings ./clis/prepareWasmFiles.ts --mode debug",
2018
"prepareVirtualFs": "node --experimental-strip-types --no-warnings ./clis/prepareFilesystem.ts --path fixtures/filesystem --format ts > src/wasm/virtualFs.ts; biome format --write ./src/wasm/virtualFs.ts",
2119
"test:e2e:all": "playwright test",
2220
"test:e2e:ui": "playwright test --ui",

scripts/prepare-wasm-files.sh

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#!/bin/bash
2+
3+
# Prepare wasm files for the web host
4+
# Usage: ./scripts/prepare-wasm-files.sh --mode debug|release [--target-dir <dir>]
5+
6+
set -e
7+
8+
usage() {
9+
echo "Usage: $0 --mode <mode> [--target-dir <dir>]"
10+
echo " mode: debug or release"
11+
echo " target-dir: optional custom target directory (default: packages/web-host/public/plugins)"
12+
echo ""
13+
echo "Example:"
14+
echo " $0 --mode debug"
15+
echo " $0 --mode release"
16+
echo " $0 --mode debug --target-dir ./custom/plugins"
17+
exit 1
18+
}
19+
20+
validate_mode() {
21+
local mode="$1"
22+
if [[ "$mode" != "debug" && "$mode" != "release" ]]; then
23+
echo "Error: --mode must be one of: debug, release."
24+
exit 1
25+
fi
26+
}
27+
28+
prepare_wasm_files() {
29+
local mode="$1"
30+
local target_dir="$2"
31+
echo "Preparing wasm files for mode: $mode"
32+
33+
local workspace_root="$(cd "$(dirname "$0")/.." && pwd)"
34+
35+
mkdir -p "$target_dir"
36+
37+
local wasm_files=(
38+
"target/wasm32-wasip1/$mode/plugin_echo.wasm"
39+
"target/wasm32-wasip1/$mode/plugin_greet.wasm"
40+
"target/wasm32-wasip1/$mode/plugin_ls.wasm"
41+
"target/wasm32-wasip1/$mode/plugin_cat.wasm"
42+
"target/wasm32-wasip1/$mode/plugin_weather.wasm"
43+
"c_modules/plugin-echo/plugin-echo-c.wasm"
44+
"target/wasm32-wasip1/$mode/repl_logic_guest.wasm"
45+
)
46+
47+
# Copy each wasm file
48+
for wasm_file in "${wasm_files[@]}"; do
49+
local copy_from="$workspace_root/$wasm_file"
50+
local copy_to="$target_dir/$(basename "$wasm_file")"
51+
52+
if [[ ! -f "$copy_from" ]]; then
53+
echo ""
54+
echo "Failed to copy $copy_from to $copy_to"
55+
echo ""
56+
if [[ "$mode" == "debug" ]]; then
57+
echo "Please run the command: just build"
58+
else
59+
echo "Please run the command: just build-release"
60+
fi
61+
echo ""
62+
exit 1
63+
fi
64+
65+
cp "$copy_from" "$copy_to"
66+
echo "Copied $copy_from to $copy_to"
67+
done
68+
}
69+
70+
# Parse command line arguments
71+
MODE=""
72+
TARGET_DIR=""
73+
74+
while [[ $# -gt 0 ]]; do
75+
case $1 in
76+
--mode)
77+
MODE="$2"
78+
shift 2
79+
;;
80+
--target-dir)
81+
TARGET_DIR="$2"
82+
shift 2
83+
;;
84+
-h|--help)
85+
usage
86+
;;
87+
*)
88+
echo "Unknown option: $1"
89+
usage
90+
;;
91+
esac
92+
done
93+
94+
# Check if mode is provided
95+
if [[ -z "$MODE" ]]; then
96+
echo "Error: --mode is required"
97+
usage
98+
fi
99+
100+
# Set default target directory if not provided
101+
if [[ -z "$TARGET_DIR" ]]; then
102+
WORKSPACE_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
103+
TARGET_DIR="$WORKSPACE_ROOT/packages/web-host/public/plugins"
104+
fi
105+
106+
# Validate mode and prepare files
107+
validate_mode "$MODE"
108+
prepare_wasm_files "$MODE" "$TARGET_DIR"

0 commit comments

Comments
 (0)