didFinishPackageGeneration method

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

Implementation

@override
void didFinishPackageGeneration(BuildContext context) {
  if (context.forTests) {
    final devPackages = [
      {'name': 'fs_test_agent', 'path': 'fs_test_agent'},
      {'name': 'conduit_test', 'path': 'test_harness'},
    ];
    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']!}"};

      copyPathSync(
        context.sourceApplicationDirectory.uri
            .resolve("../")
            .resolve(package['path']!)
            .toFilePath(windows: Platform.isWindows),
        context.buildPackagesDirectory.uri
            .resolve(package['path']!)
            .toFilePath(windows: Platform.isWindows),
      );
    }

    pubspecContents["dependency_overrides"]["conduit_core"] =
        pubspecContents["dependencies"]["conduit_core"];
    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'},
      {'name': 'conduit_runtime', 'path': 'runtime'},
    ];
    _overwritePackageDependency(context, 'conduit_core', conduitPackages);

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

    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);
  }
}