#!/bin/bash
set -euo pipefail

APP_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

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

  # Remove node_modules if present in component-library
  # (otherwise including components will make vuetify-loader
  # import another vuetify).
  if [[ $folder = "argus-component-library" ]]; then rm -fR "node_modules"; fi
  popd
done
