Before I do a small release and tag it, I'd like to update the package.json to reflect the new version of the program.
Is there a way to edit the file package.json automatically?
Would using a git pre-release hook help?
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.2
grunt bump:patch
>> Version bumped to 0.0.3
grunt bump:minor
>> Version bumped to 0.1.0
grunt bump
>> Version bumped to 0.1.1
grunt bump:major
>> Version bumped to 1.0.0
If you're using grunt anyway it might be the simplest solution.
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.
This is what I normally do with my projects:
npm version patch
git add *;
git commit -m "Commit message"
git push
npm publish
The first line, npm version patch, will increase the version by 1 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.