scan method
Scans the assets/ directory in projectPath and returns a list of DiscoveredAssets.
Returns an empty list if assets/ is missing or empty.
Implementation
List<DiscoveredAsset> scan(String projectPath) {
final assetsDir = Directory(p.join(projectPath, 'assets'));
if (!assetsDir.existsSync()) {
return const [];
}
final entities = assetsDir.listSync(recursive: true);
final results = <DiscoveredAsset>[];
for (final entity in entities) {
if (entity is File) {
final relPath = p.relative(entity.path, from: projectPath);
final pathParts = p.split(relPath);
// Path is like ['assets', 'images', 'logo.png'] or ['assets', 'logo.png']
final String category;
if (pathParts.length >= 3) {
category = pathParts[1];
} else {
category = 'assets';
}
final fileName = p.basename(entity.path);
results.add(DiscoveredAsset(
relativePath: relPath,
category: category,
fileName: fileName,
));
}
}
results.sort((a, b) => a.relativePath.compareTo(b.relativePath));
return List.unmodifiable(results);
}