forked from yehjxraymond/gmx-synthetics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics.ts
103 lines (85 loc) · 2.76 KB
/
metrics.ts
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { getAllFiles } from "get-all-files";
import { SolidityMetricsContainer } from "solidity-code-metrics";
const options = {
basePath: "",
inputFileGlobExclusions: undefined,
inputFileGlob: undefined,
inputFileGlobLimit: undefined,
debug: false,
repoInfo: {
branch: undefined,
commit: undefined,
remote: undefined,
},
};
const metrics = new SolidityMetricsContainer("metricsContainerName", options);
async function run() {
const files = await getAllFiles("./contracts").toArray();
const skipFiles = [
"./contracts/mock",
"./contracts/reader",
"./contracts/test",
"./contracts/event",
"./contracts/deposit/DepositEventUtils.sol",
"./contracts/market/MarketEventUtils.sol",
"./contracts/order/OrderEventUtils.sol",
"./contracts/position/PositionEventUtils.sol",
"./contracts/referral/ReferralEventUtils.sol",
"./contracts/withdrawal/WithdrawalEventUtils.sol",
];
const patternedFiles = [
"./contracts/data/Keys.sol",
"./contracts/deposit/Deposit.sol",
"./contracts/deposit/DepositStoreUtils.sol",
"./contracts/market/Market.sol",
"./contracts/market/MarketStoreUtils.sol",
"./contracts/order/Order.sol",
"./contracts/order/OrderStoreUtils.sol",
"./contracts/position/Position.sol",
"./contracts/position/PositionStoreUtils.sol",
"./contracts/withdrawal/Withdrawal.sol",
"./contracts/withdrawal/WithdrawalStoreUtils.sol",
];
for (let i = 0; i < files.length; i++) {
const file = files[i];
let shouldSkip = false;
for (let j = 0; j < skipFiles.length; j++) {
if (file.includes(skipFiles[j])) {
shouldSkip = true;
break;
}
}
if (shouldSkip) {
console.info("skipping", file);
continue;
}
console.info(i, file);
await metrics.analyze(files[i]);
}
let patternedFilesSourceCount = 0;
console.info(metrics.seenFiles);
console.info("contract,source,total,comment");
for (let i = 0; i < metrics.metrics.length; i++) {
const metric = metrics.metrics[i];
let isPatternedFile = false;
for (let j = 0; j < patternedFiles.length; j++) {
if (metric.filename.includes(patternedFiles[j])) {
isPatternedFile = true;
break;
}
}
if (isPatternedFile) {
patternedFilesSourceCount += metric.metrics.nsloc.source;
}
console.info(
[metric.filename, metric.metrics.nsloc.source, metric.metrics.nsloc.total, metric.metrics.nsloc.comment].join(",")
);
}
console.info("metrics including patterned files:", metrics.totals().totals.nsloc);
console.info("patterned files source count:", patternedFilesSourceCount);
console.info(
"source count excluding patterned files:",
metrics.totals().totals.nsloc.source - patternedFilesSourceCount
);
}
run();