#!/usr/bin/env bash
# Build the web client bundle.
#
# Outputs: dist/bundle.js, dist/bundle.js.map, dist/bundle.css
#
# Re-run after editing anything under src/. Commit dist/* alongside source so
# `cargo build` doesn't need a Node toolchain.
#
# To regenerate the protobuf bindings (rare — when libs/hbb_common bumps):
#   npm run protogen && npm run build

set -euo pipefail
cd "$(dirname "$0")"

if [ ! -d node_modules ]; then
  echo "Installing npm dependencies..."
  npm install
fi

mkdir -p dist
echo "Bundling JS..."
npm run --silent build:js
echo "Copying CSS..."
npm run --silent build:css

echo "Done. Bundle:"
ls -lh dist/bundle.js dist/bundle.css 2>/dev/null || true
