-
Notifications
You must be signed in to change notification settings - Fork 91
/
build.sh
executable file
·54 lines (40 loc) · 1.45 KB
/
build.sh
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
#!/bin/bash
IFS='%'
out=intercom.js
out_min=intercom.min.js
out_amd=intercom.amd.js
out_amd_min=intercom.amd.min.js
banner="/*! intercom.js | https://github.com/diy/intercom.js | Apache License (v2) */"
append_file () {
src=`cat $2 | sed 's/^ *//g' | sed 's/ *$//g'`
echo -eE "$1\n\n// --- $2 ---\n\n$src"
}
# bundle files...
src=""
for file in lib/*.js; do
if [ "$file" != "lib/intercom.js" ]; then src=`append_file "$src" $file`; fi
done
src=`append_file "$src" lib/intercom.js`
for file in lib/bindings/*.js; do src=`append_file "$src" $file`; done
# format and wrap...
src=`echo -e "$src" | while read line; do echo -e "\t$line"; done`
wrp="$banner\n\nvar Intercom = (function() {$src\n\treturn Intercom;\n})();"
echo -e "$wrp" > $out
wrp="$banner\n\ndefine(function() {$src\n\treturn Intercom;\n});"
echo -e "$wrp" > $out_amd
# generate minified version...
curl -s -d compilation_level=SIMPLE_OPTIMIZATIONS \
-d output_format=text \
-d output_info=compiled_code \
--data-urlencode "js_code@$out" \
http://closure-compiler.appspot.com/compile \
> $out_min
echo "$banner" | cat - $out_min > temp && mv temp $out_min
curl -s -d compilation_level=SIMPLE_OPTIMIZATIONS \
-d output_format=text \
-d output_info=compiled_code \
--data-urlencode "js_code@$out_amd" \
http://closure-compiler.appspot.com/compile \
> $out_amd_min
echo "$banner" | cat - $out_amd_min > temp && mv temp $out_amd_min
unset IFS