scripts/shrinksafe.sh
author Lennard de Rijk <ljvderijk@gmail.com>
Wed, 09 Sep 2009 21:14:22 +0200
changeset 2895 cad75f6ba411
parent 2873 4fb030d43575
child 2937 2252dc0be5db
permissions -rwxr-xr-x
Added the GHOP modules to the callback. The ENABLE_MODULE has been added to ensure that the current build does not suffer from any weird artefacts that might occur due to the presence of this module. Of course in time it will be removed. Thanks Madhusudan for getting us this far ^_^. Minor CSS and image patches should follow shortly.

#!/bin/bash
#Requires java installed

echo "*** SHRINKSAFE: running shrinksafe ***"

SHRINKSAFE="../thirdparty/shrinksafe/shrinksafe.jar"

echo "*** SHRINKSAFE: minifying javascript files ***"
let SOURCE_FILE_SIZES=0
let DEST_FILE_SIZES=0

shrinksafe () {
  SOURCE_DIR=$1
  for dir in $(find $SOURCE_DIR -type d); do
    for i in $(find $dir/*.js -type f); do
      echo "SHRINKSAFE: Processing $i"
      CURRENT_SOURCE_FILE_SIZE=$(stat -c%s "$i")
      let SOURCE_FILE_SIZES=$SOURCE_FILE_SIZES+$CURRENT_SOURCE_FILE_SIZE
      mv $i $i.old.js
      java -jar $SHRINKSAFE $i.old.js > $i
      if [ "$?" == "1" ]; then
        echo "*** ATTENTION ***: $i minimization failed, copying plain file"
        cp $i.old.js $i
      fi
      rm $i.old.js
      CURRENT_DEST_FILE_SIZE=$(stat -c%s "$i")
      let DEST_FILE_SIZES=$DEST_FILE_SIZES+$CURRENT_DEST_FILE_SIZE
    done
  done
}

for DEST_DIR in "$@"; do
  shrinksafe $DEST_DIR
done

let COMPRESSION_RATE=$DEST_FILE_SIZES*100/$SOURCE_FILE_SIZES
echo "*** SHRINKSAFE: Source file sizes: $SOURCE_FILE_SIZES, Dest file sizes: $DEST_FILE_SIZES"
echo "*** SHRINKSAFE: Congratulations! You achieved $COMPRESSION_RATE% compression rate!"