-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
build
executable file
·106 lines (90 loc) · 2.6 KB
/
build
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
106
#!/bin/bash
#
# See: https://google.github.io/styleguide/shell.xml
# See: https://github.com/google/closure-stylesheets
# See: https://developers.google.com/closure/compiler/
set -e
readonly CWD=$(cd $(dirname $0); pwd)
readonly LIB="${CWD}/lib"
readonly TMP="${CWD}/tmp"
readonly SRC="${CWD}/src"
readonly WGET="$(which wget)"
readonly CURL="$(which curl)"
readonly UNZIP="$(which unzip)"
readonly JAVA="$(which java)"
# Hot fix for clean installation of OS X El Capitan.
readonly JAVA_OSX="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java"
# https://github.com/google/closure-compiler/wiki/Binary-Downloads
# readonly JS_COMPILER_ZIP="compiler-latest.zip"
readonly JS_COMPILER_ZIP="compiler-20200719.zip"
readonly JS_COMPILER_URL="https://dl.google.com/closure-compiler/${JS_COMPILER_ZIP}"
readonly JS_COMPILER_JAR="${LIB}/compiler.jar"
readonly NODE_MODULES="${CWD}/node_modules"
#
# Downloads closure compiler.
#
function download() {
if [[ ! -f "${JS_COMPILER_JAR}" ]]; then
cd "${TMP}"
echo -n "Downloading closure compiler: "
if [[ -n "$CURL" ]]; then
$CURL --silent -L "${JS_COMPILER_URL}" > "${TMP}/${JS_COMPILER_ZIP}"
else
$WGET --quiet "${JS_COMPILER_URL}" -O "${TMP}/${JS_COMPILER_ZIP}"
fi
echo "Done"
echo -n "Extracting closure compiler: "
$UNZIP -q "${TMP}/${JS_COMPILER_ZIP}" -d "${LIB}"
if [[ ! -f "${JS_COMPILER_JAR}" ]]; then
mv "${LIB}"/*compiler*.jar "${JS_COMPILER_JAR}"
fi
echo "Done"
cd "${CWD}"
fi
}
#
# Runs closure compiler.
#
function run_compiler() {
echo -n "Running closure compiler: "
local JAVA_BIN="${JAVA}"
if [[ -f "${JAVA_OSX}" ]]; then
JAVA_BIN="${JAVA_OSX}"
fi
if [[ -d "${SRC}" ]]; then
"${JAVA_BIN}" -jar "${JS_COMPILER_JAR}" \
--js_output_file "/dev/null" \
--entry_point "${CWD}/index.js" \
--js "${NODE_MODULES}/**/package.json" \
--js "${NODE_MODULES}/**/**.js" \
--js "${CWD}/index.js" \
--js "${CWD}/package.json" \
--js "${SRC}/**/*.js" \
--jscomp_warning lintChecks \
--warning_level VERBOSE \
--compilation_level ADVANCED \
--use_types_for_optimization \
--dependency_mode PRUNE \
--language_out STABLE \
--charset UTF-8 \
--process_common_js_modules \
--module_resolution NODE \
--isolation_mode IIFE \
--rewrite_polyfills false
else
echo -n "[WARN] Directory '${SRC}' doesn't exist. "
fi
echo "Done"
}
#
# The main function.
#
function main() {
mkdir -p "${LIB}"
mkdir -p "${TMP}"
download
run_compiler
rm -rf "${TMP}"
rm -rf "${LIB}"
}
main "$@"