UNPKG

conventional-changelog-lint

Version:

Lint commit messages against a conventional-changelog preset and ruleset

66 lines (51 loc) 2.36 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray'); var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2); exports.default = format; var _chalk = require('chalk'); var _chalk2 = _interopRequireDefault(_chalk); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var DEFAULT_SIGNS = [' ', '⚠', '✖']; var DEFAULT_COLORS = ['white', 'yellow', 'red']; function format() { var report = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var _options$signs = options.signs, signs = _options$signs === undefined ? DEFAULT_SIGNS : _options$signs, _options$colors = options.colors, colors = _options$colors === undefined ? DEFAULT_COLORS : _options$colors, _options$color = options.color, enabled = _options$color === undefined ? true : _options$color; var _report$errors = report.errors, errors = _report$errors === undefined ? [] : _report$errors, _report$warnings = report.warnings, warnings = _report$warnings === undefined ? [] : _report$warnings; var problems = [].concat((0, _toConsumableArray3.default)(errors), (0, _toConsumableArray3.default)(warnings)).map(function (problem) { var sign = signs[problem.level] || ''; var color = colors[problem.level] || 'white'; var decoration = enabled ? _chalk2.default[color](sign) : sign; var name = _chalk2.default.grey(`[${problem.name}]`); return `${decoration} ${problem.message} ${name}`; }); var sign = selectSign({ errors, warnings }); var color = selectColor({ errors, warnings }); var decoration = enabled ? _chalk2.default[color](sign) : sign; var summary = `${decoration} found ${errors.length} problems, ${warnings.length} warnings`; return [].concat((0, _toConsumableArray3.default)(problems), [enabled ? _chalk2.default.bold(summary) : summary]); } function selectSign(report) { if (report.errors.length > 0) { return '✖'; } return report.warnings.length ? '⚠' : '✔'; } function selectColor(report) { if (report.errors.length > 0) { return 'red'; } return report.warnings.length ? 'yellow' : 'green'; } module.exports = exports['default'];