forked from mozilla/releases_insights
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun
executable file
·95 lines (83 loc) · 2.49 KB
/
run
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
#! /usr/bin/env bash
NOCOLOR='\033[0m'
GREEN='\033[0;32m'
ORANGE='\033[0;33m'
BOLD=$(tput bold)
NORMAL=$(tput sgr0)
SERVER="localhost:8082"
SUPPORTED_COMMANDS=(
'help'
'tests'
'browser-sync'
'status'
)
function ctrl_c() {
if [ $# -gt 0 ];
then
pkill browser-sync
fi
}
if [ $# -gt 0 ]
then
supported_command=false
for command in ${SUPPORTED_COMMANDS[@]};
do
if [ "${command}" == "$1" ];
then
supported_command=true
break
fi
done
if [ "${supported_command}" = false ];
then
echo -e "Unknown parameter ${ORANGE}${BOLD}${1}${NORMAL}${NOCOLOR}. Type ${GREEN}${BOLD}run -help${NORMAL} to know what the valid parameters are."
exit 1
fi
fi
if [ $# -gt 0 ] && [ $1 = 'help' ]
then
echo -e "${ORANGE}${BOLD}Usage:${NORMAL}${NOCOLOR}"
echo -e " ${BOLD}run${NORMAL} Starts the PHP web server and listen to localhost:8082"
echo -e " ${BOLD}run tests${NORMAL} Runs application test suite"
echo -e " ${BOLD}run browser-sync${NORMAL} Run with browser-sync"
echo -e " ${BOLD}run status${NORMAL} Check if the current commit is on production"
echo ""
echo "Additional parameters will be ignored."
exit 1
fi
if [ $# -gt 0 ] && [ $1 = 'tests' ]
then
composer test:all
exit 1
fi
if [ $# -gt 0 ] && [ $1 = 'status' ]
then
local=`git rev-parse master`
prod=`curl -s https://whattrainisitnow.com/deployed-version.txt`
echo -e "$GREEN""Checking if the latest commit is what we have in production""$NORMAL"
echo "Local : $local"
echo -n "Prod : $prod"
if [ $local == $prod ]
then
echo ""
echo -en "$GREEN""Yes, we are good""$NORMAL"
elif [[ condition ]]; then
x=$(($(git rev-list --count $prod..$local)))
echo ""
echo -en "$ORANGE""No, production is $x commit(s) behind""$NORMAL"
fi
exit 1
fi
echo -e "${GREEN}${BOLD}Launching PHP development server on http://${SERVER}${NORMAL}${NOCOLOR}"
if command -v browser-sync &> /dev/null; then
if [ $# -gt 0 ] && [ $1 = 'browser-sync' ]
then
echo -e "${GREEN}browser-sync is installed on the system, launching it in the background${NOCOLOR}"
browser-sync start --proxy "localhost:8082" --files "**/*" &
else
echo -e "${ORANGE}browser-sync is installed on the system but won't be launched${NOCOLOR}"
fi
fi
php -S ${SERVER} -t public/ app/inc/router.php
# trap ctrl-c and call ctrl_c()
trap ctrl_c INT