• Stars
    star
    145
  • Rank 254,144 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A CLI for semantic git commits

semantic-git-commit-cli

Backers on Open Collective Sponsors on Open Collective Build Status Build status Coverage Status

A CLI to keep semantic git commits. With emoji support πŸ˜„ πŸ‘

Why?

Many projects got different git commit rules. It is hard to remember them all. Usually you start with git commit -m ", and then? You have to think about the projects commit guidelines.

sgc will take care of the commit guidelines, so you can focus on the more important stuff: code

Installation

$ npm i -g semantic-git-commit-cli

or

$ yarn global add semantic-git-commit-cli

Usage

Forget the times when you used git commit -m "...", now just type:

$ sgc

or if you already have an alias for sgc, use following instead:

$ semantic-git-commit

Usage with parameters

Note: if any block is added it will get skipped in the questions. If there are still some questions open they will still be asked

Available parameters:

  • m | message: Add and skip the message block
  • t | type: Add and skip the type block (this has to be defined in the types as argKey)
  • s | scope: Add and skip the scope block

To skip some questions you can add parameters:

Following:

$ sgc -t feat -m some new features

Will generate: Feat: some new features

--

Following:

$ sgc -t feat -s myScope -m some new features

Will generate: Feat(myScope): some new features

Usage with semantic-release

Configure sgc for the following semantic-release options: analyzeCommits and generateNotes

First step, install the following plugins with

$ npm install --save-dev sr-commit-analyzer sr-release-notes-generator conventional-changelog-eslint

or

$ yarn add -D sr-commit-analyzer sr-release-notes-generator conventional-changelog-eslint

Then, create a release.config.js file in a config folder in the root folder of your project:

/* eslint-disable no-useless-escape */
module.exports = {
  analyzeCommits: {
    preset: 'eslint',
    releaseRules: './config/release-rules.js', // optional, only if you want to set up new/modified release rules inside another file
    parserOpts: { // optional, only you want to have emoji commit support
      headerPattern: /^(?::([\w-]*):)?\s*(\w*):\s*(.*)$/,
      headerCorrespondence: [
        'emoji',
        'tag',
        'message',
      ],
    },
  },
  generateNotes: {
    preset: 'eslint',
    parserOpts: { // optional, only you want to have emoji commit support
      headerPattern: /^(?::([\w-]*):)?\s*(\w*):\s*(.*)$/,
      headerCorrespondence: [
        'emoji',
        'tag',
        'message',
      ],
    },
  },
};

Then, update the semantic-release script to your package.json to this :

"scripts": {
    "semantic-release": "semantic-release -e ./config/release.config.js",
}

Commands

check

This will check all commits and will fail if your commits do not meet the defined config.

Flags

  • start: A commit SHA to start, in case you started using sgc later of your development
$ sgc check --start 84a1abd

Config

Just create a .sgcrc in your project root or you can add everything in your package.json with the value sgc

You can even create a global config. Just go to your users home and create a .sgcrc. The global config will be triggered if no project configurations are present.

The order and namings of the commit (this can vary with different settings):

<type>(<scope>)<delimiter> <message>

<body>

Options:

body

Type: boolean

Default: true

Asks if more info (body) should be added. This will open your default editor.

Example:

{
  "body": false
}

scope

Type: boolean

Default: false

Asks for the scope in parentheses of the commit.

Example:

{
  "scope": true
}

emoji

Type: boolean

Default: false

A boolean to enable emoji at the beginning of a commit message

Example:

{
  "emoji": true
}

delimiter

Type: string

Default: :

A string which is the delimiter between the type and the message.

Example:

{
  "delimiter": ":"
}

or type specific delimiters, which will overwrite the global one:

{
  "delimiter": ":",
  "types": [
    {
      "type": "Feat",
      "delimiter": " -"
    }, // will generate "Feat - message"
    {
      "type": "Fix",
    } // will generate "Fix: message"
  ]
}

lowercaseTypes

Type: boolean

Default: false

A boolean to lowercase types.

Example:

{
  "lowercaseTypes": true
}

initialCommit

Type: object

Default:

{
  "initialCommit": {
    "isEnabled": true,
    "emoji": ":tada:",
    "message": "Initial commit"
  }
}

Keys:

  • isEnabled - Whether an explicit initial commit should be used for the very first commit
  • emoji - An emoji which will be appended at the beginning of the commit (Emoji Cheat Sheet)
  • message - The commit message for the very first commit

types

Types will define your git commits. If types is not set in your own .sgcrc, the types of the global .sgcrc

