forked from openannotation/annotator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (31 loc) · 866 Bytes
/
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
var fs = require('fs');
var path = require('path');
var through = require('through');
/**
* Populate the Annotator namespace by require()'ing any exposed plugins.
*
* Given a browserify bundle transform any module exposed as 'annotator'
* by appending `require()` calls all other exposed modules in the bundle.
*
* @param {object} b - A browserify bundle.
*/
module.exports = function (b) {
if (b[__filename]) return b;
else b[__filename] = true;
return b
.transform(function (file) {
if (b._mapped['annotator'] == file) {
return through(null, function () {
this.queue('\n');
for (var m in b._mapped) {
if (m == 'annotator') continue;
this.queue("require('" + m + "');\n");
}
this.queue(null);
});
} else {
return through();
}
})
;
}