Thomas Bruederli
2016-04-17 cde7a9eb74b6fd6315885c30c0763e0ee5332499
commit | author | age
bc9c02 1 #!/bin/sh
c562a3 2 PWD=`dirname "$0"`
AM 3 JS_DIR="$PWD/../program/js"
54f1af 4 JAR_DIR='/tmp'
55ee25 5 LANG_IN='ECMASCRIPT3'
c562a3 6 # latest version requires Java 7, we'll use an older one
AM 7 #CLOSURE_COMPILER_URL='http://dl.google.com/closure-compiler/compiler-latest.zip'
d5c381 8 CLOSURE_COMPILER_URL='http://dl.google.com/closure-compiler/compiler-20131014.zip'
bc9c02 9
T 10 do_shrink() {
11     rm -f "$2"
55ee25 12     java -jar $JAR_DIR/compiler.jar --compilation_level=SIMPLE_OPTIMIZATIONS --js="$1" --js_output_file="$2" --language_in="$3"
bc9c02 13 }
T 14
15 if [ ! -d "$JS_DIR" ]; then
16     echo "Directory $JS_DIR not found."
17     exit 1
54f1af 18 fi
T 19
20 if [ ! -w "$JAR_DIR" ]; then
c562a3 21     JAR_DIR=$PWD
bc9c02 22 fi
T 23
24 if java -version >/dev/null 2>&1; then
25     :
26 else
27     echo "Java not found. Please ensure that the 'java' program is in your PATH."
28     exit 1
29 fi
30
54f1af 31 if [ ! -r "$JAR_DIR/compiler.jar" ]; then
bc9c02 32     if which wget >/dev/null 2>&1 && which unzip >/dev/null 2>&1; then
T 33         wget "$CLOSURE_COMPILER_URL" -O "/tmp/$$.zip"
34     elif which curl >/dev/null 2>&1 && which unzip >/dev/null 2>&1; then
35         curl "$CLOSURE_COMPILER_URL" -o "/tmp/$$.zip"
36     else
54f1af 37         echo "Please download $CLOSURE_COMPILER_URL and extract compiler.jar to $JAR_DIR/."
bc9c02 38         exit 1
T 39     fi
54f1af 40     (cd $JAR_DIR && unzip "/tmp/$$.zip" "compiler.jar")
bc9c02 41     rm -f "/tmp/$$.zip"
T 42 fi
43
55ee25 44 # compress single file from argument
TB 45 if [ $# -gt 0 ]; then
46     JS_DIR=`dirname "$1"`
47     JS_FILE="$1"
48
49     if [ $# -gt 1 ]; then
50         LANG_IN="$2"
51     fi
52
53     echo "Shrinking $JS_FILE"
c562a3 54     minfile=`echo $JS_FILE | sed -e 's/\.js$/\.min\.js/'`
AM 55     do_shrink "$JS_FILE" "$minfile" "$LANG_IN"
55ee25 56     exit
TB 57 fi
58
c562a3 59 DIRS="$PWD/../program/js $PWD/../skins/* $PWD/../plugins/* $PWD/../plugins/*/skins/*"
55ee25 60 # default: compress application scripts
c562a3 61 for dir in $DIRS; do
AM 62     for file in $dir/*.js; do
63         echo "$file" | grep -e '.min.js$' >/dev/null
64         if [ $? -eq 0 ]; then
65             continue
66         fi
67         if [ ! -f "$file" ]; then
68             continue
69         fi
70
71         echo "Shrinking $file"
72         minfile=`echo $file | sed -e 's/\.js$/\.min\.js/'`
73         do_shrink "$file" "$minfile" "$LANG_IN"
74     done
bc9c02 75 done