<commit_before># Diversity Push <<EMAIL>>
# A simple node script to update the version of Diversity <https:#diversity.io/> components.
# More info in readme

fs    = require('fs');
exec  = require('child_process').exec;
push  = require('commander');
rls   = require('readline-sync');
shell = require('shelljs');

if not shell.which 'git'
  shell.echo 'Sorry, this script requires git'
  shell.exit 1

settings =
  diversityPath: process.cwd() + '/diversity.json',
  encoding: 'utf-8',
  jsonSpaces: 2, # Amount of spaces for indentation in output file (can also be \t)

push
  .version('2.0.0')
  .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 = (path) ->
  fs.readFileSync path, settings.encoding, (err, data) ->
    throw err if err
    return JSON.parse data

writeDiversity = (path, data) ->
  fs.writeFileSync path, data, settings.encoding, (err) ->
    throw err if err
    return true

runCommand = (command) ->
  if (shell.exec command).code != 0
    shell.echo 'Error: ' + command + ' failed. Exiting.'
    shell.exit 1

gitPullBranch = (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'
    shell.exit(1)



if push.release
    console.log 'Stashing any non-committed changes:'
    runCommand 'git stash'

    # Check out master and develop and make sure they are up-to-date with origin
    gitPullBranch 'master'
    gitPullBranch 'develop'

    # Run karma tests, if they exist
    karmaConfPath = process.cwd() + '/test/karma.conf.js'
    karmaTestsExist = fs.existsSync karmaConfPath
    skipKarmaTests = rls.question 'Do you want to proceed without running tests? [Y/n]: '

    if skipKarmaTests?.toLowerCase() is 'n'
      if karmaTestsExist
        runCommand 'gulp karma:single-run'
      else
        console.log "Could not find karma conf path."
        shell.exit 1


    diversityData = JSON.parse readDiversity(settings.diversityPath)
    versionArray = diversityData.version.split '.'

    # The default is patch, hence why position is default 2 below. Empty value is actually true.
    command = if push.release is true then 'patch' else push.release
    position = 2

    if command is 'major'
      position = 0
      versionArray[1] = '0'
      versionArray[2] = '0'
<commit_msg>Run tests by default<commit_after># Diversity Push <<EMAIL>>
# A simple node script to update the version of Diversity <https://diversity.io/> components.
# More info in readme

fs    = require('fs');
exec  = require('child_process').exec;
push  = require('commander');
rls   = require('readline-sync');
shell = require('shelljs');

if not shell.which 'git'
  shell.echo 'Sorry, this script requires git'
  shell.exit 1

settings =
  diversityPath: process.cwd() + '/diversity.json',
  encoding: 'utf-8',
  jsonSpaces: 2, # Amount of spaces for indentation in output file (can also be \t)

push
  .version('2.0.0')
  .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 = (path) ->
  fs.readFileSync path, settings.encoding, (err, data) ->
    throw err if err
    return JSON.parse data

writeDiversity = (path, data) ->
  fs.writeFileSync path, data, settings.encoding, (err) ->
    throw err if err
    return true

runCommand = (command) ->
  if (shell.exec command).code != 0
    shell.echo 'Error: ' + command + ' failed. Exiting.'
    shell.exit 1

gitPullBranch = (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'
    shell.exit(1)



if push.release
    console.log 'Stashing any non-committed changes:'
    runCommand 'git stash'

    # Check out master and develop and make sure they are up-to-date with origin
    gitPullBranch 'master'
    gitPullBranch 'develop'

    # Run karma tests, if they exist
    karmaConfPath = process.cwd() + '/test/karma.conf.js'

    skipKarmaTests = rls.question 'Do you want to run the tests? [Y/n]: '
    if skipKarmaTests?.toLowerCase() isnt 'n'
      runCommand 'gulp karma:single-run'

    diversityData = JSON.parse readDiversity(settings.diversityPath)
    versionArray = diversityData.version.split '.'

    # The default is patch, hence why position is default 2 below. Empty value is actually true.
    command = if push.release is true then 'patch' else push.release
    position = 2

    if command is 'major'
      position = 0
      versionArray[1] = '0'
      versionArray[2] = '0'

{'fraction_non_alphanumeric': 0.11219512195121951, 'fraction_numerical': 0.007113821138211382, 'mean_word_length': 3.279130434782609, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 21, 'https://': 1, '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': '3549533', 'n_tokens_mistral': 1556, 'n_tokens_neox': 1502, 'n_words': 533}