This repository has been archived by the owner on Apr 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgulpfile.js
92 lines (79 loc) · 2.35 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
'use strict';
var del = require('del');
var gulp = require('gulp');
var mocha = require('gulp-mocha');
var istanbul = require('gulp-istanbul');
var browserify = require('gulp-browserify');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var replace = require('gulp-replace');
var insert = require('gulp-insert');
var through = require('through');
var pkgInfo = require('./package.json');
var mochaOpts = { reporter: 'spec', bail: true };
var codePaths = ['lib/**/*.js', 'gulpfile.js', '!./lib/**/*.min.js'];
var banner = [
'/*!', pkgInfo.name, 'v', pkgInfo.version,
new Date().toISOString().substr(0, 10), '*/\n'
].join(' ');
// Replace node-specific components with browser-specific ones
function browserSpecific() {
var data = '';
return through(
function(buf) {
data += buf;
},
function() {
this.queue(data.replace(/\.\/node\//g, './browser/'));
this.queue(null);
}
);
}
gulp.task('clean', function() {
return del(['dist']);
});
gulp.task('watch', function() {
gulp.watch(
['./lib/**/*.js', './test/**/*.test.js'],
['test']
);
});
gulp.task('coveragePrepare', function() {
return gulp.src(codePaths)
.pipe(istanbul({}))
.pipe(istanbul.hookRequire());
});
gulp.task('coverage', ['coveragePrepare'], function() {
return getMochaStream().pipe(istanbul.writeReports());
});
gulp.task('mocha', getMochaStream);
gulp.task('browserify', function(cb) {
gulp.src('./index.js')
.pipe(browserify({
standalone: 'Imbo',
transform: [
browserSpecific,
'workerify'
]
}))
.pipe(rename('browser-bundle.js'))
.pipe(replace(new RegExp(__dirname, 'g'), '.'))
.pipe(gulp.dest('./dist'))
.on('end', cb);
});
gulp.task('uglify', function(cb) {
gulp.src('./dist/browser-bundle.js')
.pipe(rename('browser-bundle.min.js'))
.pipe(uglify({ outSourceMap: true }))
.pipe(insert.prepend(banner))
.pipe(gulp.dest('./dist'))
.on('end', cb);
});
gulp.task('default', ['clean', 'coverage', 'browserify'], function() {
gulp.start('uglify');
});
gulp.task('test', ['mocha']);
function getMochaStream() {
return gulp.src('test/**/*.test.js', { read: false })
.pipe(mocha(mochaOpts));
}