#!/bin/bash -e

ROOT=`dirname $0`

cd "$ROOT/.."

SKIP_TRANSLATIONS=false
while [[ $# -gt 0 ]]; do
  case "$1" in
    --skip-translations)
      SKIP_TRANSLATIONS=true
      shift
      ;;
    *)
      echo "Unknown argument: $1" >&2
      exit 1
      ;;
  esac
done

if [ "$SKIP_TRANSLATIONS" = false ]; then
  echo "Updating translations..."
  if ! [ -d packages/desktop-client/locale ]; then
      git clone https://github.com/actualbudget/translations packages/desktop-client/locale
  fi
  pushd packages/desktop-client/locale > /dev/null
  git checkout .
  git pull
  popd > /dev/null
  packages/desktop-client/bin/remove-untranslated-languages
fi

lage build:browser --to=@actual-app/web
