<commit_before>#!/usr/bin/env node

var path = require('path');
var fs = require('fs');
var paramaters = [];
var parameterVersion = false;
var packageDefinitionPathNpm = path.join(process.cwd(), 'package.json');
var packageDefinitionPathComposer = path.join(process.cwd(), 'composer.json');
var buildConfigPath = path.join(process.cwd(), 'build-helper-config.json');
var Helper = require('../lib');
var chalk = require('chalk');
var semver = require('semver')

function isFileReadable(file) {
  try {
    fs.accessSync(file, fs.F_OK);
    return true;
  } catch(e) {
    return false;
  }
}

var config = isFileReadable(buildConfigPath) ? require(buildConfigPath) : {};
var userPackage = isFileReadable(packageDefinitionPathNpm) ? require(packageDefinitionPathNpm) : {};
var packageDefinitionPath = packageDefinitionPathNpm;
if(!Object.getOwnPropertyNames(userPackage).length) {
  userPackage = isFileReadable(packageDefinitionPathComposer) ? require(packageDefinitionPathComposer) : {};
  var packageDefinitionPath = packageDefinitionPathComposer;
}

if(!Object.getOwnPropertyNames(userPackage).length) {
  console.log(chalk.red('no project file (package.json, composer.json)'))
  process.exit(1);
}

var options = {
  push: config.push || false,
  keep: config.keep || false,
  update: config.update || false,
  debug: config.debug || false,
  buildTimestampInName: config.buildTimestampInName || true,
  createChangelog: config.createChangelog || true,
  changelogFolder: config.changelogFolder || './changelogs',
  commitURL: config.commitURL,
  userPackage: packageDefinitionPath,
  packageSpaces: config.packageSpaces || 2,
  preConditionCommands: config.preConditionCommands || [],
};

function extend(target) {
    var sources = [].slice.call(arguments, 1);
    sources.forEach(function (source) {
        for (var prop in source) {
            target[prop] = source[prop];
        }
    });
    return target;
}

function showHelp() {
    console.log();
    console.log('build-helper');
    console.log();
    console.log('create a new release, update the version and build number and do the git stuff');
    console.log('build-helper 0.0.5');
    console.log('build-helper major|minor|patch');
    console.log('build-helper -p minor');
    console.log('build-helper --debug -p patch')
    console.log();
    console.log('Usage: build-helper');
    console.log();
    console.log('  options');
    console.log('   -h/--help     show this help');
    console.log('   -p/--push     push new release to origin');
    console.log('   -k/--keep     keep branch after performing finish');
    console.log('   -d/--debug    more output');
    console.log('   -u/--update   (BETA) experimental');
    console.log();
}

if (process.argv.length > 2) {
  var end = false;
  paramaters = process.argv.splice(2);
  paramaters.forEach(function(parameter) {
    switch (parameter) {
      case '-h':
      case '--help':
        showHelp();
        end = true;
        break;
      case '-d':
      case '--debug':
        options.debug = true;
        break;
      case '-p':
      case '--push':
        options.push = true;
        break;
      case '-k':
      case '--keep':
        options.keep = true;
        break;
      case '-u':
      case '--update':
        options.update = true;
        break;
    }
  });
  if (end) {
    process.exit(0);
  }
} else {
  showHelp();
  process.exit(1);
}
if (options.update) {
  parameterVersion = currentPackage.version;
  console.log('verison taken from package file' + parameterVersion);
} else {
  parameterVersion = paramaters[paramaters.length-1];
  if (parameterVersion.indexOf('.') > -1) {
    parameterVersion = semver.clean(parameterVersion);
  }
  if (semver.valid(parameterVersion) === null && parameterVersion !== 'patch' && parameterVersion !== 'major' && parameterVersion !== 'minor') {
    console.log(chalk.red('invalid version parameter'));
    process.exit(1);
  }
}

if (typeof parameterVersion === 'undefined') {
  showHelp();
  process.exit(1);
}

var helper = new Helper(extend({}, options, {
    currentVersion: userPackage.version,
    parameterVersion: parameterVersion
}));
<commit_msg>BUGFIX: use the correct package file for the --update flag<commit_after>#!/usr/bin/env node

