-
-
Save wotaen/03a32eb907b3af6f20d5d565a2e51ba1 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'])) { | |
$version = $package['source']['reference'] ?? $package['dist']['reference']; | |
} | |
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