<commit_before>const chalk = require('chalk');
const fs = require('fs-extra');
const readline = require('readline');
const path = require('path');
const semver = require('semver');
const yargs = require('yargs');

const changelogUtil = require('./changelog.js');
const gitUtils = require('./git-utils.js');
const githubRelease = require('./github-release.js');
const minify = require('./minify.js');
const npmUtils = require('./npm-utils.js');
const pkg = require('../package.json');

const TAG_PREFIX = '';
const VERSION_PREFIX = 'v';
const RELEASE_COMMIT_MSG = 'chore(release): publish version %s';

const argv = yargs.argv;
const options = argv;
const cwd = process.cwd();

const childProcess = require('./child-process.js');


/** 
 * Main entry, this script will execute the following steps
 * 1. Ask for version bump type
 * 2. Bump version in "package.json" and "slick.grid.js"
 * 3. Run minify script and add the new version number to each minified file headers
 * 4. Create/Update changelog.md
 * 5. Update (sync) npm lock file with new version
 * 6. Add all changed files to Git ("package.json", "slick.grid.js", "CHANGELOG.md" and all minified files)
 * 7. Create git tag of the new release
 * 8. Commit all files changed to git
 * 9. Push git tags and all commits to origin
 * 10. NPM publish
 * 11. Create GitHub Release
 */
