-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
65 lines (55 loc) · 2.14 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
var fs = require('fs'),
path = require('path'),
Instrumenter = require('istanbul').Instrumenter,
instrumenter = new Instrumenter({preserveComments: true}),
cwd = process.cwd();
module.exports = function(borschik) {
var base = borschik.getTech('js'),
File = base.File.inherit({
read: function() {
if (!this._shouldInstrument()) {
return this.__base();
}
var content = fs.readFileSync(this.processPath(this.path), 'utf8'),
instrumented = instrumenter.instrumentSync(content, path.relative(this.tech._root, this.path));
this.content = this.parse(instrumented);
},
_shouldInstrument: function() {
var ip = this.tech._instrumentPaths;
if (!ip) {
// instrumentPaths option was not specified -> instrument
// every file
return true;
}
// Validate include path if instrumentPaths option is specified
var instrument = false;
for(var p = 0; p < ip.length; p++) {
if (this.path.indexOf(ip[p]) === 0) {
// processing path matches some of the specified
// instrument paths so instrument it
instrument = true;
break;
}
}
return instrument;
}
}),
Tech = base.Tech.inherit({
__constructor: function(opts) {
var options = (opts.techOptions || {});
this.__base(opts);
this._instrumentPaths = options.instrumentPaths;
this._root = options.root || cwd;
if (this._instrumentPaths) {
this._instrumentPaths = this._instrumentPaths.map(function(p) {
return path.resolve(this._root, p);
}, this);
}
},
File: File
});
return {
File: File,
Tech: Tech
};
};