# Homebrew Distribution Guide
This guide explains how to publish and distribute trimdown via Homebrew.
## Prerequisites
1. **Homebrew Tap Repository**: Create a GitHub repository for your Homebrew formulas (e.g., `yingkitw/homebrew-tap`)
2. **Local Setup**: Clone your tap repository locally
```bash
git clone git@github.com:yingkitw/homebrew-tap.git
cd homebrew-tap
mkdir -p Formula
```
## Publishing a New Release
### Step 1: Create a GitHub Release
```bash
# Update version and create release
./scripts/release.sh 0.1.3
# Push the tag
git push origin v0.1.3
```
Then create a GitHub release at: https://github.com/yingkitw/trimdown-rs/releases/new
### Step 2: Update Homebrew Formula
```bash
# Update the formula with new version and SHA256
./scripts/update-formula.sh 0.1.3
```
This will create `Formula/trimdown.rb` with the correct SHA256.
### Step 3: Commit and Push to Tap
```bash
cd ../homebrew-tap
cp ../trimdown-rs/Formula/trimdown.rb Formula/
git add Formula/trimdown.rb
git commit -m "Update trimdown to version 0.1.3"
git push origin main
```
### Step 4: Test Installation
```bash
brew tap yingkitw/tap
brew install trimdown
trimdown --version
```
## Manual Formula Creation
If you need to create the formula manually:
```bash
# Download release archive
VERSION="0.1.3"
curl -L -o trimdown.tar.gz "https://github.com/yingkitw/trimdown-rs/archive/refs/tags/v${VERSION}.tar.gz"
# Calculate SHA256
shasum -a 256 trimdown.tar.gz
# Create formula using the template
```
## Formula Template
The formula uses the following structure:
```ruby
class Trimdown < Formula
version "0.1.3"
homepage "https://github.com/yingkitw/trimdown-rs"
url "https://github.com/yingkitw/trimdown-rs/archive/refs/tags/v0.1.3.tar.gz"
sha256 "CALCULATED_SHA256"
license "Apache-2.0"
depends_on "rust" => :build
depends_on "ffmpeg" => :recommended
depends_on "qpdf" => :recommended
depends_on "ghostscript" => :optional
def install
system "cargo", "install", "--locked", "--root", prefix, "--path", "."
end
test do
system bin/"trimdown", "--version"
end
end
```
## Optional Dependencies
- **ffmpeg**: Required for video compression
- **qpdf**: Recommended for PDF compression
- **ghostscript**: Optional, alternative PDF compression method
Users can install these separately:
```bash
brew install ffmpeg qpdf ghostscript
```
## Updating Formula
To update an existing formula:
```bash
brew upgrade trimdown
```
## Troubleshooting
### Formula fails to install
Check if all dependencies are available:
```bash
brew install rust ffmpeg qpdf
```
### SHA256 mismatch
Ensure the correct SHA256 is calculated for the release archive:
```bash
### Binary not found after installation
Add Homebrew to your PATH (for Apple Silicon Macs):
```bash
echo 'export PATH="/opt/homebrew/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
```
## Installation from Local Formula
For testing before publishing:
```bash
brew install --build-from-source Formula/trimdown.rb
```