Repository navigation
Expand file tree
/
Copy pathembed
More file actions
executable file
·60 lines (49 loc) · 1.41 KB
/
Copy pathembed
File metadata and controls
executable file
·60 lines (49 loc) · 1.41 KB
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
#!/bin/bash
bm="$(realpath "$(dirname "$0")")";
data="$bm/internal/static/";
jslibJS="$(realpath "$bm/../jslib/lib.js/")";
tmpFile="$(mktemp)";
(
cd "$data";
head -n5 index.html | tr -d '\n ';
echo -n "<script type=\"module\">";
jspacker -i "/$(grep "<script" index.html | sed -e 's/.*src="\([^"]*\)".*/\1/')" | if command -v terser > /dev/null; then terser -m --module --compress pure_getters,passes=3 --ecma 2020 | tr -d '\n'; else tr -d '\n\t'; fi;
echo -n "</script>";
tail -n5 index.html | tr -d '\n ';
) > "$tmpFile";
if [ "$1" = "-size" ]; then
stat -c %s "$tmpFile";
if command -v zopfli > /dev/null; then
zopfli --gzip --i1000 -c "$tmpFile" > "$tmpFile.gz";
else
gzip -f -9 "$tmpFile";
fi;
stat -c %s "$tmpFile.gz";
rm -f "$tmpFile" "$tmpFile.gz";
exit 0;
fi;
cat > index.go <<HEREDOC
package battlemap
import (
_ "embed" // required for index embed
"time"
"vimagination.zapto.org/httpembed"
)
var (
//go:embed index.gz
indexData []byte
index = httpembed.HandleBuffer("index.html", indexData, $(stat --format "%s" "$tmpFile"), time.Unix($(date "+%s"), 0))
)
HEREDOC
if command -v zopfli > /dev/null; then
zopfli --gzip --i1000 -c "$tmpFile" > index.gz;
rm -f "$tmpFile";
else
gzip -f -9 "$tmpFile";
fi;
(
cd "$data";
for i in plugins/*.js; do
jspacker -i "/$i" -p | terser -m --module --compress pure_getters,passes=3 --ecma 6 | tr -d '\n' > "$bm/plugins/$(basename "$i")";
done;
);