UNPKG

1.08 kBJavaScriptView Raw
1'use strict';
2
3var gulp = require('gulp'),
4 jshint = require('gulp-jshint'),
5 stylish = require('jshint-stylish'),
6 gutil = require('gulp-util'),
7 mocha = require('gulp-mocha');
8
9function errorLogger(err) {
10 gutil.beep();
11 gutil.log(err.message);
12}
13
14function lint() {
15 return gulp.src([
16 './**/*.js',
17 '!./node_modules/**/*.js'
18 ])
19 .pipe(jshint('.jshintrc'))
20 .pipe(jshint.reporter(stylish))
21 .pipe(jshint.reporter('fail'))
22 .on('error', errorLogger);
23}
24
25function test() {
26 return gulp.src('./test/**/*.js')
27 .pipe(mocha({reporter: 'dot'}))
28 .on('error', errorLogger);
29}
30
31gulp.task('lint', function () {
32 return lint();
33});
34
35gulp.task('test', ['lint'], function () {
36 return test();
37});
38
39// when watching, do NOT return the stream, otherwise watch won't continue on error
40gulp.task('lint-watch', function () {
41 lint();
42});
43
44gulp.task('test-watch', ['lint-watch'], function () {
45 test();
46});
47
48gulp.task('watch', function () {
49 gulp.watch([
50 './**/*.js',
51 '!./node_modules/**/*.js'
52 ], ['test-watch']);
53});
54
55gulp.task('default', ['watch']);