didFinishPackageGeneration method Null safety

  1. @override
void didFinishPackageGeneration(
  1. BuildContext context
)
override

Implementation

@override
void didFinishPackageGeneration(BuildContext context) {
  if (context.forTests) {
    final devPackages = [
      {'name': 'conduit_test', 'path': 'test_harness'},
      {'name': 'conduit_common_test', 'path': 'common_test'},
      {'name': 'fs_test_agent', 'path': 'fs_test_agent'},
    ];
    final targetPubspecFile =
        File.fromUri(context.buildDirectoryUri.resolve("pubspec.yaml"));
    final pubspecContents = json.decode(targetPubspecFile.readAsStringSync());
    for (final package in devPackages) {
      pubspecContents["dev_dependencies"]
          [package['name']!] = {"path": "packages/${package['path']!}"};

      copyDirectory(
          src: context.sourceApplicationDirectory.uri
              .resolve("../")
              .resolve(package['path']!),
          dst: context.buildPackagesDirectory.uri.resolve(package['path']!));
    }

    pubspecContents["dependency_overrides"]["conduit"] =
        pubspecContents["dependencies"]["conduit"];
    targetPubspecFile.writeAsStringSync(json.encode(pubspecContents));

    final conduitPackages = [
      {'name': 'conduit_codable', 'path': 'codable'},
      {'name': 'conduit_common', 'path': 'common'},
      {'name': 'conduit_config', 'path': 'config'},
      {'name': 'conduit_isolate_exec', 'path': 'isolate_exec'},
      {'name': 'conduit_open_api', 'path': 'open_api'},
      {'name': 'conduit_password_hash', 'path': 'password_hash'},
    ];
    _overwritePackageDependency(context, 'conduit', conduitPackages);

    final runtimePackages = [
      {'name': 'conduit_isolate_exec', 'path': 'isolate_exec'},
    ];
    _overwritePackageDependency(context, 'conduit_runtime', runtimePackages);

    final commonTestPackages = [
      {'name': 'conduit_common', 'path': 'common'},
    ];
    _overwritePackageDependency(context, 'common_test', commonTestPackages);

    final commonPackages = [
      {'name': 'conduit_open_api', 'path': 'open_api'},
    ];
    _overwritePackageDependency(context, 'common', commonPackages);

    final oapiPackages = [
      {'name': 'conduit_codable', 'path': 'codable'},
    ];
    _overwritePackageDependency(context, 'open_api', oapiPackages);
  }
}