-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathplatform-validation-service.ts
87 lines (72 loc) · 3.09 KB
/
platform-validation-service.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
import * as helpers from "../../common/helpers";
import * as path from "path";
export class PlatformValidationService implements IPlatformValidationService {
constructor(
private $errors: IErrors,
private $fs: IFileSystem,
private $logger: ILogger,
private $mobileHelper: Mobile.IMobileHelper,
private $platformsDataService: IPlatformsDataService
) { }
public isValidPlatform(platform: string, projectData: IProjectData): boolean {
if (!platform) {
return false;
}
platform = platform.split("@")[0].toLowerCase();
if (!this.$platformsDataService.getPlatformData(platform, projectData)) {
return false;
}
return true;
}
public validatePlatform(platform: string, projectData: IProjectData): void {
if (!platform) {
this.$errors.fail("No platform specified.");
}
if (!this.isValidPlatform(platform, projectData)) {
const platformNames = helpers.formatListOfNames(this.$mobileHelper.platformNames);
this.$errors.fail(`Invalid platform ${platform}. Valid platforms are ${platformNames}.`);
}
}
public validatePlatformInstalled(platform: string, projectData: IProjectData): void {
this.validatePlatform(platform, projectData);
const hasPlatformDirectory = this.$fs.exists(path.join(projectData.platformsDir, platform.toLowerCase()));
if (!hasPlatformDirectory) {
this.$errors.fail("The platform %s is not added to this project. Please use 'tns platform add <platform>'", platform);
}
}
public async validateOptions(provision: true | string, teamId: true | string, projectData: IProjectData, platform?: string, aab?: boolean): Promise<boolean> {
if (platform && !this.$mobileHelper.isAndroidPlatform(platform) && aab) {
this.$errors.failWithoutHelp("The --aab option is supported only for the Android platform.");
}
if (platform) {
platform = this.$mobileHelper.normalizePlatformName(platform);
this.$logger.trace("Validate options for platform: " + platform);
const platformData = this.$platformsDataService.getPlatformData(platform, projectData);
const result = await platformData.platformProjectService.validateOptions(
projectData.projectIdentifiers[platform.toLowerCase()],
provision,
teamId
);
return result;
} else {
let valid = true;
const platforms = this.$mobileHelper.platformNames.map(p => p.toLowerCase());
for (const availablePlatform of platforms) {
this.$logger.trace("Validate options for platform: " + availablePlatform);
const platformData = this.$platformsDataService.getPlatformData(availablePlatform, projectData);
valid = valid && await platformData.platformProjectService.validateOptions(
projectData.projectIdentifiers[availablePlatform.toLowerCase()],
provision,
teamId
);
}
return valid;
}
}
public isPlatformSupportedForOS(platform: string, projectData: IProjectData): boolean {
const targetedOS = this.$platformsDataService.getPlatformData(platform, projectData).targetedOS;
const res = !targetedOS || targetedOS.indexOf("*") >= 0 || targetedOS.indexOf(process.platform) >= 0;
return res;
}
}
$injector.register("platformValidationService", PlatformValidationService);