-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy.sh
executable file
·239 lines (199 loc) · 5.48 KB
/
deploy.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/bin/bash
BOLD=$(tput bold)
RESET=$(tput sgr0)
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
BLUE=$(tput setaf 4)
PURPLE=$(tput setaf 5)
echo "${BOLD}============================================================"
echo "${PWD##*/}"
echo "============================================================${RESET}"
#============================================================
# run dev server or deploy directly
#============================================================
dev_or_deploy() {
while true; do
printf "\n"
printf "${YELLOW}Select one below\n${RESET}"
read -p "${BOLD}${GREEN}Run dev server (R) / Deploy (D) / Lint (L) / Install (I) ${RESET}" rdli
case ${rdli} in
[Rr]* )
printf "\n"
echo "${BOLD}${PURPLE}🔥 Run dev server 🔥${RESET}"
image_resizer
npm_run_serve
npm_run_build
firebase_deploy
git_commit
break;;
[Dd]* )
printf "\n"
echo "${BOLD}${PURPLE}🔥 lint 🔥${RESET}"
npm run lint;
printf "\n"
echo "${BOLD}${PURPLE}🔥 npm run build 🔥${RESET}"
npm run build:modern;
printf "\n"
echo "${BOLD}${PURPLE}🔥 firebase deploy 🔥${RESET}"
firebase deploy;
break;;
[Ll]* )
printf "\n"
echo "${BOLD}${PURPLE}🔥 Lint fix 🔥${RESET}"
npm run lint;
break;;
[Ii]* )
printf "\n"
echo "${BOLD}${PURPLE}🔥 Install dependencies 🔥${RESET}"
npm_install
break;;
* ) echo "${YELLOW}Please answer R(un) / D(eploy) / I(nstall).${RESET}";;
esac
done
}
#============================================================
# get OS type && install dependencies
#============================================================
npm_install() {
while true; do
printf "\n"
if [[ "$OSTYPE" == "win32" || "cygwin" || "msys" ]]; then
npm install --no-optional
else
read -p "${BOLD}${GREEN}sudo install? (Y/n) ${RESET}" yn
case ${yn} in
[Yy]* )
sudo npm install
break;;
[Nn]* )
npm install
break;;
* ) echo "${YELLOW}Please answer yes or no.${RESET}";;
esac
fi
done
}
#============================================================
# run gulpfile.js image resizer
#============================================================
image_resizer() {
while true; do
printf "\n"
read -p "${BOLD}${GREEN}Run gulpfile.js(image resizer)? (Y/n) ${RESET}" yn
case ${yn} in
[Yy]* )
trap 'echo Stop gulp' SIGINT
sudo gulp;
trap SIGINT
break;;
[Nn]* )
return 0;;
* ) echo "${YELLOW}Please answer yes or no.${RESET}";;
esac
done
}
#============================================================
# serve with hot reload at localhost:5000
#============================================================
npm_run_serve() {
while true; do
printf "\n"
read -p "${BOLD}${GREEN}npm run serve? (Y/n) ${RESET}" yn
case ${yn} in
[Yy]* )
npm run serve;
break;;
[Nn]* )
return 0;;
* ) echo "${YELLOW}Please answer yes or no.${RESET}";;
esac
done
}
#============================================================
# build for production with minification
#============================================================
npm_run_build() {
while true; do
printf "\n"
read -p "${BOLD}${GREEN}npm run build? (Y/n) ${RESET}" yn
case ${yn} in
[Yy]* )
npm run build:modern;
break;;
[Nn]* )
return 0;;
* ) echo "${YELLOW}Please answer yes or no.${RESET}";;
esac
done
}
#============================================================
# deploy with firebase cli
#============================================================
firebase_deploy() {
while true; do
printf "\n"
read -p "${BOLD}${GREEN}firebase deploy? (Y/n) ${RESET}" yn
case ${yn} in
[Yy]* )
firebase deploy;
break;;
[Nn]* )
return 0;;
* ) echo "${YELLOW}Please answer yes or no.${RESET}";;
esac
done
}
#============================================================
# git commit
#============================================================
git_commit() {
while true; do
printf "\n"
read -p "${BOLD}${GREEN}git commit? (Y/n) ${RESET}" yn
case ${yn} in
[Yy]* )
IFS= read -r -p "${BOLD}Enter commit message: ${RESET}" commitmsg
# if commitmsg empty
if [ -z "$commitmsg" ]
then
echo "${BOLD}${RED}👻 Commit message is empty 👻${RESET}"
commitmsg="Add files via upload"
fi
printf "\n"
git add .
git commit -m "$commitmsg"
git_push
break;;
[Nn]* )
return 0;;
* ) echo "${YELLOW}Please answer yes or no.${RESET}";;
esac
done
}
#============================================================
# git push
#============================================================
git_push() {
while true; do
printf "\n"
read -p "${BOLD}${GREEN}git push? (Y/n) ${RESET}" yn
case ${yn} in
[Yy]* )
printf "\n"
echo "${BOLD}${PURPLE}🔥 Push 🔥${RESET}"
git push;
break;;
[Nn]* )
return 0;;
* ) echo "${YELLOW}Please answer yes or no.${RESET}";;
esac
done
}
#============================================================
# main
#============================================================
main() {
dev_or_deploy
}
main