2023-02-28 11:54:30 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
# compress static assets
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
cd ui/react-app
|
|
|
|
cp embed.go.tmpl embed.go
|
|
|
|
|
2023-11-03 14:50:06 +00:00
|
|
|
GZIP_OPTS="-fkn"
|
2023-02-28 11:54:30 +00:00
|
|
|
# gzip option '-k' may not always exist in the latest gzip available on different distros.
|
2023-11-03 14:50:06 +00:00
|
|
|
if ! gzip -k -h &>/dev/null; then GZIP_OPTS="-fn"; fi
|
2023-02-28 11:54:30 +00:00
|
|
|
|
|
|
|
dist="dist"
|
|
|
|
|
|
|
|
if ! [[ -d "${dist}" ]]; then
|
|
|
|
mkdir -p ${dist}
|
|
|
|
echo "<!doctype html>
|
|
|
|
<html lang=\"en\">
|
|
|
|
<head>
|
|
|
|
<meta charset=\"utf-8\">
|
|
|
|
<title>Node</title>
|
|
|
|
<base href=\"/\">
|
|
|
|
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">
|
|
|
|
<link rel=\"icon\" type=\"image/x-icon\" href=\"favicon.ico\">
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div>
|
|
|
|
<p> This is the default index, looks like you forget to generate the react app before generating the golang endpoint.</p>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>" > ${dist}/index.html
|
|
|
|
fi
|
|
|
|
|
|
|
|
find dist -type f -name '*.gz' -delete
|
2023-11-03 14:50:06 +00:00
|
|
|
find dist -type f -exec gzip $GZIP_OPTS '{}' \; -print0 | xargs -0 -I % echo %.gz | sort | xargs echo //go:embed >> embed.go
|
2023-02-28 11:54:30 +00:00
|
|
|
echo var embedFS embed.FS >> embed.go
|