-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
executable file
·44 lines (41 loc) · 1.47 KB
/
index.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
var through2 = require('through2');
var BrowserStackTunnel = require('browserstacktunnel-wrapper');
var tunnel;
var gutil = require('gulp-util');
module.exports.startTunnel = function(options) {
// we don't care for the files, so we just pass them along and start the tunnel
return through2.obj(function(file, enc, callback) {
if(!tunnel || tunnel.state === 'stop') {
tunnel = new BrowserStackTunnel(options);
tunnel.start(function(err) {
if(err) {
var messageStart = err.message.indexOf('*** Error');
var messageEnd = err.message.indexOf('Configuration Options');
var message = err.message.substr(
messageStart,
messageEnd - messageStart
);
gutil.log(gutil.colors.red('Failed to start BrowserStack tunnel'));
gutil.log(gutil.colors.red(message));
}
callback(err, file);
});
} else {
// tunnel already started
callback(null, file);
}
});
};
module.exports.stopTunnel = function() {
return through2.obj(function(file, enc, callback) {
if(!!tunnel) {
tunnel.stop(function(err) {
callback(err, file);
});
tunnel = undefined;
} else {
// no tunnel to stop
callback(null, file);
}
});
};