|
@@ -0,0 +1,79 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+use Symfony\Component\Yaml\Yaml;
|
|
|
+
|
|
|
+function composer_check_drush_command() {
|
|
|
+ $cmds['lock'] = [
|
|
|
+ 'arguments' => [
|
|
|
+ 'lock file' => 'The path to the lock file. Defaults to the one in drupal root.',
|
|
|
+ ],
|
|
|
+ ];
|
|
|
+
|
|
|
+ return $cmds;
|
|
|
+}
|
|
|
+
|
|
|
+function drush_composer_check_lock($path = NULL) {
|
|
|
+ if (empty($path)) {
|
|
|
+ $path = DRUPAL_ROOT . '/composer.lock';
|
|
|
+ }
|
|
|
+ if (!is_file($path) && is_readable($path)) {
|
|
|
+ drush_die("Cannot read lock file");
|
|
|
+ }
|
|
|
+
|
|
|
+ $jsonPath = dirname($path) . '/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'] ?? [];
|
|
|
+
|
|
|
+ $lock = json_decode(file_get_contents($path), TRUE);
|
|
|
+ $lockPackages = $lock['packages'];
|
|
|
+ $lockDevPackages = $lock['packages-dev'];
|
|
|
+
|
|
|
+ $packages = ['dev' => [], 'run' => []];
|
|
|
+ foreach ($jsonPackages as $package => $requirement) {
|
|
|
+ $packages['run'][$package]['requirement'] = $requirement;
|
|
|
+ }
|
|
|
+ foreach ($jsonDevPackages as $package => $requirement) {
|
|
|
+ $packages['dev'][$package] = $requirement;
|
|
|
+ }
|
|
|
+ foreach ($lockPackages as $packageInfo) {
|
|
|
+ $package = $packageInfo['name'];
|
|
|
+ $version = $packageInfo['version'];
|
|
|
+ $packages['run'][$package]['version'] = $version;
|
|
|
+ }
|
|
|
+ foreach ($lockDevPackages as $packageInfo) {
|
|
|
+ $package = $packageInfo['name'];
|
|
|
+ $version = $packageInfo['version'];
|
|
|
+ $packages['dev'][$package]['version'] = $version;
|
|
|
+ }
|
|
|
+ ksort($packages['dev']);
|
|
|
+ ksort($packages['run']);
|
|
|
+
|
|
|
+ if (drush_get_option('pipe')) {
|
|
|
+ drush_print(Yaml::dump($packages));
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ _composer_check_output_human($packages);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function _composer_check_output_human($packages) {
|
|
|
+ $header = ['Kind', 'Name', '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);
|
|
|
+}
|