#!/usr/bin/env bash

set -eo pipefail

script_dir="$(dirname "$0")"

args=("$@")

# If the command is used like `yarn build plugin`, set the --build option to point to
# plugin/tsconfig.json
if [ "$1" == "plugin" ]; then
  # `--build` must be the first argument, so reset the array
  args=()
  args+=("--build")
  args+=("$(pwd)/plugin")
  # Push the rest of the arguments minus the `plugin` arg
  args+=("${@:2}")
fi

if [[ -t 1 && (-z "$CI" && -z "$EXPO_NONINTERACTIVE") ]]; then
  args+=("--watch")
fi

"$script_dir/expo-module-tsc" "${args[@]}"
