-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport.js
32 lines (24 loc) · 799 Bytes
/
report.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
export { reportpages };
import fs from 'fs';
import path from 'path';
function reportpages(pages) {
console.log('Report is starting');
const SortedPages = Object.entries(pages).sort((a, b) => {
return b[1] - a[1];
});
let csvContent = 'URL, Count\n'; // this is name of the header Row in spreadsheet
SortedPages.forEach(([url, count]) => {
csvContent += `${url}, ${count}\n`;
});
// path to a spreadsheet
const outputPath = path.join(process.cwd(), 'report.csv');
// Write the CSV content to a file
fs.writeFile(outputPath, csvContent, (err) => {
if (err) {
console.log(`Error writing the report to cst `, err);
}
else {
console.log(`Report saved at: ${outputPath}`);
}
});
}