forked from maxime1992/pizza-sync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-and-serve-prod.sh
executable file
·73 lines (55 loc) · 1.21 KB
/
build-and-serve-prod.sh
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
#!/bin/bash
latestRemoteHash=$(git ls-remote https://github.com/maxime1992/pizza-sync.git HEAD | cut -d ' ' -f 1)
latestLocalHash=$(git rev-parse HEAD)
needsGitUpdate=false
if [ "$latestRemoteHash" == "$latestLocalHash" ];then
echo "GIT IS UP-TO-DATE, NO NEED TO FETCH AND REBASE"
else
needsGitUpdate=true
echo "GIT IS NOT UP-TO-DATE, FETCHING AND REBASING"
git fetch && git pull --rebase
fi
exists()
{
command -v "$1" >/dev/null 2>&1
}
isYarnAvailable=false
if exists yarn; then
echo "YARN'S AVAILABLE"
isYarnAvailable=true
else
echo "YARN'S NOT AVAILABLE, FALLING BACK TO NPM"
fi
cd frontend
echo "UPDATING FRONTEND DEPENDENCIES"
if "$isYarnAvailable"; then
yarn
else
npm
fi
if [ "$needsGitUpdate" = true -o ! -d dist ]; then
if [ -d dist ]; then
rm -rf dist
fi
if exists yarn; then
yarn run prod
else
npm run prod
fi
fi
cd ../backend
echo "UPDATING BACKEND DEPENDENCIES"
if "$isYarnAvailable"; then
yarn
else
npm
fi
if [ "$needsGitUpdate" = true -o ! -d public ]; then
if [ -d public ]; then
rm -rf public
fi
cp -r ../frontend/dist/ ./public
fi
ip=$(ip route get 1.1.1.1 | awk '{print $NF; exit}')
echo "PIZZA SYNC NOW AVAILABLE AT http://$ip:3000"
node index.js