Add bash build script

This commit is contained in:
Jordan Wages 2026-01-06 21:07:55 -06:00
commit 2178de9a90
3 changed files with 82 additions and 3 deletions

View file

@ -12,6 +12,7 @@ This file provides guidelines for codex agents contributing to the Sortana proje
- `resources/`: Images and other static files.
- `prompt_templates/`: Prompt template files for the AI service.
- `build-xpi.ps1`: PowerShell script to package the extension.
- `build-xpi.sh`: Bash script to package the extension.
## Coding Style

View file

@ -29,7 +29,7 @@ with JSON indicating whether the message meets a specified criterion.
- **View reasoning** inspect why rules matched via the Details popup.
- **Cache management** clear cached results from the context menu or options page.
- **Queue & timing stats** monitor processing time on the Maintenance tab.
- **Packaging script** `build-xpi.ps1` builds an XPI ready for installation.
- **Packaging scripts** `build-xpi.ps1` (PowerShell) or `build-xpi.sh` (bash) build an XPI ready for installation.
- **Maintenance tab** view rule counts, cache entries and clear cached results from the options page.
### Cache Storage
@ -65,8 +65,9 @@ Sortana is implemented entirely with standard WebExtension scripts—no custom e
1. Ensure PowerShell is available (for Windows) or adapt the script for other
environments.
2. The Bulma stylesheet (v1.0.3) is already included as `options/bulma.css`.
3. Run `powershell ./build-xpi.ps1` from the repository root. The script reads
the version from `manifest.json` and creates an XPI in the `release` folder.
3. Run `powershell ./build-xpi.ps1` or `./build-xpi.sh` from the repository root.
The script reads the version from `manifest.json` and creates an XPI in the
`release` folder.
4. Install the generated XPI in Thunderbird via the Add-ons Manager. During
development you can also load the directory as a temporary add-on.
5. To regenerate PNG icons from the SVG sources, run `resources/svg2img.ps1`.

77
build-xpi.sh Executable file
View file

@ -0,0 +1,77 @@
#!/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 - <<'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
"$manifest")"
fi
if [[ -z "$version" ]]; then
echo "No version found in manifest.json" >&2
exit 1
fi
mkdir -p "$release_dir"
xpi_name="sortana-$version.xpi"
zip_path="$release_dir/ai-filter-$version.zip"
xpi_path="$release_dir/$xpi_name"
rm -f "$zip_path" "$xpi_path"
mapfile -d '' files < <(
find "$script_dir" -type f \
! -name '*.sln' \
! -name '*.ps1' \
! -name '*.sh' \
! -path "$release_dir/*" \
! -path "$script_dir/.vs/*" \
! -path "$script_dir/.git/*" \
-printf '%P\0'
)
if [[ ${#files[@]} -eq 0 ]]; then
echo "No files found to package." >&2
exit 0
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"