There are solutions to increment the version number in different application. Cocoa apps have agvtool and maven has the maven-release-plugin which increments the version number on releases. Are there similar tools for nodejs?
3 Answers
I think such a tool seems excessively heavy-handed when the only thing you need to do to increment the version number in Node.js is something as simple as:
sed -i 's/0.1.2/0.2.4/' package.json
Will change the version for your Node.js package?
If you're talking about something that will deploy your code when you explicitly mark a new version, I'd be more inclined to use git hooks and write a script to detect when a git tag is created and then start the deployment process.
You could use the pre-applypatch
hook to detect when a tag is being created to run the sed
script listed above and run npm publish
for you automatically, but again, I don't see the point of having a heavyweight tool handle all of that when it's a simple script away (and said script could be written in Node.js, too!)
-
I wouldn't use that `sed` invocation to change the version because the string `0.1.2` might appear in the dependencies. It would be better to parse the JSON and then do `.version="0.2.4"` and then stringify. – Dan D. May 02 '12 at 00:18
-
Yes and no. You probably should use the full qualification, ``version: "0.1.2",`` but since the ``package.json`` format is fully defined and the ``version`` field is unambiguous in the definition, I don't see the point of a full JSON parse and stringify. – May 02 '12 at 00:42
I think the most correct answer is to use npm version
.
For example, to increment the major version of your package:
npm version major
This will increment the major version of your package and if it is a git repository it will also commit that change and create a tag of the same name of the version.
Follow up with:
git push
git push --tags

- 13,061
- 8
- 52
- 100
grunt-bump provides version bumping, as well as git tagging/commit/push. There are similar packages for other build tools such as gulp-bump
.
Similar functionality is also now available with npm version
, but with fewer configuration options.

- 99
- 3