#!/bin/bash
set -euo pipefail

pushd node_modules/@zoox

# Build symlinked zoox dependencies
declare -a deps=("bobjs" "tsprotos" "worker" "three-zrn" "spectrum3d")
for folder in "${deps[@]}"; do
  pushd $folder
  yarn install
  # use npm instead of yarn because it has --if-present flag
  npm run build --if-present
  popd
done

# Remove node_modules if present in component-library
# (otherwise including components/Speedometer.vue will
#  make vuetify-loader import another vuetify).
pushd "component-library"
if [ -d "node_modules" ]; then rm -fR "node_modules"; fi
popd

popd
