-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuildExample
More file actions
executable file
·36 lines (34 loc) · 1.49 KB
/
buildExample
File metadata and controls
executable file
·36 lines (34 loc) · 1.49 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
#!/bin/bash
dataFile="$(cat $1)";
bm="$(realpath "$(dirname "$0")")";
data="$bm/internal/static/";
jslibJS="$(realpath "$bm/../jslib/lib.js/")";
shift;
(
cd "$data";
head -n5 index.html | tr -d '\n ';
echo -n "<script type=\"module\">";
(
echo -n "const exampleData = $(echo "$dataFile" | sed -e 's/\"admin\": *[^,]*,/\"admin\": window.location.search === "?admin",/')";
echo ";";
echo "{";
cat "$bm/examples/overrides.js";
echo "}";
while IFS= read -r line; do
if [ "$line" = " return url => Promise.resolve(imports.get(url) ?? import(url));" ]; then
echo -n " const plugins = new Map([";
while read plugin; do
echo "[\"/plugins/$plugin\", async () => {";
jspacker -i "/plugins/$plugin" -p | sed -e 's@import\.meta@\{"url": "/plugins/'"$plugin"'"\}@g';
echo -e "\nreturn {};\n}],";
done < <(echo "$dataFile" | jq -r ".plugins | keys[]");
echo "]);";
echo " return url => Promise.resolve(imports.get(url) ?? plugins.get(url)?.() ?? import(url));";
else
echo "$line";
fi;
done < <(jspacker -i "/$(grep "<script" index.html | sed -e 's/.*src="\([^"]*\)".*/\1/')");
) | sed -e 's/^\(.*imageIDtoURL =\).*\(.\)$/\1 id => exampleData.urls.images[id]\2/' -e 's/^\(.*audioIDtoURL =\).*\(.\)$/\1 id => exampleData.urls.audio[id]\2/' -e 's@"login/logout" : "login/login"@"?" : "?admin", "method": "post"@' | terser -m --module --compress pure_getters,passes=3 --ecma 6 --format ascii_only | tr -d '\n';
echo -n "</script>";
tail -n5 index.html | tr -d '\n ';
);