Created
October 30, 2012 22:54
-
-
Save mattbierner/3983634 to your computer and use it in GitHub Desktop.
Closure Compiler Git pre-commit Hook
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/sh | |
# Minify js files | |
COMPILER="java -jar compiler.jar" | |
OPTIONS="--compilation_level=ADVANCED_OPTIMIZATIONS" | |
SRC=lib | |
DEST=dist | |
function _minify { | |
local file=$1 | |
local path=${file##*/} | |
local out="$DEST/${path%.js}.min.js" | |
echo "Compiling '$file' to '$out'" | |
$COMPILER $OPTIONS --js=$file --js_output_file=$out | |
echo "gzip size: $(gzip -c $out | wc -c) bytes" | |
git add $out | |
} | |
for file in $(git diff --cached --name-only --diff-filter=ACM) | |
do | |
if [[ $file =~ $SRC/.+\.js ]]; | |
then | |
_minify $file | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment