#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

# Ensure all JavaScript files staged for commit pass standard code style
function xargsr() {
  # Portable version of "xargs -r". The -r flag is a GNU extension that
  # prevents xargs from running if there are no input files.
  if IFS= read -r -d $'\n' path; then
    echo "$path" | cat - | xargs "$@"
  fi
}
git diff --name-only --cached --relative | grep '\.[jt]sx\?$' | sed 's/[^[:alnum:]]/\\&/g' | xargsr -E '' -t ts-standard
if [[ $? -ne 0 ]]; then
  echo 'TypeScript Standard Style errors were detected. Aborting commit.'
  exit 1
fi

pipx run reuse lint
if [[ $? -ne 0 ]]; then
  echo 'Unfortunately, your project is not compliant with version 3.0 of the REUSE Specification :-('
  exit 1
fi

