-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloc.dart
66 lines (52 loc) · 1.76 KB
/
loc.dart
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
// ignore_for_file: avoid_print
import 'dart:io';
Future<void> main(List<String> args) async {
String mostLines = '';
int mostLinesTotal = 0;
const List<String> scanDirs = [
'lib',
'test',
];
int totalLines = 0;
int totalLinesSkipped = 0;
Map<String, int> extensionCounts = <String, int>{};
for (String dir in scanDirs) {
// Counts how many lines in total of all files in the current directory.
List<FileSystemEntity> files =
Directory('${Directory.current.path}\\$dir').listSync(recursive: true);
for (FileSystemEntity file in files) {
if (file is File) {
try {
String codeFile = await file.readAsString();
int length = codeFile.split('\n').length;
totalLines += length;
if (length > mostLinesTotal) {
mostLines = file.path;
mostLinesTotal = length;
}
if (extensionCounts[file.path.split('.').last] == null) {
extensionCounts[file.path.split('.').last] = 1;
} else {
extensionCounts[file.path.split('.').last] =
extensionCounts[file.path.split('.').last]! + 1;
}
} catch (_) {
totalLinesSkipped++;
}
}
}
}
print('Total lines: $totalLines');
print('Total files skipped: $totalLinesSkipped');
print('Most lines file: $mostLines');
print('Most lines file total lines: $mostLinesTotal');
print('Extension counts:');
// Prints the top 10 extensions and their counts.
extensionCounts.keys.toList()
..sort((String a, String b) =>
extensionCounts[b]!.compareTo(extensionCounts[a]!))
..take(10).forEach((String extension) {
print(
' - ${extension.toUpperCase()}: ${extensionCounts[extension]} file(s)');
});
}