generate method
Generates Dart code for an input Dart library.
May create additional outputs through the buildStep, but the 'primary'
output is Dart code returned through the Future. If there is nothing to
generate for this library may return null, or a Future that resolves to
null or the empty string.
Implementation
@override
Future<String?> generate(LibraryReader library, BuildStep buildStep) async {
final componentsResults =
Stream. //
fromIterable(generateComponents(library, buildStep))
.asyncExpand((result) => Stream.fromFuture(Future.value(result)));
final directives = <String>{};
final contents = <String>[];
await for (final item in componentsResults) {
directives.addAll(item.directives);
if (item.content != null) contents.add(item.content!);
}
if (directives.isEmpty && contents.isEmpty) return null;
final sorted = directives.toList()..sort((a, b) => a.compareTo(b));
return '${sorted.join('\n')}\n\n${contents.join('\n\n')}';
}