-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcount_lines.dart
More file actions
36 lines (27 loc) · 932 Bytes
/
count_lines.dart
File metadata and controls
36 lines (27 loc) · 932 Bytes
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
import 'dart:io';
import 'package:path/path.dart' as p;
void main() {
final directory = Directory('lib');
final folderLineCounts = <String, int>{};
int totalLines = 0;
final files = directory
.listSync(recursive: true)
.whereType<File>()
.where((file) => file.path.endsWith('.dart'));
print('File-wise Dart LOC:\n');
for (var file in files) {
final lines = file.readAsLinesSync().length;
totalLines += lines;
final relativePath = p.relative(file.path, from: 'lib');
final firstFolder = relativePath.contains(p.separator)
? relativePath.split(p.separator).first
: '(root)';
folderLineCounts[firstFolder] = (folderLineCounts[firstFolder] ?? 0) + lines;
print(' $relativePath: $lines');
}
print('\nLine count per folder:');
folderLineCounts.forEach((folder, lines) {
print(' $folder: $lines');
});
print('\nTotal Dart LOC: $totalLines');
}