<commit_before>/**
 * Author: <NAME>
 * Date: 1/20/15
 *
 *
 */
var cssbuild    = require('./streams.cssbuild');
var jsbuild     = require('./streams.jsbuild');
var s3          = require('./streams.s3');
var aws         = require('./streams.aws');
var Q           = require('q');
var _           = require('lodash');
var eventStream = require('event-stream');
var streamqueue = require('streamqueue');
var rename      = require('gulp-rename');
var concat      = require('gulp-concat');
var uglify      = require('gulp-uglify');
var minifyCSS   = require('gulp-minify-css');
var gutil       = require('gulp-util');
var path        = require('path');
var delim       = path.normalize('/');
var objMode     = { objectMode: true };

module.exports = function (gulp, opts) {
    opts = opts || {};
    opts.deploy = true;

    var timestamp       = (new Date()).getTime() + '';
    var outputPrefix    = opts.outputPrefix;
    var config          = opts.config || {};
    var env             = opts.env;
    var assetsDir       = opts.assetsDir || (opts.rootDir + delim + 'assets');
    var jsAssets        = opts.jsAssets;
    var awsConfig       = config.aws || {};
    var s3opts = {
        accessKeyId:        awsConfig.keyId,
        secretAccessKey:    awsConfig.secret,
        params: {
            Bucket:         awsConfig.assets && awsConfig.assets.bucket
        }
    };

    return {

        // copy all the local assets to the target s3 bucket
        assets: function () {
            if (!env) {
                throw new Error('env param must be set for deploy    tasks');
            }

            gutil.log('deploying assets to CDN');
            return eventStream.merge(
                s3.uploadFiles(gulp, [assetsDir + delim + 'fonts/*'], 'fonts', s3opts),
                s3.uploadFiles(gulp, [assetsDir + delim + 'html/*'], 'html', s3opts),
                s3.uploadFiles(gulp, [assetsDir + delim + 'img/*'], 'img', s3opts),
                s3.uploadFiles(gulp, jsAssets, 'js', s3opts)
            );
        },

        // deploy latest JavaScript and CSS
        jscss: function () {
            if (!env) {
                throw new Error('env param must be set for deploy    tasks');
            }

            var cssName = outputPrefix + '.all.' + timestamp + '.css';
            var jsCommonName = outputPrefix + '.common.' + timestamp + '.js';
            var newFiles = [cssName, jsCommonName];

            var cssStream = cssbuild.generateCss(gulp, opts)
                .pipe(rename(cssName))
                .pipe(minifyCSS());

            var jsStream = streamqueue(objMode,
                jsbuild.generateLibJs(gulp, opts),
                jsbuild.generateCommonJs(gulp, opts).pipe(uglify())
            ).pipe(concat(jsCommonName));

            //return jsStream.pipe(gulp.dest(__dirname + '/../../../'));

            // array will contains streams for each custom JS and CSS file going to s3
            var buildArr = [<commit_msg>Fix for minifying CSS with node v4<commit_after>/**
 * Author: <NAME>
 * Date: 1/20/15
 *
 *
 */
var cssbuild    = require('./streams.cssbuild');
var jsbuild     = require('./streams.jsbuild');
var s3          = require('./streams.s3');
var aws         = require('./streams.aws');
var Q           = require('q');
var _           = require('lodash');
var eventStream = require('event-stream');
var streamqueue = require('streamqueue');
var rename      = require('gulp-rename');
var concat      = require('gulp-concat');
var uglify      = require('gulp-uglify');
var minifyCSS   = require('gulp-minify-css');
var gutil       = require('gulp-util');
var path        = require('path');
var delim       = path.normalize('/');
var objMode     = { objectMode: true };

module.exports = function (gulp, opts) {
    opts = opts || {};
    opts.deploy = true;

    var timestamp       = (new Date()).getTime() + '';
    var outputPrefix    = opts.outputPrefix;
    var config          = opts.config || {};
    var env             = opts.env;
    var assetsDir       = opts.assetsDir || (opts.rootDir + delim + 'assets');
    var jsAssets        = opts.jsAssets;
    var awsConfig       = config.aws || {};
    var s3opts = {
        accessKeyId:        awsConfig.keyId,
        secretAccessKey:    awsConfig.secret,
        params: {
            Bucket:         awsConfig.assets && awsConfig.assets.bucket
        }
    };

    return {

        // copy all the local assets to the target s3 bucket
        assets: function () {
            if (!env) {
                throw new Error('env param must be set for deploy    tasks');
            }

            gutil.log('deploying assets to CDN');
            return eventStream.merge(
                s3.uploadFiles(gulp, [assetsDir + delim + 'fonts/*'], 'fonts', s3opts),
                s3.uploadFiles(gulp, [assetsDir + delim + 'html/*'], 'html', s3opts),
                s3.uploadFiles(gulp, [assetsDir + delim + 'img/*'], 'img', s3opts),
                s3.uploadFiles(gulp, jsAssets, 'js', s3opts)
            );
        },

        // deploy latest JavaScript and CSS
        jscss: function () {
            if (!env) {
                throw new Error('env param must be set for deploy    tasks');
            }

            var cssName = outputPrefix + '.all.' + timestamp + '.css';
            var jsCommonName = outputPrefix + '.common.' + timestamp + '.js';
            var newFiles = [cssName, jsCommonName];

            var cssStream = cssbuild.generateCss(gulp, opts)
                .pipe(rename(cssName))
                .pipe(minifyCSS({ rebase: false }));

            var jsStream = streamqueue(objMode,
                jsbuild.generateLibJs(gulp, opts),
                jsbuild.generateCommonJs(gulp, opts).pipe(uglify())
            ).pipe(concat(jsCommonName));

            //return jsStream.pipe(gulp.dest(__dirname + '/../../../'));

            // array will contains streams for each custom JS and CSS file going to s3
            var buildArr = [
{'fraction_non_alphanumeric': 0.1386849132176235, 'fraction_numerical': 0.006174899866488652, 'mean_word_length': 1.8647227533460804, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2716299', 'n_tokens_mistral': 1754, 'n_tokens_neox': 1687, 'n_words': 440}