'use strict'

import gulp from 'gulp'

import browserSync from 'browser-sync'
import csscomb from 'gulp-csscomb'
import cssnano from 'cssnano'
import cssnext from 'postcss-cssnext'
import plumber from 'gulp-plumber'
import postcss from 'gulp-postcss'
import rename from 'gulp-rename'
import sass from 'gulp-sass'
import sourcemaps from 'gulp-sourcemaps'

const processors = [
  cssnext({
    browsers: [
      'Chrome >= 45',
      'Firefox >= 35',
      'ie >= 9',
      'last 5 versions',
      'Safari >= 7'
    ]
  }),
  cssnano({
    autoprefixer: false
  })
]

// Compile Sass to CSS - default
gulp.task('sass:default', () => {
  return gulp.src('src/ethercss.scss')
    .pipe(plumber())
    .pipe(sourcemaps.init())
    .pipe(sass({
      outputStyle: 'nested'
    }).on('error', (e) => {
      console.log(e + '\r\n There\'s something wrong with the Sass file(s).')
    }))
    .pipe(csscomb())
    .pipe(postcss(processors))
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest('./dist/css'))
    .pipe(gulp.dest('dist'))
    .pipe(browserSync.stream({
      match: '**/*.css'
    }))
})

// Compile Sass to CSS - minified
gulp.task('sass:min', () => {
  return gulp.src('./src/ethercss.scss')
    .pipe(plumber())
    .pipe(sourcemaps.init())
    .pipe(sass({
      outputStyle: 'compressed'
    }).on('error', (e) => {
      console.log(e + '\r\n There\'s something wrong with minified Sass file(s).')
    }))
    .pipe(csscomb())
    .pipe(postcss(processors))
    .pipe(rename({
      suffix: '.min'
    }))
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest('./dist/css'))
    .pipe(browserSync.stream({
      match: '**/*.css'
    }))
})

gulp.task('sass:test', () => {
  const sassLint = require('gulp-sass-lint')

  console.log('Running Sass lint test')

  return gulp.src('./src/**/*.scss')
    .pipe(plumber())
    .pipe(sassLint())
    .pipe(sassLint.format())
    .pipe(sassLint.failOnError())
})

@@ -354,26 +354,268 @@
 %0A%0Aconst 
-processors
+dirs = %7B%0A  src: './src/ethercss.scss',%0A  dest: './dist'%0A%7D%0A%0Aconst processorsDev = %5B%0A  cssnext(%7B%0A    browsers: %5B%0A      'Chrome %3E= 45',%0A      'Firefox %3E= 35',%0A      'ie %3E= 9',%0A      'last 5 versions',%0A      'Safari %3E= 7'%0A    %5D%0A  %7D)%0A%5D%0A%0Aconst processorsProd
  = %5B%0A  c
@@ -891,27 +891,16 @@
 src(
-'src/ethercss.scss'
+dirs.src
 )%0A  
@@ -1147,32 +1147,35 @@
 stcss(processors
+Dev
 ))%0A    .pipe(sou
@@ -1218,49 +1218,17 @@
 est(
-'./dist/css'))%0A    .pipe(gulp.dest('dist'
+dirs.dest
 ))%0A 
@@ -1375,37 +1375,24 @@
 ulp.src(
-'./src/ethercss.scss'
+dirs.src
 )%0A    .p
@@ -1652,16 +1652,20 @@
 ocessors
+Prod
 ))%0A    .
@@ -1764,20 +1764,17 @@
 est(
-'./dist/css'
+dirs.dest
 ))%0A 

Fix and refactor gulp task for sass