|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Build a GNOME Shell extension ZIP for local install or extensions.gnome.org upload. |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +ROOT="$(cd "$(dirname "$0")/.." && pwd)" |
| 6 | +EXT_DIR="$ROOT/extension/lay@radislabus-star.github.io" |
| 7 | +OUT_DIR="$ROOT/dist/gnome-extension" |
| 8 | + |
| 9 | +if ! command -v zip >/dev/null; then |
| 10 | + echo "zip is required. Install it with: sudo apt-get install zip" >&2 |
| 11 | + exit 1 |
| 12 | +fi |
| 13 | +if ! command -v unzip >/dev/null; then |
| 14 | + echo "unzip is required. Install it with: sudo apt-get install unzip" >&2 |
| 15 | + exit 1 |
| 16 | +fi |
| 17 | + |
| 18 | +read -r UUID VERSION_NAME < <( |
| 19 | + python3 - "$EXT_DIR/metadata.json" <<'PY' |
| 20 | +import json |
| 21 | +import sys |
| 22 | +from pathlib import Path |
| 23 | +
|
| 24 | +metadata = json.loads(Path(sys.argv[1]).read_text(encoding="utf-8")) |
| 25 | +print(metadata["uuid"], metadata["version-name"]) |
| 26 | +PY |
| 27 | +) |
| 28 | + |
| 29 | +mkdir -p "$OUT_DIR" |
| 30 | +ZIP_PATH="$OUT_DIR/${UUID}-${VERSION_NAME}.zip" |
| 31 | +TMP_DIR="$(mktemp -d)" |
| 32 | +trap 'rm -rf "$TMP_DIR"' EXIT |
| 33 | +rm -f "$ZIP_PATH" |
| 34 | + |
| 35 | +cp "$EXT_DIR/extension.js" "$TMP_DIR/" |
| 36 | +cp "$EXT_DIR/lay-impl.js" "$TMP_DIR/" |
| 37 | +python3 - "$EXT_DIR/metadata.json" "$TMP_DIR/metadata.json" <<'PY' |
| 38 | +import json |
| 39 | +import sys |
| 40 | +from pathlib import Path |
| 41 | +
|
| 42 | +metadata = json.loads(Path(sys.argv[1]).read_text(encoding="utf-8")) |
| 43 | +# extensions.gnome.org owns the numeric submission version. Keep version-name |
| 44 | +# visible in the UI, but don't ship the internal numeric field in the upload ZIP. |
| 45 | +metadata.pop("version", None) |
| 46 | +Path(sys.argv[2]).write_text( |
| 47 | + json.dumps(metadata, ensure_ascii=False, indent=4) + "\n", |
| 48 | + encoding="utf-8", |
| 49 | +) |
| 50 | +PY |
| 51 | + |
| 52 | +( |
| 53 | + cd "$TMP_DIR" |
| 54 | + zip -X -q "$ZIP_PATH" metadata.json extension.js lay-impl.js |
| 55 | +) |
| 56 | + |
| 57 | +echo "Built: $ZIP_PATH" |
| 58 | +echo "" |
| 59 | +echo "Archive contents:" |
| 60 | +unzip -l "$ZIP_PATH" |
| 61 | + |
| 62 | +echo "" |
| 63 | +echo "Local extension-only install:" |
| 64 | +echo " gnome-extensions install --force \"$ZIP_PATH\"" |
| 65 | +echo " gnome-extensions enable \"$UUID\"" |
0 commit comments