Skip to content

Commit 33d79ab

Browse files
nadyaADimitar Kerezov
authored andcommitted
Move OS compatibility check to commands
1 parent 9b83cda commit 33d79ab

File tree

9 files changed

+76
-21
lines changed

9 files changed

+76
-21
lines changed

lib/commands/appstore-list.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,19 @@ export class ListiOSApps implements ICommand {
77
constructor(private $injector: IInjector,
88
private $itmsTransporterService: IITMSTransporterService,
99
private $logger: ILogger,
10-
private $prompter: IPrompter) { }
10+
private $projectData: IProjectData,
11+
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
12+
private $platformService: IPlatformService,
13+
private $errors: IErrors,
14+
private $prompter: IPrompter) {
15+
this.$projectData.initializeProjectData();
16+
}
1117

1218
public async execute(args: string[]): Promise<void> {
19+
if (!this.$platformService.isPlatformSupportedForOS(this.$devicePlatformsConstants.iOS, this.$projectData)) {
20+
this.$errors.fail("Applications for platform %s can not be built on this OS - %s", this.$devicePlatformsConstants.iOS, process.platform);
21+
}
22+
1323
let username = args[0],
1424
password = args[1];
1525

lib/commands/appstore-upload.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export class PublishIOS implements ICommand {
77
new StringCommandParameter(this.$injector), new StringCommandParameter(this.$injector)];
88

99
constructor(private $errors: IErrors,
10-
private $hostInfo: IHostInfo,
1110
private $injector: IInjector,
1211
private $itmsTransporterService: IITMSTransporterService,
1312
private $logger: ILogger,
@@ -100,8 +99,8 @@ export class PublishIOS implements ICommand {
10099
}
101100

102101
public async canExecute(args: string[]): Promise<boolean> {
103-
if (!this.$hostInfo.isDarwin) {
104-
this.$errors.failWithoutHelp("This command is only available on Mac OS X.");
102+
if (!this.$platformService.isPlatformSupportedForOS(this.$devicePlatformsConstants.iOS, this.$projectData)) {
103+
this.$errors.fail("Applications for platform %s can not be built on this OS - %s", this.$devicePlatformsConstants.iOS, process.platform);
105104
}
106105

107106
return true;

lib/commands/build.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export class BuildCommandBase {
22
constructor(protected $options: IOptions,
33
protected $projectData: IProjectData,
44
protected $platformsData: IPlatformsData,
5+
protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
56
protected $platformService: IPlatformService) {
67
this.$projectData.initializeProjectData();
78
}
@@ -35,17 +36,23 @@ export class BuildIosCommand extends BuildCommandBase implements ICommand {
3536
public allowedParameters: ICommandParameter[] = [];
3637

3738
constructor(protected $options: IOptions,
39+
private $errors: IErrors,
3840
$projectData: IProjectData,
3941
$platformsData: IPlatformsData,
42+
$devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
4043
$platformService: IPlatformService) {
41-
super($options, $projectData, $platformsData, $platformService);
44+
super($options, $projectData, $platformsData, $devicePlatformsConstants, $platformService);
4245
}
4346

4447
public async execute(args: string[]): Promise<void> {
4548
return this.executeCore([this.$platformsData.availablePlatforms.iOS]);
4649
}
4750

4851
public canExecute(args: string[]): Promise<boolean> {
52+
if (!this.$platformService.isPlatformSupportedForOS(this.$devicePlatformsConstants.iOS, this.$projectData)) {
53+
this.$errors.fail("Applications for platform %s can not be built on this OS - %s", this.$devicePlatformsConstants.iOS, process.platform);
54+
}
55+
4956
return args.length === 0 && this.$platformService.validateOptions(this.$options.provision, this.$projectData, this.$platformsData.availablePlatforms.iOS);
5057
}
5158
}
@@ -56,18 +63,23 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
5663
public allowedParameters: ICommandParameter[] = [];
5764

5865
constructor(protected $options: IOptions,
66+
private $errors: IErrors,
5967
$projectData: IProjectData,
6068
$platformsData: IPlatformsData,
61-
private $errors: IErrors,
69+
$devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
6270
$platformService: IPlatformService) {
63-
super($options, $projectData, $platformsData, $platformService);
71+
super($options, $projectData, $platformsData, $devicePlatformsConstants, $platformService);
6472
}
6573

6674
public async execute(args: string[]): Promise<void> {
6775
return this.executeCore([this.$platformsData.availablePlatforms.Android]);
6876
}
6977

7078
public async canExecute(args: string[]): Promise<boolean> {
79+
if (!this.$platformService.isPlatformSupportedForOS(this.$devicePlatformsConstants.Android, this.$projectData)) {
80+
this.$errors.fail("Applications for platform %s can not be built on this OS - %s", this.$devicePlatformsConstants.Android, process.platform);
81+
}
82+
7183
if (this.$options.release && (!this.$options.keyStorePath || !this.$options.keyStorePassword || !this.$options.keyStoreAlias || !this.$options.keyStoreAliasPassword)) {
7284
this.$errors.fail("When producing a release build, you need to specify all --key-store-* options.");
7385
}

lib/commands/clean-app.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export class CleanAppCommandBase {
22
constructor(protected $options: IOptions,
33
protected $projectData: IProjectData,
4-
private $platformService: IPlatformService) {
4+
protected $platformService: IPlatformService) {
55
this.$projectData.initializeProjectData();
66
}
77

@@ -14,7 +14,9 @@ export class CleanAppCommandBase {
1414

1515
export class CleanAppIosCommand extends CleanAppCommandBase implements ICommand {
1616
constructor(protected $options: IOptions,
17+
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
1718
private $platformsData: IPlatformsData,
19+
private $errors: IErrors,
1820
$platformService: IPlatformService,
1921
$projectData: IProjectData) {
2022
super($options, $projectData, $platformService);
@@ -23,6 +25,9 @@ export class CleanAppIosCommand extends CleanAppCommandBase implements ICommand
2325
public allowedParameters: ICommandParameter[] = [];
2426

2527
public async execute(args: string[]): Promise<void> {
28+
if (!this.$platformService.isPlatformSupportedForOS(this.$devicePlatformsConstants.iOS, this.$projectData)) {
29+
this.$errors.fail("Applications for platform %s can not be built on this OS - %s", this.$devicePlatformsConstants.iOS, process.platform);
30+
}
2631
return super.execute([this.$platformsData.availablePlatforms.iOS]);
2732
}
2833
}
@@ -33,13 +38,18 @@ export class CleanAppAndroidCommand extends CleanAppCommandBase implements IComm
3338
public allowedParameters: ICommandParameter[] = [];
3439

3540
constructor(protected $options: IOptions,
41+
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
3642
private $platformsData: IPlatformsData,
43+
private $errors: IErrors,
3744
$platformService: IPlatformService,
3845
$projectData: IProjectData) {
3946
super($options, $projectData, $platformService);
4047
}
4148

4249
public async execute(args: string[]): Promise<void> {
50+
if (!this.$platformService.isPlatformSupportedForOS(this.$devicePlatformsConstants.iOS, this.$projectData)) {
51+
this.$errors.fail("Applications for platform %s can not be built on this OS - %s", this.$devicePlatformsConstants.iOS, process.platform);
52+
}
4353
return super.execute([this.$platformsData.availablePlatforms.Android]);
4454
}
4555
}

lib/commands/debug.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,12 @@ export abstract class DebugPlatformCommand implements ICommand {
8484
}
8585

8686
export class DebugIOSCommand extends DebugPlatformCommand {
87-
constructor(protected $logger: ILogger,
87+
constructor(private $errors: IErrors,
88+
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
89+
$logger: ILogger,
8890
$iOSDebugService: IPlatformDebugService,
8991
$devicesService: Mobile.IDevicesService,
9092
$injector: IInjector,
91-
$devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
9293
$config: IConfiguration,
9394
$usbLiveSyncService: ILiveSyncService,
9495
$debugDataService: IDebugDataService,
@@ -106,6 +107,10 @@ export class DebugIOSCommand extends DebugPlatformCommand {
106107
}
107108

108109
public async canExecute(args: string[]): Promise<boolean> {
110+
if (!this.$platformService.isPlatformSupportedForOS(this.$devicePlatformsConstants.iOS, this.$projectData)) {
111+
this.$errors.fail("Applications for platform %s can not be built on this OS - %s", this.$devicePlatformsConstants.iOS, process.platform);
112+
}
113+
109114
return await super.canExecute(args) && await this.$platformService.validateOptions(this.$options.provision, this.$projectData, this.$platformsData.availablePlatforms.iOS);
110115
}
111116

@@ -119,11 +124,12 @@ export class DebugIOSCommand extends DebugPlatformCommand {
119124
$injector.registerCommand("debug|ios", DebugIOSCommand);
120125

121126
export class DebugAndroidCommand extends DebugPlatformCommand {
122-
constructor($logger: ILogger,
127+
constructor(private $errors: IErrors,
128+
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
129+
$logger: ILogger,
123130
$androidDebugService: IPlatformDebugService,
124131
$devicesService: Mobile.IDevicesService,
125132
$injector: IInjector,
126-
$devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
127133
$config: IConfiguration,
128134
$usbLiveSyncService: ILiveSyncService,
129135
$debugDataService: IDebugDataService,
@@ -135,6 +141,10 @@ export class DebugAndroidCommand extends DebugPlatformCommand {
135141
}
136142

137143
public async canExecute(args: string[]): Promise<boolean> {
144+
if (!this.$platformService.isPlatformSupportedForOS(this.$devicePlatformsConstants.Android, this.$projectData)) {
145+
this.$errors.fail("Applications for platform %s can not be built on this OS - %s", this.$devicePlatformsConstants.Android, process.platform);
146+
}
147+
138148
return await super.canExecute(args) && await this.$platformService.validateOptions(this.$options.provision, this.$projectData, this.$platformsData.availablePlatforms.Android);
139149
}
140150
}

lib/commands/run.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ export class RunIosCommand extends RunCommandBase implements ICommand {
5151

5252
constructor($platformService: IPlatformService,
5353
private $platformsData: IPlatformsData,
54+
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
55+
private $errors: IErrors,
5456
$usbLiveSyncService: ILiveSyncService,
5557
$projectData: IProjectData,
5658
$options: IOptions,
@@ -59,6 +61,10 @@ export class RunIosCommand extends RunCommandBase implements ICommand {
5961
}
6062

6163
public async execute(args: string[]): Promise<void> {
64+
if (!this.$platformService.isPlatformSupportedForOS(this.$devicePlatformsConstants.iOS, this.$projectData)) {
65+
this.$errors.fail("Applications for platform %s can not be built on this OS - %s", this.$devicePlatformsConstants.iOS, process.platform);
66+
}
67+
6268
return this.executeCore([this.$platformsData.availablePlatforms.iOS]);
6369
}
6470

@@ -74,11 +80,12 @@ export class RunAndroidCommand extends RunCommandBase implements ICommand {
7480

7581
constructor($platformService: IPlatformService,
7682
private $platformsData: IPlatformsData,
83+
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
84+
private $errors: IErrors,
7785
$usbLiveSyncService: ILiveSyncService,
7886
$projectData: IProjectData,
7987
$options: IOptions,
80-
$emulatorPlatformService: IEmulatorPlatformService,
81-
private $errors: IErrors) {
88+
$emulatorPlatformService: IEmulatorPlatformService) {
8289
super($platformService, $usbLiveSyncService, $projectData, $options, $emulatorPlatformService);
8390
}
8491

@@ -87,6 +94,10 @@ export class RunAndroidCommand extends RunCommandBase implements ICommand {
8794
}
8895

8996
public async canExecute(args: string[]): Promise<boolean> {
97+
if (!this.$platformService.isPlatformSupportedForOS(this.$devicePlatformsConstants.Android, this.$projectData)) {
98+
this.$errors.fail("Applications for platform %s can not be built on this OS - %s", this.$devicePlatformsConstants.Android, process.platform);
99+
}
100+
90101
if (this.$options.release && (!this.$options.keyStorePath || !this.$options.keyStorePassword || !this.$options.keyStoreAlias || !this.$options.keyStoreAliasPassword)) {
91102
this.$errors.fail("When producing a release build, you need to specify all --key-store-* options.");
92103
}

lib/definitions/platform.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,14 @@ interface IPlatformService extends NodeJS.EventEmitter {
125125

126126
/**
127127
* Ensures the passed platform is a valid one (from the supported ones)
128-
* and that it can be built on the current OS
129128
*/
130129
validatePlatform(platform: string, projectData: IProjectData): void;
131130

131+
/**
132+
* Ensures that passed platform can be built on the current OS
133+
*/
134+
isPlatformSupportedForOS(platform: string, projectData: IProjectData): boolean;
135+
132136
/**
133137
* Returns information about the latest built application for device in the current project.
134138
* @param {IPlatformData} platformData Data describing the current platform.

lib/services/platform-service.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -679,11 +679,6 @@ export class PlatformService extends EventEmitter implements IPlatformService {
679679
if (!this.isValidPlatform(platform, projectData)) {
680680
this.$errors.fail("Invalid platform %s. Valid platforms are %s.", platform, helpers.formatListOfNames(this.$platformsData.platformsNames));
681681
}
682-
683-
//TODO: move to commands.
684-
// if (!this.isPlatformSupportedForOS(platform, projectData)) {
685-
// this.$errors.fail("Applications for platform %s can not be built on this OS - %s", platform, process.platform);
686-
// }
687682
}
688683

689684
public validatePlatformInstalled(platform: string, projectData: IProjectData): void {
@@ -708,7 +703,7 @@ export class PlatformService extends EventEmitter implements IPlatformService {
708703
return this.$platformsData.getPlatformData(platform, projectData);
709704
}
710705

711-
private isPlatformSupportedForOS(platform: string, projectData: IProjectData): boolean {
706+
public isPlatformSupportedForOS(platform: string, projectData: IProjectData): boolean {
712707
let targetedOS = this.$platformsData.getPlatformData(platform, projectData).targetedOS;
713708
let res = !targetedOS || targetedOS.indexOf("*") >= 0 || targetedOS.indexOf(process.platform) >= 0;
714709
return res;

test/stubs.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,10 @@ export class PlatformServiceStub extends EventEmitter implements IPlatformServic
665665

666666
}
667667

668+
isPlatformSupportedForOS(platform: string, projectData: IProjectData): boolean {
669+
return true;
670+
}
671+
668672
public getLatestApplicationPackageForDevice(platformData: IPlatformData): IApplicationPackage {
669673
return null;
670674
}

0 commit comments

Comments
 (0)