build method
Generates the outputs for a given BuildStep
.
Implementation
@override
Future<void> build(BuildStep buildStep) async {
final annotatedElements = await getAnnotatedElements(buildStep);
final filesToContents = <String, String>{};
await for (final asset in buildStep.findAssets(modelFiles)) {
filesToContents[asset.path] = await buildStep.readAsString(asset);
}
final contents = await buildStep.readAsString(buildStep.inputId);
final stopwatch = Stopwatch();
stopwatch.start();
final allImports = AggregateBuilder.findAllImports(contents);
final classNamesByFileNames = classFilePathsFromAnnotations(annotatedElements, filesToContents);
final modelDictionaryOutput = modelDictionaryGenerator.generate(classNamesByFileNames);
allImports.removeAll(["import 'dart:convert';", 'import "dart:convert";']);
allImports.removeAll(expectedImportRemovals);
final analyzedImports = allImports
.map((i) => '// ignore: unused_import, unused_shown_name, unnecessary_import\n$i')
.join('\n');
final output = analyzedImports + modelDictionaryOutput;
await manuallyUpsertBrickFile('brick.g.dart', output);
await buildStep.writeAsString(buildStep.inputId.changeExtension(outputExtension), output);
logStopwatch('Generated brick.g.dart', stopwatch);
}