internal-events.js
2.29 KB
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
"use strict";
var utils = require("./utils");
var fileUtils = require("./file-utils");
module.exports = function (bs) {
var events = {
/**
* File changes
*/
"file:changed": function (data) {
fileUtils.changedFile(bs, data);
},
/**
* File reloads
* @param data
*/
"file:reload": function (data) {
bs.doFileReload(data);
},
/**
* Browser Reloads
*/
"browser:reload": function () {
bs.doBrowserReload();
},
/**
* Browser Notify
* @param data
*/
"browser:notify": function (data) {
bs.io.sockets.emit("browser:notify", data);
},
/**
* Things that happened after the service is running
* @param data
*/
"service:running": function (data) {
var mode = bs.options.get("mode");
var open = bs.options.get("open");
if (mode === "proxy" || mode === "server" || open === "ui" || open === "ui-external") {
utils.openBrowser(data.url, bs.options, bs);
}
// log about any file watching
if (bs.watchers) {
bs.events.emit("file:watching", bs.watchers);
}
},
/**
* Option setting
* @param data
*/
"options:set": function (data) {
if (bs.io) {
bs.io.sockets.emit("options:set", data);
}
},
/**
* Plugin configuration setting
* @param data
*/
"plugins:configure": function (data) {
if (data.active) {
bs.pluginManager.enablePlugin(data.name);
} else {
bs.pluginManager.disablePlugin(data.name);
}
bs.setOption("userPlugins", bs.getUserPlugins());
},
"plugins:opts": function (data) {
if (bs.pluginManager.pluginOptions[data.name]) {
bs.pluginManager.pluginOptions[data.name] = data.opts;
bs.setOption("userPlugins", bs.getUserPlugins());
}
}
};
Object.keys(events).forEach(function (event) {
bs.events.on(event, events[event]);
});
};