This repository was archived by the owner on Jun 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
72 lines (54 loc) · 1.41 KB
/
utils.js
File metadata and controls
72 lines (54 loc) · 1.41 KB
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
'use strict';
const gutil = require('gulp-util');
const logSymbols = require('log-symbols');
const indentString = require('indent-string');
var Utils = {
/**
* Resolve writable.
*/
resolveWritable: function (writable) {
if (!writable) {
writable = gutil.log;
}
else if (typeof writable === 'function') {
writable = writable.bind(writable);
}
return writable;
},
/**
* Format report.
*/
formatReport: function (file, onlyFailures = false) {
let output = '';
if (file && file.paa) {
let audits = file.paa.audit || [];
let passes = '';
let failures = '';
audits.forEach(function (audit) {
if (audit.result === 'PASS' && !onlyFailures) {
passes += logSymbols.success + ' ' + audit.heading + '\n';
}
if (audit.result === 'FAIL') {
failures += logSymbols.error + ' ' + audit.heading + '\n';
failures += audit.elements + '\n\n';
}
});
if (passes || failures) {
output += '\n\n';
output += indentString(gutil.colors.yellow(file.path), 2);
output += '\n\n';
output += indentString(failures + passes, 2);
}
}
return output;
},
/**
* Write results to writable / output.
*/
writeReport: function (report, writable) {
if (writable && report) {
writable(report);
}
}
};
module.exports = Utils;