11import { ANDROID_RELEASE_BUILD_ERROR_MESSAGE } from "../constants" ;
2+ import { ValidatePlatformCommandBase } from "./command-base" ;
23
3- export class BuildCommandBase {
4- constructor ( protected $options : IOptions ,
4+ export abstract class BuildCommandBase extends ValidatePlatformCommandBase {
5+ constructor ( $options : IOptions ,
56 protected $errors : IErrors ,
6- protected $projectData : IProjectData ,
7- protected $platformsData : IPlatformsData ,
7+ $projectData : IProjectData ,
8+ $platformsData : IPlatformsData ,
89 protected $devicePlatformsConstants : Mobile . IDevicePlatformsConstants ,
9- protected $platformService : IPlatformService ,
10+ $platformService : IPlatformService ,
1011 private $bundleValidatorHelper : IBundleValidatorHelper ) {
12+ super ( $options , $platformsData , $platformService , $projectData ) ;
1113 this . $projectData . initializeProjectData ( ) ;
1214 }
1315
@@ -43,16 +45,29 @@ export class BuildCommandBase {
4345 }
4446 }
4547
46- protected async validatePlatform ( platform : string ) : Promise < void > {
48+ protected validatePlatform ( platform : string ) : void {
4749 if ( ! this . $platformService . isPlatformSupportedForOS ( platform , this . $projectData ) ) {
4850 this . $errors . fail ( `Applications for platform ${ platform } can not be built on this OS` ) ;
4951 }
5052
5153 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+ }
5263
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 ;
5671 }
5772}
5873
@@ -73,9 +88,17 @@ export class BuildIosCommand extends BuildCommandBase implements ICommand {
7388 return this . executeCore ( [ this . $platformsData . availablePlatforms . iOS ] ) ;
7489 }
7590
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 ;
79102 }
80103}
81104
@@ -98,13 +121,20 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
98121 return this . executeCore ( [ this . $platformsData . availablePlatforms . Android ] ) ;
99122 }
100123
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 ) ;
105135 }
106136
107- return args . length === 0 && await this . $platformService . validateOptions ( this . $options . provision , this . $options . teamId , this . $projectData , this . $platformsData . availablePlatforms . Android ) ;
137+ return result ;
108138 }
109139}
110140
0 commit comments