The Activity is now the full bug.tv site plus a small Discord overlay. Whoever starts the instance hosts and controls everything; everyone else mirrors the host's page and playback. The server is a relay keyed by activity instance and checks membership through Discord's activity-instances API, so it works in DM and group calls. The bot gateway, slash commands and control message are gone.
71 lines
2.9 KiB
Bash
Executable File
71 lines
2.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Build the Discord Activity: the bug.tv site + the watch-party overlay (docs/protocol.md "Build").
|
|
#
|
|
# scripts/build-activity.sh <bug-tv web dir> <out dir> [apiBase=/tv]
|
|
#
|
|
# - copies the site (bug-tv `web/` or its nix packages.web output) to <out dir>
|
|
# - index.html + 404.html: sets the bug-tv-api / -tmdb / -img / -force-proxy metas (inserted when
|
|
# missing), drops the Google Fonts links (Activity CSP), appends overlay.css + discord.js
|
|
# - bundles activity/js/discord.js with @discord/embedded-app-sdk → <out dir>/discord.js
|
|
#
|
|
# esbuild: $ESBUILD (e.g. nixpkgs' esbuild) or `npx esbuild`. No network access needed;
|
|
# @discord/embedded-app-sdk must be in node_modules.
|
|
set -euo pipefail
|
|
|
|
if [ $# -lt 2 ]; then
|
|
echo "usage: $0 <bug-tv web dir> <out dir> [apiBase=/tv]" >&2
|
|
exit 2
|
|
fi
|
|
web=$1
|
|
out=$2
|
|
api=${3:-/tv}
|
|
here=$(cd "$(dirname "$0")/.." && pwd)
|
|
esbuild=${ESBUILD:-npx esbuild}
|
|
|
|
[ -f "$web/index.html" ] || { echo "build-activity: $web/index.html not found" >&2; exit 1; }
|
|
|
|
rm -rf "$out"
|
|
mkdir -p "$out"
|
|
cp -R "$web"/. "$out"/
|
|
chmod -R u+w "$out"
|
|
rm -rf "$out/test" # bug-tv's web tests, if building from the source dir
|
|
|
|
# The site's own img/ would sit under Discord's /img → image.tmdb.org mapping: move it to
|
|
# site-img/ and rewrite the references in the pages and stylesheets (before the metas below).
|
|
if [ -d "$out/img" ]; then
|
|
mv "$out/img" "$out/site-img"
|
|
find "$out" -path "$out/vendor" -prune -o -type f \( -name '*.html' -o -name '*.css' \) -print |
|
|
while IFS= read -r f; do
|
|
sed -i -E "s#([\"'(=])(\\.\\./|\\./|/)?img/#\\1\\2site-img/#g" "$f"
|
|
done
|
|
fi
|
|
|
|
set_meta() { # file name content
|
|
local f=$1 name=$2 content=$3
|
|
if grep -q "<meta name=\"$name\"" "$f"; then
|
|
sed -i -E "s|<meta name=\"$name\"[^>]*>|<meta name=\"$name\" content=\"$content\">|" "$f"
|
|
else
|
|
sed -i -E "0,/<\/head>/s|</head>| <meta name=\"$name\" content=\"$content\">\n</head>|" "$f"
|
|
fi
|
|
}
|
|
|
|
for page in index.html 404.html; do
|
|
f=$out/$page
|
|
[ -f "$f" ] || continue
|
|
set_meta "$f" bug-tv-api "$api"
|
|
set_meta "$f" bug-tv-tmdb /tmdb/3
|
|
set_meta "$f" bug-tv-img /img/t/p/
|
|
set_meta "$f" bug-tv-force-proxy 1
|
|
# Google Fonts (stylesheet + preconnects) are blocked by the Activity CSP
|
|
sed -i -E '/<link[^>]*fonts\.(googleapis|gstatic)\.com[^>]*>/d; /<link rel="preconnect"[^>]*(image|api)\.(tmdb|themoviedb)\.org[^>]*>/d' "$f"
|
|
grep -q 'href="/overlay.css"' "$f" || sed -i -E '0,/<\/head>/s|</head>| <link rel="stylesheet" href="/overlay.css">\n</head>|' "$f"
|
|
grep -q 'src="/discord.js"' "$f" || sed -i -E '0,/<\/body>/s|</body>| <script type="module" src="/discord.js"></script>\n</body>|' "$f"
|
|
done
|
|
|
|
cp "$here/activity/overlay.css" "$out/overlay.css"
|
|
# shellcheck disable=SC2086
|
|
(cd "$here" && $esbuild activity/js/discord.js --bundle --format=esm --target=es2020 --minify --legal-comments=none \
|
|
--log-level=warning --outfile="$out/discord.js")
|
|
|
|
echo "build-activity: $out (api $api)"
|