From 19f34d1a72b5688b250636c970ef01223a86401b Mon Sep 17 00:00:00 2001 From: bruno DA SILVA Date: Thu, 5 Mar 2020 11:29:53 +0100 Subject: [PATCH] composer reflexion: list outdated packages --- .make/composer/listOutdated.php | 98 +++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 .make/composer/listOutdated.php diff --git a/.make/composer/listOutdated.php b/.make/composer/listOutdated.php new file mode 100644 index 000000000..f67a2fcf2 --- /dev/null +++ b/.make/composer/listOutdated.php @@ -0,0 +1,98 @@ + + * + */ + +$iTopFolder = __DIR__ . "/../../" ; + +require_once ("$iTopFolder/approot.inc.php"); +$sApproot = APPROOT; +$aTrace = array(); + +$aParamsConfig = array( + 'composer-path' => array( + 'default' => 'composer.phar', + ) +); +$aParamsConfigNotFound = array_flip(array_keys($aParamsConfig)); +$aGivenArgs = $argv; +unset($aGivenArgs[0]); + +$aParams = array(); + +foreach ($aParamsConfig as $sParam => $aConfig) +{ + $bParamsFound = false; + foreach ($aGivenArgs as $sGivenArg) + { + if (preg_match("/--$sParam(?:=(?.*))?$/", $sGivenArg, $aMatches)) + { + $aParams[$sParam] = + isset($aMatches['value']) + ? $aMatches['value'] + : true + ; + $bParamsFound = true; + unset($aGivenArgs[$sGivenArg]); + + } + } + + if ($bParamsFound) + { + unset($aParamsConfigNotFound[$sParam]); + } +} + +foreach ($aParamsConfigNotFound as $sParamsConfigNotFound => $void) +{ + if (isset($aParamsConfig[$sParamsConfigNotFound]['default'])) + { + $aParams[$sParamsConfigNotFound] = $aParamsConfig[$sParamsConfigNotFound]['default']; + $aTrace[] = "\e[1;30mUsing default value '{$aParams[$sParamsConfigNotFound]}' for '$sParamsConfigNotFound'\e[0m\n"; + continue; + } + + die("Missing '$sParamsConfigNotFound'"); +} + +echo "This command aims at helping you find upgradable dependencies\n"; +echo "\e[0;33mBeware of the version colored in orange, they probably introduce BC breaks!\e[0m\n"; + +$sCommand = "{$aParams['composer-path']} show -loD --working-dir=$sApproot --ansi"; +$execCode = exec($sCommand, $output); +$sOutput = implode("\n", $output)."\n"; + +if (!$execCode) +{ + echo "\e[41mFailed to execute '$sCommand'\e[0m\n"; + echo "Trace: \n".implode("\n", $aTrace); +} +else +{ + $iCountDepdendenciesFound = count($output); + + $iCountBc = substr_count($sOutput, '[33m'); + + echo sprintf("Found \033[44m%d\033[0m upgradable dependencies, including \e[41m%s BC break\e[0m 😱 :\n\n", $iCountDepdendenciesFound, $iCountBc); +} + + +echo $sOutput; +