]> git.donarmstrong.com Git - roundcube.git/blob - bin/jsshrink.sh
be5aad16d1d96bab1421b230c5654e7914012561
[roundcube.git] / bin / jsshrink.sh
1 #!/bin/sh
2 JS_DIR=`dirname "$0"`/../program/js
3 CLOSURE_COMPILER_URL='http://closure-compiler.googlecode.com/files/compiler-latest.zip'
4
5 do_shrink() {
6         rm -f "$2"
7         java -jar compiler.jar --compilation_level=SIMPLE_OPTIMIZATIONS --js="$1" --js_output_file="$2"
8 }
9
10 if [ ! -d "$JS_DIR" ]; then
11         echo "Directory $JS_DIR not found."
12         exit 1
13 fi
14
15 if java -version >/dev/null 2>&1; then
16         :
17 else
18         echo "Java not found. Please ensure that the 'java' program is in your PATH."
19         exit 1
20 fi
21
22 if [ ! -r "compiler.jar" ]; then
23         if which wget >/dev/null 2>&1 && which unzip >/dev/null 2>&1; then
24                 wget "$CLOSURE_COMPILER_URL" -O "/tmp/$$.zip"
25         elif which curl >/dev/null 2>&1 && which unzip >/dev/null 2>&1; then
26                 curl "$CLOSURE_COMPILER_URL" -o "/tmp/$$.zip"
27         else
28                 echo "Please download $CLOSURE_COMPILER_URL and extract compiler.jar to this directory."
29                 exit 1
30         fi
31         unzip "/tmp/$$.zip" "compiler.jar"
32         rm -f "/tmp/$$.zip"
33 fi
34
35 for fn in app common googiespell list; do
36         if [ -r "$JS_DIR/${fn}.js.src" ]; then
37                 echo "$JS_DIR/${fn}.js.src already exists, not overwriting"
38         else
39                 mv "$JS_DIR/${fn}.js" "$JS_DIR/${fn}.js.src"
40         fi
41         echo "Shrinking $JS_DIR/${fn}.js"
42         do_shrink "$JS_DIR/${fn}.js.src" "$JS_DIR/${fn}.js"
43 done