| 1 | #!/bin/sh |
|---|
| 2 | JS_DIR=`dirname "$0"`/../program/js |
|---|
| 3 | JAR_DIR='/tmp' |
|---|
| 4 | LANG_IN='ECMASCRIPT3' |
|---|
| 5 | CLOSURE_COMPILER_URL='http://closure-compiler.googlecode.com/files/compiler-latest.zip' |
|---|
| 6 | |
|---|
| 7 | do_shrink() { |
|---|
| 8 | rm -f "$2" |
|---|
| 9 | java -jar $JAR_DIR/compiler.jar --compilation_level=SIMPLE_OPTIMIZATIONS --js="$1" --js_output_file="$2" --language_in="$3" |
|---|
| 10 | } |
|---|
| 11 | |
|---|
| 12 | if [ ! -d "$JS_DIR" ]; then |
|---|
| 13 | echo "Directory $JS_DIR not found." |
|---|
| 14 | exit 1 |
|---|
| 15 | fi |
|---|
| 16 | |
|---|
| 17 | if [ ! -w "$JAR_DIR" ]; then |
|---|
| 18 | JAR_DIR=`dirname "$0"` |
|---|
| 19 | fi |
|---|
| 20 | |
|---|
| 21 | if java -version >/dev/null 2>&1; then |
|---|
| 22 | : |
|---|
| 23 | else |
|---|
| 24 | echo "Java not found. Please ensure that the 'java' program is in your PATH." |
|---|
| 25 | exit 1 |
|---|
| 26 | fi |
|---|
| 27 | |
|---|
| 28 | if [ ! -r "$JAR_DIR/compiler.jar" ]; then |
|---|
| 29 | if which wget >/dev/null 2>&1 && which unzip >/dev/null 2>&1; then |
|---|
| 30 | wget "$CLOSURE_COMPILER_URL" -O "/tmp/$$.zip" |
|---|
| 31 | elif which curl >/dev/null 2>&1 && which unzip >/dev/null 2>&1; then |
|---|
| 32 | curl "$CLOSURE_COMPILER_URL" -o "/tmp/$$.zip" |
|---|
| 33 | else |
|---|
| 34 | echo "Please download $CLOSURE_COMPILER_URL and extract compiler.jar to $JAR_DIR/." |
|---|
| 35 | exit 1 |
|---|
| 36 | fi |
|---|
| 37 | (cd $JAR_DIR && unzip "/tmp/$$.zip" "compiler.jar") |
|---|
| 38 | rm -f "/tmp/$$.zip" |
|---|
| 39 | fi |
|---|
| 40 | |
|---|
| 41 | # compress single file from argument |
|---|
| 42 | if [ $# -gt 0 ]; then |
|---|
| 43 | JS_DIR=`dirname "$1"` |
|---|
| 44 | JS_FILE="$1" |
|---|
| 45 | |
|---|
| 46 | if [ $# -gt 1 ]; then |
|---|
| 47 | LANG_IN="$2" |
|---|
| 48 | fi |
|---|
| 49 | |
|---|
| 50 | if [ ! -r "${JS_FILE}.src" ]; then |
|---|
| 51 | mv "$JS_FILE" "${JS_FILE}.src" |
|---|
| 52 | fi |
|---|
| 53 | echo "Shrinking $JS_FILE" |
|---|
| 54 | do_shrink "${JS_FILE}.src" "$JS_FILE" "$LANG_IN" |
|---|
| 55 | exit |
|---|
| 56 | fi |
|---|
| 57 | |
|---|
| 58 | # default: compress application scripts |
|---|
| 59 | for fn in app common googiespell list treelist; do |
|---|
| 60 | if [ -r "$JS_DIR/${fn}.js.src" ]; then |
|---|
| 61 | echo "$JS_DIR/${fn}.js.src already exists, not overwriting" |
|---|
| 62 | else |
|---|
| 63 | mv "$JS_DIR/${fn}.js" "$JS_DIR/${fn}.js.src" |
|---|
| 64 | fi |
|---|
| 65 | echo "Shrinking $JS_DIR/${fn}.js" |
|---|
| 66 | do_shrink "$JS_DIR/${fn}.js.src" "$JS_DIR/${fn}.js" "$LANG_IN" |
|---|
| 67 | done |
|---|