var gulp = require('gulp'),
	connect = require('gulp-connect');
    jshint = require('gulp-jshint'),
    uglify = require('gulp-uglify'),
    concat = require('gulp-concat'),
	build = require('gulp-build'),
	minifyCSS = require('gulp-minify-css'),
	sourcemaps = require('gulp-sourcemaps'),
	clean = require('gulp-clean'),
	htmlreplace = require('gulp-html-replace'),
	stylish = require('jshint-stylish'),
	gutil = require('gulp-util'),
	ftp = require('gulp-ftp');

var t = new Date().getTime(),
	js_all = 'js/all.min.js',
	js_vendor = 'js/vendor.min.js',
	css_file_min = 'all.min.css';




// build tasks
gulp.task('minify-css', function () {
	gulp.src(['css/reset.css', 'css/fonts.css', 'css/styles.css'], { cwd: 'webapp' })
    .pipe(minifyCSS())
    .pipe(concat(css_file_min))
    .pipe(gulp.dest('build/css'));
});

// test JS
gulp.task('test_js', function(){
	return gulp.src(['js/scripts.js', 'js/elecciones_app.js'], { cwd: 'webapp' })
		.pipe(jshint())
		.pipe(jshint.reporter('default'))
		.pipe(jshint.reporter(stylish));
});

gulp.task('js', ['test_js'], function () {
	gulp.src('js/scripts.js, js/elecciones_app.js', { cwd: 'webapp' })
		.pipe(sourcemaps.init())
		.pipe(uglify())
		.pipe(concat(js_all))
		.pipe(sourcemaps.write('./'))
		.pipe(gulp.dest('build'));
	
	gulp.src([
		'js/jquery.min.js', 
		], { cwd: 'webapp' })
		.pipe(sourcemaps.init())
      	.pipe(uglify())
      	.pipe(concat(js_vendor))
		.pipe(sourcemaps.write())
      	.pipe(gulp.dest('build'));
	
});

gulp.task('copy', function () {
	gulp.src('**/*.html', { cwd: 'webapp' })
		.pipe(htmlreplace({
			js:[(js_vendor+'?'+t), (js_all+'?'+t)],
			css: ['css/'+css_file_min+'?'+t]
		}))
		.pipe(gulp.dest('build'));
	
	gulp.src('css/fonts/*', { cwd: 'webapp' })
		.pipe(gulp.dest('build/css/fonts'));

	gulp.src('img/*', { cwd: 'webapp' })
		.pipe(gulp.dest('build/img'));

	gulp.src('data', { cwd: 'webapp' })
		.pipe(gulp.dest('build'));

});

gulp.task('build', ['minify-css', 'js', 'copy']);


// SERVER
gulp.task('connect', function() {
  connect.server({
    root: 'webapp',
    livereload: true
  });
});

gulp.task('html', function () {
  gulp.src('./webapp/*.html')
    .pipe(connect.reload());
});
 
gulp.task('watch', function () {
  gulp.watch(['./webapp/*.html', './webapp/**/*.css', './webapp/**/*.js'], ['html', 'test_js']);
});
 
gulp.task('server', ['connect', 'watch']);

gulp.task('server_pro', function() {
  connect.server({
    root: 'build',
  });
});


// default task
gulp.task('default', function() {
  console.log("Elecciones 2015 CABA");
});


//  push build to FTP
gulp.task('deploy_ftp', function () {
    var keys = require('./keys_ftp');
    return gulp.src('**/*', { cwd: 'build' })
        .pipe(ftp({
            host: keys.host,
            user: keys.user,
            pass: keys.pass,
            remotePath: keys.remotePath,
        }))
        // you need to have some kind of stream after gulp-ftp to make sure it's flushed 
        // this can be a gulp plugin, gulp.dest, or any kind of stream 
        // here we use a passthrough stream 
        .pipe(gutil.noop());
});
@@ -456,16 +456,53 @@
 p-ftp');
+%0A    merge = require('merge-stream');
 %0A%0Avar t 
@@ -618,18 +618,16 @@
 css';%0A%0A%0A
-%0A%0A
 // build
@@ -1102,32 +1102,42 @@
  function () %7B%0A%09
+var all = 
 gulp.src('js/scr
@@ -1129,16 +1129,17 @@
 ulp.src(
+%5B
 'js/scri
@@ -1144,18 +1144,20 @@
 ripts.js
+'
 , 
+'
 js/elecc
@@ -1169,16 +1169,18 @@
 _app.js'
+%5D 
 , %7B cwd:
@@ -1317,32 +1317,45 @@
 t('build'));%0A%09%0A%09
+var vendor = 
 gulp.src(%5B%0A%09%09'js
@@ -1503,16 +1503,20 @@
 s.write(
+'./'
 ))%0A     
@@ -1543,16 +1543,47 @@
 uild'));
+%0A%0A    return merge(all,vendor);
 %0A%09%0A%7D);%0A%0A
@@ -1965,16 +1965,18 @@
 rc('data
+/*
 ', %7B cwd
@@ -2009,24 +2009,29 @@
 .dest('build
+/data
 '));%0A%0A%7D);%0A%0Ag
@@ -2521,32 +2521,32 @@
 onnect.server(%7B%0A
+
     root: 'build
@@ -2546,17 +2546,16 @@
  'build'
-,
 %0A  %7D);%0A%7D

Fix gulp task with multiple sources