2023-11-29 16:18:10 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
|
2023-12-03 21:28:55 +00:00
|
|
|
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 16:18:10 +00:00
|
|
|
)
|
|
|
|
|
2023-12-03 21:28:55 +00:00
|
|
|
MIX_TARGETS=()
|
|
|
|
WEB_TARGETS=()
|
|
|
|
while IFS= read -r FILENAME
|
|
|
|
do
|
2023-12-19 12:48:06 +00:00
|
|
|
if [[ "$FILENAME" =~ .*\.exs?$ ]]; then
|
2023-12-03 21:28:55 +00:00
|
|
|
MIX_TARGETS+=("${FILENAME}")
|
2023-12-19 12:48:06 +00:00
|
|
|
elif [[ "$FILENAME" =~ .*\.jsx?$ ]] || [[ "$FILENAME" =~ .*\.tsx?$ ]]; then
|
2023-12-03 21:28:55 +00:00
|
|
|
WEB_TARGETS+=("${FILENAME}")
|
|
|
|
fi
|
|
|
|
done <<< "$STAGED"
|
2023-12-03 18:32:45 +00:00
|
|
|
|
2023-12-03 21:28:55 +00:00
|
|
|
if (( ${#MIX_TARGETS[@]} )); then
|
|
|
|
mix format "${MIX_TARGETS[@]}"
|
|
|
|
git add "${MIX_TARGETS[@]}"
|
|
|
|
fi
|
2023-12-02 13:32:19 +00:00
|
|
|
|
2023-12-03 21:28:55 +00:00
|
|
|
if (( ${#WEB_TARGETS[@]} )); then
|
|
|
|
prettier --write "${WEB_TARGETS[@]}"
|
|
|
|
git add "${WEB_TARGETS[@]}"
|
2023-12-03 18:32:45 +00:00
|
|
|
fi
|