gitmoji-cli
Advanced tools
Comparing version 4.2.0 to 4.3.0
@@ -17,2 +17,4 @@ #!/usr/bin/env node | ||
var _flags = _interopRequireDefault(require("./constants/flags")); | ||
var _findGitmojiCommand = _interopRequireDefault(require("./utils/findGitmojiCommand")); | ||
@@ -31,10 +33,10 @@ | ||
Options | ||
--commit, -c Interactively commit using the prompts | ||
--config, -g Setup gitmoji-cli preferences. | ||
--init, -i Initialize gitmoji as a commit hook | ||
--list, -l List all the available gitmojis | ||
--remove, -r Remove a previously initialized commit hook | ||
--search, -s Search gitmojis | ||
--update, -u Sync emoji list with the repo | ||
--version, -v Print gitmoji-cli installed version | ||
--${_flags.default.COMMIT}, -c Interactively commit using the prompts | ||
--${_flags.default.CONFIG}, -g Setup gitmoji-cli preferences. | ||
--${_flags.default.INIT}, -i Initialize gitmoji as a commit hook | ||
--${_flags.default.LIST}, -l List all the available gitmojis | ||
--${_flags.default.REMOVE}, -r Remove a previously initialized commit hook | ||
--${_flags.default.SEARCH}, -s Search gitmojis | ||
--${_flags.default.UPDATE}, -u Sync emoji list with the repo | ||
--${_flags.default.VERSION}, -v Print gitmoji-cli installed version | ||
Examples | ||
@@ -45,35 +47,35 @@ $ gitmoji -l | ||
flags: { | ||
commit: { | ||
[_flags.default.COMMIT]: { | ||
type: 'boolean', | ||
alias: 'c' | ||
}, | ||
config: { | ||
[_flags.default.CONFIG]: { | ||
type: 'boolean', | ||
alias: 'g' | ||
}, | ||
help: { | ||
[_flags.default.HELP]: { | ||
type: 'boolean', | ||
alias: 'h' | ||
}, | ||
init: { | ||
[_flags.default.INIT]: { | ||
type: 'boolean', | ||
alias: 'i' | ||
}, | ||
list: { | ||
[_flags.default.LIST]: { | ||
type: 'boolean', | ||
alias: 'l' | ||
}, | ||
remove: { | ||
[_flags.default.REMOVE]: { | ||
type: 'boolean', | ||
alias: 'r' | ||
}, | ||
search: { | ||
[_flags.default.SEARCH]: { | ||
type: 'boolean', | ||
alias: 's' | ||
}, | ||
update: { | ||
[_flags.default.UPDATE]: { | ||
type: 'boolean', | ||
alias: 'u' | ||
}, | ||
version: { | ||
[_flags.default.VERSION]: { | ||
type: 'boolean', | ||
@@ -85,12 +87,12 @@ alias: 'v' | ||
const options = { | ||
commit: () => _commands.default.commit('client'), | ||
config: () => _commands.default.config(), | ||
hook: () => _commands.default.commit('hook'), | ||
init: () => _commands.default.createHook(), | ||
list: () => _commands.default.list(), | ||
remove: () => _commands.default.removeHook(), | ||
search: () => cli.input.map(input => _commands.default.search(input)), | ||
update: () => _commands.default.update() | ||
[_flags.default.COMMIT]: options => _commands.default.commit(options), | ||
[_flags.default.CONFIG]: () => _commands.default.config(), | ||
[_flags.default.HOOK]: options => _commands.default.commit(options), | ||
[_flags.default.INIT]: () => _commands.default.createHook(), | ||
[_flags.default.LIST]: () => _commands.default.list(), | ||
[_flags.default.REMOVE]: () => _commands.default.removeHook(), | ||
[_flags.default.SEARCH]: () => cli.input.map(input => _commands.default.search(input)), | ||
[_flags.default.UPDATE]: () => _commands.default.update() | ||
}; | ||
exports.options = options; | ||
(0, _findGitmojiCommand.default)(cli, options); |
@@ -14,2 +14,4 @@ "use strict"; | ||
var _commit = _interopRequireDefault(require("../../constants/commit")); | ||
var _withHook = _interopRequireWildcard(require("./withHook")); | ||
@@ -25,19 +27,19 @@ | ||
const commit = mode => { | ||
if (mode === 'hook') { | ||
const promptAndCommit = options => (0, _getEmojis.default)().then(gitmojis => (0, _prompts.default)(gitmojis, options)).then(questions => { | ||
_inquirer.default.prompt(questions).then(answers => { | ||
if (options.mode === _commit.default.HOOK) return (0, _withHook.default)(answers); | ||
return (0, _withClient.default)(answers); | ||
}); | ||
}); | ||
const commit = options => { | ||
if (options.mode === _commit.default.HOOK) { | ||
(0, _withHook.registerHookInterruptionHandler)(); | ||
return (0, _withHook.cancelIfNeeded)().then(() => promptAndCommit(mode)); | ||
return (0, _withHook.cancelIfNeeded)().then(() => promptAndCommit(options)); | ||
} | ||
return promptAndCommit(mode); | ||
return promptAndCommit(options); | ||
}; | ||
const promptAndCommit = mode => (0, _getEmojis.default)().then(gitmojis => (0, _prompts.default)(gitmojis, mode)).then(questions => { | ||
_inquirer.default.prompt(questions).then(answers => { | ||
if (mode === 'hook') return (0, _withHook.default)(answers); | ||
return (0, _withClient.default)(answers); | ||
}); | ||
}); | ||
var _default = commit; | ||
exports.default = _default; |
@@ -24,7 +24,8 @@ "use strict"; | ||
var _default = (gitmojis, mode) => { | ||
var _default = (gitmojis, options) => { | ||
const { | ||
title, | ||
message | ||
} = (0, _getDefaultCommitContent.default)(mode); | ||
message, | ||
scope | ||
} = (0, _getDefaultCommitContent.default)(options); | ||
return [{ | ||
@@ -43,3 +44,6 @@ name: 'gitmoji', | ||
message: 'Enter the scope of current changes:', | ||
validate: _guard.default.scope | ||
validate: _guard.default.scope, | ||
...(scope ? { | ||
default: scope | ||
} : {}) | ||
}] : []), { | ||
@@ -46,0 +50,0 @@ name: 'title', |
@@ -8,6 +8,28 @@ "use strict"; | ||
var _commit = _interopRequireDefault(require("../constants/commit")); | ||
var _flags = _interopRequireDefault(require("../constants/flags")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
const getOptionsForCommand = (command, flags) => { | ||
const commandsWithOptions = [_flags.default.COMMIT, _flags.default.HOOK]; | ||
if (commandsWithOptions.includes(command)) { | ||
return { | ||
message: flags['message'], | ||
mode: command === _flags.default.HOOK ? _commit.default.HOOK : _commit.default.CLIENT, | ||
scope: flags['scope'], | ||
title: flags['title'] | ||
}; | ||
} | ||
return null; | ||
}; | ||
const findGitmojiCommand = (cli, options) => { | ||
const flags = cli.flags; | ||
const matchedFlagsWithInput = Object.keys(flags).map(flag => flags[flag] && flag).filter(flag => options[flag]); | ||
return options[matchedFlagsWithInput] ? options[matchedFlagsWithInput]() : cli.showHelp(); | ||
const commandFlag = Object.keys(flags).map(flag => flags[flag] && flag).find(flag => options[flag]); | ||
const commandOptions = getOptionsForCommand(commandFlag, flags); | ||
return options[commandFlag] ? options[commandFlag](commandOptions) : cli.showHelp(); | ||
}; | ||
@@ -14,0 +36,0 @@ |
@@ -10,2 +10,4 @@ "use strict"; | ||
var _commit = _interopRequireDefault(require("../constants/commit")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -17,3 +19,3 @@ | ||
const getDefaultCommitContent = mode => { | ||
const getDefaultCommitContent = options => { | ||
/* | ||
@@ -26,6 +28,7 @@ Since the hook is called with `gitmoji --hook $1` | ||
if (mode === 'client' || !_fs.default.existsSync(commitFilePath)) { | ||
if (options.mode === _commit.default.CLIENT || !_fs.default.existsSync(commitFilePath)) { | ||
return { | ||
title: null, | ||
message: null | ||
message: options['message'] || null, | ||
scope: options['scope'] || null, | ||
title: options['title'] || null | ||
}; | ||
@@ -37,4 +40,5 @@ } | ||
return { | ||
title: commitFileContent[COMMIT_TITLE_LINE_INDEX], | ||
message: commitFileContent.length > COMMIT_MESSAGE_LINE_INDEX ? commitFileContent[COMMIT_MESSAGE_LINE_INDEX] : null | ||
message: commitFileContent.length > COMMIT_MESSAGE_LINE_INDEX ? commitFileContent[COMMIT_MESSAGE_LINE_INDEX] : null, | ||
scope: options['scope'], | ||
title: commitFileContent[COMMIT_TITLE_LINE_INDEX] | ||
}; | ||
@@ -41,0 +45,0 @@ }; |
{ | ||
"name": "gitmoji-cli", | ||
"version": "4.2.0", | ||
"version": "4.3.0", | ||
"description": "A gitmoji client for using emojis on commit messages.", | ||
@@ -108,3 +108,3 @@ "engines": { | ||
"*.{js}": [ | ||
"prettier --write src/**/*.js", | ||
"prettier --write", | ||
"git add" | ||
@@ -111,0 +111,0 @@ ] |
@@ -67,2 +67,16 @@ # gitmoji-cli | ||
##### Options | ||
You can pass default values to the prompts using the following flags: | ||
- `title`: For setting the commit title. | ||
- `message`: For setting the commit message. | ||
- `scope`: For setting the commit scope. | ||
Those flags should be used like this: | ||
```bash | ||
$ gitmoji -c --title="Commit" --message="Message" --scope="Scope" | ||
``` | ||
#### Hook | ||
@@ -69,0 +83,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
40468
31
775
137