-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinecount.js
63 lines (43 loc) · 1.11 KB
/
linecount.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
//Counts lines of code in all specified files
var fs = require('fs');
var files = [
'index.js',
'server/const.js',
'server/game-room.js',
'server/map.js',
'server/player.js',
'server/utils.js',
'server/waiting-room.js',
'server/tree.js',
'server/handler.js',
'client/client.js',
'client/hex.js',
'client/index.html',
'client/style.css',
'client/tutorial.js'
];
console.log('\n');
for(var i = 0, len, total = 0; i < files.length; i++){
len = fs.readFileSync(files[i]).toString().split('\n').length;
total += len;
console.log(files[i] + tabs(4, files[i]) + len + spaces(5, len + '') + 'lines');
}
//Gets the amount of tabs necessary to indent to s tabs (given 8 wide tabs in the cmd)
//Give a string for width
function tabs(s, width){
var tot = s - Math.floor(width.length / 8),
str = '';
for(var i = 0; i < tot; i++){
str += '\t';
}
return str;
}
function spaces(s, width){
var tot = s - width.length,
str = '';
for(var i = 0; i < tot; i++){
str += ' ';
}
return str;
}
console.log('\nTotal lines: ' + total);