update-dependencies 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env php
  2. <?php
  3. /**
  4. * Raise/update static version numbers in composer.json.
  5. *
  6. * Run on the CLI: "composer outdated --direct > outdated.txt"
  7. */
  8. $composerJson = json_decode(file_get_contents('composer.json'), true);
  9. system('composer outdated --direct > outdated.txt');
  10. $listOfOutdatedPackages = file('outdated.txt');
  11. foreach($listOfOutdatedPackages as $line) {
  12. $regexp = '/(?P<package>[\w]+\/[\w]+).*(?P<currentVersion>\d.\d.\d).*(?P<latestVersion>\d.\d.\d)/';
  13. preg_match($regexp, $line, $matches);
  14. $matches = array_filter($matches, 'is_string', ARRAY_FILTER_USE_KEY);
  15. if(isset($matches['package']))
  16. {
  17. $package = $matches['package'];
  18. if(isset($composerJson['require'][$package]))
  19. {
  20. $currentVersion = $composerJson['require'][$package];
  21. echo sprintf('Updating %s from %s to %s', $package, $currentVersion, $matches['latestVersion']);
  22. $composerJson['require'][$package] = $matches['latestVersion'];
  23. }
  24. if(isset($composerJson['require-dev'][$package]))
  25. {
  26. $currentVersion = $composerJson['require-dev'][$package];
  27. echo sprintf('Updating %s from %s to %s', $package, $currentVersion, $matches['latestVersion']);
  28. $composerJson['require-dev'][$package] = $matches['latestVersion'];
  29. }
  30. }
  31. }
  32. file_put_contents('composer.json', json_encode($composerJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));