var gulp = require('gulp'),
    gutil = require('gulp-util'),
    autoprefixer = require('gulp-autoprefixer'),
    browserSync = require('browser-sync'),
    concat = require('gulp-concat'),
    cssnano = require('gulp-cssnano'),
    rename = require('gulp-rename'),
    sass = require('gulp-sass'),
    sourcemaps = require('gulp-sourcemaps'),
    uglify = require('gulp-uglify'),
    bourbon = require('bourbon').includePaths,
    cp = require('child_process');


var messages = {
    jekyllBuild: '<span style="color: grey">Running:</span> $ jekyll build'
};

/**
 * Build the Jekyll Site
 */
gulp.task('jekyll-build', function (done) {
  browserSync.notify(messages.jekyllBuild);
  return cp.spawn( 'jekyll' , ['build'], {stdio: 'inherit'})
    .on('close', done);
});

/**
 * Rebuild Jekyll & do page reload
 */
gulp.task('jekyll-rebuild', ['jekyll-build'], function () {
    browserSync.reload();
});

/**
 * Wait for jekyll-build, then launch the Server
 */
gulp.task('browser-sync', ['css', 'jekyll-build'], function() {
  browserSync({
    server: {
      baseDir: '_site'
    },
    port: 3000
  });
});


/**
 * CSS
 */
gulp.task('css', function () {
  return gulp.src('./assets/scss/styles.scss')
    .pipe(sourcemaps.init())
    .pipe(sass({
        includePaths: ['assets/scss'].concat(bourbon),
        onError: browserSync.notify
    }))
    // .on('end', function(){ gutil.log('Almost there...'); })
    .pipe(autoprefixer({
      browsers: [
        '> 5%',
        'ie 10'
      ],
      remove: true,
      cascade: true
    }))
    .pipe(cssnano({processImport: false}))
    .pipe(rename({ suffix: '.min' }))
    .pipe(sourcemaps.write('./maps'))
    .pipe(gulp.dest('./_site/assets/css/'))
    .pipe(browserSync.reload({stream:true}))
    .pipe(gulp.dest('assets/css'));
});

/**
 * Javascripts
 */
gulp.task('scripts', function(){
  return gulp.src([
      './js/plugins/**/*.js',
      './js/*.js'
    ])
    .pipe(sourcemaps.init())
    .pipe(concat('scripts.js'))
    .pipe(rename({suffix: '.min'}))
    .pipe(uglify())
    .on('error', handleError)
    .pipe(sourcemaps.write('./maps/'))
    .pipe(gulp.dest('./_site/js/'))
    .pipe(browserSync.reload({stream:true, once: true}))
    .pipe(gulp.dest('js'));
});



/**
 * Watch scss files for changes & recompile
 * Watch html/md files, run jekyll & reload BrowserSync
 */
gulp.task('watch', function () {
    gulp.watch('assets/scss/**/*.scss', ['css']);
    gulp.watch('assets/js/*.js', ['scripts']);
    gulp.watch(['*.html', '*.md', '_includes/*.html', '_layouts/*.html', '_posts/*'], ['jekyll-rebuild']);
});

/**
 * Default task, running just `gulp` will compile the sass,
 * compile the jekyll site, launch BrowserSync & watch files.
 */
gulp.task('default', ['browser-sync', 'watch']);

// Handle errors
function handleError (error) {
  //If you want details of the error in the console
  console.log('WARNING!', error.message.toString());
  this.emit('end');
}

@@ -1787,24 +1787,655 @@
 ss'));%0A%7D);%0A%0A
+/**%0A * CSS Production%0A */%0Agulp.task('css-prod', function () %7B%0A  return gulp.src('./assets/scss/styles.scss')%0A    .pipe(sass(%7B%0A        includePaths: %5B'assets/scss'%5D.concat(bourbon),%0A        onError: browserSync.notify%0A    %7D))%0A    // .on('end', function()%7B gutil.log('Almost there...'); %7D)%0A    .pipe(autoprefixer(%7B%0A      browsers: %5B%0A        '%3E 5%25',%0A        'ie 10'%0A      %5D,%0A      remove: true,%0A      cascade: true%0A    %7D))%0A    .pipe(cssnano(%7BprocessImport: false%7D))%0A    .pipe(rename(%7B suffix: '.min' %7D))%0A    .pipe(gulp.dest('./_site/assets/css/'))%0A    .pipe(browserSync.reload(%7Bstream:true%7D))%0A    .pipe(gulp.dest('assets/css'));%0A%7D);%0A%0A
 /**%0A * Javas
@@ -3397,16 +3397,66 @@
 ch'%5D);%0A%0A
+gulp.task('build', %5B'css-prod', 'jekyll-build'%5D);%0A
 // Handl

Add gulp production build