Skip to content

Instantly share code, notes, and snippets.

@JoaoVagner
Created February 25, 2013 21:32
Show Gist options
  • Save JoaoVagner/5033520 to your computer and use it in GitHub Desktop.
Save JoaoVagner/5033520 to your computer and use it in GitHub Desktop.
Compressor using YUI Compressor
#!/bin/bash
# The files to ignore are already minified.
css_files_to_ignore=(
"jquery.colorbox-min.css"
);
js_files_to_ignore=(
"jquery.colorbox-min.js"
);
base_folder="$(git rev-parse --show-toplevel)"
yuicompressor_path=../yui/yui-2.4.2.jar
function process_assets() {
extension=$1
files_minified=0
for infile in $(echo "$base_folder/$extension/*.$extension")
do
[[ -f $infile ]] || continue
filename=${infile##*/}
# If the filename starts with an underscore, that means that the file is a
# minified file that was previously generated.
[[ ${filename:0:1} != "_" ]] || continue
ignore_this_file=false
files_to_ignore=$extension"_files_to_ignore"
for i in $(eval echo \${$files_to_ignore[@]})
do
if [[ $i == $filename ]]; then
ignore_this_file=true
break
fi
done
if [ $ignore_this_file == false ]; then
minified_file="$base_folder/$extension/_$filename"
if [ ! -f "$minified_file" ] || test $infile -nt $minified_file; then
java -jar $yuicompressor_path "$infile" -o "$minified_file"
((files_minified++))
fi
fi
done
if [ $extension == "css" ]; then
file_type=CSS
else
file_type=JavaScript
fi
echo -n "$files_minified $file_type file"
if [ "$files_minified" == "1" ]; then
echo -n " was"
else
echo -n "s were"
fi
echo " minified"
}
if [ -f $yuicompressor_path ]; then
process_assets css
process_assets js
else
echo "YUI Compressor was not found. Aborting."
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment