<commit_before>'use strict';

var fs = require('fs');
var path = require('path');
var _ = require('lodash');

module.exports = function(files, options) {
  if (!files || !Array.isArray(files)) {
    throw new TypeError('Missing files array');
  }

  if (!options || typeof options !== 'object') {
    throw new TypeError('Missing options object');
  }

  var pkgName = options.name + '-' + options.version + '-' + options.release + '.' + options.buildArch;
  var specFile = path.join(options.tempDir, 'SPECS', pkgName + '.spec');

  var b = [];

  b.push('%define   _topdir ' + path.resolve(options.tempDir));
  b.push('');
  b.push('Name: ' + options.name);
  b.push('Version: ' + options.version);
  b.push('Release: ' + options.release);
  b.push('Summary: ' + options.summary);
  b.push('License: ' + options.license);
  b.push('BuildArch: ' + options.buildArch);

  if (options.vendor && options.vendor.length > 0) {
    b.push('Vendor: ' + options.vendor);
  }

  if (options.group && options.group.length > 0) {
    b.push('Group: ' + options.group);
  }

  if (options.url && options.url.length > 0) {
    b.push('URL: ' + options.url);
  }

  if (options.prefix && options.prefix.length > 0) {
    b.push('Prefix: ' + options.prefix);
  }

  if (options.sources && Array.isArray(options.sources) && options.sources.length > 0) {
    if (options.sources.length === 1) {
      b.push('Source: ' + options.sources[0]);
    }
    else {
      _.forEach(options.sources, function(src) {
        b.push('Source' + i + ': ' + src);
      });
    }
  }

  if (options.patches && Array.isArray(options.patches) && options.patches.length > 0) {
    if (options.patches.length === 1) {
      b.push('Patch: ' + options.patches[0]);
    }
    else {
      _.forEach(options.patches, function(src) {
        b.push('Patch' + i + ': ' + src);
      });
    }
  }

  if (options.autoReq === false && options.autoProv === false) {
    b.push('AutoReqProv: no');
  } else if (options.autoReq === false) {
    b.push('AutoReq: no');
  } else if (options.autoProv === false) {
    b.push('AutoProv: no');
  }

  if (options.requires && Array.isArray(options.requires) && options.requires.length > 0) {
    b.push('Requires: ' + options.requires.join(', '));
  }

  if (options.conflicts && Array.isArray(options.conflicts) && options.conflicts.length > 0) {
    b.push('Conflicts: ' + options.conflicts.join(', '));
  }

  if (options.excludeArchs && Array.isArray(options.excludeArchs) && options.excludeArchs.length > 0) {
    b.push('ExcludeArch: ' + options.excludeArchs.join(', '));
  }

  if (options.exclusiveArchs && Array.isArray(options.exclusiveArchs) && options.exclusiveArchs.length > 0) {
    b.push('ExclusiveArch: ' + options.exclusiveArchs.join(', '));
  }

  if (options.buildRequires && Array.isArray(options.buildRequires) && options.buildRequires.length > 0) {
    _.forEach(options.buildRequires, function(str) {
      b.push('BuildRequires: ' + str);
    });
  }

  b.push('');

  b.push('%description');
  b.push(options.description);
  b.push('');

  if (options.prepScript && Array.isArray(options.prepScript) && options.prepScript.length > 0) {
    b.push('%prep');
    b.push(options.prepScript.join('\n'));
    b.push('');
  }

  if (options.buildScript && Array.isArray(options.buildScript) && options.buildScript.length > 0) {
    b.push('%build');
    b.push(options.buildScript.join('\n'));
    b.push('');
  }

  if (options.installScript && Array.isArray(options.installScript) && options.installScript.length > 0) {
    b.push('%install');
    b.push(options.installScript.join('\n'));
    b.push('');
  }

  if (options.checkScript && Array.isArray(options.checkScript) && options.checkScript.length > 0) {
    b.push('%check');
    b.push(options.checkScript.join('\n'));
    b.push('');
  }

  if (options.cleanScript && Array.isArray(options.cleanScript) && options.cleanScript.length > 0) {
    b.push('%clean');
    b.push(options.cleanScript.join('\n'));
    b.push('');
  }

  if (options.preInstallScript && Array.isArray(options.preInstallScript) && options.preInstallScript.length > 0) {
    b.push('%pre');
    b.push(options.preInstallScript.join('\n'));
    b.push('');
  }

  if (options.postInstallScript && Array.isArray(options.postInstallScript) && options.postInstallScript.length > 0) {
    b.push('%post');
    b.push(options.postInstallScript.join('\n'));
    b.push('');
  }

  if (options.preUninstallScript && Array.isArray(options.preUninstallScript) && options.preUninstallScript.length > 0) {
    b.push('%preun');
    b.push(options.preUninstallScript.join('\n'));
    b.push('');
  }

  if (options.postUninstallScript && Array.isArray(options.postUninstallScript) && options.postUninstallScript.length > 0) {
    b.push('%postun');
    b.push(options.postUninstallScript.join('\n'));
    b.push('');
  }

  if (options.verifyScript && Array.isArray(options.verifyScript) && options.verifyScript.length > 0) {
    b.push('%verifyscript');
    b.push(options.verifyScript.join('\n'));
    b.push('');
  }

  b.push('%files');
  _.forEach(files, function(file) {
    b.push('"' + file + '"');
  })

  var specFileContent = b.join('\n');
  fs.writeFileSync(specFile, specFileContent);<commit_msg>Fix bug when more than one source and/or patch was defined<commit_after>'use strict';

var fs = require('fs');
var path = require('path');
var _ = require('lodash');

module.exports = function(files, options) {
  if (!files || !Array.isArray(files)) {
    throw new TypeError('Missing files array');
  }

  if (!options || typeof options !== 'object') {
    throw new TypeError('Missing options object');
  }

  var pkgName = options.name + '-' + options.version + '-' + options.release + '.' + options.buildArch;
  var specFile = path.join(options.tempDir, 'SPECS', pkgName + '.spec');

  var b = [];

  b.push('%define   _topdir ' + path.resolve(options.tempDir));
  b.push('');
  b.push('Name: ' + options.name);
  b.push('Version: ' + options.version);
  b.push('Release: ' + options.release);
  b.push('Summary: ' + options.summary);
  b.push('License: ' + options.license);
  b.push('BuildArch: ' + options.buildArch);

  if (options.vendor && options.vendor.length > 0) {
    b.push('Vendor: ' + options.vendor);
  }

  if (options.group && options.group.length > 0) {
    b.push('Group: ' + options.group);
  }

  if (options.url && options.url.length > 0) {
    b.push('URL: ' + options.url);
  }

  if (options.prefix && options.prefix.length > 0) {
    b.push('Prefix: ' + options.prefix);
  }

  if (options.sources && Array.isArray(options.sources) && options.sources.length > 0) {
    if (options.sources.length === 1) {
      b.push('Source: ' + options.sources[0]);
    }
    else {
      _.forEach(options.sources, function(src, idx) {
        b.push('Source' + idx + ': ' + src);
      });
    }
  }

  if (options.patches && Array.isArray(options.patches) && options.patches.length > 0) {
    if (options.patches.length === 1) {
      b.push('Patch: ' + options.patches[0]);
    }
    else {
      _.forEach(options.patches, function(src, idx) {
        b.push('Patch' + idx + ': ' + src);
      });
    }
  }

  if (options.autoReq === false && options.autoProv === false) {
    b.push('AutoReqProv: no');
  } else if (options.autoReq === false) {
    b.push('AutoReq: no');
  } else if (options.autoProv === false) {
    b.push('AutoProv: no');
  }

  if (options.requires && Array.isArray(options.requires) && options.requires.length > 0) {
    b.push('Requires: ' + options.requires.join(', '));
  }

  if (options.conflicts && Array.isArray(options.conflicts) && options.conflicts.length > 0) {
    b.push('Conflicts: ' + options.conflicts.join(', '));
  }

  if (options.excludeArchs && Array.isArray(options.excludeArchs) && options.excludeArchs.length > 0) {
    b.push('ExcludeArch: ' + options.excludeArchs.join(', '));
  }

  if (options.exclusiveArchs && Array.isArray(options.exclusiveArchs) && options.exclusiveArchs.length > 0) {
    b.push('ExclusiveArch: ' + options.exclusiveArchs.join(', '));
  }

  if (options.buildRequires && Array.isArray(options.buildRequires) && options.buildRequires.length > 0) {
    _.forEach(options.buildRequires, function(str) {
      b.push('BuildRequires: ' + str);
    });
  }

  b.push('');

  b.push('%description');
  b.push(options.description);
  b.push('');

  if (options.prepScript && Array.isArray(options.prepScript) && options.prepScript.length > 0) {
    b.push('%prep');
    b.push(options.prepScript.join('\n'));
    b.push('');
  }

  if (options.buildScript && Array.isArray(options.buildScript) && options.buildScript.length > 0) {
    b.push('%build');
    b.push(options.buildScript.join('\n'));
    b.push('');
  }

  if (options.installScript && Array.isArray(options.installScript) && options.installScript.length > 0) {
    b.push('%install');
    b.push(options.installScript.join('\n'));
    b.push('');
  }

  if (options.checkScript && Array.isArray(options.checkScript) && options.checkScript.length > 0) {
    b.push('%check');
    b.push(options.checkScript.join('\n'));
    b.push('');
  }

  if (options.cleanScript && Array.isArray(options.cleanScript) && options.cleanScript.length > 0) {
    b.push('%clean');
    b.push(options.cleanScript.join('\n'));
    b.push('');
  }

  if (options.preInstallScript && Array.isArray(options.preInstallScript) && options.preInstallScript.length > 0) {
    b.push('%pre');
    b.push(options.preInstallScript.join('\n'));
    b.push('');
  }

  if (options.postInstallScript && Array.isArray(options.postInstallScript) && options.postInstallScript.length > 0) {
    b.push('%post');
    b.push(options.postInstallScript.join('\n'));
    b.push('');
  }

  if (options.preUninstallScript && Array.isArray(options.preUninstallScript) && options.preUninstallScript.length > 0) {
    b.push('%preun');
    b.push(options.preUninstallScript.join('\n'));
    b.push('');
  }

  if (options.postUninstallScript && Array.isArray(options.postUninstallScript) && options.postUninstallScript.length > 0) {
    b.push('%postun');
    b.push(options.postUninstallScript.join('\n'));
    b.push('');
  }

  if (options.verifyScript && Array.isArray(options.verifyScript) && options.verifyScript.length > 0) {
    b.push('%verifyscript');
    b.push(options.verifyScript.join('\n'));
    b.push('');
  }

  b.push('%files');
  _.forEach(files, function(file) {
    b.push('"' + file + '"');
  });

  var specFileContent = b.join('\n');
  fs.writeFileSync(specFile, specFileContent);
{'fraction_non_alphanumeric': 0.19791666666666666, 'fraction_numerical': 0.004734848484848485, 'mean_word_length': 3.5055460750853245, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4385134', 'n_tokens_mistral': 3685, 'n_tokens_neox': 3592, 'n_words': 545}