'use strict';
/**
* @module tasks/revision/fileNames
* @description revision file names based on file content e.g myScript.js -> myScript.123456.js.
* Also recursively replaces references to assets that are within revisioned assets e.g images withing css files.
* Produces a manifest file to map versioned filename to original file name.
*/
/**
* taskFactory
* @param sources {Array} glob
* @param destination {Array} glob
* @param manifestLocation {String}
* @param excludeRecurse {Array}
* @param deleteOriginals {Boolean}
* @returns {Function}
* gulp stream
*/
module.exports = function taskFactory(sources, destination, manifestLocation, excludeRecurse, deleteOriginals) {
return function task() {
var gulp = require('gulp');
var gutil = require('gulp-util');
var RevAll = require('gulp-rev-all');
var combiner = require('stream-combiner2');
var revDel = require('gulp-rev-delete-original');
var revAll = new RevAll({
dontUpdateReference: excludeRecurse
});
var revision = combiner.obj([
gulp.src(sources),
revAll.revision(),
gulp.dest(destination),
deleteOriginals ? revDel() : gutil.noop(),
revAll.manifestFile(),
gulp.dest(manifestLocation)
]);
revision.on('error', console.error.bind(console));
return revision;
};
};