#!/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 "";
tail -n5 index.html | tr -d '\n ';
) > "$tmpFile";
if [ "$1" = "-size" ]; then
stat -c %s "$tmpFile";
zopfli --gzip --i1000 -c "$tmpFile" > "$tmpFile.gz";
stat -c %s "$tmpFile.gz";
rm -f "$tmpFile" "$tmpFile.gz";
exit 0;
fi;
cat > index.go < index.gz;
rm -f "$tmpFile";
(
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;
);