npm-version-bump
A programmatic version of the npm version
command which allows you to
inject custom modifications into the version commit.
Installation
npm install --save npm-version-bump
Examples
Update the package.json version property, commit it to git and tag the commit:
var bump = var dir = '/path/to/module'var version = 'patch'
Update the package.json version property, perform custom modifications to files tracked by the git repository and finally commit everything in a single commit and tag it as a version commit:
var exec = execvar bump = var dir = '/path/to/module'var version = '2.0.0' { }
API
When you require the npm-version-bump
module, the bump
function is
returned:
bump(dir, version, [precommit], [callback])
The bump
function accepts the following arguments:
-
dir
- The base directory of the npm module whos version you'd like to modify. It's expected that this directory contains apackage.json
file with aversion
property.If the directory is not a git repository, this module will still work as normal, except it will not commit anything.
-
version
- A string representing the<newversion>
part of the thenpm version <newversion>
command. It can be either a legal semver version or one of the following convenience bump commands:major | minor | patch | premajor | preminor | prepatch | prerelease
-
precommit
- An optional function that will be called before the actual git commit is performed. This allows you to modify any file in the git repository so they in turn will be included in the final version commit.The function will be called with a callback as the first argument which you must call when you are done. Calling this callback will trigger the commit.
If this function is provided, the
callback
argument must also be provided. -
callback
- An optional function that will be called after the git commit has been performed.The callback will be parsed an Error object as the first argument in case either the commit could not be performed or the commit could not be tagged.
License
MIT