forked from bentleyvk/package-usage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
summary-component-usage.js
56 lines (48 loc) · 2.34 KB
/
summary-component-usage.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
import fs from "fs";
const getStatistics = (usageMap, isActiveIn30Days) => {
const statistics = {};
Object.keys(usageMap)
.filter(
(project) =>
!isActiveIn30Days || new Date(usageMap[project].lastModifiedDate) >= Date.now() - 30 * 24 * 60 * 60 * 1000
)
.forEach((project) => {
statistics[project] = Object.keys(usageMap[project].components).filter(
(key) => !key.toLowerCase().startsWith("svg")
).length;
});
return statistics;
};
const getUsageStatistics = (itwinuiUsage, bwcUsage, uiCoreUsage, coreReactUsage, isActiveIn30Days) => {
const itwinuiStatistics = getStatistics(itwinuiUsage, isActiveIn30Days);
const bwcStatistics = getStatistics(bwcUsage, isActiveIn30Days);
const uiCoreStatistics = getStatistics(uiCoreUsage, isActiveIn30Days);
const coreReactStatistics = getStatistics(coreReactUsage, isActiveIn30Days);
const usageStatistics = {};
Object.keys({ ...bwcStatistics, ...itwinuiStatistics, ...uiCoreStatistics }).forEach((project) => {
usageStatistics[project] = [
bwcStatistics[project],
itwinuiStatistics[project],
uiCoreStatistics[project],
coreReactStatistics[project],
];
});
console.log(usageStatistics);
return usageStatistics;
};
const writeToFile = (usageStatistics, fileName) => {
let csvFile =
"Project,BWC unique components,iTwinUI unique components,ui-core unique components,core-react unique components\n";
Object.keys(usageStatistics).forEach((project) => {
csvFile += `${project},${usageStatistics[project].map((count) => count || 0).join(",")}\n`;
});
fs.writeFileSync(fileName, csvFile);
};
const itwinuiUsage = JSON.parse(fs.readFileSync("./repositoryComponentsMap-itwin-itwinui-react.json"));
const bwcUsage = JSON.parse(fs.readFileSync("./repositoryComponentsMap-bentley-bwc-react.json"));
const uiCoreUsage = JSON.parse(fs.readFileSync("./repositoryComponentsMap-bentley-ui-core.json"));
const coreReact = JSON.parse(fs.readFileSync("./repositoryComponentsMap-itwin-core-react.json"));
const usageStatistics = getUsageStatistics(itwinuiUsage, bwcUsage, uiCoreUsage, coreReact, false);
const usageStatisticsActive30Days = getUsageStatistics(itwinuiUsage, bwcUsage, uiCoreUsage, coreReact, true);
writeToFile(usageStatistics, "./usageStatistics.csv");
writeToFile(usageStatisticsActive30Days, "./usageStatisticsActive30Days.csv");