dvReadRuntimeManifest function

DVRuntimePackage? dvReadRuntimeManifest(
  1. String name,
  2. String root
)

The manifest of the package name at root, or null when it has none or it is not one Dartvel can read.

Implementation

DVRuntimePackage? dvReadRuntimeManifest(String name, String root) {
  final File manifest = File(p.join(root, dvRuntimeManifestFile));
  if (!manifest.existsSync()) return null;
  final Object? yaml;
  try {
    yaml = loadYaml(manifest.readAsStringSync());
  } on Object {
    return null;
  }
  if (yaml is! Map || yaml['runtimes'] is! List) return null;
  final Object? client = yaml['client'];
  final Object? server = yaml['server'];
  String? text(Object? section, String key) =>
      section is Map && section[key] is String ? section[key] as String : null;
  final Object? providers = server is Map ? server['auth_providers'] : null;
  return DVRuntimePackage(
    name: name,
    root: root,
    runtimes: <String>[for (final Object? runtime in yaml['runtimes'] as List) '$runtime'],
    clientImport: text(client, 'import'),
    clientInstall: text(client, 'install'),
    terminalSurface: text(client, 'terminal_surface'),
    serverImport: text(server, 'import'),
    authProviders: <String, String>{
      if (providers is Map)
        for (final MapEntry<Object?, Object?> entry in providers.entries)
          if (entry.value is String) '${entry.key}': entry.value as String,
    },
  );
}