-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (29 loc) · 1001 Bytes
/
index.js
File metadata and controls
36 lines (29 loc) · 1001 Bytes
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
'use strict';
var path = require('path');
const istanbulMiddleware = require('istanbul-middleware');
const core = require('istanbul-middleware/lib/core');
const _ = require('lodash');
let defaultConfig = {
ignore: ['/node_modules/']
};
function IstanbulProcessor(cube, cfg) {
this.cube = cube;
this.config = _.merge(defaultConfig, cfg || {});
var config = cube.config;
istanbulMiddleware.hookLoader(config.root, {verbose: true});
}
IstanbulProcessor.type = 'script';
IstanbulProcessor.ext = '.js';
IstanbulProcessor.prototype.process = function (data, callback) {
var code = data.code;
var config = this.cube.config;
var file = path.join(config.root, data.realPath);
const isIgnore = _.some(this.config.ignore, (rule) => {
return file.toString().indexOf(rule) !== -1;
});
if (isIgnore) return callback(null, data);
let codeRes = core.getInstrumenter().instrumentSync(code, file);
data.code = codeRes;
callback(null, data);
};
module.exports = IstanbulProcessor;