# HyperFields Version Bump Script

## Overview

The `scripts/version-bump.sh` script automates version updates across all files in the HyperFields library.

## Files Updated

When you run `composer version-bump`, the following files are updated:

### 1. ✅ composer.json
**Line**: `"version": "X.Y.Z"`
- Main version declaration for the PHP package

### 2. ✅ package.json
**Line**: `"version": "X.Y.Z"`
- Version for React assets (npm package)
- **Location**: `/package.json`

### 3. ✅ bootstrap.php
- Updates the single-source default version constant:
  - `define('HYPERFIELDS_DEFAULT_VERSION', 'X.Y.Z');`
- Legacy-safe behavior: also replaces any remaining exact old-version literals.
- **Note**: this default is used when composer.json cannot be read.

### 4. ✅ src/OptionsPage.php
**Lines**: 860, 905, 927
- Version fallbacks for asset loading:
  - `defined('HYPERPRESS_VERSION') ? HYPERPRESS_VERSION : '2.0.7'`
  - `defined('HYPERPRESS_VERSION') ? HYPERPRESS_VERSION : '2.1.0'`
- **Note**: These are fallbacks when HYPERPRESS_VERSION constant is not defined

### 5. ✅ WordPress Plugin Headers (if present)
- `hyppress.php`
- `api-for-htmx.php`
- `hyperfields.php`
- `hyperblocks.php`
- **Pattern**: ` * Version: X.Y.Z`

## How It Works

1. **Detects current version** from `composer.json`
2. **Prompts for new version** (semantic versioning: X.Y.Z)
3. **Validates input** (format checking, must be different from current)
4. **Updates all files** using cross-platform `sed` command
5. **Displays confirmation** with checklist of updated files

## Usage

```bash
# Run the script
composer version-bump

# Example output:
┌─────────────────────────────────────┐
│   HyperFields Version Bump
└─────────────────────────────────────┘

  Current version: 1.1.12

  Enter new version (X.Y.Z): 1.2.0

  Bumping: 1.1.12 -> 1.2.0

  ✓ composer.json
  ✓ package.json
  ✓ bootstrap.php (default/fallback versions)
  ✓ src/OptionsPage.php (fallback versions)

┌─────────────────────────────────────┐
│  Version bumped to 1.2.0
└─────────────────────────────────────┘

  Next steps:
    1. Update changelog/release notes
    2. composer production
    3. git add -A && git commit -m 'Bump version to 1.2.0'
```

## Platform Support

The script is cross-platform:
- ✅ **Linux** (GNU sed)
- ✅ **macOS** (BSD sed via `-i ''` flag)
- ✅ **Windows** (Git Bash, WSL, Cygwin)

## Validation

The script enforces:
- **Semantic versioning format**: `X.Y.Z` (e.g., `1.2.3`)
- **Non-empty version**: Cannot be empty
- **Different version**: Must differ from current version
- **Valid numbers**: Must be numeric version parts

## Integration with Composer Production

The version bump is now integrated with the production build:

```bash
# Full production workflow
composer version-bump        # 1. Bump version
composer production           # 2. Build React assets + optimize Composer
git add -A && git commit      # 3. Commit changes
git tag v$(awk -F'"' '/"version":/{print $4; exit}' composer.json)  # 4. Tag release
```

## Troubleshooting

### Script fails with "permission denied"
```bash
chmod +x scripts/version-bump.sh
```

### "sed: command not found" error
- Ensure `sed` is installed (standard on Unix-like systems)
- Windows users: Use Git Bash or WSL, not CMD/PowerShell

### Version not updated in all files
- Check file permissions
- Verify files exist at expected paths
- Look for "✓" confirmation marks in script output

## Files NOT Updated (Intentionally)

The following files are intentionally NOT updated by the script:

- **package-lock.json** - Auto-generated by npm, don't edit manually
- **composer.lock** - Auto-generated by Composer, don't edit manually
- **Test files** - Test mocks/fixtures should use explicit versions
- **README.md** - Documentation updates are manual
- **CHANGELOG.md** - Changelog entries require human-written content

## Version Strategy

HyperFields follows **Semantic Versioning 2.0.0**:

- **MAJOR** (X): Breaking changes, API changes
- **MINOR** (Y): New features, backward-compatible additions
- **PATCH** (Z): Bug fixes, minor improvements

Example:
- `1.1.12` → `1.2.0`: Added React integration (new feature)
- `1.2.0` → `1.2.1`: Bug fix in React component
- `1.2.1` → `2.0.0`: Breaking change to Field API
