UNPKG

2.33 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 replace = require('gulp-replace');
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 if (+process.version.split('.')[0].slice(1) < 8) {
34 console.log('karma does not support Node.js < 8, skipping');
35 return done();
36 }
37 new (require('karma').Server)({
38 configFile: __dirname + '/karma.conf.js',
39 singleRun: true
40 }, done).start();
41}
42
43function lint(src){
44 return gulp.src(src)
45 .pipe(jshint('.jshintrc'))
46 .pipe(jshint.reporter(stylish));
47}
48
49gulp.task('dist', function(){
50 return Promise.all([
51 gulp.src([paths.index])
52 .pipe(browserify({
53 insertGlobals : true,
54 debug: true,
55 standalone: 'objectHash'
56 }))
57 // Hack: See https://github.com/puleos/object-hash/issues/71.
58 // It's probably better to replace gulp-browserify altogether instead.
59 .pipe(replace(/_global.crypto/g, 'false'))
60 .pipe(rename('object_hash.js'))
61 .pipe(uglify())
62 .pipe(gulp.dest('./dist')),
63 gulp.src([paths.tests])
64 // Hack: browserify seems to not support async-await.
65 // It's probably better to replace gulp-browserify altogether instead.
66 .pipe(replace(/async function/g, 'function'))
67 .pipe(browserify())
68 .pipe(rename('object_hash_test.js'))
69 .pipe(gulp.dest('./dist'))
70 ]);
71});
72
73gulp.task('pre-test', function() {
74 return preTest([paths.index]);
75});
76
77gulp.task('test', gulp.series('pre-test', function() {
78 return test([paths.tests]);
79}));
80
81gulp.task('karma', function(done) {
82 testKarma(done);
83});
84
85gulp.task('coveralls', function() {
86 return gulp.src('coverage/**/lcov.info')
87 .pipe(coveralls());
88});
89
90gulp.task('lint', function () {
91 return lint([paths.index]);
92});