#!/usr/bin/env bash # build.sh — Build PassKeeper extension for Chrome (MV3) and Firefox (MV2). # # Usage: # ./build.sh # build both targets # ./build.sh chrome # Chrome only # ./build.sh firefox # Firefox only # # Output: # dist/passkeeper-chrome.zip # dist/passkeeper-firefox.zip # # Requirements: zip (standard on macOS/Linux) set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" EXT_DIR="$SCRIPT_DIR/extension" DIST_DIR="$SCRIPT_DIR/dist" # Files and directories included in every build (relative to extension/). COMMON_FILES=( "content" "popup" "bridge" "shared" "icons" ) TARGET="${1:-both}" mkdir -p "$DIST_DIR" # ── Helpers ─────────────────────────────────────────────────────────────────── build_chrome() { local out="$DIST_DIR/passkeeper-chrome.zip" echo "Building Chrome (MV3) → $out" rm -f "$out" ( cd "$EXT_DIR" zip -r "$out" manifest.json background.js "${COMMON_FILES[@]}" \ --exclude "*.DS_Store" --exclude "**/__pycache__/*" --exclude "*.py" ) echo " ✓ Chrome build complete: $out ($(du -sh "$out" | cut -f1))" } build_firefox() { local out="$DIST_DIR/passkeeper-firefox.zip" echo "Building Firefox (MV2) → $out" rm -f "$out" # Firefox uses a different manifest and background script. # We build into a temp directory so we can swap those files cleanly. local tmp tmp="$(mktemp -d)" trap "rm -rf '$tmp'" EXIT # Copy common files into temp dir. for item in "${COMMON_FILES[@]}"; do cp -r "$EXT_DIR/$item" "$tmp/" done # Swap in Firefox-specific manifest and background. cp "$EXT_DIR/manifest.firefox.json" "$tmp/manifest.json" cp "$EXT_DIR/background.firefox.js" "$tmp/background.js" ( cd "$tmp" zip -r "$out" . \ --exclude "*.DS_Store" --exclude "**/__pycache__/*" --exclude "*.py" ) echo " ✓ Firefox build complete: $out ($(du -sh "$out" | cut -f1))" } # ── Main ────────────────────────────────────────────────────────────────────── case "$TARGET" in chrome) build_chrome ;; firefox) build_firefox ;; both) build_chrome; build_firefox ;; *) echo "Usage: $0 [chrome|firefox|both]" >&2 exit 1 ;; esac echo "Done. Packages are in $DIST_DIR/"