#!/usr/bin/env bash set -euo pipefail script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" release_dir="$script_dir/release" manifest="$script_dir/manifest.json" if [[ ! -f "$manifest" ]]; then echo "manifest.json not found at $manifest" >&2 exit 1 fi if ! command -v zip >/dev/null 2>&1; then echo "zip is required to build the XPI." >&2 exit 1 fi if command -v jq >/dev/null 2>&1; then version="$(jq -r '.version // empty' "$manifest")" else if ! command -v python3 >/dev/null 2>&1; then echo "python3 is required to read manifest.json without jq." >&2 exit 1 fi version="$(python3 - "$manifest" <<'PY' import json import sys with open(sys.argv[1], "r", encoding="utf-8") as f: data = json.load(f) print(data.get("version", "") or "") PY )" fi if [[ -z "$version" ]]; then echo "No version found in manifest.json" >&2 exit 1 fi mkdir -p "$release_dir" artifact_base="psitransfer-filelink-$version" zip_path="$release_dir/$artifact_base.zip" xpi_path="$release_dir/$artifact_base.xpi" rm -f "$zip_path" "$xpi_path" mapfile -d '' files < <( find "$script_dir" -type f \ ! -name '*.ps1' \ ! -name '*.sh' \ ! -path "$release_dir/*" \ ! -path "$script_dir/.git/*" \ ! -path "$script_dir/.idea/*" \ ! -path "$script_dir/.vscode/*" \ -printf '%P\0' ) if [[ ${#files[@]} -eq 0 ]]; then echo "No files found to package." >&2 exit 1 fi for rel in "${files[@]}"; do full="$script_dir/$rel" size=$(stat -c '%s' "$full") echo "Zipping: $rel <- $full ($size bytes)" done ( cd "$script_dir" printf '%s\n' "${files[@]}" | zip -q -9 -@ "$zip_path" ) mv -f "$zip_path" "$xpi_path" echo "Built XPI at: $xpi_path"