Source: tasks/css/inline.js

'use strict';

/**
 * @module tasks/css/inline
 */

/**
 * taskFactory
 * @param sources {Array} glob
 * @param options {Object}
 * @returns task {Function}
 */
module.exports = function taskFactory (sources, options) {

    return function task () {

        var gulp = require('gulp');
        var inlineSource = require('gulp-inline-source');
        var combiner = require('stream-combiner2');
        var destinationsHelper = require('../helpers/build-destinations');
        var destination;

        if (options && options.destination) {
            destination = options.destination;
        }

        var inlineSrcOpts = {
            'swallowErrors': false
        };

        var compile = combiner.obj([
            gulp.src(sources),
            inlineSource(inlineSrcOpts),
            gulp.dest(function (file) {
                return destinationsHelper.getDestination(file.base, destination);
            })
        ]);

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

        return compile;
    };
};