-
-
Save chx/c0d506a7d870258a49f08e20bddfce3e to your computer and use it in GitHub Desktop.
composer branch recalc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Raise/update static version numbers in composer.json. | |
* | |
* Run on the CLI: "composer outdated --direct > outdated.txt" | |
*/ | |
$composerJson = json_decode(file_get_contents('composer.json'), true); | |
$listOfOutdatedPackages = file('outdated.txt'); | |
foreach($listOfOutdatedPackages as $line) { | |
$regexp = '#(?P<package>[\w-]+/[\w-]+).* (?P<currentVersion>\d+\.\d).*~ (?P<latestVersion>\d+\.\d)#'; | |
preg_match($regexp, $line, $matches); | |
$matches = array_filter($matches, 'is_string', ARRAY_FILTER_USE_KEY); | |
if(isset($matches['package'])) | |
{ | |
$package = $matches['package']; | |
if(isset($composerJson['require'][$package])) | |
{ | |
$currentVersion = $composerJson['require'][$package]; | |
echo sprintf('Updating %s from %s to %s', $package, $currentVersion, $matches['latestVersion']); | |
$composerJson['require'][$package] = '~' . $matches['latestVersion']; | |
} | |
if(isset($composerJson['require-dev'][$package])) | |
{ | |
$currentVersion = $composerJson['require-dev'][$package]; | |
echo sprintf('Updating %s from %s to %s', $package, $currentVersion, $matches['latestVersion']); | |
$composerJson['require-dev'][$package] = $matches['latestVersion']; | |
} | |
} | |
} | |
file_put_contents('composer.json', json_encode($composerJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment