forked from SiddharthShyniben/community-health
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculate-comments.js
43 lines (32 loc) · 1.39 KB
/
calculate-comments.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
import AsciiTable, { AsciiAlign } from 'https://deno.land/x/[email protected]/mod.ts';
const files = [
['Readme', 'templates/README.md'],
['Contributing', 'templates/CONTRIBUTING.md'],
['Bug report', 'templates/issues-templates/bug-report.md'],
['Feature request', 'templates/issues-templates/feature-request.md'],
];
let decreases = [];
const table = new AsciiTable('Comments');
table
.setBorder('│', '─', '┌', '┘')
.setHeadingAlign(AsciiAlign.CENTER)
.setHeading('Name', 'Original Length', 'New length', 'Decrease', '% Decrease');
for (const file of files) {
let contents = await Deno.readTextFile(file[1]);
const initialLength = contents.length;
contents = contents.replace(/<!--[^!]([\s\S]*?)-->/gi, '');
const finalLength = contents.length;
const percentDecrease = (initialLength - finalLength) / initialLength * 100;
decreases.push(percentDecrease);
table.addRow(file[0], initialLength + '', finalLength + '', (initialLength - finalLength) + '', percentDecrease + '');
}
let tableString = table.toString();
tableString = tableString.split('\n');
tableString[0] = tableString[0].substring(0, tableString[0].length - 1) + '┐';
tableString.reverse();
tableString[0] = '└' + tableString[0].substring(1);
tableString.reverse();
tableString = tableString.join('\n');
console.log(tableString);
console.log();
console.log(`Average: ${eval(decreases.join('+')) / decreases.length + 1}`);