collect method
Run the string collection process.
Implementation
Future<void> collect() async {
final files = Directory(config.inputRoot)
.listSync(recursive: true)
.whereType<File>()
.where((file) {
final path = file.path;
return path.endsWith('.dart') && !config.excludePaths.any(path.contains);
});
final stringRegexp = RegExp(config.patternsStringRegex);
final excludeLineRegexesFormatted = config.patternsExcludeLine.join('|');
final result = <String, List<Map<String, String>>>{};
for (final file in files) {
stdout.writeln('Processing file: ${file.path}');
final lines = file.readAsLinesSync();
for (var i = 0; i < lines.length; i++) {
final line = lines[i];
if (line.contains(RegExp(excludeLineRegexesFormatted))) continue;
for (final match in stringRegexp.allMatches(line)) {
final relativePath = p.relative(file.path, from: config.inputRoot);
result.putIfAbsent(relativePath, () => []).add({
'line': '$relativePath:${i + 1}',
'src': match.group(0)!,
});
}
}
}
stdout.writeln('Collected ${result.length} files with strings.');
_writeResult(result);
stdout.writeln('Results written to ${config.outputRoot}');
}