gitnode.jsnpmgithooks

update package.json version automatically


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?


Solution

  • 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.