buildPluginYaml method

Future<Map<String, dynamic>> buildPluginYaml(
  1. Locations locations
)

Implementation

Future<Map<String, dynamic>> buildPluginYaml(Locations locations) async {
  Map<String, dynamic> result = {};

  // First read the provided file. It has the lowest priority.
  final pluginYamlFile = locations.pluginYaml;
  if (pluginYamlFile != null && await pluginYamlFile.exists()) {
    final data = loadYaml(await pluginYamlFile.readAsString());
    if (data is YamlMap) {
      result = data.toMap();
    }
  }

  final pubspecFile = locations.pubspecYaml;
  if (pubspecFile != null && await pubspecFile.exists()) {
    final data = loadYaml(await pubspecFile.readAsString());
    if (data is YamlMap) {
      final pubspec = data.toMap();

      // Overwrite metadata values with every_door section.
      final edPart = pubspec['every_door'];
      if (edPart != null && edPart is Map) {
        for (final entry in edPart.entries) {
          result[entry.key] = entry.value;
        }
      }

      // And now copy the main fields, which have the highest priority.
      result['id'] = pubspec['name'];
      if (pubspec.containsKey('description')) {
        result['name'] = pubspec['description'];
      }
      final versionMatch = RegExp(
        r'^\d+\.\d+',
      ).matchAsPrefix(pubspec['version']);
      if (versionMatch != null) {
        result['version'] = versionMatch.group(0)!;
      }
      if (pubspec.containsKey('homepage')) {
        result['homepage'] = pubspec['homepage'];
      }
    }
  }

  return result;
}