Last active
September 21, 2022 06:58
-
-
Save filda/13f38fff3e63b06c07b235afbb2f5959 to your computer and use it in GitHub Desktop.
Read composer.lock file and generate useful commands to help install packages in another project
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 | |
$cmsJsonFile = file_get_contents('composer.json'); | |
$cmsJsonArray = json_decode($cmsJsonFile, true); | |
$libsLockFile = file_get_contents('../libraries/composer.lock'); | |
$libsLockArray = json_decode($libsLockFile, true); | |
$cmsRequires = $cmsJsonArray['require']; | |
$libsPackages = $libsLockArray['packages']; | |
foreach ($libsPackages as $package) { | |
$name = $package['name']; | |
$version = $package['version']; | |
if (!array_key_exists($name, $cmsRequires)) { | |
if (in_array($version, ['dev-master', 'master'])) { | |
$hash = $package['source']['reference'] ?? $package['dist']['reference']; | |
$version .= '#' . $hash; | |
} | |
echo 'composer require ' . $name . ':' . $version . " --ignore-platform-reqs\n"; | |
} else { | |
echo 'Package "' . $name . '" already required. Cms version "' . $cmsRequires[$name] . '" Libraries version "' . $version . "\"\n"; | |
} | |
echo 'diff -r vendor/' .$name. '/ ../libraries/' . $name . '/' . "\n"; | |
echo "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run from
/vagrant-src/cms4
folder