DEV Community

Cover image for ๐Ÿค– ๐Ÿš€ โœจ Emojify your conventional commits with Devmoji
Folke Lemaitre
Folke Lemaitre

Posted on • Originally published at github.com

๐Ÿค– ๐Ÿš€ โœจ Emojify your conventional commits with Devmoji

Using Conventional Commits โญ as a standard for your commit messages, makes Semantic Versioning ๐Ÿ”– as easy as can be, with tools like Conventional Changelog ๐Ÿ“„,Standard Version ๐Ÿ”– and Semantic Release ๐Ÿ“ฆ๐Ÿš€

Devmoji is a command line tool that adds color ๐ŸŒˆ to conventional
commits, using emojis inspired by
Gitmoji ๐Ÿ˜œ

Some of the things Devmoji can do:

  • emojify: convert input between diferent emoji formats unicode, shortcode and devmoji. devmoji are easy to remember aliases like: :test:, :refactor:, :docs:, :security instead of hard to remember emoji codes
  • git commit: install a prepare-commit-msg commit hook to โœจ automagically emojify your commit message
  • git log: emojify and colorify the output of git log even for projects not using emojis

What does it look like?

๐Ÿ“ฆ Installation

Install with npm or yarn

globally



npm install -g devmoji
yarn global install devmoji


Enter fullscreen mode Exit fullscreen mode

locally inside your project. use with npx devmoji



npm install --dev devmoji
yarn add --dev devmoji


Enter fullscreen mode Exit fullscreen mode

See --edit for information on how to setup a git commit
hook.

๐Ÿ’ฅ Usage

devmoji --help



$ devmoji --help
Usage: devmoji [options]

Options:
  -c|--config <file>    location of the devmoji.config.js file
  -l|--list             list all known devmojis
  -t|--text <text>      text to format. reads from stdin when omitted
  -f|--format <format>  format should be one of: unicode, shortcode, devmoji (default: "unicode")
  --commit              automatically add a devmoji to the conventional commit header (default: true)
  --no-commit           do not process conventional commit headers
  -e|--edit             read last commit message from .git/COMMIT_EDITMSG in the git root
  --log                 format conventional commits in text similar to git log
  --color               use colors for formatting. Colors are enabled by default, unless output is piped to another command (default: true)
  --no-color            don't use colors
  --version             output the version number
  -h, --help            output usage information


Enter fullscreen mode Exit fullscreen mode

devmoji emojify

Emojify text using --text or piping it to stdin. Input can be a combination
using any valid format. Output formats:

Format Description
shortcode outputs Github Markdown short codes like :sparkles: :rocket:
unicode outputs the emoji unicode symbols like โœจ ๐Ÿš€
devmoji outputs the devmoji shortcodes like :feat: :chore-release:
strip removes all emoji from the input

The default format is unicode, since this can be used pretty much everywhere
and has the shortest text length (relevant for commit messages)



$ echo "This is a :test: of the first :release: :boom: โœจ" | devmoji --format shortcode
This is a :rotating_light: of the first :rocket: :boom: :sparkles:

$ echo "This is a :test: of the first :release: :boom: :sparkles:" | devmoji --format unicode
This is a ๐Ÿšจ of the first ๐Ÿš€ ๐Ÿ’ฅ โœจ

$ echo "๐Ÿš€ :boom: :sparkles:" | devmoji --format devmoji
:chore-release: :breaking: :feat:

$ echo "test ๐Ÿš€ :boom: :sparkles: :security:" | devmoji --format strip
test


Enter fullscreen mode Exit fullscreen mode

devmoji --commit

Automagically โœจ emojifies a conventional commit message of the format
type(scope): something useful, using the following pseudo code:



if (exists(":type-scope:")) return emoji(":type-scope:")

if (exists(":type:") && exists(":scope:"))
  return emoji(":type:") + emoji(":scope:")

if (exists(":type:")) return emoji(":type:")


Enter fullscreen mode Exit fullscreen mode

example ouput:



$ echo "feat: added a new feature :smile:" | devmoji --commit
feat: โœจ added a new feature ๐Ÿ˜„

$ echo "chore(release): 1.1.1" | devmoji --commit
chore(release): ๐Ÿš€ 1.1.1

$ echo "fix(security): upgraded lodash" | devmoji --commit
fix(security): ๐Ÿ› ๐Ÿ”’ upgraded lodash


Enter fullscreen mode Exit fullscreen mode

devmoji --edit

Formats and saves your current commit message .git/COMMIT_EDITMSG. This is
only really useful as a prepare-commit-msg hook.

Configuration using Husky



// package.json
{
  "husky": {
    "hooks": {
      "prepare-commit-msg": "devmoji -e"
    }
  }
}


Enter fullscreen mode Exit fullscreen mode

