writeDartLibrary method

Future<void> writeDartLibrary(
  1. List<MessagesWithMetadata> assetList,
  2. MessagesWithMetadata messageList
)

Generates the Dart library which extracts the messages from their file format and makes the available to the user in a way specified through the GenerationOptions.

Implementation

Future<void> writeDartLibrary(
  List<MessagesWithMetadata> assetList,
  MessagesWithMetadata messageList,
) async {
  final resourcesInContext =
      assetList.where((resource) => resource.context == messageList.context);

  final localeToResourceInfo =
      Map.fromEntries(resourcesInContext.map((resource) => MapEntry(
            resource.locale,
            (
              path: resource.assetId.changeExtension('.json').path,
              hasch: resource.hash,
            ),
          )));

  printIncludeFilesNotification(messageList.context, localeToResourceInfo);
  final libraryCode = CodeGenerator(
    options,
    messageList,
    localeToResourceInfo,
  ).generate();

  await buildStep.writeAsString(
    inputId.changeExtension('.g.dart'),
    libraryCode,
  );
}