Parcourir la source

Simple initial version.

Frederic G. MARAND il y a 8 ans
Parent
commit
5a60cc8cdc
2 fichiers modifiés avec 93 ajouts et 0 suppressions
  1. 14 0
      composer.json
  2. 79 0
      composer_check.drush.inc

+ 14 - 0
composer.json

@@ -0,0 +1,14 @@
+{
+  "name": "drupal/composer_check",
+  "type": "drupal-drush",
+  "description": "Checked installed versus requested versions of vendor packages.",
+  "keywords": ["Composer", "update", "versions"],
+  "license": "GPL-2.0+",
+  "homepage": "https://www.drupal.org/project/composer_check",
+  "minimum-stability": "dev",
+  "support": {
+    "issues": "http://drupal.org/project/issues/composer_check",
+    "source": "http://cgit.drupalcode.org/composer_check"
+  },
+  "require": { }
+}

+ 79 - 0
composer_check.drush.inc

@@ -0,0 +1,79 @@
+<?php
+
+use Symfony\Component\Yaml\Yaml;
+
+function composer_check_drush_command() {
+  $cmds['lock'] = [
+    'arguments' => [
+      'lock file' => 'The path to the lock file. Defaults to the one in drupal root.',
+    ],
+  ];
+
+  return $cmds;
+}
+
+function drush_composer_check_lock($path = NULL) {
+  if (empty($path)) {
+    $path = DRUPAL_ROOT . '/composer.lock';
+  }
+  if (!is_file($path) && is_readable($path)) {
+    drush_die("Cannot read lock file");
+  }
+
+  $jsonPath = dirname($path) . '/composer.json';
+  if (!is_file($jsonPath) && is_readable($jsonPath)) {
+    drush_die("Cannot read json file");
+  }
+
+  $json = json_decode(file_get_contents($jsonPath), TRUE);
+  $jsonPackages = $json['require'] ?? [];
+  $jsonDevPackages = $json['require-dev'] ?? [];
+
+  $lock = json_decode(file_get_contents($path), TRUE);
+  $lockPackages = $lock['packages'];
+  $lockDevPackages = $lock['packages-dev'];
+
+  $packages = ['dev' => [], 'run' => []];
+  foreach ($jsonPackages as $package => $requirement) {
+    $packages['run'][$package]['requirement'] = $requirement;
+  }
+  foreach ($jsonDevPackages as $package => $requirement) {
+    $packages['dev'][$package] = $requirement;
+  }
+  foreach ($lockPackages as $packageInfo) {
+    $package = $packageInfo['name'];
+    $version = $packageInfo['version'];
+    $packages['run'][$package]['version'] = $version;
+  }
+  foreach ($lockDevPackages as $packageInfo) {
+    $package = $packageInfo['name'];
+    $version = $packageInfo['version'];
+    $packages['dev'][$package]['version'] = $version;
+  }
+  ksort($packages['dev']);
+  ksort($packages['run']);
+
+  if (drush_get_option('pipe')) {
+    drush_print(Yaml::dump($packages));
+  }
+  else {
+    _composer_check_output_human($packages);
+  }
+}
+
+function _composer_check_output_human($packages) {
+  $header = ['Kind', 'Name', 'Requirement', 'Version'];
+  $rows = [$header];
+  foreach ($packages as $kind => $kindPackages) {
+    foreach ($kindPackages as $package => $info) {
+      $rows["$package/$kind"] = [
+        $package,
+        $kind,
+        $info['requirement'] ?? '',
+        $info['version'] ?? ''
+      ];
+    }
+  }
+  ksort($rows);
+  drush_print_table($rows, FALSE);
+}