#!/usr/bin/env bash

set -euo pipefail

current_directory="$(pwd)"

cleanup() {
    cd ${current_directory}
    exit
}
trap cleanup EXIT

if [[ "$OSTYPE" == "darwin"* ]]; then
  DRIVING_ROOT="$(cd ../../ && pwd)"
else
  DRIVING_ROOT=$(readlink -f $(dirname "${BASH_SOURCE[0]}")/../../../)
fi
SPECTRUM_ROOT=${DRIVING_ROOT}/spectrum
FLEETDASH_ROOT=${DRIVING_ROOT}/fleetdash_v2/

link_spectrum_ui(){
    echo "link_spectrum_ui"
    cd ${SPECTRUM_ROOT}/spectrum-ui/
    yarn
    yarn build
    yarn link

    cd ${FLEETDASH_ROOT}/frontend
    yarn link @zoox/spectrum-ui
}

link_spectrum_ui
