This repository has been archived on 2024-01-13. You can view files and clone it, but cannot push or open issues or pull requests.
privacytools.io/bin/html-beautify-check.sh

24 lines
746 B
Bash
Raw Normal View History

#!/bin/bash
2019-08-03 18:18:03 -07:00
# A custom script, that formats the file(s) with html-beautify,
# but instead of changing it, it only errors with 0/1 if it needs to be changed
# Ref: https://web.archive.org/web/20190522172323/https://medium.com/@jtomaszewski/keep-your-code-clean-forever-65c71f7f2df
APPDIR=$(readlink -f $(dirname $(dirname $0)))
2019-08-03 18:18:03 -07:00
TMPDIR=$(mktemp -d)
cd $APPDIR
for line in $*; do
filepath=$(readlink -f $line)
2019-08-03 18:18:03 -07:00
file=${filepath/$APPDIR\//}
mkdir -p $TMPDIR/$(dirname $file)
cp $APPDIR/$file $TMPDIR/$file
done
message=$(find $TMPDIR -type f | xargs node_modules/.bin/html-beautify -r | grep -v unchanged || true)
if [[ $message ]]; then
echo "$message" | sed "s#$TMPDIR##g" | sed "s#\.\.\/##g"
rm -rf $TMPDIR
exit 1
fi
rm -rf $TMPDIR