-
-
Save Cosmicist/3860074 to your computer and use it in GitHub Desktop.
pre-commit hook to automatically minify javascript/css
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=`find ~/. -type f -name yuicompressor\*.jar` | |
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..." | |
java -jar $YUIC $1 > $dest_fname | |
git add $dest_fname | |
echo "Done." | |
echo "" | |
} | |
for file in $(find -E . -iregex '.*\.(js|css)$' -and -not -iregex '.*\.min\.(js|css)$'); | |
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