Source: tasks/javascript/annotate.js

'use strict';

/**
 * @module tasks/javascript/annotate
 */

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

    return function task() {

        var gulp = require('gulp');
        var combiner = require('stream-combiner2');
        var ngAnnotate = require('gulp-ng-annotate');
        var destinationsHelper = require('../helpers/build-destinations');
        var destination;

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

        var annotate = combiner.obj([
            gulp.src(sources),
            ngAnnotate({
                add: true,
                single_quotes: true // eslint-disable-line camelcase
            }),
            gulp.dest(function (file) {
                return destinationsHelper.getDestination(file.base, destination);
            })
        ]);

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

        return annotate;
    };
};