scripts/shrinksafe.sh
author Sverre Rabbelier <srabbelier@gmail.com>
Sat, 12 Sep 2009 00:59:58 +0200
changeset 2899 691735924efb
parent 2873 4fb030d43575
child 2937 2252dc0be5db
permissions -rwxr-xr-x
Fix broken maintenance mode Maintenance mode has been broken since r7fe19ebfe0d3 (Thu Jun 4) "Display caught errors on the page itself", fix it by passing the site entity, rather than the site module to isActivePeriod.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2873
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
     1
#!/bin/bash
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
     2
#Requires java installed
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
     3
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
     4
echo "*** SHRINKSAFE: running shrinksafe ***"
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
     5
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
     6
SHRINKSAFE="../thirdparty/shrinksafe/shrinksafe.jar"
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
     7
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
     8
echo "*** SHRINKSAFE: minifying javascript files ***"
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
     9
let SOURCE_FILE_SIZES=0
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    10
let DEST_FILE_SIZES=0
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    11
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    12
shrinksafe () {
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    13
  SOURCE_DIR=$1
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    14
  for dir in $(find $SOURCE_DIR -type d); do
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    15
    for i in $(find $dir/*.js -type f); do
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    16
      echo "SHRINKSAFE: Processing $i"
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    17
      CURRENT_SOURCE_FILE_SIZE=$(stat -c%s "$i")
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    18
      let SOURCE_FILE_SIZES=$SOURCE_FILE_SIZES+$CURRENT_SOURCE_FILE_SIZE
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    19
      mv $i $i.old.js
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    20
      java -jar $SHRINKSAFE $i.old.js > $i
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    21
      if [ "$?" == "1" ]; then
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    22
        echo "*** ATTENTION ***: $i minimization failed, copying plain file"
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    23
        cp $i.old.js $i
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    24
      fi
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    25
      rm $i.old.js
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    26
      CURRENT_DEST_FILE_SIZE=$(stat -c%s "$i")
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    27
      let DEST_FILE_SIZES=$DEST_FILE_SIZES+$CURRENT_DEST_FILE_SIZE
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    28
    done
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    29
  done
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    30
}
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    31
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    32
for DEST_DIR in "$@"; do
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    33
  shrinksafe $DEST_DIR
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    34
done
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    35
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    36
let COMPRESSION_RATE=$DEST_FILE_SIZES*100/$SOURCE_FILE_SIZES
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    37
echo "*** SHRINKSAFE: Source file sizes: $SOURCE_FILE_SIZES, Dest file sizes: $DEST_FILE_SIZES"
4fb030d43575 Scripts to run Shrinksafe during build.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    38
echo "*** SHRINKSAFE: Congratulations! You achieved $COMPRESSION_RATE% compression rate!"