'use strict';

var gulp = require('gulp'),
    sass = require('gulp-sass'),
    gutil = require('gulp-util'),
    buffer = require('vinyl-buffer'),
    source = require('vinyl-source-stream'),
    connect = require('gulp-connect'),
    plumber = require('gulp-plumber'),
    babelify = require('babelify'),
    sourcemap = require('gulp-sourcemaps'),
    browserify = require('browserify');

gulp.task('default', ['watch-www', 'watch-src', 'watch-styles', 'watch-templates', 'build', 'copy-templates', 'serve'], function () {});

gulp.task('build', ['build-sass', 'build-es6'], function () {});

gulp.task('build-sass', function () {
    return gulp.src('./styles/**/*.scss')
        .pipe(plumber())
        .pipe(sass())
        .pipe(gulp.dest('./public/styles/'));
});

gulp.task('build-es6', function () {
    return browserify({debug: true})
        .transform(babelify)
        .require('./src/scripts/bootstrap.js', {entry: true})
        .bundle()
        .on('error', function (err) {
            gutil.log('Browserify error.');
        })
        .pipe(plumber())
        .pipe(source('bootstrap.js'))
        .pipe(buffer())
        .pipe(sourcemap.init({loadMaps: true}))
        .pipe(sourcemap.write('./'))
        .pipe(gulp.dest('./public/scripts/'));
});

gulp.task('copy-templates', function () {
    return gulp.src('./src/templates/**/*.html')
        .pipe(gulp.dest('./public/templates'));
});

gulp.task('serve', function () {
    return connect.server({
        root: './public',
        port: 3000,
        livereload: true
    });
});

gulp.task('watch-src', function () {
    return gulp.watch('./src/**/*.js', ['build-es6']);
});

gulp.task('watch-www', function () {
    return gulp.watch('./public/**/*.{js,html,css}', ['livereload']);
});

gulp.task('watch-styles', function () {
    return gulp.watch('./styles/**/*.scss', ['build-sass']);
});

gulp.task('watch-templates', function () {
    return gulp.watch('./src/templates/**/*.html', ['copy-templates']);
});

gulp.task('livereload', function () {
    return gulp.src('./public/**/*.{js,html}')
        .pipe(connect.reload());
});

@@ -454,52 +454,16 @@
 ', '
-watch-templates', 'build', 'copy-templates',
+build', 
  'se
@@ -1235,152 +1235,8 @@
 );%0A%0A
-gulp.task('copy-templates', function () %7B%0A    return gulp.src('./src/templates/**/*.html')%0A        .pipe(gulp.dest('./public/templates'));%0A%7D);%0A%0A
 gulp
@@ -1695,128 +1695,8 @@
 );%0A%0A
-gulp.task('watch-templates', function () %7B%0A    return gulp.watch('./src/templates/**/*.html', %5B'copy-templates'%5D);%0A%7D);%0A%0A
 gulp

Remove no longer needed template tasks.