UNPKG

1.5 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');
10
11var paths = {
12 index: './index.js',
13 tests: './test/**/*.js'
14};
15
16function test(src){
17 return gulp.src(src, { read: false } )
18 .pipe(exec('node <%= file.path %>')
19 .on('error', function(err){ console.log(err.message); }));
20}
21
22function lint(src){
23 return gulp.src(src)
24 .pipe(jshint('.jshintrc'))
25 .pipe(jshint.reporter(stylish));
26}
27
28gulp.task('dist', function(){
29 gulp.src([paths.index])
30 .pipe(browserify({
31 insertGlobals : true,
32 debug: true,
33 }))
34 .pipe(rename('object_hash.js'))
35 .pipe(uglify({outSourceMap: true}))
36 .pipe(gulp.dest('./dist'));
37 // tests
38 gulp.src([paths.tests])
39 .pipe(browserify())
40 .pipe(rename('object_hash_test.js'))
41 .pipe(gulp.dest('./dist'));
42});
43
44gulp.task('test', function() {
45 test([paths.tests]);
46});
47
48gulp.task('lint', function () {
49 return lint([paths.index, paths.tests]);
50});
51
52gulp.task('watch', function () {
53
54 // watch and lint any files that are added or changed
55 gulp.watch([paths.index, paths.tests], function(event){
56 if(event.type !== 'deleted') {
57 lint([event.path]);
58 }
59 });
60
61 // run the tests when something changes
62 gulp.watch([paths.index, paths.tests], ['test']);
63
64});
65
66gulp.task('default', ['watch']);