Grunt task to handle versioning of a project.
npm install grunt-version --save-dev
Once that's done, add this line to your project's Gruntfile:
If the plugin has been installed correctly, running
grunt --help at the command line should list the newly-installed plugin's task. In addition, the plugin should be listed in package.json as a
devDependency, which ensures that it will be installed whenever the
npm install command is run.
In your project's Gruntfile, add a section named
version to the data object passed into
A string representing a package file's path relative to Gruntfile.js, or an object representing a parsed package file.
This package file is where your "canonical" version should be set, in a
"version" property. The
grunt-version plugin uses that version (either incremented by the
release option or not) when it updates version info in other files.
A string value representing a regular expression to match text preceding the actual version within the file.
If you're following one of the popular documentation syntaxes in your js files, you might want to set the option like so:
A string value representing a regular expression to match the version number (immediately following the
A string value representing one or more regular expression flags (e.g.
A string value representing one of the semver 2.x release types (
'prerelease') used to increment the value of the specified package version. See node-semver for more information about release incrementing. The value may also be a literal semver-valid release (for example, '1.3.2').
In this example, the default options are used to update the version in
src/testing.js based on the
version property set in a
package.json file located in the same directory as your
Gruntfile.js. So if the version property in
"0.1.2", and the
src/testing.js file has the content
var version = '0';, that content would change to
var version = '0.1.2';
It can be a hassle to add a grunt target for every release type you might want to use. Fortunately, you can avoid that. Simply provide at least one target that lists the files you want to update:
Then, from the command line (designated by the
$, so don't include that if you're copying the code below), you can bump the patch version, for example:
$ grunt version:project:patch
You can also skip the target name:
$ grunt version::minor
In this example, it bumps the minor version in the files listed within the "project" target, even though "project" is not identified explicitly between the two
:. Note that if the version config includes more than one target, the example would update the files listed within every target.
In this example, custom options are used.
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.