-
-
Save keesvanbochove/4319624 to your computer and use it in GitHub Desktop.
Use this script as git pre-commit hook to automatically minify JS and CSS files in a Grails project (specifically GSCF in this case, https://github.com/thehyve/GSCF).
Installation instructions: put this text in .git/hooks/pre-commit, and make it executable (shmod +x pre-commit). Also, install yuicompressor, e.g. via 'brew install yuicompressor' …
This file contains 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/bash | |
# Search YUI Compressor anywhere in your home dir | |
echo "Searching for YUI Compressor..." | |
YUIC=`which yuicompressor` | |
if ! [ $YUIC ] | |
then | |
echo "Unable to find YUI Compressor! Goodbye!" | |
exit | |
fi | |
echo -e "YUI Compressor found! Start compressing...\n" | |
function _c | |
{ | |
fname=$(basename "$1") | |
dest=$(dirname "$1") | |
ext="${fname##*.}" | |
dest_fname="$dest/${fname%.*}.min.$ext" | |
echo "Compressing $1..." | |
$YUIC $1 > $dest_fname | |
git add $dest_fname | |
echo "Done." | |
echo "" | |
} | |
for file in $(ls web-app/js/*.js web-app/css/*.css|grep -vi min.); | |
do | |
_c $file | |
done | |
echo "That is all." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment