-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdev.bash
executable file
·92 lines (75 loc) · 1.96 KB
/
dev.bash
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
#!/usr/bin/bash
readonly PORT=8080
cd "$(dirname $0)"
cd "$(git rev-parse --show-toplevel)"
sass_pid=
esb_pid=
ejs_pid=
function cleanup {
for pid in ${sass_pid} ${esb_pid} ${ejs_pid}; do
kill -- "-$pid"
done
echo "bye"
}
trap cleanup SIGINT SIGTERM EXIT
set -mx
if ! test -d node_modules/http-server; then
npm install . --production=false ||
exit 1
fi
if ! test -d .dev/public; then
mkdir -p .dev/public
ln -s ../index.html .dev/public/index.html
ln -s ../../resources/icon/16x16.ico .dev/public/favicon.ico
ln -s ../index.css .dev/public/style.css
ln -s ../app.js .dev/public/bundle.js
wget -P .dev/public 'https://unpkg.com/react@18/umd/react.development.js' || exit 1
wget -P .dev/public 'https://unpkg.com/react-dom@18/umd/react-dom.development.js' || exit 1
fi
function sass {
exec npx sass "src/style/index.scss:.dev/index.css" \
--no-error-css \
--embed-sources \
--embed-source-map \
--watch
}
function esb {
exec npx esbuild ./src/app --outdir=.dev \
--bundle --global-name=App \
--loader:.bin=binary \
--sourcemap=inline \
--platform=browser \
--watch
}
function ejs {
set +x
local curStat
local newStat
local gitRev
while true; do
if [[ "${curStat}" == "${newStat}" ]]; then
gitRev="$(git log --format=%h -n1)"
newStat="$(stat -c%Z package.json) $(stat -c%Z ./src/index.ejs) ${gitRev}"
else
npx ejs ./src/index.ejs --output-file .dev/index.html \
--rm-whitespace --strict \
--data-file ./package.json \
"gitRev=${gitRev}" \
"port=${PORT}"
curStat="${newStat}"
echo "Rendered index.html."
fi
sleep 0.5
done
}
sass &
sass_pid=$!
esb &
esb_pid=$!
ejs &
ejs_pid=$!
npx http-server .dev/public \
--port "${PORT}" \
--no-dotfiles \
--silent \
-c-1 \