-
Notifications
You must be signed in to change notification settings - Fork 3
/
dev.sh
171 lines (113 loc) · 4.4 KB
/
dev.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
# /bin/bash dev.sh
# will not open browser nor ide
#
# /bin/bash dev.sh browser
# will open browser
#
# /bin/bash dev.sh launch_ide
# will open browser and ide
#
_SHELL="$(ps -p $$ -o comm=)"; # bash || sh || zsh
_SHELL="$(basename ${_SHELL//-/})"
case ${_SHELL} in
zsh)
_DIR="$( cd "$( dirname "${(%):-%N}" )" && pwd -P )"
;;
sh)
_DIR="$( cd "$( dirname "${0}" )" && pwd -P )"
;;
*)
_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd -P )"
;;
esac
cd "${_DIR}"
OPENBROWSER="0"
OPENIDE="0"
if [ "${1}" = "browser" ]; then
OPENBROWSER="1"
fi
if [ "${1}" = "launch_ide" ]; then
OPENBROWSER="1"
OPENIDE="1"
fi
export NODE_OPTIONS=""
set -e
if [ ! -d "${_DIR}/node_modules" ]; then
yarn
fi
source "${_DIR}/bash/colours.sh";
# -L file True if file exists and is a symbolic link.
if [ ! -L _______index.html ]; then
set +e
ln -s index.html _______index.html
fi
if [ ! -L _______index.html ]; then
{ red "${0} error: _______index.html is not a symbolic link and it can't be created"; } 2>&3
exit 1
fi
ENV=".env"
if [ ! -f "${ENV}" ]; then
{ red "${0} error: file >${ENV}< doesn't exist"; } 2>&3
exit 1
fi
source "${ENV}"
source ".env.sh"
__HOST="0.0.0.0"
if [ "${LOCAL_HOSTS}" != "" ]; then
__HOST="${LOCAL_HOSTS}"
fi
function _kill {
echo "final cleanup: kill"
ps aux | grep "_${FLAG}" | grep -v grep | awk '{print $2}' | xargs kill
kill "${PID1}" 1> /dev/null 2> /dev/null || :
kill "${PID2}" 1> /dev/null 2> /dev/null || :
kill "${PID3}" 1> /dev/null 2> /dev/null || :
kill "${PID4}" 1> /dev/null 2> /dev/null || :
kill "${PID5}" 1> /dev/null 2> /dev/null || :
}
_kill;
trap _kill EXIT;
node libs/preprocessor.js
LOGFILE="${_DIR}/var/log.log"
rm -rf "${LOGFILE}"
# /bin/bash "${_DIR}/bash/proc/run-with-flag-and-kill.sh" "1_${FLAG}" \
# node node_modules/.bin/webpack --watch 2>&1 >> "${LOGFILE}" &
node node_modules/.bin/webpack --watch --name "webpack_${FLAG}" 1> >(/bin/bash bash/dlogger.sh " " webpack >> "${LOGFILE}") 2> >(/bin/bash bash/dlogger.sh e webpack >> "${LOGFILE}") &
PID1="${!}"
/bin/bash esbuild.sh watch >> "${LOGFILE}" 1> >(/bin/bash bash/dlogger.sh " " esbuild >> "${LOGFILE}") 2> >(/bin/bash bash/dlogger.sh e esbuild >> "${LOGFILE}") &
PID3="${!}"
/bin/bash .github/injector.sh watch >> "${LOGFILE}" 1> >(/bin/bash bash/dlogger.sh " " esbuild >> "${LOGFILE}") 2> >(/bin/bash bash/dlogger.sh e esbuild >> "${LOGFILE}") &
PID4="${!}"
/bin/bash pages/bash/xx/xx.inverse.postprocessor.sh watch >> "${LOGFILE}" 1> >(/bin/bash bash/dlogger.sh " " invpost >> "${LOGFILE}") 2> >(/bin/bash bash/dlogger.sh e invpost >> "${LOGFILE}") &
PID5="${!}"
# WAITINGMESSAGE="hidden modules" # this text shows at the end of webpack build
WAITINGMESSAGE="compiled successfully in" # this text shows at the end of webpack build
cat <<EEE
Now let's wait for webpack to spit '${WAITINGMESSAGE}' message
if it takes too long go and inspect
${LOGFILE}
EEE
while [ "$(cat "${LOGFILE}" | grep "${WAITINGMESSAGE}")" = "" ]
do
sleep 1;
# echo "================================ waiting for webpack to finish build ================================" >> "${LOGFILE}"
echo "================================ waiting for webpack to finish build ================================" 1> >(/bin/bash bash/dlogger.sh " " "server " >> "${LOGFILE}")
done
# /bin/bash "${_DIR}/bash/proc/run-with-flag-and-kill.sh" "2_${FLAG}" \
# node server.js --flag "3_${FLAG}" 2>&1 >> "${LOGFILE}" &
node server.js --flag "3_${FLAG}" 1> >(/bin/bash bash/dlogger.sh " " "server " >> "${LOGFILE}") 2> >(/bin/bash bash/dlogger.sh e "server " >> "${LOGFILE}") &
PID2="${!}"
if [ "${OPENBROWSER}" = "1" ]; then
sleep 3 && node "${_DIR}/node_modules/.bin/open-cli" http://${__HOST}:${NODE_API_PORT}/index.html 1> >(/bin/bash bash/dlogger.sh " " "opencli" >> "${LOGFILE}") 2> >(/bin/bash bash/dlogger.sh e "opencli" >> "${LOGFILE}") &
fi
if [ "${OPENIDE}" = "1" ]; then
code "${_DIR}"
fi
set -e
/bin/bash bash/proc/pid-is-running.sh ${PID1} "webpack process"
/bin/bash bash/proc/pid-is-running.sh ${PID2} "server process"
/bin/bash bash/proc/pid-is-running.sh ${PID3} "esbuild process"
/bin/bash bash/proc/pid-is-running.sh ${PID4} "injector process"
/bin/bash bash/proc/pid-is-running.sh ${PID5} "pages/bash/xx/xx.inverse.postprocessor.sh"
# tail -n 10000 -f "${LOGFILE}"
/bin/bash "${_DIR}/bash/proc/run-with-flag-and-kill.sh" "tail_${FLAG}" tail -n 10000 -f "${LOGFILE}"