Skip to content

Instantly share code, notes, and snippets.

@javifm86
Created September 10, 2018 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javifm86/399456455cc15c334de95cf5149a6abd to your computer and use it in GitHub Desktop.
Save javifm86/399456455cc15c334de95cf5149a6abd to your computer and use it in GitHub Desktop.
pre-commit prettier + js-beautify for HTML
#!/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