#!/bin/sh
# See https://prettier.io/docs/en/precommit.html#option-6-bash-script for reference

FILES=$(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g')
[ -z "$FILES" ] && exit 0

echo -e "\x1b[1;35m[.githooks/pre-commit]\x1b[0m Running Prettier on any modified files..."

# Prettify all selected files
echo "$FILES" | xargs ./node_modules/.bin/prettier --write

# Add back the modified/prettified files to staging
echo "$FILES" | xargs git add

exit 0