DVCloudBuildSpec.fromJson constructor

DVCloudBuildSpec.fromJson(
  1. Map<String, Object?> json
)

Implementation

factory DVCloudBuildSpec.fromJson(Map<String, Object?> json) {
  final String project = _string(json, 'project');
  if (!dvCloudIsProjectName(project)) {
    throw FormatException('"$project" is not a project name.');
  }
  final String target = _string(json, 'target');
  if (!dvCloudTargets.containsKey(target)) {
    throw FormatException('"$target" does not build in the cloud. '
        'Targets: ${dvCloudTargets.keys.join(', ')}.');
  }
  final String profile = json['profile'] == null ? 'release' : _string(json, 'profile');
  if (!dvCloudProfiles.contains(profile)) {
    throw FormatException('"$profile" is not a build profile.');
  }
  final Object? publish = json['publish'];
  if (publish != null && !dvCloudStores.contains(publish)) {
    throw FormatException('"$publish" is not a store Dartvel deploys to.');
  }
  final String app = json['app'] == null ? '.' : _string(json, 'app');
  if (app != '.' && !DVCloudArtifact.isSafeName(app)) {
    throw FormatException('"$app" is not a directory inside the source.');
  }
  final Object? format = json['format'];
  if (format != null &&
      !(format == 'aab' && target == 'android') &&
      !(format == 'ipa' && target == 'ios')) {
    throw FormatException('"$format" is not a package $target builds as: '
        'aab is for android and ipa for ios.');
  }
  final bool simulator = json['simulator'] == true;
  if (simulator != dvCloudSimulatorOnlyTargets.contains(target)) {
    throw FormatException(simulator
        ? '$target does not build for a simulator in the cloud.'
        : '$target builds in the cloud for the simulator only: a device build is '
            'signed with a team Dartvel Cloud does not keep. Pass --simulator.');
  }
  final Object? os = json['os'];
  DVCloudWorkerOs? workerOs;
  if (os != null) {
    workerOs = DVCloudWorkerOs.values.where((DVCloudWorkerOs o) => o.name == os).firstOrNull;
    if (workerOs == null) {
      throw FormatException('"$os" is not a worker OS: linux, macos or windows.');
    }
    if (workerOs != dvCloudTargets[target] && !dvCloudHostTargets.contains(target)) {
      throw FormatException('$target builds on a ${dvCloudTargets[target]!.name} worker, not $os.');
    }
  }
  return DVCloudBuildSpec(
    format: format as String?,
    os: workerOs,
    codesign: json['codesign'] != false,
    simulator: simulator,
    app: app,
    project: project,
    target: target,
    profile: profile,
    publish: publish as String?,
    dryRun: json['dryRun'] == true,
  );
}