UNPKG

jack-cli

Version:

Chop through that Git log wicked fast!

91 lines 3.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var keys_def_1 = require("./keys-def"); var KEY_REGEX = /^([CS]-)?[a-z]$/; var validateCommandProperty = function (_a) { var command = _a.command; if (!command) { throw new Error("Missing required property \"command\"."); } if (typeof command !== 'string') { throw new Error("Property \"command\" must be a string."); } var invalidTokenIndex = command.search(/\[% [^\%]+ %\]/g); if (invalidTokenIndex !== -1) { var invalidTokenString = command.slice(invalidTokenIndex, command.indexOf('%]', invalidTokenIndex) + 2); throw new Error("Invalid token " + invalidTokenString + " in command: \"" + command + "\"\n\nUse " + invalidTokenString.replace(/ /g, '') + " instead."); } }; var validateCommandArrayProperty = function (_a) { var commandArray = _a.commandArray; if (commandArray) { throw new Error("Property 'commandArray' is deprecated. Use 'command' instead:\n\n \"command\": \"" + commandArray.join(' ') + "\""); } }; var validateDescriptionProperty = function (_a) { var description = _a.description; if (!description) { throw new Error("Missing required property \"description\"."); } if (typeof description !== 'string') { throw new Error("Property \"description\" must be a string."); } }; var validateKeyProperty = function (_a) { var key = _a.key; if (!key) { throw new Error("Missing required property \"key\"."); } if (typeof key !== 'string') { throw new Error("Property \"key\" must be a string."); } if (!KEY_REGEX.test(key)) { throw new Error("Property \"key\" must match against the regex \"" + KEY_REGEX + "\""); } if (keys_def_1.ALL_KEYS.includes(key)) { throw new Error( // tslint:disable-next-line:max-line-length "The key combination \"" + key + "\" is reserved. Here is the list of reserved key combinations: " + keys_def_1.ALL_KEYS.join(' ')); } }; var validateForegroundProperty = function (_a) { var foreground = _a.foreground; if (foreground && typeof foreground !== 'boolean') { throw new Error('Property "foreground" must be a boolean.'); } }; var validateOnErrorCommandProperty = function (_a) { var onErrorCommand = _a.onErrorCommand; if (onErrorCommand && typeof onErrorCommand !== 'string') { throw new Error('Property "onErrorCommand" must be a string'); } }; var validateRefreshOnCompleteProperty = function (_a) { var refreshOnComplete = _a.refreshOnComplete; if (refreshOnComplete && typeof refreshOnComplete !== 'boolean') { throw new Error('Property "refreshOnComplete" must be a boolean.'); } }; var VALIDATORS = [ validateCommandProperty, validateCommandArrayProperty, validateDescriptionProperty, validateKeyProperty, validateForegroundProperty, validateOnErrorCommandProperty, validateRefreshOnCompleteProperty, ]; exports.validateCommand = function (command) { var commandErrors = []; for (var _i = 0, VALIDATORS_1 = VALIDATORS; _i < VALIDATORS_1.length; _i++) { var validator = VALIDATORS_1[_i]; try { validator(command); } catch (error) { commandErrors.push(error.message); } } return commandErrors; }; //# sourceMappingURL=validators.js.map