function drush_make_convert_make_to_composer

master make.drush.inc drush_make_convert_make_to_composer($info)

Converts a drush info array to a composer.json array.

Parameters

array $info: A drush make info array.

Return value

string A json encoded composer.json schema object.

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

File

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

Code

function drush_make_convert_make_to_composer($info) {
  $core_major_version = substr($info['core'], 0, 1);
  $core_project_name = $core_major_version == 7 ? 'drupal/drupal' : 'drupal/core';

  // Add default projects.
  $projects = array(
    'composer/installers' => '^1.0.20',
    'cweagans/composer-patches' => '~1.0',
    $core_project_name => str_replace('x', '*', $info['core']),
  );

  $patches = array();

  // Iterate over projects, populating composer-friendly array.
  foreach ($info['projects'] as $project_name => $project) {
    switch ($project['type']) {
      case 'core':
        $project['name'] = 'drupal/core';
        $projects[$project['name']] = str_replace('x', '*', $project['version']);
        break;

      default:
        $project['name'] = "drupal/$project_name";
        $projects[$project['name']] = drush_make_convert_project_to_composer($project, $core_major_version);
        break;
    }

    // Add project patches.
    if (!empty($project['patch'])) {
      foreach ($project['patch'] as $key => $patch) {
        $patch_description = "Enter {$project['name']} patch #$key description here";
        $patches[$project['name']][$patch_description] = $patch;
      }
    }
  }

  // Iterate over libraries, populating composer-friendly array.
  if (!empty($info['libraries'])) {
    foreach ($info['libraries'] as $library_name => $library) {
      $library_name = 'Verify project name: ' . $library_name;
      $projects[$library_name] = drush_make_convert_project_to_composer($library);
    }
  }

  $output = array(
    'name' => 'Enter project name here',
    'description' => 'Enter project description here',
    'type' => 'project',
    'repositories' => array(
      array(
        'type' => 'composer',
        'url' => 'https://packagist.drupal-composer.org',
      ),
    ),
    'require' => $projects,
    'minimum-stability' => 'dev',
    'prefer-stable' => TRUE,
    'extra' => array(
      'installer-paths' => array(
        'core' => array('type:drupal-core'),
        'docroot/modules/contrib/{$name}' => array('type:drupal-module'),
        'docroot/profiles/contrib/{$name}' => array('type:drupal-profile'),
        'docroot/themes/contrib/{$name}' => array('type:drupal-theme'),
        'drush/contrib/{$name}' => array('type:drupal-drush'),
      ),
      'patches' => $patches,
    ),
  );

  $output = json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);

  return $output;
}