Created
September 17, 2019 08:19
-
-
Save shengjie/2d0a544ac21223af604a6bd2f952ff34 to your computer and use it in GitHub Desktop.
Update composer lock given package reference fastly
This file contains hidden or 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 | |
$lockFile = $argv[1]; | |
$packageName = $argv[2]; | |
$ref = $argv[3]; | |
if ($argc !== 4) { | |
echo "Usage update_lock.php composer.lock mypackage 123abc\n"; | |
exit; | |
} | |
$lockData = json_decode(file_get_contents($lockFile), true); | |
foreach($lockData['packages'] as &$package) { | |
if ($package['name'] === $packageName) { | |
$package['source']['reference'] = $ref; | |
$package['dist']['url'] = sprintf('https://api.github.com/repos/%s/zipball/%s', $packageName, $ref); | |
$package['dist']['reference'] = $ref; | |
} | |
} | |
file_put_contents($lockFile, json_encode($lockData, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES). PHP_EOL); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment