-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathandroid-bundle-validator-helper.ts
91 lines (84 loc) · 2.67 KB
/
android-bundle-validator-helper.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import * as util from "util";
import { AndroidBundleValidatorMessages, PlatformTypes } from "../constants";
import { VersionValidatorHelper } from "./version-validator-helper";
import * as semver from "semver";
import { IProjectDataService, IProjectData } from "../definitions/project";
import { IOptions, IAndroidBundleValidatorHelper } from "../declarations";
import { IBuildData, IAndroidBuildData } from "../definitions/build";
import { IErrors } from "../common/declarations";
import { injector } from "../common/yok";
export class AndroidBundleValidatorHelper
extends VersionValidatorHelper
implements IAndroidBundleValidatorHelper {
public static MIN_RUNTIME_VERSION = "5.0.0";
public static MIN_ANDROID_WITH_AAB_SUPPORT = "4.4.0";
constructor(
protected $projectData: IProjectData,
protected $errors: IErrors,
protected $options: IOptions,
protected $projectDataService: IProjectDataService,
private $mobileHelper: Mobile.IMobileHelper
) {
super();
}
public validateNoAab(): void {
if (this.$options.aab) {
this.$errors.failWithHelp(
AndroidBundleValidatorMessages.AAB_NOT_SUPPORTED_BY_COMMNAND_MESSAGE
);
}
}
public validateRuntimeVersion(projectData: IProjectData): void {
if (this.$options.aab) {
const runtimePackage = this.$projectDataService.getRuntimePackage(
projectData.projectDir,
PlatformTypes.android
);
const androidRuntimeVersion = runtimePackage
? runtimePackage.version
: "";
const shouldThrowError =
androidRuntimeVersion &&
this.isValidVersion(androidRuntimeVersion) &&
this.isVersionLowerThan(
androidRuntimeVersion,
AndroidBundleValidatorHelper.MIN_RUNTIME_VERSION
);
if (shouldThrowError) {
this.$errors.fail(
util.format(
AndroidBundleValidatorMessages.NOT_SUPPORTED_RUNTIME_VERSION,
AndroidBundleValidatorHelper.MIN_RUNTIME_VERSION
)
);
}
}
}
public validateDeviceApiLevel(
device: Mobile.IDevice,
buildData: IBuildData
): void {
if (this.$mobileHelper.isAndroidPlatform(device.deviceInfo.platform)) {
const androidBuildData = <IAndroidBuildData>buildData;
if (androidBuildData.androidBundle) {
if (
!!device.deviceInfo.version &&
semver.lt(
semver.coerce(device.deviceInfo.version),
AndroidBundleValidatorHelper.MIN_ANDROID_WITH_AAB_SUPPORT
)
) {
this.$errors.fail(
util.format(
AndroidBundleValidatorMessages.NOT_SUPPORTED_ANDROID_VERSION,
device.deviceInfo.identifier,
device.deviceInfo.version,
AndroidBundleValidatorHelper.MIN_ANDROID_WITH_AAB_SUPPORT
)
);
}
}
}
}
}
injector.register("androidBundleValidatorHelper", AndroidBundleValidatorHelper);