devmoji

repository·master·Indexed 18 days ago

https://github.com/folke/devmoji

A CLI tool that enhances conventional commits by adding color and emojis. It provides functionality to emojify commit headers, lint conventional commit messages, format git logs, and convert text between emoji formats (unicode, shortcode, devmoji, and strip). It supports custom configurations via devmoji.config.js and can be integrated into git workflows using hooks like Husky or Yorkie.

Tokens
6.7K
Snippets
23
Records
27
Agent score
14%

What's inside devmoji

  1. Setup a git commit hook for Devmoji

    master

    To automatically emojify and lint your commit messages, you should set up a git hook. The --edit flag allows Devmoji to read and write to .git/COMMIT_EDITMSG.

    Using Husky

    If you use Husky, add a prepare-commit-msg hook. If you use commit-msg instead, Devmoji will also perform linting.

    Using Yorkie

    Add the command to your package.json under gitHooks.

    Note: If Devmoji is installed locally as a dev dependency, use npx --no-install devmoji -e in your hook configuration.

    # Using Husky
    $ npx husky install
    $ npx husky add .husky/prepare-commit-msg "npx devmoji -e --lint"
    // Using Yorkie in package.json
    {
      "gitHooks": {
        "prepare-commit-msg": "devmoji -e --lint"
      }
    }
  2. Install Devmoji

    master

    You can install Devmoji either globally for use across your system or locally within a specific project.

    Global Installation

    Use this if you want to use the devmoji command anywhere in your terminal.

    Local Installation

    Use this to add Devmoji as a development dependency in your project. When installed locally, you should invoke it using npx devmoji.

    # Global installation
    npm install -g devmoji
    yarn global add devmoji
    
    # Local installation
    npm install --dev devmoji
    yarn add --dev devmoji
  3. Configure devmoji via devmoji.config.js

    master

    You can customize devmoji by creating a devmoji.config.js file. The tool searches for this file in the current directory, the parent directory containing a package.json, the parent directory that is a git repository, or the home directory. You can also explicitly specify a config file using the --config option.

    Configuration options include:

    • types: An array of extra types to be used in commit messages.
    • devmoji: An array of custom devmoji definitions. You can:
      • Override an existing code with a different emoji.
      • Add a completely new devmoji with a code, emoji, and description.
      • Base a new devmoji on an existing gitmoji using the gitmoji key (the description will be inherited).
      • Base a new devmoji on a gitmoji but override the emoji using the emoji key.
    module.exports = {
      // 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",
        },
      ],
    }
  4. Define custom devmoji in configuration

    master

    When defining custom devmoji entries in your devmoji.config.js, you have two primary ways to specify them:

    1. Using Gitmoji: Provide a gitmoji key. The library will automatically resolve the emoji and the description for you.
    2. Manual Definition: Provide an emoji and a description directly.

    Note: Every entry must have either a gitmoji key or an emoji key. If you use gitmoji, the code field is still required to identify the entry.

    // devmoji.config.js
    module.exports = {
      types: ['feat', 'fix'],
      devmoji: [
        // Option 1: Resolve via Gitmoji name
        { code: 'feat', gitmoji: 'sparkles' },
    
        // Option 2: Manual definition
        { code: 'fix', emoji: '🐛', description: 'fixing a bug' }
      ]
    };
  5. Use the devmoji CLI

    master

    The devmoji command is a CLI tool used to manage and automate the use of devmojis in your git workflow. It provides commands for emojifying text, managing commits, linting commit messages, and editing existing ones.

    To use the tool, ensure it is installed in your environment and then invoke it via the terminal using devmoji followed by your desired command and flags.

    devmoji --help
  6. Lint conventional commits with --lint

    master

    The --lint flag enables validation of conventional commit messages. When enabled, the CLI checks if the commit message follows the expected pattern: type(scope)!: description. It also verifies that the type is included in your configured allowed types.

    If linting fails, the CLI will output errors and exit with code 1. Note that linting is automatically disabled when using the --log flag.

    devmoji --lint --text "feat: my feature"
  7. Use the devmoji CLI to format text

    master

    The devmoji CLI can be used to transform commit messages using different formats. By default, it reads from stdin if no text is provided via the --text flag. You can specify the output format using the --format flag.

    Available Formats:

    • unicode: Converts shortcodes to actual emoji characters (default).
    • shortcode: Converts emojis back to shortcodes.
    • devmoji: Uses the devmojify logic.
    • strip: Removes all devmoji related content.

    Example: Formatting via stdin

    echo ":sparkles: new feature" | devmoji
  8. Edit the last commit message with --edit

    master

    The --edit flag allows you to automatically process the current commit message being written in Git. It locates the .git/COMMIT_EDITMSG file in your git root, reads the content, applies the devmoji formatting, and writes it back to the file.

    devmoji --edit
  9. Automatically add devmoji to commits with --commit

    master

    The --commit flag (enabled by default) automatically attempts to add a devmoji to the conventional commit header. This is particularly useful when piping text or using the --edit mode.

    devmoji --commit --text "feat: something"
  10. Format git logs with `--log`

    master

    The --log flag emojifies and colorifies the output of git log. Unlike --commit, it searches for type(scope): message patterns anywhere in the input, making it ideal for viewing history.

    Recommended usage with a custom git log format:

    $ 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 | devmoji --log
  11. Lint conventional commits with `--lint`

    master
    The --lint flag checks if a commit message follows the Conventional Commits standard. This is typically used in conjunction with git hooks to ensure all commits are properly formatted.