forked from ambroseus/sfcc-logs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
formatter.js
53 lines (48 loc) · 998 Bytes
/
formatter.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
'use strict';
module.exports = { summaryHtml }
/*
errors: [
{
total: Number
sites: {
siteName: Number
}
pipes: {
pipeName: Number
}
msg: String
desc: String
}
]
*/
function summaryHtml(errors) {
const sortDesc = obj => Object.keys(obj)
.sort( (a,b) => obj[b] - obj[a] )
.map( key => `<b>${obj[key]}</b> ${key}` )
.join('<br/>');
const row = err => `<tr>
<td><b>${err.total}</b></td>
<td nowrap>${sortDesc(err.sites)}</td>
<td nowrap>${sortDesc(err.pipes)}</td>
<td><b>${err.msg}</b><br/>${err.desc}</td>
</tr>`;
return `<html>
<head><style>
th {
text-transform: uppercase;
text-align: left;
}
th, td {
font-size: 10pt;
font-family: arial;
vertical-align: top;
padding: 10px;
border-bottom: 1px solid #ddd;
}
</style></head>
<body><table>
<thead><tr><th>total</th><th>sites</th><th>pipelines</th><th>error</th></tr></thead>
<tbody>${errors.map(row).join("\n")}</tbody>
</table></body>
</html>`;
}