All files index.js

80% Statements 16/20
80% Branches 20/25
100% Functions 1/1
80% Lines 16/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 831x 1x 1x 1x                                                         1x                       2x       2x 2x 2x   2x             2x 2x   2x       2x       2x                     1x  
const { color, OPTIONS } = require('./global');
const { commitFiles, getOverrideVersion, getVersion } = require('./cmds');
const { parseCommits, semverBump } = require('./parse');
const { updateChangelog, updatePackage } = require('./files');
 
/**
 * Start `changelog` updates
 *
 * @module Init
 */
 
/**
 * Set changelog and package.
 *
 * @param {object} options
 * @param {string} options.changelogFile
 * @param {string} options.contextPath
 * @param {boolean} options.isCommit
 * @param {boolean} options.isDryRun
 * @param {string} options.overrideVersion
 * @param {object} settings
 * @param {Function} settings.commitFiles
 * @param {Function} settings.getOverrideVersion
 * @param {Function} settings.getVersion
 * @param {Function} settings.parseCommits
 * @param {Function} settings.semverBump
 * @param {Function} settings.updateChangelog
 * @param {Function} settings.updatePackage
 * @returns {{parsedCommits: {"Bug Fixes": {commits: string[], title: string}, Chores: {commits: string[],
 *     title: string}, Features: {commits: string[], title: string}}, semverBump: ("major"|"minor"|"patch"),
 *     package: string, versionClean: *, changelog: string, semverWeight: number, version: *}}
 */
const commitChangelog = (
  { changelogFile, contextPath, isCommit, isDryRun, overrideVersion } = OPTIONS,
  {
    commitFiles: commitAliasFiles = commitFiles,
    getOverrideVersion: getAliasOverrideVersion = getOverrideVersion,
    getVersion: getAliasVersion = getVersion,
    parseCommits: parseAliasCommits = parseCommits,
    semverBump: semverAliasBump = semverBump,
    updateChangelog: updateAliasChangelog = updateChangelog,
    updatePackage: updateAliasPackage = updatePackage
  } = {}
) => {
  Iif (process.env.NODE_ENV !== 'test') {
    process.chdir(contextPath);
  }
 
  const { commits, isBreakingChanges } = parseAliasCommits();
  const { bump, weight } = semverAliasBump({ commits, isBreakingChanges });
  const { clean: cleanVersion, version } = (overrideVersion && getAliasOverrideVersion()) || getAliasVersion(bump);
 
  Iif (isDryRun) {
    console.info(
      color.CYAN,
      `\nDry run ${changelogFile} output...\nVersion: ${version}\nSemver bump: ${bump}\nSemver weight: ${weight}`
    );
  }
 
  const changelog = updateAliasChangelog({ commits, packageVersion: cleanVersion, isBreakingChanges });
  const packageJSON = updateAliasPackage((overrideVersion && cleanVersion) || bump);
 
  Iif (isCommit && !isDryRun) {
    commitAliasFiles(cleanVersion);
  }
 
  Iif (isDryRun) {
    console.info(color.NOCOLOR);
  }
 
  return {
    changelog,
    package: packageJSON,
    parsedCommits: commits,
    semverBump: bump,
    semverWeight: weight,
    version,
    versionClean: cleanVersion
  };
};
 
module.exports = { commitChangelog, OPTIONS };