Reputation: 1
In a web project with grunt, how to configure my gruntfile.js for when it run, apply the version of my cache item in the index.html and heading of the .js and .css from the changes it has in this version. for example:
i probably have:
... js/last.js, js/new.js ...
i run and i want get:
js/lastAndNew.js <- version 0.0.2
but when probably i have: ... js/last.js, js/new1.js, js/new2.js, js/new3.js, js/new4.js, js/new5.js ...
i want get, for example:
js/lastAndAllNews.js --> version 0.1.0 (or maybe 1.0.0 i dont know how works really)
for grunt change automatically the versions on my project, what i do in the gruntfile.js code?
only i get with bump, change 1 by 1 the number of the version. with one easy configuration.
Upvotes: 0
Views: 722
Reputation: 23379
I usually do something like this in my grunt file..
Put this at the top of the grunt file to read the version from the package.json which reads the version into a variable, increments it, then updates the package.json. If you don't want to increment the version on every build just use the first line.
var pkg = grunt.file.readJSON('package.json');
pkg.version = pkg.version.split(".");
var subversion = pkg.version.pop();
subversion++;
pkg.version.push(subversion);
pkg.version = pkg.version.join(".");
grunt.file.write('package.json', JSON.stringify(pkg, null, 2));
Then you can use that to define your headers and footers using your preferred tasks.
Here's an example of one of my grunt files that does this.
Upvotes: 2