(async function main() {
  let dryRunPrefix = options.dryRun ? '[dry-run]' : '';
  let newTag;
  if (options.dryRun) {
    console.info(`-- ${chalk.bgMagenta('DRY-RUN')} mode --`);
  }
  await gitUtils.hasUncommittedChanges(options);
  const repo = githubRelease.parseGitRepo();


  console.log(`🚀 Let's create a new release for "${repo.owner}/${repo.name}" (currently at ${pkg.version})\n`);

  // 1. choose bump type
  const bumpTypes = [
    { bump: 'patch', desc: ' - Bug Fixes' },
    { bump: 'minor', desc: ' - Features & Fixes' },
    { bump: 'major', desc: ' - Breaking Change' },
    { bump: 'preminor.alpha', desc: '' },
    { bump: 'preminor.beta', desc: '' },
    { bump: 'premajor.alpha', desc: '' },
    { bump: 'premajor.beta', desc: '' },
  ]
  const versionIncrements = [];
  for (const bumpType of bumpTypes) {
    versionIncrements.push({
      key: bumpType.bump,
      name: `${bumpType.bump} (${chalk.bold.magenta(bumpVersion(bumpType.bump, false))}) ${bumpType.desc}`,
      value: bumpType.bump
    });
  }
  versionIncrements.push(
    { key: 'o', name: 'Other, please specify...', value: 'other' },
    { key: 'q', name: 'QUIT', value: 'quit' }
  );

  const whichBumpType = await promptConfirmation(
    `${chalk.bgMagenta(dryRunPrefix)} Select increment to apply (next version)`,
    versionIncrements,
    defaultIndex = versionIncrements.length - 1
  );
 
  if (whichBumpType !== 'quit') {
    let newVersion = '';
    if (whichBumpType === 'other') {
      newVersion = await getConsoleInput('Please enter a valid version number (or type "q" to quit):');
      if (newVersion === 'q') {
        return;
      }
    } else {
      newVersion = bumpVersion(whichBumpType, false);
    }

    newTag = `${TAG_PREFIX}${newVersion}`;
    console.log(`${chalk.bgMagenta(dryRunPrefix)} Bumping new version to "${newTag}"`);

    // 2. update package.json & slick.grid.js with new version
    updatePackageVersion(newVersion);
    updateSlickGridVersion(newVersion);

    // 3. minify JS/CSS files
    const changedFiles = await minify.execute();
    changedFiles.add(path.resolve('./package.json'));
    changedFiles.add(path.resolve('./slick.grid.js'));

    // 4. Create/Update changelog.md
    const { location: changelogPath, newEntry: newChangelogEntry } = await changelogUtil.updateChangelog({
      infile: './CHANGELOG.md',
      preset: 'angular',
      tagPrefix: TAG_PREFIX,
    }, newVersion);
    changedFiles.add(changelogPath);

    // 5. Update (sync) npm lock file
    await npmUtils.syncLockFile({ cwd, dryRun: options.dryRun });
    changedFiles.add(path.resolve('./package-lock.json'));

    // 6. "git add" all changed files
    options.dryRun
      ? await gitUtils.gitAdd(null, { cwd, dryRun: options.dryRun })<commit_msg>chore: release script need to await version update before minify process starts<commit_after>const chalk = require('chalk');
const fs = require('fs-extra');
const readline = require('readline');
const path = require('path');
const semver = require('semver');
const yargs = require('yargs');

const changelogUtil = require('./changelog.js');
const gitUtils = require('./git-utils.js');
const githubRelease = require('./github-release.js');
const minify = require('./minify.js');
const npmUtils = require('./npm-utils.js');
const pkg = require('../package.json');

const TAG_PREFIX = '';
const VERSION_PREFIX = 'v';
const RELEASE_COMMIT_MSG = 'chore(release): publish version %s';

const argv = yargs.argv;
const options = argv;
const cwd = process.cwd();

const childProcess = require('./child-process.js');


/** 
 * Main entry, this script will execute the following steps
 * 1. Ask for version bump type
 * 2. Bump version in "package.json" and "slick.grid.js"
 * 3. Run minify script and add the new version number to each minified file headers
 * 4. Create/Update changelog.md
 * 5. Update (sync) npm lock file with new version
 * 6. Add all changed files to Git ("package.json", "slick.grid.js", "CHANGELOG.md" and all minified files)
 * 7. Create git tag of the new release
 * 8. Commit all files changed to git
 * 9. Push git tags and all commits to origin
 * 10. NPM publish
 * 11. Create GitHub Release
 */
(async function main() {
  let dryRunPrefix = options.dryRun ? '[dry-run]' : '';
  let newTag;
  if (options.dryRun) {
    console.info(`-- ${chalk.bgMagenta('DRY-RUN')} mode --`);
  }
  await gitUtils.hasUncommittedChanges(options);
  const repo = githubRelease.parseGitRepo();


  console.log(`🚀 Let's create a new release for "${repo.owner}/${repo.name}" (currently at ${pkg.version})\n`);

  // 1. choose bump type
  const bumpTypes = [
    { bump: 'patch', desc: ' - Bug Fixes' },
    { bump: 'minor', desc: ' - Features & Fixes' },
    { bump: 'major', desc: ' - Breaking Change' },
    { bump: 'preminor.alpha', desc: '' },
    { bump: 'preminor.beta', desc: '' },
    { bump: 'premajor.alpha', desc: '' },
    { bump: 'premajor.beta', desc: '' },
  ]
  const versionIncrements = [];
  for (const bumpType of bumpTypes) {
    versionIncrements.push({
      key: bumpType.bump,
      name: `${bumpType.bump} (${chalk.bold.magenta(bumpVersion(bumpType.bump, false))}) ${bumpType.desc}`,
      value: bumpType.bump
    });
  }
  versionIncrements.push(
    { key: 'o', name: 'Other, please specify...', value: 'other' },
    { key: 'q', name: 'QUIT', value: 'quit' }
  );

  const whichBumpType = await promptConfirmation(
    `${chalk.bgMagenta(dryRunPrefix)} Select increment to apply (next version)`,
    versionIncrements,
    defaultIndex = versionIncrements.length - 1
  );
 
  if (whichBumpType !== 'quit') {
    let newVersion = '';
    if (whichBumpType === 'other') {
      newVersion = await getConsoleInput('Please enter a valid version number (or type "q" to quit):');
      if (newVersion === 'q') {
        return;
      }
    } else {
      newVersion = bumpVersion(whichBumpType, false);
    }

    newTag = `${TAG_PREFIX}${newVersion}`;
    console.log(`${chalk.bgMagenta(dryRunPrefix)} Bumping new version to "${newTag}"`);

    // 2. update package.json & slick.grid.js with new version
    await updatePackageVersion(newVersion);
    await updateSlickGridVersion(newVersion);

    // 3. minify JS/CSS files
    const changedFiles = await minify.execute();
    changedFiles.add(path.resolve('./package.json'));
    changedFiles.add(path.resolve('./slick.grid.js'));

    // 4. Create/Update changelog.md
    const { location: changelogPath, newEntry: newChangelogEntry } = await changelogUtil.updateChangelog({
      infile: './CHANGELOG.md',
      preset: 'angular',
      tagPrefix: TAG_PREFIX,
    }, newVersion);
    changedFiles.add(changelogPath);

    // 5. Update (sync) npm lock file
    await npmUtils.syncLockFile({ cwd, dryRun: options.dryRun });
    changedFiles.add(path.resolve('./package-lock.json'));

    // 6. "git add" all changed files
    options.dryRun
      ? await gitUtils.gitAdd(null, { cwd, dryRun: options.dryRun })
{'fraction_non_alphanumeric': 0.15621230398069963, 'fraction_numerical': 0.0048250904704463205, 'mean_word_length': 3.5157952069716774, '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': '6467301', 'n_tokens_mistral': 2729, 'n_tokens_neox': 2626, 'n_words': 735}