Add CI format check script

This commit is contained in:
nitrohorse
2019-08-03 18:18:03 -07:00
parent 81a0fd91c2
commit 4c44a3c510
6 changed files with 842 additions and 9 deletions

13
bin/get-html-ls.js Normal file
View File

@ -0,0 +1,13 @@
const glob = require('glob');
const pattern = '**/*.html';
const options = {
'ignore': [
'_site/**/*.html',
'node_modules/**/*.html'
]
};
glob(pattern, options, (error, files) => {
if (error) throw error;
process.stdout.write(files.join('\n') + '\n');
});

22
bin/html-beautify-check.sh Executable file
View File

@ -0,0 +1,22 @@
# 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=$(realpath $(dirname $(dirname $0)))
TMPDIR=$(mktemp -d)
cd $APPDIR
for line in $*; do
filepath=$(realpath $line)
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