22
33NOCOLOR=' \033[0m'
44GREEN=' \033[0;32m'
5- ORANGE=' \033[0;33m'
5+ ORANGE=' \033[38;5;208m' # 256-colour palette orange, ANSI 33 is yellow
6+ GRAY=' \e[2;37m'
7+ BLACK=" \033[0;30m" # Black
8+ RED=" \033[0;31m" # Red
9+ YELLOW=" \033[0;33m" # Yellow
10+ BLUE=" \033[0;34m" # Blue
11+ PURPLE=" \033[0;35m" # Purple
12+ CYAN=" \033[0;36m" # Cyan
13+ WHITE=" \033[0;37m" # White
614BOLD=$( tput bold)
715NORMAL=$( tput sgr0)
816
@@ -19,12 +27,15 @@ SUPPORTED_COMMANDS=(
1927# This disables twig caching and activate debugging tools
2028export DEV_MODE=true
2129
22- function ctrl_c() {
23- if [ $# -gt 0 ];
30+ # Stop browser-sync when the script exits (Ctrl-C on the PHP server included)
31+ BROWSER_SYNC_PID=' '
32+ function cleanup() {
33+ if [ -n " ${BROWSER_SYNC_PID} " ];
2434 then
25- pkill browser-sync
35+ kill " ${BROWSER_SYNC_PID} " 2> /dev/null
2636 fi
2737}
38+ trap cleanup EXIT
2839
2940if [ $# -gt 0 ]
3041then
5364 echo -e " ${BOLD} run status${NORMAL} Check if the current commit is on production"
5465 echo " "
5566 echo " Additional parameters will be ignored."
56- exit 1
67+ exit 0
5768fi
5869
5970if [ $# -gt 0 ] && [ $1 = ' tests' ]
6071then
6172 composer test:all
62- exit 1
73+ exit $?
6374fi
6475
6576if [ $# -gt 0 ] && [ $1 = ' status' ]
6677then
6778 local=` git rev-parse master`
79+ dev=` curl -s https://dev.whattrainisitnow.nonprod.webservices.mozgcp.net/deployed-version.txt`
6880 prod=` curl -s https://whattrainisitnow.com/deployed-version.txt`
6981 echo -e " $GREEN " " Checking if the latest commit is what we have in production" " $NORMAL "
70- echo " Local : $local "
71- echo -n " Prod : $prod "
82+ echo -e " $GRAY " " Dev $dev " " $NORMAL "
83+ echo " Local $local "
84+ echo -n " Prod $prod "
7285 if [ $local == $prod ]
7386 then
7487 echo " "
7588 echo -en " $GREEN " " Yes, we are good" " $NORMAL "
76- elif [[ condition ]] ; then
89+ else
7790 x=$(( $(git rev- list -- count $prod ..$local )) )
7891 echo " "
7992 if [ $x == 1 ]
8396 echo -en " $ORANGE " " No, production is $x commits behind" " $NORMAL "
8497 fi
8598 fi
86- exit 1
99+ exit 0
87100fi
88101
89102echo -e " ${GREEN}${BOLD} Launching PHP development server on http://${SERVER}${NORMAL}${NOCOLOR} "
@@ -93,12 +106,10 @@ if command -v browser-sync &> /dev/null; then
93106 then
94107 echo -e " ${GREEN} browser-sync is installed on the system, launching it in the background${NOCOLOR} "
95108 browser-sync start --proxy " localhost:8082" --files " **/*" &
109+ BROWSER_SYNC_PID=$!
96110 else
97111 echo -e " ${ORANGE} browser-sync is installed on the system but won't be launched${NOCOLOR} "
98112 fi
99113fi
100114
101115php -d opcache.jit=disable -S ${SERVER} -t public/ app/inc/router.php
102-
103- # trap ctrl-c and call ctrl_c()
104- trap ctrl_c INT
0 commit comments