import gulp from 'gulp';
import del from 'del';
import eslint from 'gulp-eslint';
import babel from 'gulp-babel';
import sourcemaps from 'gulp-sourcemaps';
import mocha from 'gulp-mocha';
import istanbul from 'gulp-istanbul';
import remapIstanbul from 'remap-istanbul/lib/gulpRemapIstanbul';


gulp.task('clean', () => del(['lib/', 'test/', 'maps/', 'coverage/']));

gulp.task('lint', () => {
  return gulp.src('src/**/*.js')
    .pipe(eslint())
    .pipe(eslint.format())
    .pipe(eslint.failAfterError());
});

gulp.task('build', ['clean'], () => {
  return gulp.src('src/lib/**/*.js')
    .pipe(sourcemaps.init())
    .pipe(babel())
    .pipe(sourcemaps.write('../maps', { includeContent: false, sourceRoot: '../src/lib' }))
    .pipe(gulp.dest('lib'));
});

gulp.task('build:test', ['build'], () => {
  return gulp.src('src/test/**/*.js')
    .pipe(babel())
    .pipe(gulp.dest('test'));
});

gulp.task('pre-test', ['build:test'], () => {
  return gulp.src(['lib/**/*.js'])
    .pipe(istanbul())
    .pipe(istanbul.hookRequire());
});

gulp.task('test', ['pre-test'], () => {
  return gulp.src(['test/**/*.js'])
    .pipe(mocha({ timeout: 10000 }))
    .pipe(istanbul.writeReports())
    .pipe(istanbul.enforceThresholds({ thresholds: { global: 50 } }));
});


gulp.task('remap-istanbul', ['test'], function () {
  return gulp.src('coverage/coverage-final.json')
    .pipe(remapIstanbul({
      reports: {
        'json': 'coverage/coverage.json',
        'html': 'coverage/lcov-report',
        'lcovonly': 'coverage/lcov.info'
      }
    }));
});

gulp.task('default', ['lint', 'test']);

@@ -379,36 +379,27 @@
 lint', () =%3E
- %7B
 %0A  
-return 
 gulp.src('sr
@@ -391,24 +391,25 @@
 %0A  gulp.src(
+%5B
 'src/**/*.js
@@ -401,32 +401,54 @@
 c(%5B'src/**/*.js'
+, 'gulpfile.babel.js'%5D
 )%0A    .pipe(esli
@@ -514,19 +514,17 @@
 Error())
-;%0A%7D
+%0A
 );%0A%0Agulp
@@ -550,35 +550,26 @@
 ean'%5D, () =%3E
+%0A
  
-%7B%0A  return
  gulp.src('s
@@ -752,19 +752,17 @@
 ('lib'))
-;%0A%7D
+%0A
 );%0A%0Agulp
@@ -793,35 +793,26 @@
 ild'%5D, () =%3E
+%0A
  
-%7B%0A  return
  gulp.src('s
@@ -876,19 +876,17 @@
 'test'))
-;%0A%7D
+%0A
 );%0A%0Agulp
@@ -920,36 +920,27 @@
 est'%5D, () =%3E
- %7B
 %0A  
-return 
 gulp.src(%5B'l
@@ -1008,19 +1008,17 @@
 quire())
-;%0A%7D
+%0A
 );%0A%0Agulp
@@ -1050,27 +1050,18 @@
 %5D, () =%3E
+%0A
  
-%7B%0A  return
  gulp.sr
@@ -1217,27 +1217,25 @@
 al: 50 %7D %7D))
-;%0A%7D
+%0A
 );%0A%0A%0Agulp.ta
@@ -1268,32 +1268,17 @@
 t'%5D,
- function
  () 
-%7B
+=%3E
 %0A  
-return 
 gulp
@@ -1369,14 +1369,12 @@
     
-'
 json
-'
 : 'c
@@ -1409,14 +1409,12 @@
     
-'
 html
-'
 : 'c
@@ -1447,17 +1447,16 @@
     
-'
 lcovonly
 ': '
@@ -1451,17 +1451,16 @@
 lcovonly
-'
 : 'cover
@@ -1477,16 +1477,17 @@
 nfo'
+,
 %0A      %7D
 %0A   
@@ -1486,16 +1486,17 @@
    %7D
+,
 %0A    %7D))
 ;%0A%7D)
@@ -1495,11 +1495,9 @@
  %7D))
-;%0A%7D
+%0A
 );%0A%0A

Fix codes detectd by ESLint