1 | 'use strict';
|
2 |
|
3 | var gulp = require('gulp');
|
4 | var jshint = require('gulp-jshint');
|
5 | var exec = require('gulp-exec');
|
6 | var stylish = require('jshint-stylish');
|
7 | var browserify = require('gulp-browserify');
|
8 | var uglify = require('gulp-uglify');
|
9 | var rename = require('gulp-rename');
|
10 | var karma = require('karma');
|
11 | var coveralls = require('gulp-coveralls');
|
12 | var istanbul = require('gulp-istanbul');
|
13 | var mocha = require('gulp-mocha');
|
14 |
|
15 | var paths = {
|
16 | index: './index.js',
|
17 | tests: './test/**/*.js'
|
18 | };
|
19 |
|
20 | function preTest(src) {
|
21 | return gulp.src(src)
|
22 | .pipe(istanbul())
|
23 | .pipe(istanbul.hookRequire());
|
24 | }
|
25 |
|
26 | function test(src){
|
27 | return gulp.src(src)
|
28 | .pipe(mocha())
|
29 | .pipe(istanbul.writeReports());
|
30 | }
|
31 |
|
32 | function testKarma(done){
|
33 | new karma.Server({
|
34 | configFile: __dirname + '/karma.conf.js',
|
35 | singleRun: true
|
36 | }, done).start();
|
37 | }
|
38 |
|
39 | function lint(src){
|
40 | return gulp.src(src)
|
41 | .pipe(jshint('.jshintrc'))
|
42 | .pipe(jshint.reporter(stylish));
|
43 | }
|
44 |
|
45 | gulp.task('dist', function(){
|
46 | gulp.src([paths.index])
|
47 | .pipe(browserify({
|
48 | insertGlobals : true,
|
49 | debug: true,
|
50 | standalone: 'objectHash'
|
51 | }))
|
52 | .pipe(rename('object_hash.js'))
|
53 | .pipe(uglify({outSourceMap: true}))
|
54 | .pipe(gulp.dest('./dist'));
|
55 |
|
56 | gulp.src([paths.tests])
|
57 | .pipe(browserify())
|
58 | .pipe(rename('object_hash_test.js'))
|
59 | .pipe(gulp.dest('./dist'));
|
60 | });
|
61 |
|
62 | gulp.task('pre-test', function() {
|
63 | preTest([paths.index]);
|
64 | });
|
65 |
|
66 | gulp.task('test', ['pre-test'], function() {
|
67 | test([paths.tests]);
|
68 | });
|
69 |
|
70 | gulp.task('karma', function() {
|
71 | testKarma();
|
72 | });
|
73 |
|
74 | gulp.task('coveralls', function() {
|
75 | gulp.src('coverage/**/lcov.info')
|
76 | .pipe(coveralls());
|
77 | });
|
78 |
|
79 | gulp.task('lint', function () {
|
80 | return lint([paths.index]);
|
81 | });
|
82 |
|
83 | gulp.task('watch', function () {
|
84 |
|
85 |
|
86 | gulp.watch([paths.index, paths.tests], function(event){
|
87 | if(event.type !== 'deleted') {
|
88 | lint([event.path]);
|
89 | }
|
90 | });
|
91 |
|
92 |
|
93 | gulp.watch([paths.index, paths.tests], ['test', 'karma']);
|
94 |
|
95 | });
|
96 |
|
97 | gulp.task('default', ['watch']);
|