Jelajahi Sumber

Fix bin path.

Frederic G. MARAND 7 tahun lalu
induk
melakukan
68f4ec6846
2 mengubah file dengan 38 tambahan dan 3 penghapusan
  1. 37 2
      bin/composer-check.php
  2. 1 1
      composer.json

+ 37 - 2
bin/composer-check.php

@@ -2,13 +2,48 @@
 <?php
 namespace Fgm\ComposerCheck;
 
-require_once __DIR__ . '/../vendor/autoload.php';
+/**
+ * Guess the path where the Composer autoloader is available.
+ *
+ * TODO find a better logic.
+ *
+ * @return string
+ *   The path to the
+ */
+function setupAutoload($debug = FALSE) {
+  $runningFrom = [
+    // Straight git clone, then composer install.
+    "git clone" => __DIR__ . '/../vendor',
+    // Composer install as drush plugin with default config/bin.
+    "composer default" => __DIR__ . '/../../../../vendor',
+  ];
+
+  foreach ($runningFrom as $kind => $location) {
+    $path = "${location}/autoload.php";
+    if (is_file($path) && is_readable($path)) {
+      $autoloader = include_once $path;
+      if ($autoloader instanceof \Composer\Autoload\ClassLoader) {
+        if ($debug) {
+          echo "Install appears to be: $kind\n";
+        }
+        break;
+      }
+    }
+  }
+
+  return realpath(dirname($location));
+}
 
 // TODO use options.
 $all = FALSE;
+$debug = TRUE;
 $useYaml = TRUE;
 
-$factory = new LoaderFactory(__DIR__ . '/..', $all);
+$path = setupAutoload($debug);
+if (empty($path)) {
+  die("Autoloader not found.");
+}
+$factory = new LoaderFactory($path, $all);
 
 $requirementsLoader = $factory->createLoader('requirements');
 $requirementsLoader->load();

+ 1 - 1
composer.json

@@ -4,7 +4,7 @@
       "Fgm\\ComposerCheck\\": "ComposerCheck/"
     }
   },
-  "bin": ["composer-check.php"],
+  "bin": ["bin/composer-check.php"],
   "description": "A Drush plugin to check installed versus requested versions of vendor packages in Drupal 8 projects.",
   "homepage": "http://code.osinet.fr/fgm/drush_plugin__composer_check",
   "keywords": ["composer", "drupal", "drush", "update", "versions"],