This repository has been archived by the owner on Apr 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
/
index.js
73 lines (61 loc) 路 1.78 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
66
67
68
69
70
71
72
73
'use strict';
const program = require('commander');
const pth = require('path');
const { consoleError } = require('../helpers/console');
const stats = {
errors: 0,
hasTypos: false,
ok: 0,
total: 0,
};
const reports = [];
const reportNames = new Set();
const buffer = [];
module.exports = {
addReports(names) {
names.forEach(function(name) {
const moduleName = pth.extname(name) === '.js' ? name : './' + name;
if (reportNames.has(moduleName)) {
return;
}
try {
reports.push(require(moduleName));
reportNames.add(moduleName);
} catch (e) {
consoleError(`Can't load report module "${moduleName}".`);
consoleError(e);
}
});
},
onStart() {
reports.forEach(function(name) {
name.onStart && name.onStart();
});
},
onResourceComplete(hasError, data, dictionary) {
stats.total++;
const hasTypos = Boolean(data && data.data && data.data.length);
if (hasTypos) {
stats.hasTypos = true;
}
if (hasError || hasTypos) {
stats.errors++;
buffer.push([hasError, data]);
} else {
stats.ok++;
if (!program.onlyErrors) {
buffer.push([hasError, data]);
}
}
if (!program.onlyErrors || hasError || hasTypos) {
reports.forEach(function(name) {
name.onResourceComplete && name.onResourceComplete(hasError, data, dictionary);
});
}
},
onComplete(configPath) {
reports.forEach(function(name) {
name.onComplete && name.onComplete(buffer, stats, configPath);
});
}
};