|
| 1 | +var gulp = require('gulp'); |
| 2 | +var eslint = require('gulp-eslint'); |
| 3 | +var excludeGitignore = require('gulp-exclude-gitignore'); |
| 4 | +var mocha = require('gulp-mocha'); |
| 5 | +var istanbul = require('gulp-istanbul'); |
| 6 | +var nsp = require('gulp-nsp'); |
| 7 | +var plumber = require('gulp-plumber'); |
| 8 | +var babel = require('gulp-babel'); |
| 9 | + |
| 10 | +// Initialize the babel transpiler so ES2015 files gets compiled |
| 11 | +// when they're loaded |
| 12 | +require('babel-core/register'); |
| 13 | + |
| 14 | +gulp.task('static', function () { |
| 15 | + return gulp.src('**/*.js') |
| 16 | + .pipe(excludeGitignore()) |
| 17 | + .pipe(eslint()) |
| 18 | + .pipe(eslint.format()) |
| 19 | + .pipe(eslint.failAfterError()); |
| 20 | +}); |
| 21 | + |
| 22 | +gulp.task('nsp', function (cb) { |
| 23 | + nsp('package.json', cb); |
| 24 | +}); |
| 25 | + |
| 26 | +gulp.task('pre-test', function () { |
| 27 | + return gulp.src('lib/**/*.js') |
| 28 | + .pipe(babel()) |
| 29 | + .pipe(istanbul({includeUntested: true})) |
| 30 | + .pipe(istanbul.hookRequire()); |
| 31 | +}); |
| 32 | + |
| 33 | +gulp.task('test', ['pre-test'], function (cb) { |
| 34 | + var mochaErr; |
| 35 | + |
| 36 | + gulp.src('test/**/*.js') |
| 37 | + .pipe(plumber()) |
| 38 | + .pipe(mocha({reporter: 'spec'})) |
| 39 | + .on('error', function (err) { |
| 40 | + mochaErr = err; |
| 41 | + }) |
| 42 | + .pipe(istanbul.writeReports()) |
| 43 | + .on('end', function () { |
| 44 | + cb(mochaErr); |
| 45 | + }); |
| 46 | +}); |
| 47 | + |
| 48 | +gulp.task('babel', function () { |
| 49 | + return gulp.src('lib/**/*.js') |
| 50 | + .pipe(babel()) |
| 51 | + .pipe(gulp.dest('dist')); |
| 52 | +}); |
| 53 | + |
| 54 | +gulp.task('prepublish', ['nsp', 'babel']); |
| 55 | +gulp.task('default', ['static', 'test']); |
0 commit comments