#!/usr/bin/env bash
set -euo pipefail

root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
frontend_dir="${root_dir}/frontend"

if command -v bun >/dev/null 2>&1; then
  bun_cmd=(bun)
elif [[ -x "${HOME}/.bun/bin/bun" ]]; then
  bun_cmd=("${HOME}/.bun/bin/bun")
else
  echo "bun is required to run frontend checks" >&2
  exit 1
fi

cd "${frontend_dir}"
"${bun_cmd[@]}" run check
"${bun_cmd[@]}" run build
