Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gitmoji-cli

Package Overview
Dependencies
Maintainers
1
Versions
119
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gitmoji-cli - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

test/test.js

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();
}

19

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc