Created
September 10, 2018 09:09
-
-
Save javifm86/399456455cc15c334de95cf5149a6abd to your computer and use it in GitHub Desktop.
pre-commit prettier + js-beautify for HTML
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
jsfiles=$(git diff --cached --name-only --diff-filter=ACM "*.js" "*.jsx" "*.ts" "*.css" "*.scss" | tr '\n' ' ') | |
if [ "$jsfiles" != "" ]; then | |
# Prettify all staged .js files | |
echo "$jsfiles" | xargs ./node_modules/.bin/prettier --write | |
# Add back the modified/prettified files to staging | |
echo "$jsfiles" | xargs git add | |
fi | |
htmlfiles=$(git diff --cached --name-only --diff-filter=ACM "*.html") | |
if [ "$htmlfiles" != "" ]; then | |
# Prettify all staged .html files | |
echo "$htmlfiles" | xargs ./node_modules/.bin/html-beautify -r -P --config .jsbeautifyrc | |
# Add back the modified/prettified files to staging | |
echo "$htmlfiles" | xargs git add | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment