update package.json version automatically
Right answer
To do so, just npm version patch
=)
My old answer
There is no pre-release
hook originally in git
. At least, man githooks
does not show it.
If you're using git-extra
(https://github.com/visionmedia/git-extras), for instance, you can use a pre-release
hook which is implemented by it, as you can see at https://github.com/visionmedia/git-extras/blob/master/bin/git-release. It is needed only a .git/hook/pre-release.sh
executable file which edits your package.json
file. Committing, pushing and tagging will be done by the git release
command.
If you're not using any extension for git
, you can write a shell script (I'll name it git-release.sh
) and than you can alias it to git release
with something like:
git config --global alias.release '!sh path/to/pre-release.sh $1'
You can, than, use git release 0.4
which will execute path/to/pre-release.sh 0.4
. Your script can edit package.json
, create the tag and push it to the server.
npm version
is probably the correct answer. Just to give an alternative I recommend grunt-bump. It is maintained by one of the guys from angular.js.
Usage:
grunt bump>> Version bumped to 0.0.2grunt bump:patch>> Version bumped to 0.0.3grunt bump:minor>> Version bumped to 0.1.0grunt bump>> Version bumped to 0.1.1grunt bump:major>> Version bumped to 1.0.0
If you're using grunt anyway it might be the simplest solution.
This is what I normally do with my projects:
npm version patchgit add *;git commit -m "Commit message"git pushnpm publish
The first line, npm version patch
, will increase the patch version by 1 (x.x.1 to x.x.2) in package.json
. Then you add all files -- including package.json
which at that point has been modified.Then, the usual git commit
and git push
, and finally npm publish
to publish the module.
I hope this makes sense...
Merc.