forked from arronwoods/jzform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·57 lines (48 loc) · 1.71 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
#!/bin/bash
if [ -x "$(command -v nodejs)" ]; then
NODECOMMAND=nodejs
elif [ -x "$(command -v node)" ]; then
NODECOMMAND=node
else
echo >&2 "Cannot find nodejs or node. Aborting."; exit 1;
fi
fg_red="$(tput setaf 1)"
fg_green="$(tput setaf 2)"
fg_blue="$(tput setaf 4)"
reset="$(tput sgr0)"
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
case "$1" in
"build")
if [ -z "$2" ] || [ "$2" == "production" ]; then
${NODECOMMAND} ${DIR}/r.js -o ${DIR}/build.js out=${DIR}/js/jzform.min.js
if [ $? != "0" ]; then
exit $?;
fi
fi
if [ -z "$2" ] || [ "$2" == "development" ]; then
${NODECOMMAND} ${DIR}/r.js -o ${DIR}/build.js optimize=none out=${DIR}/js/jzform.js
if [ $? != "0" ]; then
exit $?;
fi
fi ;;
"watch")
command -v inotifywait >/dev/null 2>&1 || { echo >&2 "Cannot find inotifywait. (ubuntu package inotify-tools) Aborting."; exit 1; }
echo -e "${fg_green}Beginning watch $(date)${reset}"
while true; do
inotifywait -q -r -e modify ${DIR}/js > /dev/null &&
echo -e "${fg_blue}Compiling $(date)${reset}"
if [ -z "$2" ] || [ "$2" == "production" ]; then
${NODECOMMAND} ${DIR}/r.js -o ${DIR}/build.js out=${DIR}/js/jzform.min.js > /dev/null
fi
if [ -z "$2" ] || [ "$2" == "development" ]; then
${NODECOMMAND} ${DIR}/r.js -o ${DIR}/build.js optimize=none out=${DIR}/js/jzform.js > /dev/null
fi
if [ $? == '0' ]; then
echo -e "${fg_green}Success $(date)${reset}"
else
echo -e "${fg_red}Erorr compiling $(date)${reset}"
fi
done ;;
*)
echo -e "command missing, enter build or watch" ;;
esac