1
1
import { ANDROID_RELEASE_BUILD_ERROR_MESSAGE } from "../constants" ;
2
+ import { ValidatePlatformCommandBase } from "./command-base" ;
2
3
3
- export class BuildCommandBase {
4
- constructor ( protected $options : IOptions ,
4
+ export abstract class BuildCommandBase extends ValidatePlatformCommandBase {
5
+ constructor ( $options : IOptions ,
5
6
protected $errors : IErrors ,
6
- protected $projectData : IProjectData ,
7
- protected $platformsData : IPlatformsData ,
7
+ $projectData : IProjectData ,
8
+ $platformsData : IPlatformsData ,
8
9
protected $devicePlatformsConstants : Mobile . IDevicePlatformsConstants ,
9
- protected $platformService : IPlatformService ,
10
+ $platformService : IPlatformService ,
10
11
private $bundleValidatorHelper : IBundleValidatorHelper ) {
12
+ super ( $options , $platformsData , $platformService , $projectData ) ;
11
13
this . $projectData . initializeProjectData ( ) ;
12
14
}
13
15
@@ -43,16 +45,29 @@ export class BuildCommandBase {
43
45
}
44
46
}
45
47
46
- protected async validatePlatform ( platform : string ) : Promise < void > {
48
+ protected validatePlatform ( platform : string ) : void {
47
49
if ( ! this . $platformService . isPlatformSupportedForOS ( platform , this . $projectData ) ) {
48
50
this . $errors . fail ( `Applications for platform ${ platform } can not be built on this OS` ) ;
49
51
}
50
52
51
53
this . $bundleValidatorHelper . validate ( ) ;
54
+ }
55
+
56
+ protected async validateArgs ( args : string [ ] , platform : string ) : Promise < ICanExecuteCommandOutput > {
57
+ const canExecute = await this . validateArgsCore ( args , platform ) ;
58
+ return {
59
+ canExecute,
60
+ suppressCommandHelp : false
61
+ } ;
62
+ }
52
63
53
- const platformData = this . $platformsData . getPlatformData ( platform , this . $projectData ) ;
54
- const platformProjectService = platformData . platformProjectService ;
55
- await platformProjectService . validate ( this . $projectData ) ;
64
+ private async validateArgsCore ( args : string [ ] , platform : string ) : Promise < boolean > {
65
+ if ( args . length !== 0 ) {
66
+ return false ;
67
+ }
68
+
69
+ const result = await this . $platformService . validateOptions ( this . $options . provision , this . $options . teamId , this . $projectData , platform ) ;
70
+ return result ;
56
71
}
57
72
}
58
73
@@ -73,9 +88,17 @@ export class BuildIosCommand extends BuildCommandBase implements ICommand {
73
88
return this . executeCore ( [ this . $platformsData . availablePlatforms . iOS ] ) ;
74
89
}
75
90
76
- public async canExecute ( args : string [ ] ) : Promise < boolean > {
77
- await super . validatePlatform ( this . $devicePlatformsConstants . iOS ) ;
78
- return args . length === 0 && this . $platformService . validateOptions ( this . $options . provision , this . $options . teamId , this . $projectData , this . $platformsData . availablePlatforms . iOS ) ;
91
+ public async canExecute ( args : string [ ] ) : Promise < boolean | ICanExecuteCommandOutput > {
92
+ const platform = this . $devicePlatformsConstants . iOS ;
93
+
94
+ super . validatePlatform ( platform ) ;
95
+
96
+ let result = await super . canExecuteCommandBase ( platform ) ;
97
+ if ( result . canExecute ) {
98
+ result = await super . validateArgs ( args , platform ) ;
99
+ }
100
+
101
+ return result ;
79
102
}
80
103
}
81
104
@@ -98,13 +121,20 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
98
121
return this . executeCore ( [ this . $platformsData . availablePlatforms . Android ] ) ;
99
122
}
100
123
101
- public async canExecute ( args : string [ ] ) : Promise < boolean > {
102
- await super . validatePlatform ( this . $devicePlatformsConstants . Android ) ;
103
- if ( this . $options . release && ( ! this . $options . keyStorePath || ! this . $options . keyStorePassword || ! this . $options . keyStoreAlias || ! this . $options . keyStoreAliasPassword ) ) {
104
- this . $errors . fail ( ANDROID_RELEASE_BUILD_ERROR_MESSAGE ) ;
124
+ public async canExecute ( args : string [ ] ) : Promise < boolean | ICanExecuteCommandOutput > {
125
+ const platform = this . $devicePlatformsConstants . Android ;
126
+ super . validatePlatform ( platform ) ;
127
+
128
+ let result = await super . canExecuteCommandBase ( platform ) ;
129
+ if ( result . canExecute ) {
130
+ if ( this . $options . release && ( ! this . $options . keyStorePath || ! this . $options . keyStorePassword || ! this . $options . keyStoreAlias || ! this . $options . keyStoreAliasPassword ) ) {
131
+ this . $errors . fail ( ANDROID_RELEASE_BUILD_ERROR_MESSAGE ) ;
132
+ }
133
+
134
+ result = await super . validateArgs ( args , platform ) ;
105
135
}
106
136
107
- return args . length === 0 && await this . $platformService . validateOptions ( this . $options . provision , this . $options . teamId , this . $projectData , this . $platformsData . availablePlatforms . Android ) ;
137
+ return result ;
108
138
}
109
139
}
110
140
0 commit comments