This repository has been archived by the owner on Jan 14, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathbuild.sh
executable file
·119 lines (104 loc) · 2.5 KB
/
build.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/sh
set -eu
usage() {
printf 'Usage: \033[4m%s\033[m <target>\n\n' "$(basename "$0")" >&2
cat >&2 <<-EOF
Targets:
all
bridge
client [no-deps]
publish [maintenance]
server [no-deps]
EOF
exit 1
}
test $# -lt 1 && usage
keep_maintenance=
mode="$1"
no_deps=
shift
for argument in "$@"; do
case "$argument" in
maintenance)
keep_maintenance=1
;;
no-deps)
no_deps=1
;;
*)
usage
;;
esac
done
dirname="$(dirname "$0")"
case "$mode" in
publish)
if test ! -f "$dirname/build-env"; then
cat >"$dirname/build-env" <<-EOF
#!/bin/sh
# Command to restart the API server
REMOTE_API_RESTART=''
# Command to stop the API server
REMOTE_API_STOP=''
# Hostname for SSH/rsync
REMOTE_HOSTNAME=''
# Directory containing "bridge" and "server"
REMOTE_LOVED_DIRECTORY=''
# Directory containing client index.html
REMOTE_LOVED_DIRECTORY_WWW=''
# Command to set maintenance mode, appended with an "on" or "off" argument
REMOTE_SET_MAINTENANCE=''
EOF
printf 'Configure build environment in the "build-env" file first\n' >&2
exit 1
fi
. "$dirname/build-env"
"$0" all
ssh "$REMOTE_HOSTNAME" "$REMOTE_SET_MAINTENANCE on"
rsync -aP --del --no-group --no-owner \
"$dirname/bridge/build" \
"$dirname/bridge/package.json" \
"$dirname/bridge/package-lock.json" \
"$REMOTE_HOSTNAME:$REMOTE_LOVED_DIRECTORY/bridge"
rsync -aP --del --no-group --no-owner \
"$dirname/client/build/" \
"$REMOTE_HOSTNAME:$REMOTE_LOVED_DIRECTORY_WWW"
rsync -aP --del --no-group --no-owner \
"$dirname/server/build" \
"$dirname/server/migrations" \
"$dirname/server/package.json" \
"$dirname/server/package-lock.json" \
"$REMOTE_HOSTNAME:$REMOTE_LOVED_DIRECTORY/server"
ssh "$REMOTE_HOSTNAME" "cd $REMOTE_LOVED_DIRECTORY/server && npm i --omit dev"
if test "$keep_maintenance"; then
ssh "$REMOTE_HOSTNAME" "$REMOTE_API_STOP"
else
ssh "$REMOTE_HOSTNAME" "$REMOTE_API_RESTART && $REMOTE_SET_MAINTENANCE off"
fi
;;
all)
"$0" bridge
"$0" client no-deps
"$0" server no-deps
;;
bridge)
cd "$dirname/bridge"
npm install
npm run build
;;
client)
test "$no_deps" || "$0" bridge
cd "$dirname/client"
npm install
npm run build
;;
server)
test "$no_deps" || "$0" bridge
cd "$dirname/server"
npm install
npm run build
;;
*)
usage
;;
esac