UNPKG

pivotal-flow

Version:

🔀 A command-line tool that helps you manage & automate your workflow to use with PivotalTracker.

49 lines (48 loc) • 2 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const commander_1 = require("commander"); // hooks const record_params_1 = __importDefault(require("./record-params")); const commit_msg_1 = __importDefault(require("./commit-msg")); const post_checkout_1 = __importDefault(require("./post-checkout")); const prepare_commit_msg_1 = __importDefault(require("./prepare-commit-msg")); // utils const hooks_1 = require("../../utils/hooks"); const console_1 = require("../../utils/console"); const program = new commander_1.Command(); const HANDLERS = { 'record-params': record_params_1.default, 'check-story-id-in-commit': commit_msg_1.default, 'check-story-id-in-branch': post_checkout_1.default, 'add-story-id-to-commit': prepare_commit_msg_1.default, }; const AVAILABLE_HOOKS = Object.keys(HANDLERS); const isValidHook = (hook) => AVAILABLE_HOOKS.includes(hook); const getAvailableHooks = () => `${AVAILABLE_HOOKS.map(hook => ` - ${hook}`).join('\n')}`; program .name('hook') .usage(`<type>\n\n<type>:\n${getAvailableHooks()}`) .option('-E <env_name>', 'Override the name of the environment variable where the the git-hook parameters will be provided. Use this to make the command work with a hook provider other than husky.', 'HUSKY_GIT_PARAMS') .parse(process.argv); const [hookType] = program.args; if (!isValidHook(hookType)) { program.outputHelp(); console_1.warning(`\nInvalid hook '${hookType}'.\n`); process.exit(1); } else { try { const params = hooks_1.parseHookParams(program.E || 'HUSKY_GIT_PARAMS'); HANDLERS[hookType](...params); } catch (e) { console_1.error(`Error running hook '${hookType}'.`); if (e instanceof Error) { console_1.warning(`${e.name}: ${e.message} ${e.stack}`); } process.exit(1); } }