#!/usr/bin/env sh
# pre-push — code quality checks before pushing to the remote.
#
# Install (per clone):
#   git config core.hooksPath hooks
#
# The hook is a no-op until the application toolchain (package.json)
# exists. When it does, `lint` and `test` scripts are run if defined.

status=0

if [ -f package.json ]; then
  if npm run lint --if-present --silent; then
    echo "pre-push: lint passed"
  else
    echo "pre-push: lint FAILED — push aborted" >&2
    status=1
  fi

  if [ "$status" -eq 0 ] && npm run test --if-present --silent; then
    echo "pre-push: tests passed"
  else
    [ "$status" -eq 0 ] && echo "pre-push: tests FAILED — push aborted" >&2
    status=1
  fi
fi

exit "$status"
