|
@@ -6,6 +6,9 @@
|
|
|
*/
|
|
|
|
|
|
use Drupal\Component\Utility\Unicode;
|
|
|
+use Fgm\ComposerCheck\DrushReporter;
|
|
|
+use Fgm\ComposerCheck\LoaderFactory;
|
|
|
+use Fgm\ComposerCheck\YamlReporter;
|
|
|
use Symfony\Component\Yaml\Yaml;
|
|
|
|
|
|
/**
|
|
@@ -33,98 +36,19 @@ function composer_check_drush_command() {
|
|
|
/**
|
|
|
* Command callback for composer-check.
|
|
|
*
|
|
|
- * @param null|string $lockPath
|
|
|
- * Optional. The path to a composer.lock file.
|
|
|
+ * @param null|string $path
|
|
|
+ * Optional. The path to a directory holding a composer.[json|lock] file pair.
|
|
|
*/
|
|
|
-function drush_composer_check($lockPath = NULL) {
|
|
|
- if (empty($lockPath)) {
|
|
|
- $lockPath = DRUPAL_ROOT . '/composer.lock';
|
|
|
- }
|
|
|
- if (!is_file($lockPath) && is_readable($lockPath)) {
|
|
|
- drush_die("Cannot read lock file");
|
|
|
- }
|
|
|
-
|
|
|
- $jsonPath = dirname($lockPath) . '/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'] ?? [];
|
|
|
-
|
|
|
- $lockFile = json_decode(file_get_contents($lockPath), TRUE);
|
|
|
- $lockPackages = $lockFile['packages'];
|
|
|
- $lockDevPackages = $lockFile['packages-dev'];
|
|
|
-
|
|
|
- $lockPlatform = $lockFile['platform'];
|
|
|
- array_walk($lockPlatform, function (&$requirement, $component) {
|
|
|
- $requirement = [
|
|
|
- 'name' => $component,
|
|
|
- 'version' => $requirement,
|
|
|
- ];
|
|
|
- });
|
|
|
- $lockPackages = array_merge($lockPackages, $lockPlatform);
|
|
|
- $lockDevPackages = array_merge($lockDevPackages, $lockPlatform);
|
|
|
-
|
|
|
+function drush_composer_check($path = DRUPAL_ROOT) {
|
|
|
$all = !!drush_get_option('all');
|
|
|
- $packages = ['dev' => [], 'run' => []];
|
|
|
- foreach ($jsonPackages as $package => $requirement) {
|
|
|
- if ($all || !empty($requirement)) {
|
|
|
- $package = Unicode::strtolower($package);
|
|
|
- $packages['run'][$package]['requirement'] = $requirement;
|
|
|
- }
|
|
|
- }
|
|
|
- foreach ($jsonDevPackages as $package => $requirement) {
|
|
|
- if ($all || !empty($requirement)) {
|
|
|
- $package = Unicode::strtolower($package);
|
|
|
- $packages['dev'][$package]['requirement'] = $requirement;
|
|
|
- }
|
|
|
- }
|
|
|
- foreach ($lockPackages as $packageInfo) {
|
|
|
- $package = Unicode::strtolower($packageInfo['name']);
|
|
|
- if ($all || !empty($packages['run'][$package])) {
|
|
|
- $version = $packageInfo['version'];
|
|
|
- $packages['run'][$package]['version'] = $version;
|
|
|
- }
|
|
|
- }
|
|
|
- foreach ($lockDevPackages as $packageInfo) {
|
|
|
- $package = Unicode::strtolower($packageInfo['name']);
|
|
|
- if ($all || !empty($packages['dev'][$package])) {
|
|
|
- $version = $packageInfo['version'];
|
|
|
- $packages['dev'][$package]['version'] = $version;
|
|
|
- }
|
|
|
- }
|
|
|
- ksort($packages['dev']);
|
|
|
- ksort($packages['run']);
|
|
|
+ $useYaml = !!drush_get_option('yaml');
|
|
|
|
|
|
- if (drush_get_option('yaml')) {
|
|
|
- echo Yaml::dump($packages, 3);
|
|
|
- return;
|
|
|
- }
|
|
|
+ $factory = new LoaderFactory($path, $all);
|
|
|
+ $requirementsLoader = $factory->createLoader('requirements');
|
|
|
+ $lockLoader = $factory->createLoader('lock');
|
|
|
|
|
|
- _composer_check_output_human($packages);
|
|
|
-}
|
|
|
+ $merger = new Merger($requirementsLoader, $lockLoader);
|
|
|
|
|
|
-/**
|
|
|
- * Display a package comparison as a text table.
|
|
|
- *
|
|
|
- * @param array $packages
|
|
|
- * A package comparison array.
|
|
|
- */
|
|
|
-function _composer_check_output_human($packages) {
|
|
|
- $header = ['Name', 'Kind', '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);
|
|
|
+ $reporter = $useYaml ? new YamlReporter() : new DrushReporter();
|
|
|
+ $reporter->report($merger);
|
|
|
}
|