UNPKG

commitiquette

Version:

Plugin for commitizen to use commitLint config

84 lines (83 loc) 3.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.typeMaker = exports.choicesFactory = exports.filterFactory = exports.validatorFactory = void 0; var tslib_1 = require("tslib"); var conventional_commit_types_1 = require("conventional-commit-types"); var utils_1 = require("../utils"); var validators_1 = require("../validators"); var when_1 = require("../when"); var filters_1 = require("../filters"); function validatorFactory(rules) { return function (value) { return (0, validators_1.validate)([ { value: value, rule: rules['type-max-length'], validator: validators_1.maxLengthValidator, message: function (length) { return "Type maximum length of " + length + " has been exceeded"; }, }, { value: value, rule: rules['type-min-length'], validator: validators_1.minLengthValidator, message: function (length) { return "Type minimum length of " + length + " has not been met"; }, }, { value: value, rule: rules['type-empty'], validator: validators_1.emptyValidator, message: function () { return 'Type cannot be empty'; }, }, { value: value, rule: rules['type-case'], validator: validators_1.caseValidator, message: function (ruleValue, applicable) { return "Type must " + (applicable == 'never' ? 'not ' : '') + "be in " + ruleValue; }, }, ]); }; } exports.validatorFactory = validatorFactory; function filterFactory(rules) { return function (value) { return (0, filters_1.wordCaseFilter)(value, rules['type-case']); }; } exports.filterFactory = filterFactory; function choicesFactory(rules, commitTypes) { var _a; var _b = (_a = rules['type-enum']) !== null && _a !== void 0 ? _a : [, , null], typeEnum = _b[2]; var choices; if (typeEnum && typeEnum.length > 0) { var longest_1 = (0, utils_1.getLongest)(typeEnum); choices = typeEnum.map(function (value) { var _a, _b; return ({ name: value.padEnd(longest_1) + ": " + ((_b = (_a = commitTypes[value]) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : ''), value: value, short: value, }); }); } return (choices || Object.keys(commitTypes).map(function (commitType) { var _a; return ({ name: commitType + ": " + ((_a = commitTypes[commitType].description) !== null && _a !== void 0 ? _a : ''), value: commitType, short: commitType, }); })); } exports.choicesFactory = choicesFactory; function typeMaker(questions, rules) { var question = { name: 'type', message: "Select the type of change you're committing:\n", type: 'list', choices: choicesFactory(rules, conventional_commit_types_1.types), validate: validatorFactory(rules), when: (0, when_1.whenFactory)(rules['type-enum'], rules['type-empty']), filter: filterFactory(rules), }; return (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([], questions, true), [question], false); } exports.typeMaker = typeMaker;