Skip to content

Commit 443efad

Browse files
committed
(feat) Start script checks for needed components, starts server, and launches browser.
1 parent bc22ece commit 443efad

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

start.sh

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ function program_is_installed {
2121
# echo echo_fail "No"
2222
function echo_fail {
2323
# 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"
2725
}
2826

2927
# display a message in green with a tick by it
@@ -46,9 +44,41 @@ function echo_if {
4644
fi
4745
}
4846

47+
echo
4948
echo "Thanks for reviewing my code challenge!"
5049
echo "Checking if necessary dev environment exists..."
5150
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+
5468
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

Comments
 (0)