Reputation: 4928
I'd like to add a grunt task that accepts a version number. This version number will then be set in the package.json
file. I have found grunt-bump, which bumps the version number, but I would like to set the version number to a known value, that will come from the build server.
Grunt task:
grunt.registerTask('setversion', function() {
// Something to go here to update the version number.
});
package.json:
{
"name": "scoreboard",
"version": "0.2",
...
}
Anyone got any idea's?
Upvotes: 1
Views: 683
Reputation: 4928
Thanks for the answer, but it turned out to be a lot more straightforward. I am using TeamCity, so I ran an NPM task with the following command, where %system.build.number%
follows the pattern n.n.n
, e.g.: 0.1.6
.
--no-git-tag-version version %system.build.number%
Upvotes: 1
Reputation: 2248
You could use something like:
grunt.registerTask('setversion', function(arg1) {
console.log("Attempting to update version to "+arg1);
var parsedJson= grunt.file.readJSON("package.json");//read in the current
parsedJson["version"] = arg1; //set the top level version field to arg1
grunt.file.write("package.json", JSON.stringify(parsedJson, null, 2));
});
add in some error checking etc.. make sure package.json is writable and execute with grunt setversion:newVersion
e.g.: grunt setversion:0.3
Upvotes: 3