'use strict';
const gulp = require('gulp');
const csslint = require('gulp-csslint');
const htmlhint = require("gulp-htmlhint");
const eslint = require('gulp-eslint');
const babel = require('gulp-babel');
const connect = require('gulp-connect');
const jsdoc = require('gulp-jsdoc3');
const gulpIf = require('gulp-if');

const paths = {
  src: 'src', dst: './',
  css:   ['demo/*.css', 'demo/**/*.css',
          'test/*.css', 'test/**/*.css',
          'src/*.css',   'src/**/*.css'],
  html:  ['demo/*.html', 'demo/**/*.html',
          'test/*.html', 'test/**/*.html'],
  js:    ['demo/*.js',   'demo/**/*.js',
          'test/*.js',   'test/**/*.js',
          'src/*.js',    'src/**/*.js'],
  csssrc:['src/*.css',   'src/**/*.css'],
  jssrc: ['./src/*.js',    './src/**/*.js']
};

function isFixed(file) {
  // Has ESLint fixed the file contents?
  return file.eslint != null && file.eslint.fixed;
}

gulp.task('reload', function () {
  return gulp.src(paths.js, { read: false })
    .pipe(connect.reload());
});

gulp.task('doc', function () {
  var config = require('./.jsdoc.json');
  return gulp.src(['./README.md'].concat(paths.jssrc), { read: false })
    .pipe(jsdoc(config));
});

gulp.task('css-lint', function() {
  return gulp.src(paths.css)
    .pipe(csslint())
    .pipe(csslint.formatter());
});

gulp.task('html-hint', _ => {
  return gulp.src(paths.html)
    .pipe(htmlhint())
    .pipe(htmlhint.reporter());
});

gulp.task('js-lint', _ => {
  return gulp.src(paths.jssrc, {base: './'})
    .pipe(eslint({fix: true}))
    .pipe(eslint.format())
    .pipe(gulpIf(isFixed, gulp.dest('./')));
});

gulp.task('js-copy', _ => {
  return gulp.src(paths.jssrc)
    .pipe(babel())
    .pipe(gulp.dest(paths.dst));
});

gulp.task('css-copy', _ => {
  return gulp.src(paths.csssrc)
    .pipe(gulp.dest(paths.dst));
});

gulp.task('watch', _ => {
  gulp.watch(paths.js, ['reload']);
  gulp.watch(paths.html, ['html-hint', 'doc', 'reload']);
  gulp.watch(paths.jssrc, ['js-lint', 'js-copy', 'doc', 'reload']);
  gulp.watch(paths.csssrc, ['css-lint', 'css-copy', 'reload']);
});

gulp.task('connect', function() {
  connect.server({
    root: paths.dst,
    livereload: true,
    port: 9003
  });
});

gulp.task('default', [
  'js-lint',
  'css-lint',
  'html-hint',
  'css-copy',
  'js-copy',
  'doc',
  'watch',
  'connect'
]);


@@ -7,16 +7,17 @@
 trict';%0A
+%0A
 const gu
@@ -19,16 +19,20 @@
 st gulp 
+    
 = requir
@@ -52,24 +52,25 @@
 nst csslint 
+ 
 = require('g
@@ -136,24 +136,26 @@
 onst eslint 
+  
 = require('g
@@ -180,16 +180,19 @@
 t babel 
+   
 = requir
@@ -222,16 +222,17 @@
 connect 
+ 
 = requir
@@ -262,16 +262,19 @@
 t jsdoc 
+   
 = requir
@@ -304,16 +304,18 @@
  gulpIf 
+  
 = requir
@@ -355,20 +355,28 @@
 src:
+   
  'src',
+%0A 
  dst:
+   
  './
@@ -391,23 +391,10 @@
 :   
-%5B'demo/*.css',
  
+%5B
 'dem
@@ -409,74 +409,25 @@
 ss',
-%0A          'test/*.css', 'test/**/*.css',%0A          'src/*.css',  
+ 'test/**/*.css',
  'sr
@@ -453,24 +453,10 @@
 l:  
-%5B'demo/*.html',
  
+%5B
 'dem
@@ -472,33 +472,8 @@
 ml',
-%0A          'test/*.html',
  'te
@@ -500,25 +500,11 @@
 :   
- %5B'demo/*.js',
   
- 
+%5B
 'dem
@@ -518,74 +518,24 @@
 js',
-%0A          'test/*.js',   'test/**/*.js',%0A          'src/*.js',   
+ 'test/**/*.js',
  'sr
@@ -560,24 +560,10 @@
 src:
+ 
 %5B
-'src/*.css',   
 'src
@@ -588,26 +588,10 @@
 rc: 
-%5B'./src/*.js',   
  
+%5B
 './s
@@ -857,27 +857,21 @@
 ('doc', 
-function ()
+() =%3E
  %7B%0A  var
@@ -939,16 +939,21 @@
 DME.md'%5D
+%0A    
 .concat(
@@ -1032,34 +1032,29 @@
 'css-lint', 
-function()
+() =%3E
  %7B%0A  return 
@@ -1150,25 +1150,26 @@
 html-hint', 
-_
+()
  =%3E %7B%0A  retu
@@ -1272,17 +1272,18 @@
 -lint', 
-_
+()
  =%3E %7B%0A  
@@ -1312,16 +1312,17 @@
 jssrc, %7B
+ 
 base: '.
@@ -1323,16 +1323,17 @@
 se: './'
+ 
 %7D)%0A    .
@@ -1448,33 +1448,34 @@
 task('js-copy', 
-_
+()
  =%3E %7B%0A  return g
@@ -1574,17 +1574,18 @@
 -copy', 
-_
+()
  =%3E %7B%0A  
@@ -1675,9 +1675,10 @@
 h', 
-_
+()
  =%3E 
@@ -1935,18 +1935,13 @@
 t', 
-function()
+() =%3E
  %7B%0A 
@@ -2155,9 +2155,8 @@
 ct'%0A%5D);%0A
-%0A

Improve gulpfile code