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

if ! command -v node >/dev/null 2>&1; then
	export NVM_DIR="$HOME/.nvm"
	if [ -s "$NVM_DIR/nvm.sh" ]; then
		. "$NVM_DIR/nvm.sh"
	fi
fi

# Normalize commit type to lowercase
sed -E 's/^[A-Za-z]+/\L&/' "$1" > "$1.tmp" && mv "$1.tmp" "$1"

if [ -x "./node_modules/.bin/commitlint" ]; then
	./node_modules/.bin/commitlint --edit "$1"
else
	echo "commitlint not found at ./node_modules/.bin/commitlint"
	echo "Run: npm install"
	exit 127
fi
