forked from osmlab/osm-community-index
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.js
68 lines (58 loc) · 1.78 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
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
/* 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 featureSize = 0;
let resourceSize = 0;
let featureFiles = 0;
let resourceFiles = 0;
let currSize = 0;
let currFiles = 0;
let t = new Table;
currSize = 0;
currFiles = 0;
glob.sync(__dirname + '/features/**/*.geojson').forEach(addRow);
t.sort(['Size|des']);
console.log(t.toString());
featureSize = bytes(currSize, { unitSeparator: ' ' });
featureFiles = currFiles;
t = new Table;
currSize = 0;
currFiles = 0;
glob.sync(__dirname + '/resources/**/*.json').forEach(addRow);
t.sort(['Size|des']);
console.log(t.toString());
resourceSize = bytes(currSize, { unitSeparator: ' ' });
resourceFiles = currFiles;
console.info(`\nTotals:`);
console.info(`-------`);
console.info(colors.blue.bold(`Features: ${featureSize} in ${featureFiles} files.`));
console.info(colors.blue.bold(`Resources: ${resourceSize} in ${resourceFiles} files.`));
console.info('');
function addRow(file) {
let stats = fs.statSync(file);
let color = colorBytes(stats.size);
currSize += stats.size;
currFiles++;
t.cell('Size', stats.size, function sizePrinter(val, width) {
let displaySize = bytes(stats.size, { unitSeparator: ' ' });
return width ? Table.padLeft(displaySize, width) : color(displaySize);
});
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;
}
}
}