#!/usr/bin/env bash

set -eo pipefail

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

args=()

# If the command is used like `yarn lint plugin` then set the target to `plugin/src`
extra_module_build_types=("plugin" "cli" "utils" "scripts")
found_target=""
for i in "${extra_module_build_types[@]}"
do
  if [ "$1" == "$i" ]; then
    found_target=$i
  fi
done

if [[ -n "$found_target" ]]; then
  # Push the rest of the arguments minus the `plugin` arg
  args+=("${@:2}")
  args+=("$found_target/src")
  if ! [[ -d "$found_target" ]]; then
    # Good DX cuz Expo
    printf "\n\033[1;33mThe \`$found_target/src\` folder does not exist in this project; please create it and try again.\033[0m\n\n"
    exit 0
  fi
else
  args+=("$@")
  args+=("src")
fi

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