gitmoji-cli
Advanced tools
Comparing version 1.0.0 to 1.1.0
10
cli.js
@@ -6,4 +6,8 @@ #!/usr/bin/env node | ||
const axios = require('axios'); | ||
const updateNotifier = require('update-notifier'); | ||
const GitmojiCli = require('./src/gitmoji.js'); | ||
const pkg = require('./package.json'); | ||
updateNotifier({pkg}).notify(); | ||
const cli = meow(` | ||
@@ -13,3 +17,3 @@ Usage | ||
Options | ||
--init, -i Create and initialize the gitmoji commit hook | ||
--init, -i Initialize gitmoji as a commit hook | ||
--commit, -c Interactively commit using the prompts | ||
@@ -53,1 +57,5 @@ --list, -l List all the available gitmojis | ||
} | ||
if (cli.flags.init) { | ||
gitmojiCli.init(); | ||
} |
{ | ||
"name": "gitmoji-cli", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "A gitmoji client for using emojis on commit messages.", | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"bin": { | ||
@@ -12,7 +15,11 @@ "gitmoji": "cli.js" | ||
"array-callback-return": 1 | ||
} | ||
}, | ||
"ignores": [ | ||
"test/**" | ||
] | ||
}, | ||
"scripts": { | ||
"lint": "xo", | ||
"test": "npm run lint" | ||
"mocha": "mocha ./test/*.js", | ||
"test": "npm run lint && npm run mocha" | ||
}, | ||
@@ -40,7 +47,11 @@ "repository": { | ||
"inquirer": "^1.2.3", | ||
"meow": "^3.7.0" | ||
"meow": "^3.7.0", | ||
"path-exists": "^3.0.0", | ||
"update-notifier": "^1.0.2" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^3.1.2", | ||
"should": "^11.1.1", | ||
"xo": "^0.17.1" | ||
} | ||
} |
# gitmoji-cli | ||
[![Travis Build Status](https://img.shields.io/travis/carloscuesta/gitmoji-cli.svg?style=flat-square)](https://travis-ci.org/carloscuesta/gitmoji-cli) | ||
[![David Dependencies](https://img.shields.io/david/carloscuesta/gitmoji-cli.svg?style=flat-square)](https://david-dm.org/carloscuesta/gitmoji-cli) | ||
[![npm version](https://img.shields.io/npm/v/gitmoji-cli.svg?style=flat-square)](https://www.npmjs.com/package/gitmoji-cli) | ||
[![gitmoji badge](https://img.shields.io/badge/gitmoji-%20😜%20😍-FFDD67.svg?style=flat-square)](https://github.com/carloscuesta/gitmoji) | ||
[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg?style=flat-square)](https://github.com/sindresorhus/xo) | ||
@@ -5,0 +8,0 @@ |
'use strict'; | ||
const fs = require('fs'); | ||
const chalk = require('chalk'); | ||
const inquirer = require('inquirer'); | ||
const execa = require('execa'); | ||
const pathExists = require('path-exists'); | ||
@@ -14,2 +16,16 @@ class GitmojiCli { | ||
init() { | ||
if (this._isAGitRepo('.git')) { | ||
const path = `${process.env.PWD}/.git/hooks`; | ||
const fileContents = `#!/bin/sh\n# gitmoji as a commit hook\ngitmoji -c $1`; | ||
fs.writeFile(`${path}/prepare-commit-msg`, fileContents, {mode: 755}, err => { | ||
if (err) { | ||
console.error(chalk.red(`ERROR: ${err}`)); | ||
} | ||
console.log(`${chalk.yellow('gitmoji')} commit hook created succesfully.`); | ||
}); | ||
} | ||
} | ||
list() { | ||
@@ -21,5 +37,3 @@ return this._gitmojiApiClient.request({ | ||
.then(gitmojis => this._parseGitmojis(gitmojis)) | ||
.catch(err => { | ||
console.error(chalk.red(`ERROR: gitmoji list not found - ${err.code}`)); | ||
}); | ||
.catch(err => console.error(chalk.red(`ERROR: gitmoji list not found - ${err.code}`))); | ||
} | ||
@@ -32,42 +46,37 @@ | ||
}).then(res => res.data.gitmojis) | ||
.then(gitmojis => gitmojis.filter(gitmoji => gitmoji.name.concat(gitmoji.description).indexOf(name) !== -1)) | ||
.then(gitmojisFiltered => this._parseGitmojis(gitmojisFiltered)); | ||
.then(gitmojis => gitmojis.filter(gitmoji => gitmoji.name.concat(gitmoji.description).toLowerCase().indexOf(name.toLowerCase()) !== -1)) | ||
.then(gitmojisFiltered => this._parseGitmojis(gitmojisFiltered)) | ||
.catch(err => console.error(chalk.red(`ERROR: ${err.code}`))); | ||
} | ||
ask() { | ||
return this._gitmojiApiClient.request({ | ||
method: 'GET', | ||
url: '/src/data/gitmojis.json' | ||
}).then(res => res.data.gitmojis) | ||
.then(gitmojis => this._questions(gitmojis)) | ||
.then(questions => { | ||
inquirer.prompt(questions).then(answers => { | ||
this._commit(answers); | ||
}); | ||
}) | ||
.catch(err => { | ||
console.error(err); | ||
}); | ||
if (this._isAGitRepo('.git')) { | ||
return this._gitmojiApiClient.request({ | ||
method: 'GET', | ||
url: '/src/data/gitmojis.json' | ||
}).then(res => res.data.gitmojis) | ||
.then(gitmojis => this._questions(gitmojis)) | ||
.then(questions => { | ||
inquirer.prompt(questions).then(answers => { | ||
this._commit(answers); | ||
}); | ||
}) | ||
.catch(err => console.error(chalk.red(`ERROR: ${err.code}`))); | ||
} | ||
console.error(chalk.red('ERROR: This directory is not a git repository.')); | ||
} | ||
_commit(answers) { | ||
let signed; | ||
const commitTitle = `${answers.gitmoji} ${answers.title}`; | ||
const reference = (answers.reference) ? `#${answers.reference}` : ''; | ||
const signed = this._isCommitSigned(answers.signed); | ||
const commitBody = `${answers.message} ${reference}`; | ||
if (answers.signed === true) { | ||
signed = '-s'; | ||
} else { | ||
signed = ''; | ||
} | ||
execa.stdout('git', ['add', '.']).then(res => console.log(res)).catch(err => console.error(err)); | ||
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(res.stdout); | ||
}) | ||
.catch(err => { | ||
console.error(chalk.red(`ERROR: ${err.stderr}`)); | ||
}); | ||
.then(res => console.log(chalk.blue(res.stdout))) | ||
.catch(err => console.error(chalk.red(`ERROR: ${err.stderr}`))); | ||
} | ||
@@ -79,3 +88,3 @@ | ||
name: 'gitmoji', | ||
message: 'Choose a gitmoji', | ||
message: 'Choose a gitmoji:', | ||
type: 'list', | ||
@@ -91,3 +100,3 @@ choices: gitmojis.map(gitmoji => { | ||
name: 'title', | ||
message: 'Enter the commit title', | ||
message: 'Enter the commit title:', | ||
validate(value) { | ||
@@ -102,7 +111,7 @@ if (value === '') { | ||
name: 'message', | ||
message: 'Enter the commit message' | ||
message: 'Enter the commit message:' | ||
}, | ||
{ | ||
name: 'reference', | ||
message: 'Issue / PR reference #', | ||
message: 'Issue / PR reference #:', | ||
validate(value) { | ||
@@ -113,3 +122,3 @@ if (value === '') { | ||
if (value !== null) { | ||
const validReference = value.match(/(^0|[1-9][0-9]*)+$/); | ||
const validReference = value.match(/(^[1-9][0-9]*)+$/); | ||
if (validReference) { | ||
@@ -124,3 +133,3 @@ return true; | ||
name: 'signed', | ||
message: 'Signed commit', | ||
message: 'Signed commit:', | ||
type: 'confirm' | ||
@@ -138,4 +147,20 @@ } | ||
} | ||
_isCommitSigned(sign) { | ||
let signed; | ||
if (sign) { | ||
signed = '-s'; | ||
} else { | ||
signed = ''; | ||
} | ||
return signed; | ||
} | ||
_isAGitRepo(dir) { | ||
return pathExists.sync(dir); | ||
} | ||
} | ||
module.exports = GitmojiCli; |
Sorry, the diff of this file is not supported yet
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
77333
217
70
7
3
2
+ Addedpath-exists@^3.0.0
+ Addedupdate-notifier@^1.0.2
+ Addedansi-align@1.1.0(transitive)
+ Addedboxen@0.6.0(transitive)
+ Addedcapture-stack-trace@1.0.2(transitive)
+ Addedcli-boxes@1.0.0(transitive)
+ Addedconfigstore@2.1.0(transitive)
+ Addedcreate-error-class@3.0.2(transitive)
+ Addeddeep-extend@0.6.0(transitive)
+ Addeddot-prop@3.0.0(transitive)
+ Addedduplexer2@0.1.4(transitive)
+ Addedfilled-array@1.1.0(transitive)
+ Addedgot@5.7.1(transitive)
+ Addedimurmurhash@0.1.4(transitive)
+ Addedini@1.3.8(transitive)
+ Addedis-npm@1.0.0(transitive)
+ Addedis-obj@1.0.1(transitive)
+ Addedis-redirect@1.0.0(transitive)
+ Addedis-retry-allowed@1.2.0(transitive)
+ Addedlatest-version@2.0.0(transitive)
+ Addedlazy-req@1.1.0(transitive)
+ Addedlowercase-keys@1.0.1(transitive)
+ Addedmkdirp@0.5.6(transitive)
+ Addednode-status-codes@1.0.0(transitive)
+ Addedos-homedir@1.0.2(transitive)
+ Addedosenv@0.1.5(transitive)
+ Addedpackage-json@2.4.0(transitive)
+ Addedpath-exists@3.0.0(transitive)
+ Addedprepend-http@1.0.4(transitive)
+ Addedrc@1.2.8(transitive)
+ Addedread-all-stream@3.1.0(transitive)
+ Addedregistry-auth-token@3.4.0(transitive)
+ Addedregistry-url@3.1.0(transitive)
+ Addedsemver-diff@2.1.0(transitive)
+ Addedslide@1.1.6(transitive)
+ Addedstrip-json-comments@2.0.1(transitive)
+ Addedtimed-out@3.1.3(transitive)
+ Addedunzip-response@1.0.2(transitive)
+ Addedupdate-notifier@1.0.3(transitive)
+ Addedurl-parse-lax@1.0.0(transitive)
+ Addeduuid@2.0.3(transitive)
+ Addedwidest-line@1.0.0(transitive)
+ Addedwrite-file-atomic@1.3.4(transitive)
+ Addedxdg-basedir@2.0.0(transitive)