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 |
|
11 | var paths = {
|
12 | index: './index.js',
|
13 | tests: './test/**/*.js'
|
14 | };
|
15 |
|
16 | function 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 |
|
22 | function lint(src){
|
23 | return gulp.src(src)
|
24 | .pipe(jshint('.jshintrc'))
|
25 | .pipe(jshint.reporter(stylish));
|
26 | }
|
27 |
|
28 | gulp.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 |
|
38 | gulp.src([paths.tests])
|
39 | .pipe(browserify())
|
40 | .pipe(rename('object_hash_test.js'))
|
41 | .pipe(gulp.dest('./dist'));
|
42 | });
|
43 |
|
44 | gulp.task('test', function() {
|
45 | test([paths.tests]);
|
46 | });
|
47 |
|
48 | gulp.task('lint', function () {
|
49 | return lint([paths.index, paths.tests]);
|
50 | });
|
51 |
|
52 | gulp.task('watch', function () {
|
53 |
|
54 |
|
55 | gulp.watch([paths.index, paths.tests], function(event){
|
56 | if(event.type !== 'deleted') {
|
57 | lint([event.path]);
|
58 | }
|
59 | });
|
60 |
|
61 |
|
62 | gulp.watch([paths.index, paths.tests], ['test']);
|
63 |
|
64 | });
|
65 |
|
66 | gulp.task('default', ['watch']);
|