{"size": 1226, "ext": "js", "max_stars_repo_path": "plugins/gcc/java-writer.js", "max_stars_repo_name": "csgibson/opensphere-build-resolver", "max_stars_repo_stars_event_min_datetime": "2018-01-04T17:45:32.000Z", "max_stars_repo_stars_event_max_datetime": "2018-04-23T16:24:44.000Z", "max_issues_repo_path": "plugins/gcc/java-writer.js", "max_issues_repo_name": "csgibson/opensphere-build-resolver", "max_issues_repo_issues_event_min_datetime": "2017-12-19T17:10:12.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-05T17:07:04.000Z", "max_forks_repo_path": "plugins/gcc/java-writer.js", "max_forks_repo_name": "csgibson/opensphere-build-resolver", "max_forks_repo_forks_event_min_datetime": "2017-12-15T20:11:39.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-09T20:12:44.000Z"}
{"max_stars_count": 3, "max_issues_count": 79, "max_forks_count": 8, "avg_line_length": 25.0204081633, "max_line_length": 93, "alphanum_fraction": 0.5889070147}
'use strict';

const Promise = require('bluebird');
const fs = Promise.promisifyAll(require('fs'));
const path = require('path');

const genericWriter = function(basePackage, dir, options, file, test) {
  var javaArgs = [];
  var equalsKeys = ['js', 'jscomp_error', 'jscomp_off', 'jscomp_warning'];

  for (var key in options) {
    var value = options[key];

    if (test && key === 'js_output_file' && value) {
      value = value.replace(basePackage.name + '.min.js', basePackage.name + '-test.min.js');
    }

    if (!(value instanceof Array)) {
      value = [value];
    }

    for (var i = 0, n = value.length; i < n; i++) {
      if (equalsKeys.indexOf(key) > -1) {
        javaArgs.push('--' + key + '=\'' + value[i] + '\'');
      } else {
        javaArgs.push('--' + key);

        if (value[i] !== true) {
          javaArgs.push(value[i]);
        }
      }
    }
  }

  var outputfile = path.join(dir, file);
  console.log('Writing ' + outputfile);

  return fs.writeFileAsync(outputfile, javaArgs.join(' '));
};

const writer = function(basePackage, dir, options) {
  return genericWriter(basePackage, dir, options, 'gcc-java-args');
};

module.exports = {
  writer: writer,
  genericWriter: genericWriter
};