Notice: If the type is false it will let you to manually add the type. This is usefull especially if you have a prefix named SGC- to reference these as a ticket number for your ticket tool

Keys

  • type (string or false) - This will be your commit convention and will be your start of your commit - e.g.: Feat:
  • prefix (optional) - This option is just valid, if type is false
  • description (optional) - The description to explain what your type is about
  • emoji (optional) - An emoji which will be appended at the beginning of the commit (Emoji Cheat Sheet)
  • argKeys | Array (optional) - Keys which will be accessed through the -t parameter

The .sgcrc:

{
    "types": [
      {
        "emoji": ":sparkles:",
        "type": "Feat:",
        "description": "Any description to describe the type",
        "argKeys": ["f", "feat", "feature"]
      }
    ]
}

or the package.json:

{
    "name": "Your application name",
    "version": "1.0.0",
    "sgc": {
        "types": [
            {
              "emoji": ":sparkles:",
              "type": "Feat:",
              "description": "Any description to describe the type",
              "argKeys": ["f", "feat", "feature"]
            }
        ]
    }
}

addScopeSpace

Type: boolean

Default: true

This rule just affects the commit message if scope is set to true

If set to false there will be no space between <type> and (<scope>)

Example:

{
  "addScopeSpace": false
}

rules

Available rules:

maxChar

Type: number

Default: 72

If a number is set, it will not allow to commit messages more than the given number. If it is set to -1 the rule is deactivated

Example:

{
  "rules": {
    "maxChar": -1
  }
}

minChar

Type: number

Default: 10

If a number is set, it will not allow to commit messages less than the given number. If it is set to -1 the rule is deactivated

Example:

{
  "rules": {
    "minChar": -1
  }
}

endWithDot

Type: boolean

Default: true

If it is set to false, it will not allow to commit messages with a dot at the

Example:

{
  "rules": {
    "endWithDot": false
  }
}

More Repositories

1

node-rename-css-selectors

πŸ“ Rename css classes and id's in files
TypeScript
65
star
2

node-rcs-core

Rename css selectors across all files
TypeScript
35
star
3

toastr2

Simple javascript toast notifications
TypeScript
29
star
4

wordpress-docker-vscode-xdebug-boilerplate

A boilerplate to debug Wordpress using Docker on VSCode
Dockerfile
20
star
5

node-current-git-branch

A tool to get the branch name of a specific directory
JavaScript
10
star
6

gulp-rcs

The gulp task to the main module rename-css-selectors
JavaScript
10
star
7

node-is-git-repository

A tool to check if a specific location is a git repository
JavaScript
8
star
8

vanillajs

Vanilla JS is a fast, lightweight, cross-platform framework for building incredible, powerful JavaScript applications.
TypeScript
8
star
9

node-git-commit-info

Get the info of an specific commit hash
TypeScript
7
star
10

rcs-webpack-plugin

The webpack plugin for rcs-core
TypeScript
5
star
11

node-json-extra

A node module to give you more power for json files
TypeScript
4
star
12

node-git-root

A module to find the git root synchronously
JavaScript
3
star
13

node-is-git-dirty

Check if a repository has untracked, modified or added files
TypeScript
3
star
14

sgc-commit-analyzer

A commit analyzer for semantic-release
JavaScript
2
star
15

postcss-rcs

The postcss plugin for rcs-core
JavaScript
2
star
16

grunt-rcs

The grunt task to the main module rename-css-selectors
JavaScript
2
star
17

node-git-needs-pull

Check synchronously if a git repository needs to pull
Shell
2
star
18

react-finland-2021

JavaScript
2
star
19

JPeer.at

πŸ’» My website on Github
SCSS
1
star
20

parcel-issue

1
star
21

ssr-workshop

TypeScript
1
star
22

federation-hpa

JavaScript
1
star
23

node-is-merge-commit

A tool to check if a specific commit is a merge commit
TypeScript
1
star
24

node-is-git-added

Check if a files are added in a git repository
JavaScript
1
star
25

gatsby-plugin-rcs

The gatsby plugin for rcs
JavaScript
1
star
26

docusaurus-cache

JavaScript
1
star
27

et-grunt

Load tasks if you really need them
JavaScript
1
star
28

showcase

JavaScript
1
star
29

reactsummit24

JavaScript
1
star
30

git-dummy-repo

A dummy repo for git-needs-push and git-needs-pull
1
star
31

parcel-plugin-rcs

A parcel plugin for rcs-core
JavaScript
1
star
32

node-git-needs-push

Check synchronously if a git repository needs to push
JavaScript
1
star