-
Notifications
You must be signed in to change notification settings - Fork 0
/
run
executable file
·74 lines (63 loc) · 1.79 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
#! /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'
)
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 ""
echo "Additional parameters will be ignored."
exit 1
fi
if [ $# -gt 0 ] && [ $1 = '-tests' ]
then
composer test:all
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/
# trap ctrl-c and call ctrl_c()
trap ctrl_c INT