UNPKG

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