Source: tasks/revision/filePaths.js

'use strict';

/**
 * @module tasks/revision/filePaths
 * @description Uses manifest file to replace instances of file names with versioned file name
 */

/**
 * taskFactory
 * @param sources {Array} glob
 * @param destination {Array} glob
 * @param manifestLocation {String}
 * @returns {Function}
 * gulp stream
 */
module.exports = function taskFactory(sources, destination, manifestLocation) {

    return function task() {

        var gulp = require('gulp');
        var revReplace = require('gulp-rev-replace');
        var combiner = require('stream-combiner2');
        var path = require('path');

        var manifest = gulp.src(
            path.join(manifestLocation, 'rev-manifest.json')
        );

        var revision = combiner.obj([
            gulp.src(sources),
            revReplace({manifest: manifest}),
            gulp.dest(destination)
        ]);

        revision.on('error', console.error.bind(console));

        return revision;
    };
};