gitmoji-cli
Advanced tools
Comparing version 1.1.1 to 1.2.0
37
cli.js
@@ -20,2 +20,3 @@ #!/usr/bin/env node | ||
--search, -s Search gitmojis | ||
--version, -v Print gitmoji-cli installed version | ||
Examples | ||
@@ -30,3 +31,4 @@ $ gitmoji -l | ||
s: 'search', | ||
h: 'help' | ||
h: 'help', | ||
v: 'version' | ||
} | ||
@@ -44,22 +46,17 @@ }); | ||
if (cli.flags.list) { | ||
gitmojiCli.list(); | ||
} | ||
const commands = { | ||
list: () => gitmojiCli.list(), | ||
search: () => cli.input.map(element => gitmojiCli.search(element)), | ||
init: () => gitmojiCli.init(), | ||
hook: () => gitmojiCli.ask('hook'), | ||
version: () => console.log(gitmojiCli.version(pkg.version)), | ||
commit: () => gitmojiCli.ask('client'), | ||
undefined: () => gitmojiCli.ask('client') | ||
}; | ||
if (cli.flags.search) { | ||
cli.input.map(element => { | ||
return gitmojiCli.search(element); | ||
}); | ||
const arg = Object.keys(cli.flags)[1]; | ||
if (commands[arg]) { | ||
commands[arg](); | ||
} else { | ||
cli.showHelp(); | ||
} | ||
if (cli.flags.commit) { | ||
gitmojiCli.ask('client'); | ||
} | ||
if (cli.flags.init) { | ||
gitmojiCli.init(); | ||
} | ||
if (cli.flags.hook) { | ||
gitmojiCli.ask('hook'); | ||
} |
{ | ||
"name": "gitmoji-cli", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "A gitmoji client for using emojis on commit messages.", | ||
@@ -14,3 +14,4 @@ "engines": { | ||
"rules": { | ||
"array-callback-return": 1 | ||
"array-callback-return": 1, | ||
"default-case": 1 | ||
}, | ||
@@ -17,0 +18,0 @@ "ignores": [ |
@@ -35,5 +35,7 @@ # gitmoji-cli | ||
Options | ||
--init, -i Initialize gitmoji as a commit hook | ||
--commit, -c Interactively commit using the prompts | ||
--list, -l List all the available gitmojis | ||
--search, -s Search gitmojis | ||
--version, -v Print gitmoji-cli installed version | ||
``` | ||
@@ -43,4 +45,8 @@ | ||
Add your changes and start the interactive commit client, to auto generate your commit based on your prompts. | ||
You can use the commit functionality in two ways, directly or via a commit-hook. | ||
#### Client | ||
Start the interactive commit client, to auto generate your commit based on your prompts. | ||
```bash | ||
@@ -50,2 +56,12 @@ $ gitmoji -c | ||
#### Hook | ||
Run the init option, add your changes and commit them, after that the prompts will begin and your commit message will be built. | ||
```bash | ||
$ gitmoji -i # this will create the .git/hook/prepare-commit-msg | ||
$ git add . | ||
$ git commit | ||
``` | ||
![gitmoji commit](https://cloud.githubusercontent.com/assets/7629661/20454513/5db2750a-ae43-11e6-99d7-4757108fe640.png) | ||
@@ -52,0 +68,0 @@ |
@@ -17,7 +17,8 @@ 'use strict'; | ||
init() { | ||
const hookFile = 'prepare-commit-msg'; | ||
const path = `${process.env.PWD}/.git/hooks/${hookFile}`; | ||
const fileContents = `#!/bin/sh\n# gitmoji as a commit hook\nexec < /dev/tty\ngitmoji --hook $1`; | ||
if (this._isAGitRepo('.git')) { | ||
const path = `${process.env.PWD}/.git/hooks`; | ||
const fileContents = `#!/bin/sh\n# gitmoji as a commit hook\nexec < /dev/tty\ngitmoji --hook $1`; | ||
fs.writeFile(`${path}/prepare-commit-msg`, fileContents, {mode: 755}, err => { | ||
fs.writeFile(path, fileContents, {mode: 755}, err => { | ||
if (err) { | ||
@@ -29,4 +30,13 @@ console.error(chalk.red(`ERROR: ${err}`)); | ||
} | ||
return { | ||
path, | ||
fileContents | ||
}; | ||
} | ||
version(number) { | ||
return number; | ||
} | ||
list() { | ||
@@ -63,7 +73,7 @@ return this._gitmojiApiClient.request({ | ||
this._commit(answers); | ||
break; | ||
break; | ||
case 'hook': | ||
this._hook(answers); | ||
break; | ||
break; | ||
} | ||
@@ -91,8 +101,12 @@ }); | ||
execa.stdout('git', ['add', '.']) | ||
.then(res => console.log(chalk.blue(res))) | ||
.catch(err => console.error(chalk.red(`ERROR: ${err.stderr}`))); | ||
execa.shell(`git commit ${signed} -m "${commitTitle}" -m "${commitBody}"`) | ||
.then(res => console.log(chalk.blue(res.stdout))) | ||
.catch(err => console.error(chalk.red(`ERROR: ${err.stderr}`))); | ||
if (this._isAGitRepo('.git')) { | ||
execa.stdout('git', ['add', '.']) | ||
.then(res => console.log(chalk.blue(res))) | ||
.catch(err => console.error(chalk.red(`ERROR: ${err.stderr}`))); | ||
execa.shell(`git commit ${signed} -m "${commitTitle}" -m "${commitBody}"`) | ||
.then(res => console.log(chalk.blue(res.stdout))) | ||
.catch(err => console.error(chalk.red(`ERROR: ${err.stderr}`))); | ||
} | ||
return `git commit ${signed} -m "${commitTitle}" -m "${commitBody}"`; | ||
} | ||
@@ -99,0 +113,0 @@ |
@@ -7,2 +7,3 @@ 'use strict'; | ||
const should = require('should'); | ||
const pkg = require('./../package.json'); | ||
@@ -16,6 +17,41 @@ const gitmojiApiClient = axios.create({ | ||
const prompts = { | ||
gitmoji: ':zap:', | ||
title: 'Improving performance issues.', | ||
message: 'Refactored code.', | ||
reference: '5', | ||
signed: true | ||
}; | ||
const gitmojiCli = new GitmojiCli(gitmojiApiClient); | ||
describe('gitmoji', function() { | ||
describe('commit', function() { | ||
it('should return the formed commit based on the input prompts', function() { | ||
gitmojiCli._commit(prompts).should.equal('git commit -s -m ":zap: Improving performance issues." -m "Refactored code. #5"'); | ||
}); | ||
}); | ||
describe('init', function() { | ||
it('path should be set to .git/hooks/prepare-commit-msg', function() { | ||
gitmojiCli.init().path.should.containEql('.git/hooks/prepare-commit-msg'); | ||
}); | ||
it('prepare-commit-msg should contain the hook script', function() { | ||
gitmojiCli.init().fileContents.should.containEql('exec < /dev/tty\ngitmoji --hook $1'); | ||
}); | ||
}); | ||
describe('version', function() { | ||
it('should return the version number equal to the package.json one', function() { | ||
gitmojiCli.version(pkg.version).should.be.equal(pkg.version); | ||
}); | ||
it('should return a version number not equal to the package.json', function() { | ||
gitmojiCli.version(pkg.version).should.not.be.equal('1.0.0'); | ||
}); | ||
}); | ||
describe('_isAGitRepo', function() { | ||
@@ -22,0 +58,0 @@ it('should find a .git repo and return true', function() { |
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
81104
11
273
86