forked from Antriel/phaser3-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
total.js
73 lines (51 loc) · 1.54 KB
/
total.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
68
69
70
71
72
73
var fs = require('fs');
var dirTree = require('directory-tree');
var stringOccurrence = require('string-occurrence');
var rootDir = '../phaser/src/';
var output = './desc.txt';
var total = 0;
var subtotal = 0;
var dump = '';
var prevFolder = '';
var filteredTree = dirTree(rootDir, { extensions: /\.js$/ }, (item, PATH) => {
var file = fs.readFileSync(item.path, 'utf8');
var fileTotal = stringOccurrence(file, '[description]');
if (fileTotal > 0)
{
item.path = item.path.replace('..\\phaser\\src\\', '');
item.path = item.path.replace('.js', '');
var folder = item.path.substr(0, item.path.indexOf('\\'));
if (prevFolder === '')
{
prevFolder = folder;
}
if (folder !== prevFolder)
{
console.log(prevFolder, '=', subtotal);
dump = dump.concat('\n' + prevFolder + ' total = ' + subtotal + '\n\n');
prevFolder = folder;
subtotal = fileTotal;
}
else
{
subtotal += fileTotal;
}
dump = dump.concat(item.path + ' = ' + fileTotal + '\n');
// console.log(item.path, '=', fileTotal);
total += fileTotal;
}
});
console.log(prevFolder, 'total', subtotal);
dump = dump.concat(prevFolder + ' total = ' + subtotal + '\n\n');
console.log('Total: ' + total);
dump = dump.concat('Total: ' + total);
fs.writeFile(output, dump, function (error) {
if (error)
{
throw error;
}
else
{
console.log('desc.txt saved');
}
});