Skip to content

Instantly share code, notes, and snippets.

@keesvanbochove
Forked from Cosmicist/gist:3860074
Created December 17, 2012 16:29
Show Gist options
  • Save keesvanbochove/4319624 to your computer and use it in GitHub Desktop.
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' …
#!/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