I have been encountering an issue while using the gulp-rev plugin to add a revision of my app/html page generated by the Yeomann webapp generator. My workflow involves zipping the app and then adding a revision, but I am having trouble replacing the hash that is created by the gulp-rev plugin.
In my gruntfile.js :
var rev = require('gulp-rev');
var date = new Date(dateString);
gulp.task('rev', function () {
return gulp.src('app/*.zip')
.pipe(rev(new Date().toString()))
.pipe(gulp.dest('deploy/'));
});
The rev-all plugin uses rev-hash to generate the hash:
'use strict';
var crypto = require('crypto');
module.exports = function (buf) {
if (!Buffer.isBuffer(buf)) {
throw new TypeError('Expected a buffer');
}
return crypto.createHash('md5').update(buf).digest('hex').slice(0, 10);
};
and rev-path to add it to the file name:
'use strict';
var modifyFilename = require('modify-filename');
module.exports = function (pth, hash) {
if (arguments.length !== 2) {
throw new Error('`path` and `hash` required');
}
return modifyFilename(pth, function (filename, ext) {
return filename + '_' + hash + ext;
});
};
module.exports.revert = function (pth, hash) {
if (arguments.length !== 2) {
throw new Error('`path` and `hash` required');
}
return modifyFilename(pth, function (filename, ext) {
return filename.replace(new RegExp('_' + hash + '$'), '') + ext;
});
};
When I added (new Date().toString()) to the .pipe(rev()), it returned a date string object error. I want to create a custom revision string with the current date or version number e.g., v.1.0.0.
Can someone assist me in replacing the md5 hex with a timestamp in this file?