<commit_before>/*
 * Increase version number
 *
 * grunt bump
 * grunt bump:git
 * grunt bump:patch
 * grunt bump:minor
 * grunt bump:major
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */

'use strict';

var semver = require('semver');
var exec = require('child_process').exec;
var xml2js = require('xml2js');
var parseString = xml2js.parseString;
var xmlBuilder = new xml2js.Builder();

module.exports = function(grunt) {

  var DESC = 'Increment the version, commit, tag and push.';
  grunt.registerTask('bump', DESC, function(versionType, incOrCommitOnly) {
    var opts = this.options({
      bumpVersion: true,
      files: ['package.json', 'bower.json', 'config.xml'],
      updateConfigs: [], // array of config properties to update (with files)
      commit: true,
      commitMessage: 'Release %VERSION%',
      commitFiles: ['package.json', 'bower.json', 'config.xml'], // '-a' for all files
      createTag: true,
      tagName: '%VERSION%',
      tagMessage: 'Version %VERSION%',
      push: true,
      pushTo: 'upstream',
      gitDescribeOptions: '--tags --always --abbrev=1 --dirty=-d'
    });

    if (incOrCommitOnly === 'bump-only') {
      grunt.verbose.writeln('Only incrementing the version.');

      opts.commit = false;
      opts.createTag = false;
      opts.push = false;
    }

    if (incOrCommitOnly === 'commit-only') {
      grunt.verbose.writeln('Only committing/tagging/pushing.');

      opts.bumpVersion = false;
    }

    var exactVersionToSet = grunt.option('setversion');
    if (!semver.valid(exactVersionToSet)) {
        exactVersionToSet = false;
    }

    var done = this.async();
    var queue = [];
    var next = function() {
      if (!queue.length) {
        return done();
      }
      queue.shift()();
    };
    var runIf = function(condition, behavior) {
      if (condition) {
        queue.push(behavior);
      }
    };

    var globalVersion; // when bumping multiple files
    var gitVersion;    // when bumping using `git describe`
    var XML_VERSION_REGEXP = /([\d||A-a|.|-]*)([\'|\"]?)/i;
    var VERSION_REGEXP = /([\'|\"]?version[\'|\"]?[ ]*:[ ]*[\'|\"]?)([\d||A-a|.|-]*)([\'|\"]?)/i;


    // GET VERSION FROM GIT
    runIf(opts.bumpVersion && versionType === 'git', function(){
      exec('git describe ' + opts.gitDescribeOptions, function(err, stdout, stderr){
        if (err) {
          grunt.fatal('Can not get a version number using `git describe`');
        }
        gitVersion = stdout.trim();
        next();
      });
    });


    // BUMP ALL FILES
    runIf(opts.bumpVersion, function(){
      grunt.file.expand(opts.files).forEach(function(file, idx) {
        var version = null;
        var fileString = grunt.file.read(file);
        var content;

        if (file === 'config.xml') {
          parseString(fileString, function (err, result) {
            result.widget.$.version = result.widget.$.version.replace(XML_VERSION_REGEXP, function (match, parsedVersion) {
                gitVersion = gitVersion && parsedVersion;
                version = exactVersionToSet || gitVersion || semver.inc(parsedVersion, versionType || 'patch');
                // Removes prerelease tag
                return !~version.indexOf('-') ? version : version.slice(0, version.indexOf('-'));
            });
            content = xmlBuilder.buildObject(result);
          });
        } else {
          content = fileString.replace(VERSION_REGEXP, function(match, prefix, parsedVersion, suffix) {
            gitVersion = gitVersion && parsedVersion + '-' + gitVersion;
            version = exactVersionToSet || gitVersion || semver.inc(parsedVersion, versionType || 'patch');<commit_msg>Add bump of versionCode for android<commit_after>/*
 * Increase version number
 *
 * grunt bump
 * grunt bump:git
 * grunt bump:patch
 * grunt bump:minor
 * grunt bump:major
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */

'use strict';

var semver = require('semver');
var exec = require('child_process').exec;
var xml2js = require('xml2js');
var parseString = xml2js.parseString;
var xmlBuilder = new xml2js.Builder();

module.exports = function(grunt) {

  var DESC = 'Increment the version, commit, tag and push.';
  grunt.registerTask('bump', DESC, function(versionType, incOrCommitOnly) {
    var opts = this.options({
      bumpVersion: true,
      files: ['package.json', 'bower.json', 'config.xml'],
      updateConfigs: [], // array of config properties to update (with files)
      commit: true,
      commitMessage: 'Release %VERSION%',
      commitFiles: ['package.json', 'bower.json', 'config.xml'], // '-a' for all files
      createTag: true,
      tagName: '%VERSION%',
      tagMessage: 'Version %VERSION%',
      push: true,
      pushTo: 'upstream',
      gitDescribeOptions: '--tags --always --abbrev=1 --dirty=-d'
    });

    if (incOrCommitOnly === 'bump-only') {
      grunt.verbose.writeln('Only incrementing the version.');

      opts.commit = false;
      opts.createTag = false;
      opts.push = false;
    }

    if (incOrCommitOnly === 'commit-only') {
      grunt.verbose.writeln('Only committing/tagging/pushing.');

      opts.bumpVersion = false;
    }

    var exactVersionToSet = grunt.option('setversion');
    if (!semver.valid(exactVersionToSet)) {
        exactVersionToSet = false;
    }

    var done = this.async();
    var queue = [];
    var next = function() {
      if (!queue.length) {
        return done();
      }
      queue.shift()();
    };
    var runIf = function(condition, behavior) {
      if (condition) {
        queue.push(behavior);
      }
    };

    var globalVersion; // when bumping multiple files
    var gitVersion;    // when bumping using `git describe`
    var XML_VERSION_REGEXP = /([\d||A-a|.|-]*)([\'|\"]?)/i;
    var VERSION_REGEXP = /([\'|\"]?version[\'|\"]?[ ]*:[ ]*[\'|\"]?)([\d||A-a|.|-]*)([\'|\"]?)/i;


    // GET VERSION FROM GIT
    runIf(opts.bumpVersion && versionType === 'git', function(){
      exec('git describe ' + opts.gitDescribeOptions, function(err, stdout, stderr){
        if (err) {
          grunt.fatal('Can not get a version number using `git describe`');
        }
        gitVersion = stdout.trim();
        next();
      });
    });


    // BUMP ALL FILES
    runIf(opts.bumpVersion, function(){
      grunt.file.expand(opts.files).forEach(function(file, idx) {
        var version = null;
        var fileString = grunt.file.read(file);
        var content;

        if (file === 'config.xml') {
          parseString(fileString, function (err, result) {
            result.widget.$.version = result.widget.$.version.replace(XML_VERSION_REGEXP, function (match, parsedVersion) {
                gitVersion = gitVersion && parsedVersion;
                version = exactVersionToSet || gitVersion || semver.inc(parsedVersion, versionType || 'patch');
                if (result.widget.$['android-versionCode']) {
                  result.widget.$['android-versionCode'] = parseInt(result.widget.$['android-versionCode']) + 1;
                }
                // Removes prerelease tag
                return !~version.indexOf('-') ? version : version.slice(0, version.indexOf('-'));
            });
            content = xmlBuilder.buildObject(result);
          });
        } else {
          content = fileString.replace(VERSION_REGEXP, function(match, prefix, parsedVersion, suffix) {
            gitVersion = gitVersion && parsedVersion + '-' + gitVersion;
            version = exactVersionToSet || gitVersion || semver.inc(parsedVersion, versionType || 'patch');
{'fraction_non_alphanumeric': 0.16100481582715084, 'fraction_numerical': 0.001692047377326565, 'mean_word_length': 2.6211121583411874, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 18}, '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': '1299819', 'n_tokens_mistral': 2355, 'n_tokens_neox': 2321, 'n_words': 537}