Mercurial > hg > rc2
comparison bin/jsshrink.sh @ 0:4681f974d28b
vanilla 1.3.3 distro, I hope
author | Charlie Root |
---|---|
date | Thu, 04 Jan 2018 15:52:31 -0500 |
parents | |
children | bf99236cc5cd |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4681f974d28b |
---|---|
1 #!/bin/sh | |
2 PWD=`dirname "$0"` | |
3 JS_DIR="$PWD/../program/js" | |
4 JAR_DIR='/tmp' | |
5 LANG_IN='ECMASCRIPT3' | |
6 # latest version requires Java 7, we'll use an older one | |
7 #CLOSURE_COMPILER_URL='http://dl.google.com/closure-compiler/compiler-latest.zip' | |
8 CLOSURE_COMPILER_URL='http://dl.google.com/closure-compiler/compiler-20131014.zip' | |
9 | |
10 do_shrink() { | |
11 rm -f "$2" | |
12 # copy the first comment block with license information for LibreJS | |
13 grep -q '@lic' $1 && sed -n '/\/\*/,/\*\// { p; /\*\//q; }' $1 > $2 | |
14 java -jar $JAR_DIR/compiler.jar --compilation_level=SIMPLE_OPTIMIZATIONS --js="$1" --language_in="$3" >> $2 | |
15 } | |
16 | |
17 if [ ! -d "$JS_DIR" ]; then | |
18 echo "Directory $JS_DIR not found." | |
19 exit 1 | |
20 fi | |
21 | |
22 if [ ! -w "$JAR_DIR" ]; then | |
23 JAR_DIR=$PWD | |
24 fi | |
25 | |
26 if java -version >/dev/null 2>&1; then | |
27 : | |
28 else | |
29 echo "Java not found. Please ensure that the 'java' program is in your PATH." | |
30 exit 1 | |
31 fi | |
32 | |
33 if [ ! -r "$JAR_DIR/compiler.jar" ]; then | |
34 if which wget >/dev/null 2>&1 && which unzip >/dev/null 2>&1; then | |
35 wget "$CLOSURE_COMPILER_URL" -O "/tmp/$$.zip" | |
36 elif which curl >/dev/null 2>&1 && which unzip >/dev/null 2>&1; then | |
37 curl "$CLOSURE_COMPILER_URL" -o "/tmp/$$.zip" | |
38 else | |
39 echo "Please download $CLOSURE_COMPILER_URL and extract compiler.jar to $JAR_DIR/." | |
40 exit 1 | |
41 fi | |
42 (cd $JAR_DIR && unzip "/tmp/$$.zip" "compiler.jar") | |
43 rm -f "/tmp/$$.zip" | |
44 fi | |
45 | |
46 # compress single file from argument | |
47 if [ $# -gt 0 ]; then | |
48 JS_DIR=`dirname "$1"` | |
49 JS_FILE="$1" | |
50 | |
51 if [ $# -gt 1 ]; then | |
52 LANG_IN="$2" | |
53 fi | |
54 | |
55 echo "Shrinking $JS_FILE" | |
56 minfile=`echo $JS_FILE | sed -e 's/\.js$/\.min\.js/'` | |
57 do_shrink "$JS_FILE" "$minfile" "$LANG_IN" | |
58 exit | |
59 fi | |
60 | |
61 DIRS="$PWD/../program/js $PWD/../skins/* $PWD/../plugins/* $PWD/../plugins/*/skins/*" | |
62 # default: compress application scripts | |
63 for dir in $DIRS; do | |
64 for file in $dir/*.js; do | |
65 echo "$file" | grep -e '.min.js$' >/dev/null | |
66 if [ $? -eq 0 ]; then | |
67 continue | |
68 fi | |
69 if [ ! -f "$file" ]; then | |
70 continue | |
71 fi | |
72 | |
73 echo "Shrinking $file" | |
74 minfile=`echo $file | sed -e 's/\.js$/\.min\.js/'` | |
75 do_shrink "$file" "$minfile" "$LANG_IN" | |
76 done | |
77 done |