@@ -21,9 +21,7 @@ function program_is_installed {
21
21
# echo echo_fail "No"
22
22
function echo_fail {
23
23
# echo first argument in red
24
- printf " \e[31m✘ ${1} "
25
- # reset colours back to normal
26
- echo " \033[0m"
24
+ printf " \e[31m✘ ${1} \033[0m"
27
25
}
28
26
29
27
# display a message in green with a tick by it
@@ -46,9 +44,41 @@ function echo_if {
46
44
fi
47
45
}
48
46
47
+ echo
49
48
echo " Thanks for reviewing my code challenge!"
50
49
echo " Checking if necessary dev environment exists..."
51
50
echo
52
- echo " node $( echo_if $( program_is_installed node) ) "
53
- echo " npm $( echo_if $( program_is_installed npm) ) "
51
+
52
+ NODE_INSTALLED=$( program_is_installed node)
53
+ NPM_INSTALLED=$( program_is_installed npm)
54
+
55
+ echo " node $( echo_if $NODE_INSTALLED ) "
56
+ echo " npm $( echo_if $NPM_INSTALLED ) "
57
+
58
+ if [ " $NODE_INSTALLED " == 0 ]; then
59
+ printf " \e[31mPlease install Node.js first."
60
+ exit
61
+ fi
62
+
63
+ if [ " $NPM_INSTALLED " == 0 ]; then
64
+ printf " \e[31mPlease install npm first. It's surprising you have Node.js installed, but not npm."
65
+ exit
66
+ fi
67
+
54
68
echo
69
+ echo " Installing dependencies."
70
+ npm install --production
71
+ echo
72
+
73
+ printf " Launching application and starting server"
74
+
75
+ PYTHON_INSTALLED=$( program_is_installed python)
76
+
77
+ if [ " $PYTHON_INSTALLED " == 0 ]; then
78
+ printf " Please open http://localhost:3000 in your favorite browser"
79
+ node ./bin/www
80
+ else
81
+ node ./bin/www & python -mwebbrowser http://localhost:3000
82
+ fi
83
+
84
+ exit
0 commit comments