comparison bin/jsshrink.sh @ 0:1e000243b222

vanilla 1.3.3 distro, I hope
author Charlie Root
date Thu, 04 Jan 2018 15:50:29 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:1e000243b222
1 #!/bin/sh
2 PWD=`dirname "$0"`
3 JS_DIR="$PWD/../program/js"
4 JAR_DIR='/tmp'
5 LANG_IN='ECMASCRIPT5'
6 CLOSURE_COMPILER_URL='http://dl.google.com/closure-compiler/compiler-latest.zip'
7
8 do_shrink() {
9 rm -f "$2"
10 # copy the first comment block with license information for LibreJS
11 grep -q '@lic' $1 && sed -n '/\/\*/,/\*\// { p; /\*\//q; }' $1 > $2
12 java -jar $JAR_DIR/compiler.jar --compilation_level=SIMPLE_OPTIMIZATIONS --js="$1" --language_in="$3" >> $2
13 }
14
15 if [ ! -d "$JS_DIR" ]; then
16 echo "Directory $JS_DIR not found."
17 exit 1
18 fi
19
20 if [ ! -w "$JAR_DIR" ]; then
21 JAR_DIR=$PWD
22 fi
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
31 if [ ! -r "$JAR_DIR/compiler.jar" ]; then
32 if which wget >/dev/null 2>&1 && which unzip >/dev/null 2>&1; then
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
37 echo "Please download $CLOSURE_COMPILER_URL and extract compiler.jar to $JAR_DIR/."
38 exit 1
39 fi
40 (cd $JAR_DIR && unzip -p "/tmp/$$.zip" "*.jar" > "$JAR_DIR/compiler.jar")
41 rm -f "/tmp/$$.zip"
42 fi
43
44 # compress single file from argument
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"
54 minfile=`echo $JS_FILE | sed -e 's/\.js$/\.min\.js/'`
55 do_shrink "$JS_FILE" "$minfile" "$LANG_IN"
56 exit
57 fi
58
59 DIRS="$PWD/../program/js $PWD/../skins/* $PWD/../plugins/* $PWD/../plugins/*/skins/* $PWD/../plugins/managesieve/codemirror/lib"
60 # default: compress application scripts
61 for dir in $DIRS; do
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
75 done