#!/usr/bin/env sh
set -e
cd "$(dirname "$0")/.." || exit 1

# SourceTree 等 GUI 的 PATH 通常没有 node；先补常见安装位置
export PATH="/usr/local/bin:/opt/homebrew/bin:$HOME/.local/bin:$PATH"

if [ -s "$HOME/.nvm/nvm.sh" ]; then
  export NVM_DIR="${NVM_DIR:-$HOME/.nvm}"
  # shellcheck source=/dev/null
  . "$HOME/.nvm/nvm.sh"
fi

if command -v fnm >/dev/null 2>&1; then
  eval "$(fnm env)"
fi

if ! command -v node >/dev/null 2>&1; then
  echo "pre-commit: 找不到 node，请安装 Node 或在 ~/.husky/pre-commit 里为 PATH 增加 node 所在目录。" >&2
  exit 1
fi

exec node ./node_modules/lint-staged/bin/lint-staged.js
