Browse Source

Document command.

Frederic G. MARAND 7 years ago
parent
commit
a31ede62a1
3 changed files with 35 additions and 6 deletions
  1. 2 0
      .gitignore
  2. 27 0
      README.md
  3. 6 6
      composer_check.drush.inc

+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
+/.idea/
+/vendor/

+ 27 - 0
README.md

@@ -0,0 +1,27 @@
+# Drupal Composer check
+
+This Drush plugin provides a `composer-check` (alias `cc`) command, which 
+compares the packages versions in `composer.lock` with those requested in the
+`composer.json` file of a Drupal 8 project.
+
+
+## Syntax
+
+* Arguments:
+  * `composer.lock`: Optional. The path to the lock file. Defaults to the one in 
+    Drupal root.
+* Options:
+  * `--all`: List all locked packages, even those not requested
+  * `--yaml`: Produce YAML output instead of a table
+* Aliases: `cc`
+
+
+# Examples
+
+* Default usage in a `drupal/drupal` project:
+
+      drush cc
+
+* Listing all packages in a `drupal-composer/drupal-project` project, in YAML format:
+
+      drush cc --all --yaml $PWD/composer.lock

+ 6 - 6
composer_check.drush.inc

@@ -21,15 +21,15 @@ function composer_check_drush_command() {
   return $cmds;
 }
 
-function drush_composer_check($path = NULL) {
-  if (empty($path)) {
-    $path = DRUPAL_ROOT . '/composer.lock';
+function drush_composer_check($lockPath = NULL) {
+  if (empty($lockPath)) {
+    $lockPath = DRUPAL_ROOT . '/composer.lock';
   }
-  if (!is_file($path) && is_readable($path)) {
+  if (!is_file($lockPath) && is_readable($lockPath)) {
     drush_die("Cannot read lock file");
   }
 
-  $jsonPath = dirname($path) . '/composer.json';
+  $jsonPath = dirname($lockPath) . '/composer.json';
   if (!is_file($jsonPath) && is_readable($jsonPath)) {
     drush_die("Cannot read json file");
   }
@@ -38,7 +38,7 @@ function drush_composer_check($path = NULL) {
   $jsonPackages = $json['require'] ?? [];
   $jsonDevPackages = $json['require-dev'] ?? [];
 
-  $lock = json_decode(file_get_contents($path), TRUE);
+  $lock = json_decode(file_get_contents($lockPath), TRUE);
   $lockPackages = $lock['packages'];
   $lockDevPackages = $lock['packages-dev'];