#!/usr/bin/env bash
# Build: compile ASCF demo → sync rawfile → hvigorw assembleHap
source "$(cd "$(dirname "$0")/.." && pwd)/scripts/_config.sh"

mode="${1:-release}"
log "Building (mode=$mode)..."

# Step 1: Build ASCF demo (compile + sync to OHOS + Android)
"$REPO_ROOT/scripts/build-demo.sh" "$mode"

# Step 2: Build HAP
log "Building HAP (hvigorw)..."
cd "$REPO_ROOT/flexui-engine"
build_mode_param=""
if [ "$mode" = "development" ]; then
  build_mode_param="-p buildMode=debug"
  log "(hvigorw debug mode — FOOTSTONE_DLOG enabled)"
fi
"$HVIGORW" $HVIGORW_ARGS $build_mode_param assembleHap --no-daemon 2>&1 | tail -10
log "HAP built: $(ls -lh "$HAP" | awk '{print $5}')"