var gulp = require('gulp');
var plumber = require('gulp-plumber');
var uglify = require('gulp-uglify');
var sass = require('gulp-sass');
var rename = require('gulp-rename');
var autoprefixer = require('gulp-autoprefixer');
var webserver = require('gulp-webserver');


gulp.task('scripts', function() {
    return gulp.src('js/scripts.js')
        .pipe(plumber(plumber({
            errorHandler: function (err) {
                console.log(err);
                this.emit('end');
            }
        })))
        .pipe(uglify())
        .pipe(rename({extname: '.min.js'}))
        .pipe(gulp.dest('js'));
});

gulp.task('styles', function() {
    return gulp.src('scss/styles.scss')
        .pipe(plumber(plumber({
            errorHandler: function (err) {
                console.log(err);
                this.emit('end');
            }
        })))
        .pipe(sass({outputStyle: 'compressed'}))
        .pipe(autoprefixer())
        .pipe(gulp.dest('css'));
});

gulp.task('webserver', function() {
    return gulp.src('./')
        .pipe(webserver({
            livereload: true,
            directoryListing: true,
            open: true,
            enable: true, // need this set to true to enable livereload 
            filter: function(fileName) {
                if (fileName.match(/.scss$/) || fileName.match(/.min.js$/)) {
                    return false;
                } else {
                    return true;
                }
            }
        }));
});

gulp.task('watch', ['scripts', 'styles', 'webserver'], function() {
    gulp.watch('js/*.js', ['scripts']);
    gulp.watch('scss/*.scss', ['styles']);
});

@@ -1350,38 +1350,8 @@
 s$/)
- %7C%7C fileName.match(/.min.js$/)
 ) %7B%0D
@@ -1589,17 +1589,23 @@
 tch('js/
-*
+scripts
 .js', %5B'

fix reload loop