UNPKG

gitmoji-cli

Version:

A gitmoji client for using emojis on commit messages.

40 lines (31 loc) 1.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _fs = _interopRequireDefault(require("fs")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const COMMIT_FILE_PATH_INDEX = 3; const COMMIT_TITLE_LINE_INDEX = 0; const COMMIT_MESSAGE_LINE_INDEX = 2; const getDefaultCommitContent = mode => { /* Since the hook is called with `gitmoji --hook $1` According to https://git-scm.com/docs/githooks#_prepare_commit_msg, the commit file path will be stored in the 4th argument of the command */ const commitFilePath = process.argv[COMMIT_FILE_PATH_INDEX]; if (mode === 'client' || !_fs.default.existsSync(commitFilePath)) { return { title: null, message: null }; } const commitFileContent = _fs.default.readFileSync(commitFilePath).toString().split('\n'); return { title: commitFileContent[COMMIT_TITLE_LINE_INDEX], message: commitFileContent.length > COMMIT_MESSAGE_LINE_INDEX ? commitFileContent[COMMIT_MESSAGE_LINE_INDEX] : null }; }; var _default = getDefaultCommitContent; exports.default = _default;