build method

  1. @override
Future<void> build(
  1. BuildStep buildStep
)

Generates the outputs for a given BuildStep.

Implementation

@override
Future<void> build(BuildStep buildStep) async {
  brickLogger.info('Aggregating models and migrations...');

  final imports = <String>{};
  imports.addAll([
    'library big_messy_models_migrations_file;',
  ]);
  imports.addAll(requiredImports);

  final files = <String>[];
  for (final glob in [migrationFiles, modelFiles]) {
    await for (final input in buildStep.findAssets(glob)) {
      final contents = await buildStep.readAsString(input);
      imports.addAll(findAllImports(contents));
      final newContents = contents
          .replaceAll(importRegex, '')
          .replaceAll(RegExp("part of '.*';"), '')
          .replaceAll(RegExp(r"^part\s'.*';", multiLine: true), '')
          .replaceAll(RegExp(r'^export\s.*;', multiLine: true), '');
      files.add(newContents);
    }
  }

  final contents = '${imports.join('\n')}\n${files.join('\n')}';
  await buildStep.writeAsString(
    AssetId(buildStep.inputId.package, 'lib/$outputFileName'),
    contents,
  );
}