function drush_make_convert_composer_to_make

master make.drush.inc drush_make_convert_composer_to_make($composer_lock, $composer_json)

Converts a composer.lock array into a traditional drush make array.

Parameters

array $composer_lock: An array of composer.lock data.

array $composer_json: An array of composer.json data.

Return value

array A traditional drush make info array. A traditional drush make info array.

1 call to drush_make_convert_composer_to_make()
drush_make_convert in commands/make/make.drush.inc
Command callback; convert make file format.

File

commands/make/make.drush.inc, line 605
Drush Make commands.

Code

function drush_make_convert_composer_to_make($composer_lock, $composer_json) {
  $info = array(
    'core' => array(),
    'api' => 2,
    'defaults' => array(
      'projects' => array(
        'subdir' => 'contrib',
      ),
    ),
    'projects' => array(),
    'libraries' => array(),
  );

  // The make generation function requires that projects be grouped by type,
  // or else duplicative project groups will be created.
  $core = array();
  $modules = array();
  $themes = array();
  $profiles = array();
  $libraries = array();
  foreach ($composer_lock['packages'] as $key => $package) {
    if (strpos($package['name'], 'drupal/') === 0 && in_array($package['type'], array('drupal-core', 'drupal-theme', 'drupal-module', 'drupal-profile'))) {
      $project_name = str_replace('drupal/', '', $package['name']);

      switch ($package['type']) {
        case 'drupal-core':
          $project_name = 'drupal';
          $group = &$core;
          $group[$project_name]['type'] = 'core';
          $info['core'] = substr($package['version'], 0, 1) . '.x';
          break;
        case 'drupal-theme':
          $group = &$themes;
          $group[$project_name]['type'] = 'theme';
          break;
        case 'drupal-module':
          $group = &$modules;
          $group[$project_name]['type'] = 'module';
          break;
        case 'drupal-profile':
          $group = &$profiles;
          $group[$project_name]['type'] = 'profile';
          break;
      }

      $group[$project_name]['download']['type'] = 'git';
      $group[$project_name]['download']['url'] = $package['source']['url'];
      // Dev versions should use git branch + revision, otherwise a tag is used.
      if (strstr($package['version'], 'dev')) {
        // 'dev-' prefix indicates a branch-alias. Stripping the dev prefix from
        // the branch name is sufficient.
        // @see https://getcomposer.org/doc/articles/aliases.md
        if (strpos($package['version'], 'dev-') === 0) {
          $group[$project_name]['download']['branch'] = substr($package['version'], 4);
        }
        // Otherwise, leave as is. Version may already use '-dev' suffix.
        else {
          $group[$project_name]['download']['branch'] = $package['version'];
        }
        $group[$project_name]['download']['revision'] = $package['source']['reference'];
      }
      elseif ($package['type'] == 'drupal-core') {
        // For 7.x tags, replace 7.xx.0 with 7.xx.
        if ($info['core'] == '7.x') {
          $group[$project_name]['download']['tag'] = substr($package['version'], 0, 4);
        }
        else {
          $group[$project_name]['download']['tag'] = $package['version'];
        }
      }
      else {
        // Make tag versioning drupal-friendly. 8.1.0-alpha1 => 8.x-1.0-alpha1.
        $major_version = substr($package['version'], 0, 1);
        $the_rest = substr($package['version'], 2, strlen($package['version']));
        $group[$project_name]['download']['tag'] = "$major_version.x-$the_rest";
      }

      if (!empty($package['extra']['patches_applied'])) {
        foreach ($package['extra']['patches_applied'] as $desc => $url) {
          $group[$project_name]['patch'][] = $url;
        }
      }
    }
    // Include any non-drupal libraries that exist in both .lock and .json.
    elseif (!in_array($package['type'], array('composer-plugin', 'metapackage')) && array_key_exists($package['name'], $composer_json['require'])) {
      $project_name = $package['name'];
      $libraries[$project_name]['type'] = 'library';
      $libraries[$project_name]['download']['type'] = 'git';
      $libraries[$project_name]['download']['url'] = $package['source']['url'];
      $libraries[$project_name]['download']['branch'] = $package['version'];
      $libraries[$project_name]['download']['revision'] = $package['source']['reference'];
    }
  }

  $info['projects'] = $core + $modules + $themes;
  $info['libraries'] = $libraries;

  return $info;
}