-
Notifications
You must be signed in to change notification settings - Fork 125
/
jsnormalize
executable file
·105 lines (81 loc) · 2.18 KB
/
jsnormalize
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env bash
CC_DIR="$OPAGENERAL/tools/jschecker"
CC="$CC_DIR/compiler.jar"
CC_OPT='--formatting PRETTY_PRINT'
COMPILATION_LEVEL='WHITESPACE_ONLY'
SIMPLE_OPTIMIZATIONS='SIMPLE_OPTIMIZATIONS'
ADVANCED_OPTIMIZATIONS='ADVANCED_OPTIMIZATIONS'
FILES=''
EXTERNALS="$CC_DIR/externals.js"
WITH_EXTERNALS=false
TARGET='/dev/stdout'
help() {
cat <<EOF
$0: normalize and beautify js files.
This script is meant to be runned from anywhere on js files.
It is just a wrapper to the google closure compiler:
google closure compiler
http://code.google.com/closure/compiler/
Use:
$0 [options] js-files*
Options:
--help|-help|help print this help message
-e include standard externals distributed with the checker
-c turn on simple optimizations
-cc turn on advanced optimizations
-o * produce resulting js in a file rather than stdout
-- * give all remaining options to the google closure compiler
EOF
}
while [ "$#" -gt 0 ]; do
case "$1" in
# h
--help|-help|help)
help
exit 0
;;
-e)
WITH_EXTERNALS=true
;;
-c)
COMPILATION_LEVEL=$SIMPLE_OPTIMIZATIONS
;;
-cc)
COMPILATION_LEVEL=$ADVANCED_OPTIMIZATIONS
;;
-o)
if [ -z "$2" ]; then echo "Error: option $1 requires an argument"; exit 1; fi
shift
TARGET="$1"
;;
--)
shift
CC_OPT="$CC_OPT $@"
break
;;
*)
FILES="$FILES $1"
;;
esac
shift
done
CC_OPT="$CC_OPT --compilation_level $COMPILATION_LEVEL --js_output_file $TARGET"
if [ "$WITH_EXTERNALS" = true ] ; then
CC_OPT="$CC_OPT --externs $EXTERNALS"
fi
if [ ! -f "$CC" ] ; then
cat <<EOF
Cannot find the closure compiler.
OPAGENERAL is set to : '$OPAGENERAL'
searched at:
OPAGENERAL/tools/jschecker/compiler.jar
EOF
exit 1
fi
JS_FILES=''
for file in $FILES ; do
JS_FILES="$JS_FILES --js $file"
done
command="java -jar $CC $CC_OPT $JS_FILES"
echo "$command"
$command