// *************************************
//
//   Stylesheets Task
//
// *************************************

// -------------------------------------
//   Modules
// -------------------------------------
//
// gulp-sass                : Compile scss into css
// gulp-sourcemaps          : Create sourcemaps
// gulp-autoprefixer        : Autoprefix css
// gulp-plumber             : Fix broken gulp pipes
// gulp-cssmin              : Minify & Optimize css
// gulp-rename              : Rename Files
var sass = require('gulp-sass');
var sourceMaps = require('gulp-sourcemaps');
var autoprefixer = require('gulp-autoprefixer');
var plumber = require('gulp-plumber');
var cssmin = require('gulp-cssmin');
var rename = require('gulp-rename');

/**
 *
 * @param gulp
 * @param config
 * @returns {*}
 */
module.exports = function(gulp, config){
    return gulp.src(config.scss.src)
        .pipe(plumber())
        .pipe(sourceMaps.init())
        .pipe(sass(config.scss.settings)).on('error', sass.logError)
        .pipe(autoprefixer({
            browsers: ['last 2 versions'],
            cascade: false
        }))
        .pipe(sourceMaps.write())
        .pipe(gulp.dest(config.scss.dest))
        .pipe(cssmin())
        .pipe(rename({suffix: '.min'}))
        .pipe(gulp.dest(config.scss.dest))
};
