function drush_make_convert

8.0.x make.drush.inc drush_make_convert($makefile)
7.x make.drush.inc drush_make_convert($makefile)
master make.drush.inc drush_make_convert($source)

Command callback; convert make file format.

File

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

Code

function drush_make_convert($source) {
  $dest_format = drush_get_option('format', 'yml');

  // Load source data.
  $source_format = pathinfo($source, PATHINFO_EXTENSION);

  if ($source_format == $dest_format || $source_format == 'lock' && $dest_format == 'composer') {
    drush_print('The source format cannot be the same as the destination format.');
  }

  // Obtain drush make $info array, converting if necessary.
  switch ($source_format) {
    case 'make':
    case 'yml':
    case 'yaml':
      $info = make_parse_info_file($source);
      break;
    case 'lock':
      $composer_json_file = str_replace('lock', 'json', $source);
      if (!file_exists($composer_json_file)) {
        drush_print('Please ensure that a composer.json file is in the same directory as the specified composer.lock file.');
        return FALSE;
      }
      $composer_json = json_decode(make_get_data($composer_json_file), TRUE);
      $composer_lock = json_decode(make_get_data($source), TRUE);
      $info = drush_make_convert_composer_to_make($composer_lock, $composer_json);
      break;
    case 'json':
      drush_print('Please use composer.lock instead of composer.json as source for conversion.');
      return FALSE;
      break;
  }

  // Output into destination formation.
  switch ($dest_format) {
    case 'yml':
    case 'yaml':
      $output = drush_make_convert_make_to_yml($info);
      break;

    case 'make':
      foreach ($info['projects'] as $key => $project) {
        $info['projects'][$key]['_type'] = $info['projects'][$key]['type'];
      }
      foreach ($info['libraries'] as $key => $library) {
        $info['libraries'][$key]['_type'] = 'librarie';
      }
      $output = _drush_make_generate_makefile_contents($info['projects'], $info['libraries'], $info['core'], $info['defaults']);

      break;

    case 'composer':
      $output = drush_make_convert_make_to_composer($info);
      break;
  }

  drush_print($output);
}