source: github/bin/jsshrink.sh

Last change on this file was 92ba29f, checked in by Thomas Bruederli <thomas@…>, 4 months ago

Include treelist.js in shrinking scripts

  • Property mode set to 100755
File size: 1.7 KB
Line 
1#!/bin/sh
2JS_DIR=`dirname "$0"`/../program/js
3JAR_DIR='/tmp'
4LANG_IN='ECMASCRIPT3'
5CLOSURE_COMPILER_URL='http://closure-compiler.googlecode.com/files/compiler-latest.zip'
6
7do_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
12if [ ! -d "$JS_DIR" ]; then
13        echo "Directory $JS_DIR not found."
14        exit 1
15fi
16
17if [ ! -w "$JAR_DIR" ]; then
18        JAR_DIR=`dirname "$0"`
19fi
20
21if java -version >/dev/null 2>&1; then
22        :
23else
24        echo "Java not found. Please ensure that the 'java' program is in your PATH."
25        exit 1
26fi
27
28if [ ! -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"
39fi
40
41# compress single file from argument
42if [ $# -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
56fi
57
58# default: compress application scripts
59for 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"
67done
Note: See TracBrowser for help on using the repository browser.