#!/bin/bash

set -e

echo "--- Building"
BAZEL="bazel --output_user_root=~/bazel --output_base=~/bazel/anki"
BUILDARGS="--config=ci --experimental_convenience_symlinks=ignore"

# move existing node_modules into tree
test -e ~/node_modules && mv ~/node_modules ts/

$BAZEL build $BUILDARGS ...

echo "+++ Running tests"
$BAZEL test $BUILDARGS ...

echo "--- Cleanup"
# if tests succeed, back up node_modules folder
mv ts/node_modules ~/
