Reputation: 16685
UPDATE:
The grunt-bump plugin only works for versions that meet the semantic versioning format. If I use a version, e.g., test-2.0.0
that doesn't meet semver, it doesn't work.
grunt-cli v1.4.2
Using a Gruntfile.js
, how can I set my package.json
to a specific version string that's not necessarily a semver version? I use the grunt-bump plugin, so I do this
Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
bump: {
options: {
files: ['package.json', 'package-lock.json'],
updateConfigs: ['pkg'],
versionType: 'patch',
...
},
...
});
...
var myTasks = [
"task1",
"clean",
....
"compress"
];
grunt.registerTask('build', 'Build version', function () {
grunt.config('bump.options.setVersion', "tag-2.0.0");
grunt.task.run(myTasks);
});
};
...then do this on the command line...
$ npm grunt build
However, package.json
is not updated to "version": "tag-2.0.0"
. What am I missing?
In Gulp I use the gulp-pipe
to write to a file.
Upvotes: 0
Views: 578
Reputation: 16685
UPDATE:
I marked this as the answer, but it's a wrong answer. This replaces ALL the occurrences of the x.y.z
version in the package*.json
files, NOT just the version
key.
I ended up using the grunt-text-replace plugin.
I now have this.
Gruntfile.js
module.exports = function(grunt) {
gruntfile.initConfig ({
replace: {
pkg_versions: {
src: ['./package*.json'],
overwrite: true, // overwrite matched source files in dist
replacements: [{
from: '<%= pkg.version %>',
to: '2.0.0'
}]
}
}
});
...
var myTasks = [
"task1",
"clean",
"replaceZ:pkg_version",
....
"compress"
];
...
grunt.registerTask('build', 'Build version', function () {
grunt.task.run(myTasks);
});
};
Upvotes: 0