var path = require('path');
var fs = require('fs');
var paramaters = [];
var parameterVersion = false;
var packageDefinitionPathNpm = path.join(process.cwd(), 'package.json');
var packageDefinitionPathComposer = path.join(process.cwd(), 'composer.json');
var buildConfigPath = path.join(process.cwd(), 'build-helper-config.json');
var Helper = require('../lib');
var chalk = require('chalk');
var semver = require('semver')

function isFileReadable(file) {
  try {
    fs.accessSync(file, fs.F_OK);
    return true;
  } catch(e) {
    return false;
  }
}

var config = isFileReadable(buildConfigPath) ? require(buildConfigPath) : {};
var userPackage = isFileReadable(packageDefinitionPathNpm) ? require(packageDefinitionPathNpm) : {};
var packageDefinitionPath = packageDefinitionPathNpm;
if(!Object.getOwnPropertyNames(userPackage).length) {
  userPackage = isFileReadable(packageDefinitionPathComposer) ? require(packageDefinitionPathComposer) : {};
  var packageDefinitionPath = packageDefinitionPathComposer;
}

if(!Object.getOwnPropertyNames(userPackage).length) {
  console.log(chalk.red('no project file (package.json, composer.json)'))
  process.exit(1);
}

var options = {
  push: config.push || false,
  keep: config.keep || false,
  update: config.update || false,
  debug: config.debug || false,
  buildTimestampInName: config.buildTimestampInName || true,
  createChangelog: config.createChangelog || true,
  changelogFolder: config.changelogFolder || './changelogs',
  commitURL: config.commitURL,
  userPackage: packageDefinitionPath,
  packageSpaces: config.packageSpaces || 2,
  preConditionCommands: config.preConditionCommands || [],
};

function extend(target) {
    var sources = [].slice.call(arguments, 1);
    sources.forEach(function (source) {
        for (var prop in source) {
            target[prop] = source[prop];
        }
    });
    return target;
}

function showHelp() {
    console.log();
    console.log('build-helper');
    console.log();
    console.log('create a new release, update the version and build number and do the git stuff');
    console.log('build-helper 0.0.5');
    console.log('build-helper major|minor|patch');
    console.log('build-helper -p minor');
    console.log('build-helper --debug -p patch')
    console.log();
    console.log('Usage: build-helper');
    console.log();
    console.log('  options');
    console.log('   -h/--help     show this help');
    console.log('   -p/--push     push new release to origin');
    console.log('   -k/--keep     keep branch after performing finish');
    console.log('   -d/--debug    more output');
    console.log('   -u/--update   (BETA) experimental');
    console.log();
}

if (process.argv.length > 2) {
  var end = false;
  paramaters = process.argv.splice(2);
  paramaters.forEach(function(parameter) {
    switch (parameter) {
      case '-h':
      case '--help':
        showHelp();
        end = true;
        break;
      case '-d':
      case '--debug':
        options.debug = true;
        break;
      case '-p':
      case '--push':
        options.push = true;
        break;
      case '-k':
      case '--keep':
        options.keep = true;
        break;
      case '-u':
      case '--update':
        options.update = true;
        break;
    }
  });
  if (end) {
    process.exit(0);
  }
} else {
  showHelp();
  process.exit(1);
}
if (options.update) {
  parameterVersion = userPackage.version;
  console.log('verison taken from package file ' + parameterVersion);
} else {
  parameterVersion = paramaters[paramaters.length-1];
  if (parameterVersion.indexOf('.') > -1) {
    parameterVersion = semver.clean(parameterVersion);
  }
  if (semver.valid(parameterVersion) === null && parameterVersion !== 'patch' && parameterVersion !== 'major' && parameterVersion !== 'minor') {
    console.log(chalk.red('invalid version parameter'));
    process.exit(1);
  }
}

if (typeof parameterVersion === 'undefined') {
  showHelp();
  process.exit(1);
}

var helper = new Helper(extend({}, options, {
    currentVersion: userPackage.version,
    parameterVersion: parameterVersion
}));

{'fraction_non_alphanumeric': 0.1509275882704967, 'fraction_numerical': 0.0033512866546977858, 'mean_word_length': 3.4423179160021267, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2181168', 'n_tokens_mistral': 2543, 'n_tokens_neox': 2537, 'n_words': 573}