All files global.js

95.23% Statements 20/21
57.14% Branches 4/7
100% Functions 4/4
95.23% Lines 20/21

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 83 84 85 86 87 88 89 90 91 92 93 94 95 965x 5x                       5x                                       5x                 5x                           5x 5x   5x 5x 55x                 5x               5x     1x 2x 1x 1x     1x   1x 1x       5x  
const { join } = require('path');
const commitTypes = require('conventional-commit-types');
 
/**
 * @module Global
 */
 
/**
 * Console output colors
 *
 * @type {{RED: string, WHITE: string, BLUE: string, NOCOLOR: string, BLACK: string, MAGENTA: string,
 *     YELLOW: string, CYAN: string, GREEN: string, GREY: string}}
 */
const color = {
  BLACK: '\x1b[30m',
  BLUE: '\x1b[34m',
  CYAN: '\x1b[36m',
  GREEN: '\x1b[32m',
  GREY: '\x1b[90m',
  MAGENTA: '\x1b[35m',
  NOCOLOR: '\x1b[0m',
  RED: '\x1b[31m',
  WHITE: '\x1b[37m',
  YELLOW: '\x1b[33m'
};
 
/**
 * Set context path
 *
 * @type {string}
 * @private
 */
const contextPath =
  (process.env.NODE_ENV === 'test' && join('..', 'src', '__fixtures__')) ||
  (process.env.NODE_ENV === 'development' && join(__dirname, './__fixtures__')) ||
  process.cwd();
 
/**
 * Custom catch all commit type for use with the "isAllowNonConventionalCommits"
 *
 * @type {{general: {description: string, title: string, value: string}}}
 */
const generalCommitType = {
  general: {
    description: 'Commits without category',
    title: 'General',
    value: 'general'
  }
};
 
/**
 * Conventional commit types, expose "key" as "value"
 *
 * @type {{feat: {description: string, title: string, value: string}, fix: {description: string, title: string, value: string},
 *     chore: {description: string, title: string, value: string}}}
 */
const conventionalCommitType = (types => {
  const updatedTypes = {};
 
  try {
    Object.entries(types).forEach(([key, value]) => {
      updatedTypes[key] = {
        ...value,
        value: key
      };
    });
  } catch (e) {
    console.error(color.RED, `Conventional commit types: ${e.message}`, color.NOCOLOR);
  }
 
  return updatedTypes;
})(commitTypes.types);
 
/**
 * Global options/settings. One time _set, then freeze.
 *
 * @type {{contextPath: string, _set: *}}
 */
const OPTIONS = {
  contextPath,
  set _set(obj) {
    Object.entries(obj).forEach(([key, value]) => {
      if (typeof value === 'function') {
        this[key] = value.call(this);
        return;
      }
 
      this[key] = value;
    });
    delete this._set;
    Object.freeze(this);
  }
};
 
module.exports = { color, contextPath, conventionalCommitType, generalCommitType, OPTIONS };