Repository generated by typedef
This directory contains the Homebrew formula template and scripts for distributing typedef via Homebrew.
client/homebrew/
├── Formula/
│ └── typedef.rb.template # Homebrew formula template with placeholders
├── scripts/
│ └── generate-formula.sh # Script to generate final formula with checksums
└── README.md # This file
The typedef.rb.template file is a Homebrew formula that uses placeholder variables for dynamic values:
{{VERSION}}- Release version number (e.g., 0.0.15){{SHA256_DARWIN_ARM64}}- Checksum for macOS ARM64 binary{{SHA256_DARWIN_AMD64}}- Checksum for macOS AMD64 (Intel) binary{{SHA256_LINUX_ARM64}}- Checksum for Linux ARM64 binary{{SHA256_LINUX_AMD64}}- Checksum for Linux AMD64 (x86_64) binary
The formula supports multiple platforms using Homebrew's platform detection:
macOS:
- Apple Silicon (ARM64): darwin-arm64
- Intel (AMD64): darwin-amd64
Linux:
- ARM64: linux-arm64
- x86_64 (AMD64): linux-amd64
The formula automatically detects the user's platform and architecture using Hardware::CPU and downloads the appropriate pre-built binary from GitHub releases.
The generate-formula.sh script:
- Takes a version number and checksums file as input
- Parses the checksums.txt file from GitHub releases
- Extracts SHA256 checksums for all 4 platform binaries
- Replaces placeholders in the template
- Outputs a complete, ready-to-use Homebrew formula
- Homebrew installed on your system
- Access to typedef GitHub releases (public repository)
- Shell environment with bash and curl
Download the checksums file from the latest typedef release:
curl -L -o /tmp/checksums.txt \
https://github.com/exanubes/typedef/releases/download/v0.0.15/checksums.txtReplace v0.0.15 with the version you want to test.
Run the generation script:
cd /Users/exanubes/Demo/typedef
./client/homebrew/scripts/generate-formula.sh \
0.0.15 \
/tmp/checksums.txt \
/tmp/typedef.rbThis will create a complete formula file at /tmp/typedef.rb.
Check the generated formula content:
cat /tmp/typedef.rbVerify that:
- Version is correct
- All 4 SHA256 checksums are present and non-empty
- URLs point to the correct GitHub release
Run Homebrew's audit tool to check for syntax errors:
brew audit --new-formula /tmp/typedef.rbInstall the formula locally for testing:
brew install /tmp/typedef.rbVerify the binary is installed:
which typedef
# macOS Apple Silicon: /opt/homebrew/bin/typedef
# macOS Intel: /usr/local/bin/typedef
# Linux: /home/linuxbrew/.linuxbrew/bin/typedef (or ~/.linuxbrew/bin/typedef)Test basic functionality:
typedef --format go --input '{"name": "John", "age": 30}' --target cliRun the formula's test block:
brew test typedefCheck version information:
typedef versionUninstall when done testing:
brew uninstall typedefFor convenience, you can use the Makefile targets to automate the entire testing process. This is especially useful before releasing a new version.
- Homebrew installed on your system
- Build tools configured (Go, make)
Test formula generation only:
make test-homebrew-formulaThis will:
- Build CLI binaries for all platforms (darwin and linux, amd64 and arm64)
- Package binaries into tar.gz archives
- Generate checksums.txt
- Generate the Homebrew formula
- Validate Ruby syntax
- Display the generated formula
Test with a specific version:
make test-homebrew-formula VERSION=0.0.16Test with installation:
make test-homebrew-install VERSION=0.0.16This performs all the steps above, then offers to install and test the formula locally.
The automated testing:
- Checks that local builds exist (or builds them)
- Packages binaries exactly like the release process
- Generates checksums matching the production format
- Creates a formula in a temporary directory
- Validates the formula syntax
- Shows you the complete formula
- (Optional) Tests actual installation
All test artifacts are placed in a temporary directory that you can clean up after testing.
Before creating a release:
# Test the formula with your next version number
make test-homebrew-formula VERSION=0.0.16
# Review the output and generated formula
# If everything looks good, optionally test installation
make test-homebrew-install VERSION=0.0.16
# If tests pass, proceed with creating the actual GitHub releaseThe formula downloads the appropriate tar.gz archive for the user's platform, which contains a binary named typedef-cli. During installation, the formula renames it to typedef for a cleaner user experience:
bin.install "typedef-cli" => "typedef"This allows users to run the tool simply as typedef instead of typedef-cli.
The checksums.txt file from GitHub releases uses the format:
<sha256> <filename>
For example:
abc123... typedef-cli-darwin-arm64.tar.gz
def456... typedef-cli-darwin-amd64.tar.gz
ghi789... typedef-cli-linux-arm64.tar.gz
jkl012... typedef-cli-linux-amd64.tar.gz
The generation script uses grep and awk to extract each checksum:
grep "typedef-cli-darwin-arm64.tar.gz" checksums.txt | awk '{print $1}'- Git tags: Use format
vX.X.X(with 'v' prefix, e.g.,v0.0.15) - Formula version: Uses
X.X.X(without 'v' prefix, e.g.,0.0.15) - Download URLs: Use
v${VERSION}(with 'v' prefix in the URL)
If the script reports missing checksums, verify:
- The checksums.txt file was downloaded correctly
- All 4 platform binaries exist in the release
- The filename format matches what the script expects
If brew audit reports issues:
- Check Ruby syntax in the template
- Verify all URLs are accessible
- Ensure SHA256 checksums are 64 hexadecimal characters
- Check that the test block is valid
If brew install fails:
- Check network connectivity to GitHub
- Verify the release exists and is public
- Ensure the tar.gz archive contains the
typedef-clibinary - Check Homebrew logs:
brew gist-logs typedef