Configuration using Yorkie



// package.json
{
  "gitHooks": {
    "prepare-commit-msg": "devmoji -e"
  }
}


Enter fullscreen mode Exit fullscreen mode

If you installed Devmoji locally in your project as a dev dependency, then
use something like npx --no-install devmoji -e instead of the commands
above.

devmoji --log

Works similar to --commit, but formats type(scope): something useful
anywhere in the input instead of the beginning of the first line.

This is useful to format the output of git log. Any git log option works,
but my favorite alias is:



$ git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --decorate --date=short


Enter fullscreen mode Exit fullscreen mode

I'll use my alias git l, instead of the above, for clarity. The
devmoji --format strip is only for demonstration purposes, since all devmoji
commits already have emoji
devmoji --list

using devmoji --log >
devmoji --list

devmoji --list

To get a list of all available Devmiji, run with --list. (see also
Default Devmoji)

devmoji --list

โš™๏ธ Configuration

devmoji uses the config file as specified with the --config option, or looks
for devmoji.config.js in the following paths:

  • current directory
  • parent directory that contains a package.json file
  • parent directory that is a git repository
  • home directory

Example Config File



export const defaults = {
// extra types used in commit messages
types: ["lint"],
// custom devmoji
devmoji: [
// use :boom: instead of :sparkles: for the type 'feat'
{ code: "feat", emoji: "boom" },
// add a custom devmoji
{
code: "fail",
emoji: "poop",
description: "something bad happened",
},
// add a new devmoji based on an existing gitmoji. description will be taken from the gitmoji
{
code: "css",
gitmoji: "art",
},
// the emoji from the gitmoji can be overriden as well
{
code: "config",
gitmoji: "wrench",
emoji: "gear",
},
],
}

Enter fullscreen mode Exit fullscreen mode




Default Devmoji Reference

Emoji Devmoji Code Description
โœจ :feat: feat: a new feature
๐Ÿ› :fix: fix: a bug fix
๐Ÿ“š :docs: docs: documentation only changes
๐ŸŽจ :style: style: changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
โ™ป๏ธ :refactor: refactor: a code change that neither fixes a bug nor adds a feature
โšก :perf: perf: a code change that improves performance
๐Ÿšจ :test: test: adding missing or correcting existing tests
๐Ÿ”ง :chore: chore: changes to the build process or auxiliary tools and libraries such as documentation generation
๐Ÿš€ :chore-release: chore(release): code deployment or publishing to external repositories
๐Ÿ”— :chore-deps: chore(deps): add or delete dependencies
๐Ÿ“ฆ :build: build: changes related to build processes
๐Ÿ‘ท :ci: ci: updates to the continuous integration system
๐Ÿš€ :release: code deployment or publishing to external repositories
๐Ÿ”’ :security: Fixing security issues.
๐ŸŒ :i18n: Internationalization and localization.
๐Ÿ’ฅ :breaking: Introducing breaking changes.
โš™๏ธ :config: Changing configuration files.
โž• :add: add something
โž– :remove: remove something

Top comments (7)

Collapse
 
defman profile image
Sergey Kislyakov

I'd prefer my commits to not include emojis. They are distracting, especially in a terminal. The format below works fine without any emojis whatsoever.

<type>(<scope>): <short description>

<body>

<issue id, tags, etc.>
Collapse
 
shostarsson profile image
Rรฉmi Lavedrine

I love that.
Maybe it is not good to do that in a company as some people could not love this.
But on you personnal projects, if you do love that kind of visual stuff in your Git tree, that is a very good thing.

Collapse
 
folke profile image
Folke Lemaitre

Unless it's your own company ๐Ÿ˜‰

Collapse
 
shostarsson profile image
Rรฉmi Lavedrine

Absolutely. ๐Ÿ˜„

Collapse
 
moopet profile image
Ben Sinclair

I think this is a terrible idea, mostly because I struggle to read these little pictograms. Even when I do recognise that something's a firework rather than an explosion, I don't know whether that's a good thing or a bad thing.

I rely on the surrounding text to infer meaning by context. And at that point, why don't I just read the text; reading the text is orders of magnitude faster for me.

I'd hate to have to programatically search for something by whether it had a picture of an otter or a cat.

Collapse
 
folke profile image
Folke Lemaitre

It's definitely inspired by Gitmoji, but Devmoji is meant to be used with the conventional commit message format. Emojis are automatically added with the prepare-commit-msg hook, based on the type and scope of the commit. Additionally, you can use emoji shortcodes like :security: :release: etc instead of ๐Ÿ”’ ๐Ÿš€, ... Easier to remember and fully customizable for your environment.

Collapse
 
gauravggg21 profile image
Gaurav Agarwal

Can we somehow use this in python?