#!/usr/bin/env bash
set -euo pipefail

# install deps
apt update && apt install jq -y
npm install -g web-ext pnpm

git clone --depth 1 https://github.com/Vendicated/Vencord
cd ./Vencord/

# build extension
pnpm i
pnpm run buildWeb

# change id
cd ./dist/
# can't just `tee` it directly into it, otherwise tee will erase all contents of the file, *then* jq will run
# (same for redirecting the output ofc)
tmpfile=$(mktemp)
jq '.browser_specific_settings.gecko.id = "vencord-firefox@askiiart.net"' ./firefox-unpacked/manifest.json -c >$tmpfile
mv $tmpfile ./firefox-unpacked/manifest.json

# build it to an extension or whatever idk
web-ext build -s ./firefox-unpacked/

# move to /misc and set version
mkdir -p /misc/vencord-firefox/
mv ./extension-firefox.zip /misc/vencord-firefox/vencord-firefox.zip
jq '.version' firefox-unpacked/manifest.json | tr -d '"' >/misc/vencord-firefox/version