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

'use strict';

require('shelljs/global');

function isDirectoryClean() {
  var fatalState = config.fatal;
  config.fatal = false;
  var isUnstagedChanges = exec('git diff --exit-code', {silent:true}).code;
  var isStagedChanged =
    exec('git diff --cached --exit-code', {silent:true}).code;
  config.fatal = fatalState;

  return !(isUnstagedChanges || isStagedChanged);
}

function prerelease() {
  if (!isDirectoryClean()) {
    echo('RELEASE ERROR: Working directory must be clean to push release!');
    exit(1);
  }
}

function bump(version) {
  return exec('npm --no-git-tag-version version ' + version, {silent: true})
    .output.replace(/\n$/g, '');
}

function execOrExit(cmd) {
  var code = exec(cmd).code;
  if (code !== 0) {
    exit(code);
  }
}

function changelog(releaseVersion, fileName) {
  var changelogFileName = fileName || 'CHANGELOG.md';
  execOrExit('touch ' + changelogFileName);
  execOrExit('node ./bin/changelog.js ' + releaseVersion + ' CHANGELOG.tmp');
  cat('CHANGELOG.tmp', changelogFileName).to('CHANGELOG.md.tmp');
  rm('CHANGELOG.tmp');
  rm(changelogFileName);
  mv('CHANGELOG.md.tmp', changelogFileName);
}

function commit(releaseVersion) {
  execOrExit('git add -A');
  execOrExit('git commit -m "chore(release): ' + releaseVersion + '"');
  execOrExit('git tag -f ' + releaseVersion);
  execOrExit('git push origin HEAD --tags');
}

function release(version, fileName) {
  //prerelease();
  var releaseVersion = bump(version);
  changelog(releaseVersion, fileName);
  //commit(releaseVersion);<commit_msg>chore(release.js): add prerelease and commit<commit_after>#!/usr/bin/env node

'use strict';

require('shelljs/global');

function isDirectoryClean() {
  var fatalState = config.fatal;
  config.fatal = false;
  var isUnstagedChanges = exec('git diff --exit-code', {silent:true}).code;
  var isStagedChanged =
    exec('git diff --cached --exit-code', {silent:true}).code;
  config.fatal = fatalState;

  return !(isUnstagedChanges || isStagedChanged);
}

function prerelease() {
  if (!isDirectoryClean()) {
    echo('RELEASE ERROR: Working directory must be clean to push release!');
    exit(1);
  }
}

function bump(version) {
  return exec('npm --no-git-tag-version version ' + version, {silent: true})
    .output.replace(/\n$/g, '');
}

function execOrExit(cmd) {
  var code = exec(cmd).code;
  if (code !== 0) {
    exit(code);
  }
}

function changelog(releaseVersion, fileName) {
  var changelogFileName = fileName || 'CHANGELOG.md';
  execOrExit('touch ' + changelogFileName);
  execOrExit('node ./bin/changelog.js ' + releaseVersion + ' CHANGELOG.tmp');
  cat('CHANGELOG.tmp', changelogFileName).to('CHANGELOG.md.tmp');
  rm('CHANGELOG.tmp');
  rm(changelogFileName);
  mv('CHANGELOG.md.tmp', changelogFileName);
}

function commit(releaseVersion) {
  execOrExit('git add -A');
  execOrExit('git commit -m "chore(release): ' + releaseVersion + '"');
  execOrExit('git tag -f ' + releaseVersion);
  execOrExit('git push origin HEAD --tags');
}

function release(version, fileName) {
  prerelease();
  var releaseVersion = bump(version);
  changelog(releaseVersion, fileName);
  commit(releaseVersion);
{'fraction_non_alphanumeric': 0.162754303599374, 'fraction_numerical': 0.0012519561815336462, 'mean_word_length': 4.529411764705882, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1713491', 'n_tokens_mistral': 1077, 'n_tokens_neox': 1079, 'n_words': 227}