1 | 'use strict';
|
2 |
|
3 | var gulp = require('gulp'),
|
4 | jshint = require('gulp-jshint'),
|
5 | stylish = require('jshint-stylish'),
|
6 | gutil = require('gulp-util'),
|
7 | mocha = require('gulp-mocha');
|
8 |
|
9 | function errorLogger(err) {
|
10 | gutil.beep();
|
11 | gutil.log(err.message);
|
12 | }
|
13 |
|
14 | function 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 |
|
25 | function test() {
|
26 | return gulp.src('./test/**/*.js')
|
27 | .pipe(mocha({reporter: 'dot'}))
|
28 | .on('error', errorLogger);
|
29 | }
|
30 |
|
31 | gulp.task('lint', function () {
|
32 | return lint();
|
33 | });
|
34 |
|
35 | gulp.task('test', ['lint'], function () {
|
36 | return test();
|
37 | });
|
38 |
|
39 |
|
40 | gulp.task('lint-watch', function () {
|
41 | lint();
|
42 | });
|
43 |
|
44 | gulp.task('test-watch', ['lint-watch'], function () {
|
45 | test();
|
46 | });
|
47 |
|
48 | gulp.task('watch', function () {
|
49 | gulp.watch([
|
50 | './**/*.js',
|
51 | '!./node_modules/**/*.js'
|
52 | ], ['test-watch']);
|
53 | });
|
54 |
|
55 | gulp.task('default', ['watch']);
|