|
@@ -3,16 +3,25 @@
|
|
|
use Symfony\Component\Yaml\Yaml;
|
|
|
|
|
|
function composer_check_drush_command() {
|
|
|
- $cmds['lock'] = [
|
|
|
+ $cmds['composer-check'] = [
|
|
|
+ 'aliases' => ['cc'],
|
|
|
+ 'description' => 'Lists the packages requested in composer.json and the matching locked version.',
|
|
|
'arguments' => [
|
|
|
- 'lock file' => 'The path to the lock file. Defaults to the one in drupal root.',
|
|
|
+ 'composer.lock' => 'The path to the lock file. Defaults to the one in drupal root.',
|
|
|
+ ],
|
|
|
+ 'options' => [
|
|
|
+ 'all' => [
|
|
|
+ 'description' => 'List all locked packages, even those not requested',
|
|
|
+ 'required' => FALSE,
|
|
|
+ ],
|
|
|
+ 'yaml' => 'Produce YAML output instead of a table',
|
|
|
],
|
|
|
];
|
|
|
|
|
|
return $cmds;
|
|
|
}
|
|
|
|
|
|
-function drush_composer_check_lock($path = NULL) {
|
|
|
+function drush_composer_check($path = NULL) {
|
|
|
if (empty($path)) {
|
|
|
$path = DRUPAL_ROOT . '/composer.lock';
|
|
|
}
|
|
@@ -33,28 +42,37 @@ function drush_composer_check_lock($path = NULL) {
|
|
|
$lockPackages = $lock['packages'];
|
|
|
$lockDevPackages = $lock['packages-dev'];
|
|
|
|
|
|
+ $all = !!drush_get_option('all');
|
|
|
$packages = ['dev' => [], 'run' => []];
|
|
|
foreach ($jsonPackages as $package => $requirement) {
|
|
|
- $packages['run'][$package]['requirement'] = $requirement;
|
|
|
+ if ($all || !empty($requirement)) {
|
|
|
+ $packages['run'][$package]['requirement'] = $requirement;
|
|
|
+ }
|
|
|
}
|
|
|
foreach ($jsonDevPackages as $package => $requirement) {
|
|
|
- $packages['dev'][$package] = $requirement;
|
|
|
+ if ($all || !empty($requirement)) {
|
|
|
+ $packages['dev'][$package] = $requirement;
|
|
|
+ }
|
|
|
}
|
|
|
foreach ($lockPackages as $packageInfo) {
|
|
|
$package = $packageInfo['name'];
|
|
|
- $version = $packageInfo['version'];
|
|
|
- $packages['run'][$package]['version'] = $version;
|
|
|
+ if ($all || !empty($packages['run'][$package])) {
|
|
|
+ $version = $packageInfo['version'];
|
|
|
+ $packages['run'][$package]['version'] = $version;
|
|
|
+ }
|
|
|
}
|
|
|
foreach ($lockDevPackages as $packageInfo) {
|
|
|
$package = $packageInfo['name'];
|
|
|
- $version = $packageInfo['version'];
|
|
|
- $packages['dev'][$package]['version'] = $version;
|
|
|
+ if ($all || !empty($packages['dev'][$package])) {
|
|
|
+ $version = $packageInfo['version'];
|
|
|
+ $packages['dev'][$package]['version'] = $version;
|
|
|
+ }
|
|
|
}
|
|
|
ksort($packages['dev']);
|
|
|
ksort($packages['run']);
|
|
|
|
|
|
- if (drush_get_option('pipe')) {
|
|
|
- drush_print(Yaml::dump($packages));
|
|
|
+ if (drush_get_option('yaml')) {
|
|
|
+ echo Yaml::dump($packages, 3);
|
|
|
}
|
|
|
else {
|
|
|
_composer_check_output_human($packages);
|
|
@@ -62,7 +80,7 @@ function drush_composer_check_lock($path = NULL) {
|
|
|
}
|
|
|
|
|
|
function _composer_check_output_human($packages) {
|
|
|
- $header = ['Kind', 'Name', 'Requirement', 'Version'];
|
|
|
+ $header = ['Name', 'Kind', 'Requirement', 'Version'];
|
|
|
$rows = [$header];
|
|
|
foreach ($packages as $kind => $kindPackages) {
|
|
|
foreach ($kindPackages as $package => $info) {
|