Skip to content

Commit 03e7048

Browse files
committed
Added preProcessFn and postProcessFn to allow users to hook their cuetom functions to make changes if required
1 parent 707e9ad commit 03e7048

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

run.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,11 @@ const vstsCoverageStyles = require('./index').VstsCoverageStyles;
22

33
vstsCoverageStyles({
44
coverageDir: './test',
5-
extraCss: '.test{color:red;}'
5+
extraCss: '.test{color:red;}',
6+
preProcessFn: function (html) {
7+
return html.replace(new RegExp('×', 'g'), 'x');
8+
},
9+
postProcessFn: function (html) {
10+
return html.replace(new RegExp('×', 'g'), 'x');
11+
}
612
});

src/index.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ const merge = require('merge');
66
const cleanCSS = require('clean-css');
77
var appRoot = require('app-root-path');
88

9+
var dummyFn = function (html) {
10+
return html;
11+
}
12+
913
module.exports = function (options) {
1014
if (!(options && options.coverageDir))
1115
throw new Error('coverageDir param is required');
@@ -17,7 +21,9 @@ module.exports = function (options) {
1721
extraCss: '',
1822
minifyOptions: {
1923

20-
}
24+
},
25+
preProcessFn: dummyFn,
26+
postProcessFn: dummyFn
2127
}
2228

2329
let appRootPath = appRoot.path;
@@ -40,6 +46,8 @@ module.exports = function (options) {
4046

4147
files.forEach((file) => {
4248
fs.readFile(file, opts.fileEncoding, (fileErr, data) => {
49+
data = opts.preProcessFn(data);
50+
4351
const $ = cheerio.load(data);
4452
$('link[rel="stylesheet"]').each(function (idx, elem) {
4553
let jElem = $(elem);
@@ -59,7 +67,9 @@ module.exports = function (options) {
5967
$('head').append(customCssObj);
6068
}
6169

62-
fs.writeFile(file, $.html(), () => {
70+
let processedHTML = opts.postProcessFn($.html());
71+
72+
fs.writeFile(file, processedHTML, () => {
6373
// console.log(file + ' written');
6474
});
6575
});

0 commit comments

Comments
 (0)