-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (33 loc) · 1.03 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
require('string.prototype.endswith');
var Plugin = require('broccoli-diffing-writer');
var bs = require('browser-sync');
BroccoliBsPlugin.prototype = Object.create(Plugin.prototype);
BroccoliBsPlugin.constructor = BroccoliBsPlugin;
function BroccoliBsPlugin(inputNode, options) {
options = options || {};
if (!(this instanceof BroccoliBsPlugin)) {
return new BroccoliBsPlugin(inputNode, options);
}
Plugin.call(this, inputNode, {
annotation: options.annotation
});
this.bs = bs.create();
this.bs.init(options.bs || {});
}
BroccoliBsPlugin.prototype.build = function(diff) {
var changedItems = diff.filter(function(i) {
return i[0] === "change";
});
for (var x = 0; x < changedItems.length; x++) {
if (!changedItems[x][1].endsWith(".css")) {
// A non-CSS file was changed. Reload everything!
this.bs.reload();
return;
}
}
cssPaths = changedItems.map(function(i) { return i[1]; });
if (cssPaths.length > 0) {
this.bs.reload(cssPaths);
}
};
module.exports = BroccoliBsPlugin;