2018-05-18 15:35:32 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
source ./scripts/common
|
|
|
|
|
2018-05-21 15:30:36 +01:00
|
|
|
set -e
|
|
|
|
|
2018-06-03 16:08:45 +02:00
|
|
|
uglyFiles="$(ugly "$(cachedFiles)")"
|
2018-05-18 15:35:32 +01:00
|
|
|
|
|
|
|
if [ -n "$uglyFiles" ]; then
|
2018-06-03 16:08:45 +02:00
|
|
|
IFS=$'\n'
|
|
|
|
for file in $uglyFiles; do
|
|
|
|
if cmp -s <(staged "$file") "$file"; then
|
2018-05-21 16:22:29 +01:00
|
|
|
prettier --write "$file"
|
|
|
|
git add "$file"
|
|
|
|
else
|
|
|
|
echo "WARN: Staged and working file differ: '$file'"
|
2018-05-21 16:33:58 +01:00
|
|
|
echo "WARN: Moving working file temporarily (this might upset your editor)"
|
2018-05-21 16:22:29 +01:00
|
|
|
# Get crazy: backup the working copy of the file, paste the staged version in its place, prettify, add, restore backup
|
2018-06-03 16:08:45 +02:00
|
|
|
backup=$(mktemp -p . "$file.XXXXXXXXX")
|
2018-05-21 16:22:29 +01:00
|
|
|
mv "$file" "$backup"
|
2018-06-03 16:08:45 +02:00
|
|
|
staged "$file" | prettier --stdin-filepath "$file" > "$file"
|
2018-05-21 16:22:29 +01:00
|
|
|
git add "$file"
|
|
|
|
mv "$backup" "$file"
|
|
|
|
echo "WARN: Working file restored"
|
|
|
|
fi
|
|
|
|
done
|
2018-05-18 15:35:32 +01:00
|
|
|
fi
|