0.2.0 • Published 8 years ago

babel-plugin-git-version v0.2.0

Weekly downloads
567
License
ISC
Repository
github
Last release
8 years ago

babel-plugin-git-version

Expose the current commit's hash and the name of "nearest" tag as constants in your code. Useful to quickly find out what version of your application is deployed.

Installation

npm install --save-dev babel-plugin-git-version

Also make sure that git is in your $PATH.

Usage

Add it to your .babelrc configuration

{
  "plugins": [
    "git-version"
  ]
}

After that the constants GIT_COMMIT and GIT_TAG can be used in your code. They will be replaced by the commit hash of HEAD and the name of the "nearest" tag (or "unknown" if those values can't be parsed).

console.log(`Version: ${GIT_TAG} (${GIT_COMMIT})`);

To avoid eslint warnings just add this to your config

"globals": {
  "GIT_COMMIT": false,
  "GIT_TAG": false,
},

You may customize the plugin to your liking

"plugins": [
  [
    "git-version",
    {
      "commitDefaultValue": "unknown_commit",
      "tagDefaultValue": "unknown_tag",

      "commitConstantName": "COMMIT",
      "tagConstantName": "TAG",

      "showDirty": true,
      "commitLength": 7,
      "tagCommitLength": 7
    }
  ]
]

The defaults are

const DEFAULT_OPTIONS = {
  commitDefaultValue: "unknown",
  tagDefaultValue: "unknown",

  commitConstantName: "GIT_COMMIT",
  tagConstantName: "GIT_TAG",

  showDirty: false,
  
  commitLength: 40,
  tagCommitLength: 0,
};

License

See LICENSE