server/.githooks/pre-commit

30 lines
699 B
Plaintext
Raw Permalink Normal View History

2023-11-29 17:01:06 +00:00
#!/usr/bin/env bash
set -e
STAGED=$(
git --no-pager diff --name-only --no-color --cached --diff-filter=d |
# Remove quotations used to surrounding filenames with special characters.
sed -e "s/^\"//" -e "s/\"$//g"
2023-11-29 17:01:06 +00:00
)
MIX_TARGETS=()
WEB_TARGETS=()
while IFS= read -r FILENAME
2023-11-29 17:01:06 +00:00
do
if [[ "$FILENAME" =~ .*\.exs? ]]; then
2023-12-04 13:06:54 +00:00
MIX_TARGETS+=("$FILENAME")
elif [[ "$FILENAME" =~ .*\.jsx? ]] || [[ "$FILENAME" =~ .*\.tsx? ]]; then
WEB_TARGETS+=("$FILENAME")
fi
done <<< "$STAGED"
2023-12-02 01:48:47 +00:00
if (( ${#MIX_TARGETS[@]} )); then
mix format "${MIX_TARGETS[@]}"
git add "${MIX_TARGETS[@]}"
fi
2023-12-02 01:48:47 +00:00
if (( ${#WEB_TARGETS[@]} )); then
2023-12-04 13:06:54 +00:00
prettier --write "${WEB_TARGETS[@]}"
git add "${WEB_TARGETS[@]}"
fi