forked from koemei/gulp-node-inspector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
68 lines (48 loc) · 1.66 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
'use strict';
var es = require('event-stream'),
gutil = require('gulp-util'),
merge = require('merge'),
debugServer = require('node-inspector/lib/debug-server'),
Config = require('node-inspector/lib/config'),
packageJson = require('node-inspector/package.json');
var PluginError = gutil.PluginError;
var config = new Config([]);
var DebugServer = debugServer.DebugServer;
var log = gutil.log,
colors = gutil.colors;
var PLUGIN_NAME = 'gulp-node-inspector';
var nodeInspector = function(opt) {
var stream;
var startDebugServer = function() {
var options = merge(config, opt);
log(PLUGIN_NAME, 'is using node-inspector v' + packageJson.version);
var debugServer = new DebugServer(options);
debugServer.on('error', function(err) {
if (err.code === 'EADDRINUSE') {
log(colors.red('There is another process already listening at this address.\nChange "webPort": {port} to use a different port.'));
}
stream.emit('error', PluginError(PLUGIN_NAME, 'Cannot start the server at ' + config.webHost + ':' + config.webPort + '. Error: ' + (err.message || err)));
});
debugServer.on('listening', function() {
log(colors.green('Visit', this.address().url, 'to start debugging.'));
});
debugServer.on('close', function() {
done();
});
debugServer.start(config);
}
function done() {
// End the stream if it exists
if (stream) {
stream.emit('end');
}
}
var queueFile = function(file) {};
var endStream = function() {
startDebugServer();
};
// copied from gulp-karma
stream = es.through(queueFile, endStream);
return stream;
};
module.exports = nodeInspector;