ReleasePackerFile.fromJson constructor
ReleasePackerFile.fromJson(
- Object json
Implementation
factory ReleasePackerFile.fromJson(Object json) {
if (json is String) {
return ReleasePackerFile(json, json);
} else if (json is Map) {
var platform = json['platform'];
var dartCompileExe = json['dart_compile_exe'] as String?;
var dartCompileKernel = json['dart_compile_kernel'] as String?;
var dartBuilds = ReleasePackerDartBuild.fromJsonMap(json);
var windowsGUI = json['windows_gui'];
var dartBuildCli = ReleasePackerDartBuildCli.firstOf(dartBuilds);
var entry = json.entries
.where(
(e) =>
e.key != 'platform' &&
e.key != 'dart_compile_exe' &&
e.key != 'dart_compile_kernel' &&
e.key != 'windows_gui' &&
!ReleasePackerDartBuild.isJsonKey(e.key),
)
.firstOrNull;
String sourcePath;
String destinyPath;
if (entry != null) {
sourcePath = entry.key;
destinyPath = entry.value;
} else if (dartBuildCli != null) {
// Only `dart_build_cli`: its bundle goes to the release root.
sourcePath = '${dartBuildCli.bundlePath}/';
destinyPath = '';
} else {
throw ArgumentError("No file path in: $json");
}
if (windowsGUI is bool && windowsGUI) {
windowsGUI =
dartCompileExe ?? dartBuildCli?.executablePath ?? sourcePath;
}
return ReleasePackerFile(
sourcePath,
destinyPath,
platform: platform,
dartCompileExe: dartCompileExe,
dartCompileKernel: dartCompileKernel,
dartBuilds: dartBuilds.isNotEmpty ? dartBuilds : null,
windowsGUI: windowsGUI,
);
} else {
throw ArgumentError("Unknown type: $json");
}
}