<commit_before>#!/usr/bin/env node
var askPush, command, diversityData, exec, filelist, finish, fs, gitPullBranch, newDiversity, newVersion, position, push, readDiversity, rls, runCommand, runTest, settings, shell, shouldPush, updateString, versionArray, versionNumber, writeDiversity;

fs = require('fs');

exec = require('child_process').exec;

push = require('commander');

rls = require('readline-sync');

shell = require('shelljs');

if (!shell.which('git')) {
  shell.echo('Sorry, this script requires git');
  shell.exit(1);
}

settings = {
  diversityPath: process.cwd() + '/diversity.json',
  encoding: 'utf-8',
  jsonSpaces: 2
};

push.version((function() {
  var packageJson, packagePath;
  packagePath = __dirname + '/../package.json';
  packageJson = JSON.parse(fs.readFileSync(packagePath, {
    encoding: 'utf8'
  }));
  return packageJson.version;
})()).option('-r, --release [type]', 'Start up git flow release. Type can be major, minor or patch. Default is patch. Will not finish or push without asking.').parse(process.argv);

readDiversity = function(path) {
  return fs.readFileSync(path, settings.encoding, function(err, data) {
    if (err) {
      throw err;
    }
    return JSON.parse(data);
  });
};

writeDiversity = function(path, data) {
  return fs.writeFileSync(path, data, settings.encoding, function(err) {
    if (err) {
      throw err;
    }
    return true;
  });
};

runCommand = function(command) {
  if ((shell.exec(command)).code !== 0) {
    shell.echo('Error: ' + command + ' failed. Exiting.');
    return shell.exit(1);
  }
};

runTest = function(command) {
  var question;
  if ((shell.exec(command)).code !== 0) {
    question = "\"" + command + "\" failed, do you want to abort the release and fix this? [Y/n]:";
    if (rls.question(question) !== 'n') {
      return shell.exit(0);
    }
  }
};

gitPullBranch = function(branch) {
  runCommand('git checkout ' + branch);
  if (shell.exec('git pull').code !== 0) {
    runCommand('git reset --hard');
    shell.echo('Error: master could not be automatically merged with origin/master. Please update master and try again');
    return shell.exit(1);
  }
};

if (push.release) {
  console.log('Stashing any non-committed changes:');
  runCommand('git stash');
  gitPullBranch('master');
  gitPullBranch('develop');
  runTest('gulp jscs');
  runTest('gulp jshint');
  runTest('gulp lint-css:style-names');
  runTest('gulp lint-css:doiuse');
  runTest('gulp translations-update-fail-on-incomplete');
  runTest('gulp protractor:single-run');
  runTest('gulp karma:single-run');
  diversityData = JSON.parse(readDiversity(settings.diversityPath));
  versionArray = diversityData.version.split('.');
  command = push.release === true ? 'patch' : push.release;
  position = 2;
  if (command === 'major') {
    position = 0;<commit_msg>Minified<commit_after>#!/usr/bin/env node
var askPush, command, dirty, diversityData, exec, filelist, finish, fs, gitPullBranch, newDiversity, newVersion, position, push, readDiversity, rls, runCommand, runTest, settings, shell, shouldPush, updateString, versionArray, versionNumber, writeDiversity;

fs = require('fs');

exec = require('child_process').exec;

push = require('commander');

rls = require('readline-sync');

shell = require('shelljs');

if (!shell.which('git')) {
  shell.echo('Sorry, this script requires git');
  shell.exit(1);
}

settings = {
  diversityPath: process.cwd() + '/diversity.json',
  encoding: 'utf-8',
  jsonSpaces: 2
};

push.version((function() {
  var packageJson, packagePath;
  packagePath = __dirname + '/../package.json';
  packageJson = JSON.parse(fs.readFileSync(packagePath, {
    encoding: 'utf8'
  }));
  return packageJson.version;
})()).option('-r, --release [type]', 'Start up git flow release. Type can be major, minor or patch. Default is patch. Will not finish or push without asking.').parse(process.argv);

readDiversity = function(path) {
  return fs.readFileSync(path, settings.encoding, function(err, data) {
    if (err) {
      throw err;
    }
    return JSON.parse(data);
  });
};

writeDiversity = function(path, data) {
  return fs.writeFileSync(path, data, settings.encoding, function(err) {
    if (err) {
      throw err;
    }
    return true;
  });
};

runCommand = function(command) {
  if ((shell.exec(command)).code !== 0) {
    shell.echo('Error: ' + command + ' failed. Exiting.');
    return shell.exit(1);
  }
};

runTest = function(command) {
  var question;
  if ((shell.exec(command)).code !== 0) {
    question = "\"" + command + "\" failed, do you want to abort the release and fix this? [Y/n]:";
    if (rls.question(question) !== 'n') {
      return shell.exit(0);
    }
  }
};

gitPullBranch = function(branch) {
  runCommand('git checkout ' + branch);
  if (shell.exec('git pull').code !== 0) {
    runCommand('git reset --hard');
    shell.echo('Error: master could not be automatically merged with origin/master. Please update master and try again');
    return shell.exit(1);
  }
};

if (push.release) {
  console.log('Stashing any non-committed changes:');
  runCommand('git stash');
  gitPullBranch('master');
  gitPullBranch('develop');
  runTest('gulp jscs');
  runTest('gulp jshint');
  runTest('gulp lint-css:style-names');
  runTest('gulp lint-css:doiuse');
  runTest('gulp translations-update-fail-on-incomplete');
  runTest('gulp protractor:single-run');
  runTest('gulp karma:single-run');
  runCommand('git checkout scripts.min.js');
  dirty = runCommand('expr $(git status --porcelain 2>/dev/null| egrep "^(M| M)" | wc -l)').output;
  if (dirty) {
    console.log('You have unstaged changes that you must take care of. Fix and commit this and then run diversity-push again.');
    shell.exit(1);
  }
  diversityData = JSON.parse(readDiversity(settings.diversityPath));
  versionArray = diversityData.version.split('.');
  command = push.release === true ? 'patch' : push.release;
  position = 2;
  if (command === 'major') {
    position = 0;
{'fraction_non_alphanumeric': 0.16543747904793832, 'fraction_numerical': 0.004358028830036876, 'mean_word_length': 4.148403796376186, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '560957', 'n_tokens_mistral': 1967, 'n_tokens_neox': 1935, 'n_words': 482}