forked from 11ty/11ty-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node-performance-rank.js
32 lines (27 loc) · 1.04 KB
/
node-performance-rank.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
const fastglob = require("fast-glob");
const fs = require("fs-extra");
const PerformanceLeaderboard = require("performance-leaderboard");
(async () => {
let urls = new Set();
let sites = await fastglob("./_data/sites/*.json", {
caseSensitiveMatch: false
});
for(let site of sites) {
let siteData = require(site);
if(!siteData.disabled && siteData.url && !siteData.excludedFromPerformanceLeaderboard) {
urls.add(siteData.url);
}
}
let previousResults = require("./_data/fastestSites.json");
let leaderboardUrls = Array.from(urls);
let results = await PerformanceLeaderboard(leaderboardUrls, 5);
for(let result of results) {
let previousResult = previousResults.filter(entry => entry.url === result.url);
result.previousRank = previousResult.length ? previousResult[0].rank : undefined;
}
fs.writeFile("./_data/fastestSites.json", JSON.stringify(results, null, 2));
fs.writeFile("./_data/fastestSitesMeta.json", JSON.stringify({
generated: Date.now()
}, null, 2));
console.log( results );
})();