var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var autoprefixer = require('autoprefixer');
var scss = require('postcss-scss');
var stylelint = require('stylelint');
var browserSync = require('browser-sync').create();
var config = {
	'src': './',
	'dest': 'dist/',
	'sourcemaps': false,
	'browsers': [
		'last 2 versions',
		'android >= 2.3',
		'safari >= 6',
		'ie >= 9'
	]
};


// HTML
gulp.task('html', function() {
	return gulp.src(config.src + '*.html')
		.pipe(browserSync.stream());
});

// Compile and autoprefix stylesheets
gulp.task('styles', function() {
	return gulp.src(config.src + 'scss/**/*.scss')
		.pipe($.if(config.sourcemaps, $.sourcemaps.init()))
		.pipe($.sass({
			precision: 8,
			outputStyle: 'expanded'
		}).on('error', function(error) {
			$.util.log($.util.colors.red(error.message));
			this.emit('end');
		}))
		.pipe($.postcss([
			autoprefixer({
				browsers: config.browsers
			})
		]))
		.pipe(gulp.dest(config.dest + 'css'))
		.pipe(browserSync.stream())
		.pipe($.cleanCss({compatibility: 'ie8'}))
		.pipe($.if(config.sourcemaps, $.sourcemaps.write()))
		.pipe($.rename({suffix: '.min'}))
		.pipe(gulp.dest(config.dest + 'css'))
		.pipe(browserSync.stream());
});

// Lint stylesheets
gulp.task('stylelint', function() {
	return gulp.src(config.src + 'scss/**/*.scss')
		.pipe($.postcss([
			stylelint()
		], {
			syntax: scss
		}));
});

// Compile javascript
gulp.task('scripts', function() {
	return gulp.src(config.src + 'js/*.js')
		.pipe($.include().on('error', function(error) {
			$.util.log($.util.colors.red(error.message));
			this.emit('end');
		}))
		.pipe(gulp.dest(config.dest + 'js'))
		.pipe(browserSync.stream())
		.pipe($.if(config.sourcemaps, $.sourcemaps.init()))
		.pipe($.uglify().on('error', function(error) {
			$.util.log($.util.colors.red(error.message));
			this.emit('end');
		}))
		.pipe($.if(config.sourcemaps, $.sourcemaps.write()))
		.pipe($.rename({suffix: '.min'}))
		.pipe(gulp.dest(config.dest + 'js'))
		.pipe(browserSync.stream());
});

// Optimize images
gulp.task('images', function() {
	return gulp.src(config.src + 'img/**/*.{gif,jpg,png,svg}')
		.pipe($.cache($.imagemin()))
		.pipe(gulp.dest(config.dest + 'img'))
		.pipe(browserSync.stream());
});

// Build production files
gulp.task('build', ['html', 'styles', 'scripts', 'images']);

// Serve compiled files
gulp.task('serve', ['build'], function() {
	browserSync.init({
		server: true,
		notify: false,
		snippetOptions: {
			rule: {
				match: /<\/body>/i
			}
		}
	});
});

// Watch files for changes
gulp.task('watch', function() {
	gulp.watch([config.src + '*.html'], ['html']);
	gulp.watch([config.src + 'scss/**/*.scss'], ['styles']);
	gulp.watch([config.src + 'js/*.js'], ['scripts']);
	gulp.watch([config.src + 'img/**/*.{gif,jpg,png,svg}'], ['images']);
});

// Run all tasks
gulp.task('default', ['serve', 'watch']);

@@ -449,29 +449,16 @@
 ulp.src(
-config.src + 
 '*.html'
@@ -2587,30 +2587,16 @@
 tch(
-%5Bconfig.src + 
 '*.html'
 %5D, %5B
@@ -2591,17 +2591,16 @@
 '*.html'
-%5D
 , %5B'html
@@ -2608,33 +2608,32 @@
 %5D);%0A%09gulp.watch(
-%5B
 config.src + 'sc
@@ -2645,17 +2645,16 @@
 /*.scss'
-%5D
 , %5B'styl
@@ -2664,33 +2664,32 @@
 %5D);%0A%09gulp.watch(
-%5B
 config.src + 'js
@@ -2694,17 +2694,16 @@
 js/*.js'
-%5D
 , %5B'scri
@@ -2722,17 +2722,16 @@
 p.watch(
-%5B
 config.s
@@ -2763,17 +2763,16 @@
 ng,svg%7D'
-%5D
 , %5B'imag

Change gulp paths