forked from osmlab/osm-community-index
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.js
39 lines (32 loc) · 1 KB
/
stats.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
/* eslint-disable no-console */
const bytes = require('bytes');
const colors = require('colors/safe');
const fs = require('fs');
const glob = require('glob');
const path = require('path');
const Table = require('easy-table');
getStats();
function getStats() {
let t = new Table;
glob.sync(__dirname + '/features/**/*.geojson').forEach(addRow);
console.log(t.toString());
t = new Table;
glob.sync(__dirname + '/resources/**/*.json').forEach(addRow);
console.log(t.toString());
function addRow(file) {
let stats = fs.statSync(file);
let color = colorBytes(stats.size);
t.cell('Size', color(bytes(stats.size, { unitSeparator: ' ' })));
t.cell('File', color(path.basename(file)));
t.newRow();
}
function colorBytes(size) {
if (size > 1024 * 10) { // 10 KB
return colors.red;
} else if (size > 1024 * 2) { // 2 KB
return colors.yellow;
} else {
return colors.green;
}
}
}