#!/usr/bin/env bash
# OMG library kit: parts() for spacecraft (turrets, guns up, thrusters), run in Node with the vendored three.js (browse/vendor) in a /tmp dir.
set -euo pipefail
ROOT=$(cd "$(dirname "$0")/.." && pwd); D=$(mktemp -d /tmp/kit-test-XXXX); V=$(readlink -f "${THREE_VENDOR:-$ROOT/browse/vendor}")
mkdir -p "$D/node_modules/three" && cp -r "$V/build" "$V/addons" "$D/node_modules/three/"
printf '{"name":"three","type":"module","exports":{".":"./build/three.module.min.js","./addons/*":"./addons/*"}}' > "$D/node_modules/three/package.json"
cp "$ROOT/omg/kit/index.mjs" "$D/kit.mjs"; cp "$ROOT/omg/kit/track-belt.mjs" "$D/track-belt.mjs"; cp "$ROOT/test/kit_space_parts.mjs" "$D/test.mjs"
(cd "$D" && node test.mjs); rc=$?; find "$D" -delete; exit $rc
