2.0.3 โ€ข Published 15 days ago

eemoji v2.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
15 days ago

eemoji

This is a tiny CLI tool that automatically adds emojis to your commit messages based on conventional commit types.

  • ๐Ÿ“ฆ Easy Install: just install it once and forget about it
  • ๐Ÿ› ๏ธ Customizable: you can add your own emojis and trigger words, and change the format of the commit message as per your needs.
  • ๐Ÿซง Seamless: operates with the prepare-commit-msg git hook, modifying your commit messages every time you make a commit.

!WARNING There is a known issue with GitHub Desktop on Windows.

๐Ÿ˜Ž Emojis

Hi, read the README.md first (starting with Install). This emoji table is for quick reference. Btw it's generated from the default.jsonc file.

TypeSubtypeEmojiDescription
fix.๐Ÿ”งgeneral fix
fixtypoโœ๏ธfixed typo in code, docs, ui, etc.
fixbug๐Ÿ›fixed a bug
fixsecurity๐Ÿ”’fixed security issues
chore.๐Ÿ—‘๏ธdid some chores
chorerelease๐Ÿ”–new release commit (pairs well with bumpp)
chorecleanup๐Ÿงนcleaned up code, removed logs and debug stuff, made everyting ready for production
chorelicense๐Ÿ“œchanged the license
chorelint๐Ÿงผfixed linting errors
choredeps๐Ÿ“ฆchanged dependencies
chorereadme๐Ÿ“•,๐Ÿ“—,๐Ÿ“˜,๐Ÿ“™update the README
release๐Ÿ”–
cleanup๐Ÿงน
lint๐Ÿงผ
deps.๐Ÿ“ฆadded/removed/changed dependencies
depsupโฌ†๏ธupdated dependencies
depsdownโฌ‡๏ธdowngraded dependencies
upโฌ†๏ธ
downโฌ‡๏ธ
build.๐Ÿฆบwork regarding build processes
builddeps๐Ÿ“ฆdependabot PRs (see the prefix in the dependabot.yml file on how to add an emoji to our friend's PRs)
docs.๐Ÿ“documented something
docsreadme๐Ÿ“•,๐Ÿ“—,๐Ÿ“˜,๐Ÿ“™
feat.โœจintroduced a new feature
featenhance๐Ÿ’Žmade something a little better (but still include in release notes)
enhance๐Ÿ’Žmade something a little better (omit from release notes)
test๐Ÿงชworked on tests
refactorโ™ป๏ธrefactored code, achieved the same with less
init๐ŸŽ‰started a new project!
perfโšกimproved performance, achieved the same faster
breaking๐Ÿ’ฅspecial type: will be used if the commit contains an exclamation mark (!), indicates breaking changes
ci๐Ÿฆพchanged workflow files, CI stuff
configโš™๏ธchanged configuration files
style๐ŸŽจdesign changes, style changes
ui๐ŸชŸworked on UI, UX or layout
text๐Ÿ’ฌchanged string literals, text content
revertโชrevert a commit
i18n๐ŸŒtranslated something
security๐Ÿ”’
wip๐Ÿšงwildcard type, works for anything
addโž•
removeโž–

๐Ÿš€ Install

There are two different ways to install eemoji:

  • Locally: add it to a node project as a dev dependency. This way you can share it with other contributors.
  • Globally: install it globally to use it everywhere, not just in node projects. Note that you will need to initialize it in other repository for it to work there.

Thanks to the postinstall script, after installing eemoji locally/globally, it will automatically create the git hook for the current repo. This means it will just work, but it's especially useful when other users are going to contribute to your repository.

!TIP If you use yarn or pnpm, which do not run postinstall scripts by default, you need to run eemoji init manually. Besides that, you can create a prepare script in your package.json, so that it will be run automatically for others who contribute to your repository:

{
  "scripts": {
    "prepare": "eemoji init -c none"
  }
}

Local

npm i -D eemoji

Global

npm i -g eemoji

!NOTE For eemoji to work in a repository you still need to run the init command once, so that it can install the git hook there as well.

๐Ÿ“– Usage

After installing it, just create a commit and see an emoji appended to it.

Go to the Config section for examples and to see how to customize it.

The cli tool also has some commands for removing eemoji from a repository, running it manually, etc. But they are not that important. ๐Ÿ‘‡

Commands

Use eemoji <command> if you installed it globally, or npx eemoji <command> if you installed it locally.

  • -h, --help: show help for a command
  • -v, --version: show version

๐Ÿšฉ Init

Installs the git hook in the current repository.

It will also ask you what type of config file you want to use, see Config.

The postinstall script will run this command with the -c none flag, so no config is assumed.

eemoji init

Flags:

Specify flags to skip the questions.

  • -c, --config <config>: specify the config type, json, ts or none

๐Ÿงน Cleanup

Removes eemoji from the current repository, including the git hook, config file and its vscode settings if present.

eemoji cleanup

๐Ÿฅ Run

Runs the eemoji on the current commit message manually.

This is used by the git hook, but also allows you to test eemoji manually (specify a test file or it will use the current commit message in .git/COMMIT_EDITMSG).

eemoji run

Arguments:

  • commit_file: the file to run emoji on, defaults to .git/COMMIT_EDITMSG

Flags:

  • -d, --debug: the debug level, 0 for none, 1 for some, 2 for all
  • -t, --test: test mode, input a commit message instead of a file

๐Ÿฆพ Config

The default configuration is here: default.jsonc and the Emojis section.

This is used if no config file is found in the project.

Apart from emojis, the config also specifies other things, like:

  • format: the format of the commit message, see Format.
  • strict: enforce formatting, and only allow commits with emojis (default: true)

eemoji can be configured two different ways: json and typescript config files.

TS Config

This way your emojis will be merged with the default ones.

Use the init command and select the ts config type.

  • defineDefaultConfig: use this to append your emojis to the default ones
  • defineConfig: use this to define your own config, without the default emojis

eemoji will look for these config files:

  • eemoji.config.ts
  • .eemojirc.{js,ts,cjs,mjs}
  • eemoji.config.{js,ts,cjs,mjs}
  • .config/eemoji.config.{js,ts,cjs}

Format

The format specifies how the commit message will be formatted ({emoji} {type}: {subject} is the default format btw, this property is optional here).

  • {type}: this determines the emoji
  • {subject}: rest of the commit message
  • {emoji}: the place of the emoji to be inserted

Some other formats I could think of:

  • {emoji} {type} - {subject}
  • {emoji} {type} {subject}
  • {type}: {emoji} {subject}

Simple demonstration

import { defineConfig } from 'eemoji'

export default defineConfig({
  format: '{emoji} {type}: {subject}',
  emojis: {
    fix: '๐Ÿ”ง',
    chore: '๐Ÿ—‘๏ธ',
    feat: 'โœจ',
    docs: '๐Ÿ“',
    test: '๐Ÿงช'
  }
})

Example:

Commit message:

  • before: fix: navbar issue
  • after: ๐Ÿ”ง fix: navbar issue

Nested emojis

You can also nest emojis to create subtypes.

After finding the type, eemoji will look for subtypes in the commit message.

This is useful for conventional commit scopes, but you can include the subtype anywhere in the commit message.

Notes:

  • the '.' is the fallback subtype
  • specify multiple emojis by separating them with commas and a random one will be chosen: ๐Ÿ’Ž,๐Ÿ’ฒ,๐Ÿ’ธ,๐Ÿ’ฐ
import { defineConfig } from 'eemoji'

export default defineConfig({
  emojis: {
    fix: {
      '.': '๐Ÿ”ง',
      'typo': 'โœ๏ธ',
      'bug': '๐Ÿ›'
    },
    chore: {
      '.': '๐Ÿ—‘๏ธ',
      'release': '๐Ÿ”–',
      'cleanup': '๐Ÿงน',
      'license': '๐Ÿ“œ',
      'deps': '๐Ÿ“ฆ'
    },
    feat: 'โœจ',
    bounty: '๐Ÿ’Ž,๐Ÿ’ฒ,๐Ÿ’ธ,๐Ÿ’ฐ'
  }
})

Examples:

Commit message:

  • before: fix: navbar issue
  • after: ๐Ÿ”ง fix: navbar issue
  • before: fix: typo in README
  • after: โœ๏ธ fix: typo in README
  • before: chore: release v1.0.0
  • after: ๐Ÿ”– chore: release v1.0.0
  • before: chore(deps): update eslint
  • after: ๐Ÿ“ฆ chore(deps): update eslint

Presets

You can use presets, which are just functions with emoji objects that are included in the package.

!NOTE The emojis property can be an array of presets and objects

import { defineConfig, presetDefault } from 'eemoji'

export default defineConfig({
  emojis: [
    presetDefault(),
    {
      feat: 'โœจ',
      fix: '๐Ÿ”ง'
    }
  ]
})

JSON Config

Same deal, but you overwrite the whole config.

Use the init command and select the json config type to generate a config file.

!IMPORTANT You must specify the format property

You also get types thanks to the JSON schema.

eemoji will look for these config files:

  • .eemojirc.json
  • .eemojirc
  • .eemojirc.{json,yaml,yml}
  • .config/eemojirc
  • .config/eemojirc.{json,yaml,yml}

โš ๏ธ Known issues

eemoji WILL NOT work with GitHub Desktop on Windows unless you do this.

This sucks, but this is an open issue with GitHub Desktop.

Follow these steps:

  • Move C:\Program Files\Git\cmd to the top of your system PATH
  • Add C:\Program Files\Git\bin just below that
  • Restart GitHub Desktop

If it continues to fail to work, try this as well and restart everything:

  • Run this command once: git config stash.usebuiltin false

๐Ÿค Contributing

Adding a new emoji

To add a new emoji to a preset (even the default config) or modify it, open an issue first.

Then, if it's okay:

  • modify the default.jsonc file, add the emoji and a description
  • The Action will take care of the rest (copying it to the json, updating the readme emoji table and the json schema)
  • open a PR

Creating a new emoji preset

Add a new jsonc (note the c at the end) file to the presets folder and name it as you wish. Describe the emoji using comments.

Example:

{
  "fix": "๐Ÿ”ง", // general fix
  "feat": "โœจ" // introduced a new feature
}

Locate the presets.ts file and add your preset like this:

export const [
  presetDefault,
  presetMinimal,
  /* ... */

  // add your presetSomething here
] = createPresets([
  'default',
  'minimal',
  /* ... */

  // add your file name here (without the .jsonc extension)
]) as [
  Preset,
  Preset,
  /* ... */

  // and make TypeScript happy
]

Then open a PR, the Action will take care of the rest.

Development

!TIP Install pnpm and ni.

npm i -g pnpm @antfu/ni
ni

Use the stub script to run have the latest changes build:

nr stub

Run commands with the dev script:

nr dev <command>

Also check the TODO file and open an issue first if you want to work on something.

๐Ÿ’› Badge

eemoji

[![eemoji](https://img.shields.io/badge/๐Ÿ˜Ž%20eemoji-fccf1d?style=for-the-badge)](
  https://github.com/Rettend/eemoji)

๐Ÿ“œ License

MIT

2.0.3

15 days ago

2.0.2

3 months ago

2.0.1

3 months ago

2.0.0-beta.0

3 months ago

2.0.0

3 months ago

1.1.5

4 months ago

1.1.4

5 months ago

1.1.3

5 months ago

1.1.2

5 months ago

1.1.1

5 months ago

1.0.3

5 months ago

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

6 months ago

1.0.0-beta.7

6 months ago

1.0.0-beta.6

6 months ago

1.0.0-beta.5

6 months ago

1.0.0-beta.4

6 months ago

1.0.0-beta.3

6 months ago

1.0.0-beta.2

6 months ago

1.0.0-beta.1

6 months ago

1.0.0-beta.0

6 months ago

0.2.4

6 months ago

0.2.3

6 months ago

0.2.2

6 months ago

0.2.1

6 months ago

0.2.0

6 months ago

0.1.3

6 months ago

0.1.2

6 months ago

0.1.1

6 months ago