-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
56 lines (49 loc) · 1.8 KB
/
Makefile
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
SHELL := /bin/bash
EVENT_PROCESS := notifier_event
EXAM_PROCESS := notifier_exam
_ERROR := "\\033[31m"
_SUCCESS := "\\033[32m"
_WARNING := "\\033[33m"
_DEFAULT := "\\033[0m"
_ERROR_LOG := "$(_ERROR)Error:$(_DEFAULT) %s\n"
_SUCCESS_LOG := "\n$(_SUCCESS)[%s]$(_DEFAULT)\n\n"
_WARNING_LOG := "\n$(_WARNING)[%s]$(_DEFAULT)\n"
.PHONY: all start deploy
all: start
start:
@REPLY=""; \
if ! type "yarn" &> /dev/null; then \
printf $(_ERROR_LOG) "yarn is not installed."; \
exit 1; \
fi; \
if ! type "pm2" &> /dev/null; then \
printf $(_ERROR_LOG) "pm2 is not installed."; \
exit 1; \
fi; \
printf $(_WARNING_LOG) "Please select a process to run"; \
printf " 1 event\n"; \
printf " 2 exam\n"; \
read -p " > " -r; \
REPLY=`echo $$REPLY | sed 's/^ *//'`; \
if [[ ! $$REPLY =~ ^(1|2|event|exam)$$ ]]; then \
printf $(_ERROR_LOG) "Allowed input: 1, 2, event, exam"; \
exit 1; \
fi; \
[[ $$REPLY -eq 1 || "$$REPLY" == "event" ]] && TYPE=event || TYPE=exam; \
printf $(_SUCCESS_LOG) "\"$$TYPE\" process will be running"; \
NODE_TYPE=$$TYPE yarn start;
deploy:
@if ! type "yarn" &> /dev/null; then \
printf $(_ERROR_LOG) "yarn is not installed."; \
exit 1; \
fi; \
if ! type "pm2" &> /dev/null; then \
printf $(_ERROR_LOG) "pm2 is not installed."; \
exit 1; \
fi; \
yarn build || (printf $(_ERROR_LOG) "Failed to build the application." && exit 1); \
pm2 delete $(EVENT_PROCESS) &> /dev/null || true; \
pm2 delete $(EXAM_PROCESS) &> /dev/null || true; \
NODE_TYPE=event yarn deploy --name $(EVENT_PROCESS) || (printf $(_ERROR_LOG) "Failed to deploy the event process." && exit 1); \
sleep 2; \
NODE_TYPE=exam yarn deploy --name $(EXAM_PROCESS) || (printf $(_ERROR_LOG) "Failed to deploy the event process." && exit 1);