This module will return the current project version string. The version string is made of the last git tag or package.json version (if no git tag exists) and the last commit hash.
$ npm install get-project-version
The following is a basic example:
import getProjectVersion from 'get-project-version';
const version = getProjectVersion();
console.log(version); // Version: 1.0.0 Commit: 081b152
This example shows how you can customize the output of get-project-version
using a template string:
import getProjectVersion from 'get-project-version';
const version = getProjectVersion({
template: '{{version}}-{{commit}}'
});
console.log(version); // 1.0.0-081b152
There are cases where you'd like to output a version string for a particular folder this can be done like this:
import getProjectVersion from 'get-project-version';
const version = getProjectVersion({
cwd: 'pathToProjectDir/'
});
console.log(version); // 1.0.0-081b152
Options you can pass getProjectVersion
:
template
- An optional String which templates the output ofgetProjectVersion
. Version will be injected into{{version}}
and a shortened commit hash will be injected into{{commit}}
. eg.'{{version}}-{{commit}}'
cwd
- An optional String. By default the current working directory will beprocess.cwd()
you can modify this by passing a path. eg.'pathToProjectDir/'
$ get-project-version
The above would output to stdout something like Version: 1.0.0 Commit: 081b152
$ get-project-version --template '{{version}}-{{commit}}'
The above would output to stdout something like 1.0.0-081b152
$ get-project-version --cwd pathToProjectDir/
The above would output a version string for pathToProjectDir/
MIT, see LICENSE.md for details.