-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·95 lines (87 loc) · 2.72 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·95 lines (87 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env bash
# jobmeta — per-browser build script.
#
# Concatenates src/shared/*.js (in load order) + src/background/service-worker.js
# into dist/<browser>/background/service-worker.js so the SW sees JM_CONFIG /
# JM_API / JM_getInstallId on the global scope without ES imports (Firefox
# MV3's `background.scripts` doesn't support importScripts; modules are
# half-supported across the matrix; concat is the lowest-friction path).
#
# Everything else is copied verbatim. Each browser's manifest comes from
# manifests/<browser>.json so reviewers can audit the per-browser permission
# set without diffing a generated file.
#
# Usage: ./build.sh # build all 3 browsers
# ./build.sh chrome # build chrome only
# ./build.sh chrome firefox # build chrome and firefox
# ./build.sh --zip # build all + produce zips
set -euo pipefail
ROOT="$(cd "$(dirname "$0")" && pwd)"
SRC="$ROOT/src"
DIST="$ROOT/dist"
BROWSERS=()
ZIP=0
for arg in "$@"; do
case "$arg" in
--zip) ZIP=1 ;;
chrome|firefox|edge) BROWSERS+=("$arg") ;;
*) echo "unknown arg: $arg" >&2; exit 2 ;;
esac
done
if [ "${#BROWSERS[@]}" -eq 0 ]; then
BROWSERS=(chrome firefox edge)
fi
# Shared files concatenated into the SW, in load order.
SHARED_FOR_SW=(
"$SRC/shared/constants.js"
"$SRC/shared/browser.js"
"$SRC/shared/install_id.js"
)
build_one() {
local browser="$1"
local out="$DIST/$browser"
echo "→ building $browser"
rm -rf "$out"
mkdir -p "$out"
# Copy verbatim trees.
for d in popup content pages icons shared; do
if [ -d "$SRC/$d" ]; then
cp -r "$SRC/$d" "$out/"
fi
done
# Service worker = shared concat + sw.
mkdir -p "$out/background"
{
echo "// jobmeta service worker — built $(date -u +%Y-%m-%dT%H:%M:%SZ)"
echo "// generated by build.sh — do not edit dist/ directly"
echo ""
for f in "${SHARED_FOR_SW[@]}"; do
echo "// === $(basename "$f") ==="
cat "$f"
echo ""
done
echo "// === service-worker.js ==="
cat "$SRC/background/service-worker.js"
} > "$out/background/service-worker.js"
# Manifest.
cp "$ROOT/manifests/$browser.json" "$out/manifest.json"
# Validate JSON.
python3 -c "import json,sys; json.load(open('$out/manifest.json'))" \
|| { echo "manifest.json invalid in $out" >&2; exit 3; }
echo " ✓ $out"
}
for b in "${BROWSERS[@]}"; do
build_one "$b"
done
if [ "$ZIP" = "1" ]; then
echo ""
for b in "${BROWSERS[@]}"; do
local_dir="$DIST/$b"
zip_path="$DIST/jobmeta-${b}-v2.0.0.zip"
rm -f "$zip_path"
(cd "$local_dir" && zip -qr "$zip_path" .)
sz=$(stat -c '%s' "$zip_path" 2>/dev/null || stat -f '%z' "$zip_path")
echo " 📦 $zip_path ($sz bytes)"
done
fi
echo "done."