utility to get the summary of your git repository. useful in adding a build/commit hash to your deployment/deployed scripts/html so you can track the deployment builds. Using it we can easily debug the issues in different environment and find the exact source present in that environment in case of multiple environments.
const stats = require('git-optimum-stats');
const gitDir = 'some/dir/containing/git/directory';
const info = {
Version: stats.version(gitDir),
Branch: stats.branch(gitDir),
Hash: stats.hash(gitDir),
LastCommitOn: stats.lastCommitOn(gitDir),
LastCommitBy: stats.lastCommitBy(gitDir),
};
console.log(JSON.stringify(info, null, 2));
// {
// "Version": "A_GIT_TAG-g<SHORT_HASH>-dirty",
// "Branch": "CURRENT_BRANCH",
// "Hash": "LONG_STRING_OF_APLHA-NUMERIC_CHARS",
// "LastCommitOn": "DATE",
// "LastCommitBy": "AUTHOR <AUTHOR_EMAIL>"
// }
const version = stats.rawCmd(gitDir, 'describe --always --tags --dirty="-dev"');
console.log("Version: ", version);
// "A_GIT_TAG-g<SHORT_HASH>-dev"
// hash as a class in html document
const hash = stats.hash(gitDir);
<body class="<%= hash %>"></body> // Sample ejs template
This is a Node.js module available through the npm registry.
Before installing, download and install Node.js. Node.js 6.0.0 or higher is required.
Installation is done using the
npm install
command:
$ npm install git-optimum-stats
All the below APIs take a root directory path containing a .git
directory as a first param (this is a required
param) and a optional custom git command as a second param.
- Returns a string of git tags and short hash along with
'-dirty' suffix
(the suffix can be changed by passing the custom command.
- Returns a current git branch.
- Returns a current git hash in the form alpha-numeric string.
- Returns a date when the latest commit is made.
- Returns a name and the email address of latest commit author.
- This a special function that takes a root directory path containing a
.git
directory as first param and any validgit
command as second param. Both these params arerequired
and a third optional param as a callback function. - Returns a result of passed git command.
- Note: We are using
child_process#exec
functionality which has a default buffer limit of200KB
.