composer_check.drush.inc 1.4 KB

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