|
| 1 | +import gulp from 'gulp' |
| 2 | +import loadPlugins from 'gulp-load-plugins' |
| 3 | +import {Instrumenter} from 'isparta' |
| 4 | +import del from 'del' |
| 5 | +import mkdirp from 'mkdirp' |
| 6 | +import seq from 'run-sequence' |
| 7 | + |
| 8 | +const DEST = 'lib' |
| 9 | + |
| 10 | +const $ = loadPlugins() |
| 11 | + |
| 12 | +const plumb = () => $.plumber({ |
| 13 | + errorHandler: $.notify.onError('<%= error.message %>') |
| 14 | +}) |
| 15 | + |
| 16 | +const test = () => { |
| 17 | + return gulp.src(['test/lib/setup.js', 'test/unit/**/*.js'], {read: false}) |
| 18 | + .pipe(plumb()) |
| 19 | + .pipe($.mocha({reporter: 'dot'})) |
| 20 | +} |
| 21 | + |
| 22 | +gulp.task('clean', () => del.sync(DEST)) |
| 23 | + |
| 24 | +gulp.task('transpile', () => { |
| 25 | + mkdirp.sync(DEST) |
| 26 | + return gulp.src('src/**/*.js') |
| 27 | + .pipe(plumb()) |
| 28 | + .pipe($.sourcemaps.init()) |
| 29 | + .pipe($.babel()) |
| 30 | + .pipe($.sourcemaps.write()) |
| 31 | + .pipe(gulp.dest(DEST)) |
| 32 | +}) |
| 33 | + |
| 34 | +gulp.task('lint', () => { |
| 35 | + return gulp.src('src/**/*.js') |
| 36 | + .pipe(plumb()) |
| 37 | + .pipe($.standard()) |
| 38 | + .pipe($.standard.reporter('default', { |
| 39 | + breakOnError: false |
| 40 | + })) |
| 41 | +}) |
| 42 | + |
| 43 | +gulp.task('build', (cb) => seq('lint', 'test', 'transpile', cb)) |
| 44 | + |
| 45 | +gulp.task('cleanbuild', (cb) => seq('clean', 'build', cb)) |
| 46 | + |
| 47 | +gulp.task('coverage', (cb) => { |
| 48 | + gulp.src('src/**/*.js') |
| 49 | + .pipe(plumb()) |
| 50 | + .pipe($.istanbul({instrumenter: Instrumenter})) |
| 51 | + .pipe($.istanbul.hookRequire()) |
| 52 | + .on('finish', () => test().pipe($.istanbul.writeReports()).on('end', cb)) |
| 53 | +}) |
| 54 | + |
| 55 | +gulp.task('coveralls', ['coverage'], () => { |
| 56 | + return gulp.src('coverage/lcov.info') |
| 57 | + .pipe(plumb()) |
| 58 | + .pipe($.coveralls()) |
| 59 | +}) |
| 60 | + |
| 61 | +gulp.task('test', test) |
| 62 | + |
| 63 | +gulp.task('watch', () => gulp.watch('{src,test}/**/*', ['cleanbuild'])) |
| 64 | + |
| 65 | +gulp.task('default', ['cleanbuild'], () => gulp.start('watch')) |
0 commit comments