fromMap static method

(BPConfig?, List<BPConfigValidationError>) fromMap(
  1. YamlMap data,
  2. List<String> args,
  3. String version,
  4. String buildVersion, {
  5. String workflowName = "default",
})

Parsed the config from the map

Implementation

static (BPConfig?, List<BPConfigValidationError>) fromMap(
  yaml.YamlMap data,
  List<String> args,
  String version,
  String buildVersion, {
  String workflowName = "default",
}) {
  BPConfigValidationError? replacedKeys = _replacedHookKeys(data, workflowName);
  if (replacedKeys != null) {
    return (null, [replacedKeys]);
  }

  yaml.YamlMap platforms = data["platforms"] ?? yaml.YamlMap();
  (PlatformConfig?, List<BPConfigValidationError>) android = PlatformConfig.fromMap(platforms, TargetPlatform.android, "android");
  (PlatformConfig?, List<BPConfigValidationError>) iOS = PlatformConfig.fromMap(platforms, TargetPlatform.ios, "ios");
  (PlatformConfig?, List<BPConfigValidationError>) macos = PlatformConfig.fromMap(platforms, TargetPlatform.macos, "macos");
  (PlatformConfig?, List<BPConfigValidationError>) linux = PlatformConfig.fromMap(platforms, TargetPlatform.linux, "linux");
  (PlatformConfig?, List<BPConfigValidationError>) windows = PlatformConfig.fromMap(platforms, TargetPlatform.windows, "windows");
  (PlatformConfig?, List<BPConfigValidationError>) web = PlatformConfig.fromMap(platforms, TargetPlatform.web, "web");

  (OutputMode?, List<BPConfigValidationError>) output = _outputFromMap(data);
  if (output.$1 == null) {
    return (null, output.$2);
  }

  // A mistake in a hook stops the whole command, since running the wrong hook, or none, can have
  // unintended consequences, e.g. publishing a failed build
  (({HookCommands build, HookCommands publish})?, List<BPConfigValidationError>) hooks = HookCommands.fromWorkflow(data);
  List<BPConfigValidationError> platformErrors = [...android.$2, ...iOS.$2, ...macos.$2, ...linux.$2, ...windows.$2, ...web.$2];
  List<BPConfigValidationError> hookErrors = [
    ...hooks.$2,
    ...platformErrors.where((BPConfigValidationError e) => e.errorCase == BPConfigValidationErrorCase.invalidHook),
  ];
  if (hookErrors.isNotEmpty) {
    return (null, hookErrors);
  }

  return (
    BPConfig(
      android: android.$1,
      ios: iOS.$1,
      macos: macos.$1,
      linux: linux.$1,
      windows: windows.$1,
      web: web.$1,
      xcodeDerivedKey: data["xcode_derived_data_path_env_key"],
      cleanFlutter: data["clean_flutter"] ?? true,
      generateLog: data["generate_log"] ?? true,
      output: output.$1!,
      buildHooks: hooks.$1!.build,
      publishHooks: hooks.$1!.publish,
      timestamp: DateTime.now(),
      version: version,
      buildVersion: buildVersion,
      cmdArgs: args,
      workflowName: workflowName,
    ),
    [...output.$2, ...platformErrors],
  );
}