#!/usr/bin/env bash # Build and pack all BEX plugins # # This script: # 1. Compiles all plugins to WASM (wasm32-wasip1) # 2. Converts them to WASM components (using wasm-tools) # 3. Packs them into .bex packages # # Requirements: cargo, wasm-tools (cargo install wasm-tools-cli) set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "$SCRIPT_DIR" PLUGINS=(bex-gogoanime bex-kaianime bex-hianime bex-imdb bex-kisskh) WASI_ADAPTER="" # Find WASI adapter for dir in ~/.cargo/registry/src/index.crates.io-*/wasi-preview1-component-adapter-provider-*/artefacts/; do if [ -f "${dir}wasi_snapshot_preview1.reactor.wasm" ]; then WASI_ADAPTER="${dir}wasi_snapshot_preview1.reactor.wasm" break fi done if [ -z "$WASI_ADAPTER" ]; then echo "ERROR: WASI adapter not found. Run 'cargo build -p bex-gogoanime --target wasm32-wasip1' first to download it." exit 1 fi echo "=== Building WASM plugins ===" cargo build --target wasm32-wasip1 --release ${PLUGINS[*]/#/-p } echo "" echo "=== Converting to components ===" mkdir -p target/components for plugin in "${PLUGINS[@]}"; do # Convert underscore to hyphen for the WASM file name wasm_name="${plugin/-/_}" wasm_path="target/wasm32-wasip1/release/${wasm_name}.wasm" component_path="target/components/${plugin}.component.wasm" if [ ! -f "$wasm_path" ]; then echo " SKIP: $plugin (WASM not found)" continue fi echo " Converting: $plugin" wasm-tools component new "$wasm_path" -o "$component_path" --adapt "$WASI_ADAPTER" done echo "" echo "=== Packing .bex packages ===" mkdir -p dist for plugin in "${PLUGINS[@]}"; do component_path="target/components/${plugin}.component.wasm" manifest_path="dist/${plugin}.yaml" output_path="dist/${plugin}.bex" if [ ! -f "$component_path" ]; then echo " SKIP: $plugin (component not found)" continue fi if [ ! -f "$manifest_path" ]; then echo " SKIP: $plugin (manifest not found at $manifest_path)" continue fi echo " Packing: $plugin" ./target/release/bex pack "$manifest_path" "$component_path" "$output_path" done echo "" echo "=== Done! ===" echo "Packages in dist/:" ls -la dist/*.bex 2>/dev/null || echo " (no .bex files)"