The following assumes we will use this grunt-jenkins-build-number trick.
grunt.registerMultiTask('whatever', 'versioning stuff', function() {
var version = 'tis: ' + process.env.BUILD_NUMBER;
var fs = require('fs');
var directories = ["foo","foo/bar"];
directories.forEach(function(directory) {
fs.readdir(directory, function(err, list) {
list.forEach(function(file) {
var route = directory + '/' + file;
if (route.indexOf(".html") >= 0) {
fs.readFile(route, function (err, data) {
fs.writeFile(route, '<!-- ' + version + " -->\r\n" + data, function (err) {});
});
}
if (route.indexOf(".css") >= 0) {
fs.readFile(route, function (err, data) {
fs.writeFile(route, '/* ' + version + " */\r\n" + data, function (err) {});
});
}
if (route.indexOf(".js") >= 0) {
fs.readFile(route, function (err, data) {
fs.writeFile(route, '/* ' + version + " */\r\n" + data, function (err) {});
});
}
});
});
});
});
The following helped me:
- http://nodejs.org/docs/v0.4.8/api/fs.html#file_System
- http://stackoverflow.com/questions/5827612/node-js-fs-readdir-recursive-directory-search
I take back all of my hate for node!
No comments:
Post a Comment