composer_check.drush.inc 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * @file
  4. * A Drush plugin to compare composer.json and composer.lock.
  5. */
  6. use Drupal\Component\Utility\Unicode;
  7. use Fgm\ComposerCheck\DrushReporter;
  8. use Fgm\ComposerCheck\LoaderFactory;
  9. use Fgm\ComposerCheck\YamlReporter;
  10. use Symfony\Component\Yaml\Yaml;
  11. /**
  12. * Implements hook_drush_command().
  13. */
  14. function composer_check_drush_command() {
  15. $cmds['composer-check'] = [
  16. 'aliases' => ['cck'],
  17. 'description' => 'Lists the packages requested in composer.json and the matching locked version.',
  18. 'arguments' => [
  19. 'composer.lock' => 'The path to the lock file. Defaults to the one in drupal root.',
  20. ],
  21. 'options' => [
  22. 'all' => [
  23. 'description' => 'List all locked packages, even those not requested',
  24. 'required' => FALSE,
  25. ],
  26. 'yaml' => 'Produce YAML output instead of a table',
  27. ],
  28. ];
  29. return $cmds;
  30. }
  31. /**
  32. * Command callback for composer-check.
  33. *
  34. * @param null|string $path
  35. * Optional. The path to a directory holding a composer.[json|lock] file pair.
  36. */
  37. function drush_composer_check($path = DRUPAL_ROOT) {
  38. $all = !!drush_get_option('all');
  39. $useYaml = !!drush_get_option('yaml');
  40. $factory = new LoaderFactory($path, $all);
  41. $requirementsLoader = $factory->createLoader('requirements');
  42. $lockLoader = $factory->createLoader('lock');
  43. $merger = new Merger($requirementsLoader, $lockLoader);
  44. $reporter = $useYaml ? new YamlReporter() : new DrushReporter();
  45. $reporter->report($merger);
  46. }