Fork of original mversion to allow adding files to commit in hooks
Will take this down if they accept the PR to allow it
mversion - A cross packaging manager module version handler/bumper
Imitates npm version
to
also work on other packaging files. For those times you have either
have multiple packaging files (like bower.json
, component.json
,
manifest.json
) or just not a package.json
file.
mversion
can easily bump your version and optionally commit and create a tag.
mversion
file support
package.json
npm-shrinkwrap.json
component.json
bower.json
manifest.json
*.jquery.json
(jquery plugin files, e.gplugin.jquery.json
)
Usage CLI
npm install -g mversion
Examples
$ mversion patchNew Version: 0.0.6Updated package.jsonUpdated component.json
$ mversion 0.0.5 -mNew Version: 0.0.5Updated package.jsonUpdated component.jsonUpdated manifest.jsonCommited to git and created tag v0.0.5
$ mversion 1.0.0-rc1 -m "Now in wopping v%s"New Version: 1.0.0-rc1Updated package.jsonUpdated component.jsonCommited to git and created tag v1.0.0-rc1
Help
$ mversion -h Usage: mversion [ <newversion> | major | minor | patch | prerelease ] [ -m <optional message> ] [ -n | --no-prefix ] - Update module version in either one or all of package.json,component.json, bower.json, manifest.json and *.jquery.json.
Run without arguments to get current version.
Semver Summary
Given a version number MAJOR.MINOR.PATCH, increment the:
- MAJOR version when you make incompatible API changes,,
- MINOR version when you add functionality in a backwards-compatible manner, and,
- PATCH version when you make backwards-compatible bug fixes., Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.,
Update version
Update version by defining new semver valid version or a release string (major, minor, patch, build).
Ex: "mversion minor" Ex: "mversion 1.0.1-beta"
Git
Use -m to auto commit and tag. Apply optional message and use '%s' as placeholder for the updated version. Default message is 'v%s' where %s is replaced with new version.
--tag (or -t for short) allows for overriding the tag name used. This does not change behaviour of the message, just the tag name. As with -m, all occurances of %s is replaced with the newly bumped version.
--no-prefix (or -n for short) is a short hand for setting a tag name without v as prefix. This does not change behaviour of the message, just the tag name.
-- Ex: "mversion minor -m" Ex: "mversion minor -m 'Bumped to v%s' --tag 'v%s-src'"
Version aliases
If you are lazy you can also use aliases for the version release type.
mversion p
The full list of aliases:
"pa": "patch",
"pr": "prerelease",
"ma": "major",
"mi": "minor",
// one char might be controversial, but it saves key strokes
"m": "major",
"p": "patch",
"i": "minor"
Default settings
Create a .mversionrc
file in your root with default settings
as defined in the README.md of the project.
## Default Settings
You can provide default settings by creating a `.mversionrc` file
in the root of your project (or in a directory higher up in the hierarchy).
This way you can define project specific tag names or commit messages.
See API below to see what options are accepted.
### Example `.mversionrc`
```json
{
"commitMessage": "Bumped to %s",
"tagName": "v%s-src"
}
Now, when doing this in the Terminal:
$ mversion minor
would now be the same as doing:
mversion minor -m "Bumped to %s" -t "v%s-src"
Note: CLI arguments take precedence over default options.
So doing this (with the .mversionrc
file as defined above):
mversion minor -m "Kicked version to %s"
Would lead to the commit message being Kicked version to %s
,
and tag name to be v%s-src
.
Hooks
.mversionrc
will also allow you to define hooks before (preupdate
)
and after (postupdate
) version is updated.
Example
If precommit fails (returns something other that exit 0
) the commit will be
checked out (removing the version bump changes).
Usage API
npm install mversion
var mversion = ; mversion; mversionmversionmversion // Will commit/tagmversion // Make tag without v prefixmversionmversionmversion // Will commit/tagmversionmversionmversion
mversion.get(callback(err, data))
Get version of all the different package files. See example above.
mversion.update([options, ]callback(err, data))
Update version of found package files.
Example of the data
returned from the callback:
Some times both data
and err
has values. In this case
some package files were updated and some not.
options : Undefined
If options is undefined a standard bump of minor
will be used.
options : String
If options is a string, this string is used as the version bump.
Example:
mversion
options.version : String
Used to bump version. See above.
options.commitMessage : String
Used as message when creating commit in Git. Also used as message for the annotated tag created. If undefined, no commit will be made.
Occurances of %s
in commit message will be replaced with new version number.
Example:
mversion;
options.tagName : String
Default: v%s
Allows for overriding of tagName. For instance adding a suffix and
changeing tag to be named v%s-src
.
Will only take affect if commitMessage is defined.
Occurances of %s
in tag name will be replaced with new version number.
Example:
mversion;// Might produce annotated tag named v1.0.0-src
options.noPrefix : Boolean
If true and commit message is defined, the annotated tag created
will not have 'v' as prefix. This is a short hand for defining
setting tag name to %s
. Do not work if tag name is overriden
(options.tagName
is defined).
Example:
mversion;// Might produce annotated tag named 1.0.0
This would be the same as:
mversion;// Might produce annotated tag named 1.0.0
mversion.isPackageFile(filename) : Boolean
Checks whether or not the given filename is a valid package file type.
Examples:
assert;assert;assert;assert;assert;assert;
Changelog
1.9.0
- Adds aliases for bumps (
p
,m
,i
) (#20)
1.8.0
- Adds Composer support. (#19)
1.7.0
- Replaces %s with
newVersion
in post scripts. Fixes #18
1.6.1
- Adds support for git staging files with spaces. Fixes #17
1.6.0
- Adds auto-updater to
mversion
.
1.5.0
- Fixes issue with version bump being parsed as number and running string operations.
- Improves error given on invalid version input
- Bumps minimatch and semver to latest versions.
1.4.0
- Adds pre-/postcommit hooks allowing for commands to be run before and after version bump git commit.
1.3.0
- Adds
.mversionrc
file for defining default settings - Adds pre-/postupdate hooks allowing for commands to be run before and after version bump.
Useful for instance for doing
npm publish
orgit push
.
1.2.0
- Adds option to override tag name (options.tagName) in
#update
. - Misc. refactoring and further testing.
1.1.0
- Improves CLI arguments. Now arguments is indifferent to order
- Adds better error handling and user feedback on partial version update (not all files).
1.0.0
- Changes API to use an object literal, avoiding magic strings/primitives.
0.5.0
- Adds
noPrefix
flag. Allowing to define whether or not to prefix tags with "v".