Files
shopify-ai-backup/VERSION_MANAGEMENT.md
southseact-3d 0513000a9e Fix builder page layout: make new chat and history buttons sticky at top on desktop
- Moved sticky positioning from mobile-only to global CSS for .top-left-actions

- Buttons now stay fixed at top above content on all screen sizes

- Includes various other app updates (version management, server improvements)
2026-02-11 19:23:23 +00:00

144 lines
4.0 KiB
Markdown

# WordPress Plugin Version Management - Implementation Summary
## Overview
Automatic version number management for WordPress plugins has been implemented. The system now detects versions from plugin files, tracks version history, and automatically bumps versions when exporting ZIP files.
## Files Created/Modified
### New Files
1. **`chat/src/utils/versionManager.js`** - Core version management utilities
2. **`chat/src/utils/versionManager.test.js`** - Unit tests for version manager
### Modified Files
1. **`chat/server.js`**
- Added version tracking to session object (lines ~7641-7658)
- Added version manager import (line ~20)
- Modified `handleExportZip()` to detect and bump versions (lines ~16944-17138)
- Modified `handleUploadApp()` to detect version from imported plugins (lines ~16837-16889)
- Updated `serializeSession()` to include version fields (lines ~7463-7481)
## Features Implemented
### 1. Automatic Version Detection
- Detects version from WordPress plugin headers (`Version: X.X.X`)
- Detects version from PHP constants (`define('CONSTANT_NAME', 'X.X.X')`)
- Works with imported plugins of any version number
### 2. Version Bumping
- Automatically bumps patch version on export (1.0.0 → 1.0.1)
- Supports major, minor, patch, and keep bump types
- Tracks bump history in session
### 3. Imported Plugin Support
- Detects existing version from uploaded ZIP files
- Preserves original version number on import
- Maintains version continuity for imported plugins
### 4. Version History Tracking
```javascript
session.pluginVersionHistory = [
{
version: '1.0.1',
previousVersion: '1.0.0',
bumpType: 'patch',
timestamp: '2026-02-11T10:30:00.000Z',
fileUpdated: 'my-plugin/my-plugin.php'
}
]
```
### 5. Session Data
```javascript
session.pluginVersion = '1.2.3'; // Current version
session.lastVersionBumpType = 'patch'; // Last bump type
session.pluginVersionHistory = []; // Full history
```
## How It Works
### Export Flow
1. User clicks "Export ZIP"
2. System finds main plugin PHP file
3. Extracts current version (from session or file)
4. Bumps version number (patch by default)
5. Updates version in plugin file content
6. Adds updated file to ZIP archive
7. Tracks version change in session history
### Import Flow
1. User uploads ZIP file
2. System extracts files to workspace
3. Searches for main plugin file
4. Extracts version from plugin header/constants
5. Stores detected version in session
6. Records import event in version history
## Version Formats Supported
### Plugin Headers
```php
/**
* Plugin Name: My Plugin
* Version: 1.2.3
*/
```
### PHP Constants
```php
define('MY_PLUGIN_VERSION', '1.2.3');
define( "PLUGIN_VERSION", "2.0.0" );
```
### PHP Const Assignments
```php
const PLUGIN_VERSION = '1.2.3';
```
## API Response Changes
Sessions now include version fields:
```json
{
"session": {
"id": "...",
"pluginVersion": "1.2.4",
"pluginVersionHistory": [...],
"lastVersionBumpType": "patch"
}
}
```
## Future Enhancements (Optional)
1. **UI Controls**: Add version bump selector in export UI (major/minor/patch/custom)
2. **Changelog Generation**: Auto-generate changelog entries with AI
3. **Version Strategy**: Let AI analyze changes and suggest appropriate bump type
4. **Multi-file Updates**: Update version in all plugin files, not just main file
5. **readme.txt Support**: Update version in WordPress.org readme.txt format
## Testing
Run unit tests:
```bash
cd chat/src/utils
node versionManager.test.js
```
All tests pass:
- ✓ parseVersion
- ✓ formatVersion
- ✓ bumpVersion
- ✓ extractHeaderVersion
- ✓ extractDefineVersion
- ✓ extractAllVersions
- ✓ updateVersionInContent
- ✓ isWordPressPluginFile
- ✓ getPluginSlugFromPath
## Backwards Compatibility
- Plugins without version detection start at 1.0.0
- Existing sessions without version data will detect from file on first export
- Import works with any plugin structure or version format
- Graceful fallback if version detection fails