"use strict";

const gulp = require('gulp');
const browserSync = require('browser-sync');
const cleanCSS = require('gulp-clean-css');
const exec = require('child_process').exec
const prettify = require('gulp-prettify');
const rmEmptyLines = require('gulp-remove-empty-lines');
const sass = require('gulp-sass');
const uglify = require('gulp-uglify');


const paths = {
  build: '_site',
  css: 'css',
  sass: ['css'],
  scripts: ['js']
};

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

function errorHandler(error) {
  console.error(String(error));
  this.emit('end');
  browserSync.notify('Error');
}


gulp.task('jekyll-build', function(cb) {
  exec('bundle exec jekyll build', function(err, stdout, stderr) {
    console.log(stdout);
    console.log(stderr);
    cb(err);
  });
});

gulp.task('jekyll-rebuild', gulp.series('jekyll-build', function() {
  browserSync.reload();
}));

gulp.task('js', function() {
  return gulp.src(paths.scripts + '/**/*.js')
    .pipe(gulp.dest(paths.build + '/' + paths.scripts))
    .pipe(browserSync.reload({
      stream: true
    }));
});

gulp.task('prettify', gulp.series('jekyll-build', function() {
  return gulp.src([paths.build + '/**/*.html'])
    .pipe(prettify({
      indent_inner_html: true,
      indent_with_tabs: false,
      indent_size: 2
    }))
    .pipe(rmEmptyLines())
    .pipe(gulp.dest(paths.build));
}));

gulp.task('minify', function() {
  return gulp.src([paths.build + '/' + paths.css + '/*.css'])
    .pipe(
      cleanCSS({
        debug: true,
        keepBreaks: true,
        keepSpecialComments: false
      }, function(details) {
        console.log(details.name + ': ' + details.stats.originalSize + ' ==> ' + details.stats.minifiedSize);
      }))
    .pipe(gulp.dest(paths.build + '/' + paths.css))
});

gulp.task('serve', gulp.series(gulp.parallel('js', 'jekyll-build', 'minify'), function(done) {

  browserSync.init({
    server: {
      baseDir: paths.build
    }
  });

  gulp.watch([paths.sass + '/**/*', '_sass/**/*'], gulp.parallel('jekyll-rebuild')).on('change', browserSync.reload);
  gulp.watch(paths.scripts + '/**/*', gulp.parallel('js')).on('change', browserSync.reload);
  gulp.watch(['**/*.{html,yml,md,markdown}'], gulp.parallel('jekyll-rebuild')).on('all', browserSync.reload);
  return console.log('Serve function ran'), done();

}));

gulp.task('travis', gulp.series(gulp.parallel('jekyll-build', 'js', 'prettify', 'minify'), function(done) {
  console.log('complete'), done();
}));

gulp.task('default', gulp.series('serve'));
@@ -8,20 +8,18 @@
 rict%22;%0A%0A
-cons
+le
 t gulp =
@@ -36,20 +36,18 @@
 gulp');%0A
-cons
+le
 t browse
@@ -79,20 +79,18 @@
 sync');%0A
-cons
+le
 t cleanC
@@ -121,20 +121,18 @@
 -css');%0A
-cons
+le
 t exec =
@@ -162,20 +162,18 @@
 ').exec%0A
-cons
+le
 t pretti
@@ -203,20 +203,18 @@
 tify');%0A
-cons
+le
 t rmEmpt
@@ -258,20 +258,18 @@
 ines');%0A
-cons
+le
 t sass =
@@ -291,20 +291,18 @@
 sass');%0A
-cons
+le
 t uglify
@@ -329,17 +329,16 @@
 ify');%0A%0A
-%0A
 const pa
@@ -416,16 +416,104 @@
 s'%5D%0A%7D;%0A%0A
+const sassFiles = %5B%0A  'css/**/*',%0A  '_sass/**/*'%0A%5D%0A%0Aconst jsFiles = %5B%0A  'js/**/*.js'%0A%5D%0A%0A
 const me
@@ -718,17 +718,16 @@
 r');%0A%7D%0A%0A
-%0A
 gulp.tas
@@ -753,18 +753,20 @@
 unction(
-cb
+done
 ) %7B%0A  ex
@@ -886,10 +886,12 @@
     
-cb
+done
 (err
@@ -908,107 +908,8 @@
 );%0A%0A
-gulp.task('jekyll-rebuild', gulp.series('jekyll-build', function() %7B%0A  browserSync.reload();%0A%7D));%0A%0A
 gulp
@@ -955,34 +955,15 @@
 src(
-paths.scripts + '/**/*.js'
+jsFiles
 )%0A  
@@ -1832,16 +1832,25 @@
 l('js', 
+'minify',
 'jekyll-
@@ -1855,26 +1855,16 @@
 l-build'
-, 'minify'
 ), funct
@@ -1968,59 +1968,43 @@
 tch(
-%5Bpaths.sass + '/**/*', '_sass/**/*'%5D, gulp.parallel
+sassFiles).on('change', gulp.series
 ('je
@@ -2004,34 +2004,32 @@
 ies('jekyll-
-re
 build'))
 .on('change'
@@ -2020,151 +2020,190 @@
 d'))
-.on('change', browserSync.reload);%0A  gulp.watch(paths.scripts + '/**/*', gulp.parallel('js')).on('change', browserSync.reload);%0A  gulp.watch(%5B'
+;%0A  gulp.watch(jsFiles).on('change', gulp.series('js'));%0A  gulp.watch(%5B'*.%7Bhtml,yml,md,markdown%7D', '_posts/*.%7Bhtml,yml,md,markdown%7D', '_layouts/*.%7Bhtml,yml,md,markdown%7D', '_includes/
 **/*
@@ -2231,23 +2231,31 @@
 n%7D'%5D
-, gulp.parallel
+).on('all', gulp.series
 ('je
@@ -2263,18 +2263,16 @@
 yll-
-re
 build'))
 .on(
@@ -2267,16 +2267,43 @@
 build'))
+;%0A  gulp.watch(paths.build)
 .on('all
@@ -2352,26 +2352,30 @@
 og('
-Serve function ran
+Initializing Server...
 '), 

Fix janky reload