var config = require('../config');

var gulp = require('gulp');
var util = require('gulp-util');

var coffee = require('gulp-coffee');
var sourcemaps = require('gulp-sourcemaps');
var plumber = require('gulp-plumber');
var autoprefixer = require('gulp-autoprefixer');
var browserSync = require('browser-sync');


gulp.task('scripts:dev', function(){
    var browserSyncObj = browserSync.get('og');

    return gulp.src(config.scripts.src)
        .pipe(plumber({
            errorHandler: function(err) {
                console.log(err.message);
                this.emit('end');
            }
        }))
        .pipe(sourcemaps.init())
        .pipe(coffee().on('error', util.log))
        .pipe(sourcemaps.write('.'))
        .pipe(gulp.dest(config.scripts.dest))
        .pipe(browserSyncObj.stream());
});
