Scripts to run Shrinksafe during build.
authorMario Ferraro <fadinlight@gmail.com>
Mon, 07 Sep 2009 15:20:49 +0200
changeset 2873 4fb030d43575
parent 2872 7d5c8039fbe2
child 2874 fda118f51264
Scripts to run Shrinksafe during build. The function that runs shrinksafe over JS files has been put to a separate shell file to be run standalone without building if needed.
scripts/build.sh
scripts/shrinksafe.sh
--- a/scripts/build.sh	Mon Sep 07 15:07:37 2009 +0200
+++ b/scripts/build.sh	Mon Sep 07 15:20:49 2009 +0200
@@ -89,7 +89,14 @@
 # Create symbolic links.
 for x in $APP_FILES $APP_DIRS $ZIP_FILES
 do
-    ln -s $APP_FOLDER/$x $APP_BUILD/$x
+    if [[ $x != "soc" && $x != "jquery" && $x != "json" ]] ; then
+      ln -s $APP_FOLDER/$x $APP_BUILD/$x
+    else
+      cp -R $APP_FOLDER/$x $APP_BUILD/$x
+    fi
 done
 
+# Run shrinksafe
+bash ../scripts/shrinksafe.sh $APP_BUILD/soc/content/js $APP_BUILD/jquery $APP_BUILD/json
+
 echo "Build results in $APP_BUILD."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/shrinksafe.sh	Mon Sep 07 15:20:49 2009 +0200
@@ -0,0 +1,38 @@
+#!/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!"