-
Notifications
You must be signed in to change notification settings - Fork 187
/
build.sh
executable file
·82 lines (69 loc) · 3.21 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
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
#!/bin/bash
################################################################################
# #
# Usage: #
# #
# ./build.sh - building in development (simple merging) #
# ./build.sh production - building in production (with compressing) #
# #
################################################################################
################################################################################
### Paths
APP_PATH=`pwd`
CLOSURE_LIB="./lib/google-closure-library/closure"
COMPILER="./node_modules/google-closure-compiler/compiler.jar"
################################################################################
### Options
closure_options="-o script"
less_options=""
if [ $# -ne 2 ]
then
if [[ "$1" = "production" ]]
then
closure_options="-o compiled -c ${COMPILER} -f --strict_mode_input=false -f --process_closure_primitives=false"
less_options="--compress"
fi
fi
################################################################################
### Helpers
status () {
if [ $? -gt 0 ]; then
echo -ne "[\e[1;31mERROR\e[m]\n"
exit 1
else
echo -ne "[\e[1;32mOK\e[m]\n"
fi
}
################################################################################
### Building
echo "==== Compiling JavaScript ======================================================"
python2 ${CLOSURE_LIB}/bin/calcdeps.py -i ${APP_PATH}/lib/js/jquery-ui-1.8.23.custom.js -i ${APP_PATH}/lib/js/jquery.ui.colorPicker.js -i ${APP_PATH}/js/main.js -p ${CLOSURE_LIB} ${closure_options} > ${APP_PATH}/js/compiled.js
status
echo "==== Compiling LESS ============================================================"
lessc ${APP_PATH}/less/main.less ${APP_PATH}/css/_compiled_main.css ${less_options}
status
echo "==== Merging CSS ==============================================================="
echo "===> jquery-ui => merged.css"
cat ${APP_PATH}/css/jquery-ui-1.8.23.custom.css > ${APP_PATH}/css/merged.css
status
echo "===> jquery.ui.colorPicker => merged.css"
cat ${APP_PATH}/css/jquery.ui.colorPicker.css >> ${APP_PATH}/css/merged.css
status
echo "===> _compiled_main => merged.css"
cat ${APP_PATH}/css/_compiled_main.css >> ${APP_PATH}/css/merged.css
status
if [[ "$1" = "production" ]]; then
echo "==== Replcacing JS timestamp =================================================="
echo "===> Get compiled.js modification date"
MERGED_JS_MODIFICATION_TIME=`date -r js/compiled.js +"%s"`
status
echo "===> substitute compiled.js timestamp with $MERGED_JS_MODIFICATION_TIME"
sed -i "s/compiled.js?modified=[0-9]*/compiled.js?modified=$MERGED_JS_MODIFICATION_TIME/" index.html
status
echo "==== Replcacing JS timestamp =================================================="
MERGED_CSS_MODIFICATION_TIME=`date -r css/merged.css +"%s"`
status
echo "===> substitute merged.css timestamp with $MERGED_CSS_MODIFICATION_TIME"
sed -i "s/merged.css?modified=[0-9]*/merged.css?modified=$MERGED_CSS_MODIFICATION_TIME/" index.html
status
fi