#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"
# 1. embedded registry: registry.embedded.js defines EMBEDDED_REGISTRY_JSON
printf 'const EMBEDDED_REGISTRY_JSON = %s;\n' "$(cat registry.json)" > registry.embedded.js
# 2. static install index
mkdir -p build
{
echo '
userscriptsuserscripts
'
node -e '
const r = require("./registry.json");
for (const e of r) {
const url = `https://cdn.jsdelivr.net/gh/${e.repo}@${e.ref||"main"}/${e.path}`;
console.log(`- ${e.name} —
${e.repo}/${e.path} `);
}
'
echo '
'
} > build/index.html
# 3. loader.meta.js (metadata block only, for @updateURL checks)
sed -n '/==UserScript==/,/==\/UserScript==/p' loader.user.js > build/loader.meta.js
echo "build complete: registry.embedded.js, build/index.html, build/loader.meta.js"