var gulp = require('gulp');
var browsersync = require( 'browser-sync').create();
require('./build');
require('./build-js');
require('./build-css');
require('./build-image');
require('./build-html');

gulp.task('build:js:sync', ['build:js'], function(){browsersync.reload();});
gulp.task('build:css:sync', ['build:css'], function(){browsersync.reload();});
gulp.task('build:image:sync', ['build:image'], function(){browsersync.reload();});
gulp.task('build:html:sync', ['build:html'], function(){browsersync.reload();});

gulp.task('serve', ['rebuild'], function(){
  var config = require( '../config.js');
  
  return new Promise(function(resolve, reject){
    try {
      browsersync.init({
        server: {
          baseDir: config["html"]["destIndexDir"]
        }
      }, function(){
        gulp.watch(config['js']['srcDir'] + '/**/*.js', ['build:js:sync']);
        gulp.watch(config['css']['srcDir'] + '/**/*.styl', ['build:css:sync']);
        gulp.watch(config['image']['srcDir'] + '/**/*.{tiff,svg,jpeg,jpg,png,gif}', ['build:image:sync']);
        gulp.watch(config['html']['srcDir'] + '/**/*.pug', ['build:html:sync']);
        
        resolve();
      });
    }
    catch(e){
      reject();
    }
  });
});

var gulp = require('gulp');
var browsersync = require( 'browser-sync').create();
require('./rebuild');
require('./build-js');
require('./build-css');
require('./build-image');
require('./build-html');

gulp.task('build:js:sync', ['build:js'], function(){browsersync.reload();});
gulp.task('build:css:sync', ['build:css'], function(){browsersync.reload();});
gulp.task('build:image:sync', ['build:image'], function(){browsersync.reload();});
gulp.task('build:html:sync', ['build:html'], function(){browsersync.reload();});

gulp.task('serve', ['rebuild'], function(){
  var config = require( '../config.js');
  
  return new Promise(function(resolve, reject){
    try {
      browsersync.init({
        server: {
          baseDir: config["html"]["destIndexDir"]
        }
      }, function(){
        gulp.watch(config['js']['srcDir'] + '/**/*.js', ['build:js:sync']);
        gulp.watch(config['css']['srcDir'] + '/**/*.styl', ['build:css:sync']);
        gulp.watch(config['image']['srcDir'] + '/**/*.{tiff,svg,jpeg,jpg,png,gif}', ['build:image:sync']);
        gulp.watch(config['html']['srcDir'] + '/**/*.pug', ['build:html:sync']);
        
        resolve();
      });
    }
    catch(e){
      reject();
    }
  });
});

Fix an issue where task:serve fails