|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Update Phel version in config.toml based on installed Phel package version |
| 5 | + */ |
| 6 | + |
| 7 | +$versionFinderFile = __DIR__ . '/../vendor/phel-lang/phel-lang/src/php/Console/Application/VersionFinder.php'; |
| 8 | +$configFile = __DIR__ . '/../config.toml'; |
| 9 | + |
| 10 | +if (!file_exists($versionFinderFile)) { |
| 11 | + echo "Error: VersionFinder.php not found. Make sure phel-lang/phel-lang is installed.\n"; |
| 12 | + exit(1); |
| 13 | +} |
| 14 | + |
| 15 | +if (!file_exists($configFile)) { |
| 16 | + echo "Error: config.toml not found\n"; |
| 17 | + exit(1); |
| 18 | +} |
| 19 | + |
| 20 | +// Read VersionFinder.php to extract LATEST_VERSION constant |
| 21 | +$versionFinderContent = file_get_contents($versionFinderFile); |
| 22 | + |
| 23 | +if (!$versionFinderContent) { |
| 24 | + echo "Error: Failed to read VersionFinder.php\n"; |
| 25 | + exit(1); |
| 26 | +} |
| 27 | + |
| 28 | +// Extract version from LATEST_VERSION constant |
| 29 | +$phelVersion = null; |
| 30 | +if (preg_match( |
| 31 | + '/public\s+const\s+string\s+LATEST_VERSION\s*=\s*[\'"]v?(\d+\.\d+\.\d+)[\'"]/', |
| 32 | + $versionFinderContent, |
| 33 | + $matches |
| 34 | +)) { |
| 35 | + $phelVersion = $matches[1]; |
| 36 | +} |
| 37 | + |
| 38 | +if (!$phelVersion) { |
| 39 | + echo "Warning: Could not determine Phel version from VersionFinder.php\n"; |
| 40 | + exit(0); |
| 41 | +} |
| 42 | + |
| 43 | +// Read config.toml |
| 44 | +$configContent = file_get_contents($configFile); |
| 45 | + |
| 46 | +// Update version |
| 47 | +$updatedContent = preg_replace( |
| 48 | + '/^phel_version\s*=\s*"[^"]*"/m', |
| 49 | + 'phel_version = "' . $phelVersion . '"', |
| 50 | + $configContent |
| 51 | +); |
| 52 | + |
| 53 | +if ($updatedContent === $configContent) { |
| 54 | + echo "Phel version in config.toml is already up to date: $phelVersion\n"; |
| 55 | + exit(0); |
| 56 | +} |
| 57 | + |
| 58 | +// Write updated config |
| 59 | +file_put_contents($configFile, $updatedContent); |
| 60 | + |
| 61 | +echo "Updated Phel version in config.toml to: $phelVersion\n"; |
0 commit comments