#!/bin/bash
set -euo pipefail
DIR="$(cd "$(dirname "$0")" && pwd)"; BIN="${HOME}/.local/bin"; mkdir -p "$BIN"
install -m 0755 "$DIR/bin/adom-nucleus" "$BIN/adom-nucleus"; echo "Installed adom-nucleus"
# Renamed from adom-project-manager: drop the old command so upgraders don't keep a stale binary.
rm -f "$BIN/adom-project-manager"

# Board-GLB optimizer: --render-board shrinks the raw kicad-cli board GLB (merge
# primitives, quantize) before publishing. It shells to `node <script>` using
# @gltf-transform; both are OPTIONAL — without them --render-board just publishes
# the un-optimized GLB. Install the script + its deps best-effort next to the bin.
if [ -f "$DIR/glb_optimize.mjs" ]; then
  install -m 0644 "$DIR/glb_optimize.mjs" "$BIN/glb_optimize.mjs"
  if command -v npm >/dev/null 2>&1; then
    ( cd "$BIN" && npm install --no-save --no-audit --no-fund \
        @gltf-transform/core @gltf-transform/functions @gltf-transform/extensions >/dev/null 2>&1 ) \
      && echo "Installed board-GLB optimizer (gltf-transform)" \
      || echo "Note: gltf-transform deps not installed; --render-board will publish un-optimized GLBs"
  else
    echo "Note: npm not found; --render-board will publish un-optimized GLBs (install node+npm to enable optimization)"
  fi
fi

# 0.5.0 bundled the deprecated publish-board skill; molecule-publish replaces it
# (installed as a package dependency), so clear the stale copy.
rm -rf "${HOME}/.claude/skills/publish-board"