@@ -2,26 +2,35 @@ import { CONNECTED_STATUS } from "../common/constants";
22import { isInteractive } from "../common/helpers" ;
33import { cache } from "../common/decorators" ;
44import { DebugCommandErrors } from "../constants" ;
5+ import { CommandBase } from "./command-base" ;
56
6- export class DebugPlatformCommand implements ICommand {
7+ export class DebugPlatformCommand extends CommandBase implements ICommand {
78 public allowedParameters : ICommandParameter [ ] = [ ] ;
89
910 constructor ( private platform : string ,
1011 private $debugService : IDebugService ,
1112 protected $devicesService : Mobile . IDevicesService ,
12- protected $platformService : IPlatformService ,
13- protected $projectData : IProjectData ,
14- protected $options : IOptions ,
15- protected $platformsData : IPlatformsData ,
13+ $platformService : IPlatformService ,
14+ $projectData : IProjectData ,
15+ $options : IOptions ,
16+ $platformsData : IPlatformsData ,
1617 protected $logger : ILogger ,
1718 protected $errors : IErrors ,
1819 private $debugDataService : IDebugDataService ,
1920 private $liveSyncService : IDebugLiveSyncService ,
2021 private $prompter : IPrompter ,
2122 private $liveSyncCommandHelper : ILiveSyncCommandHelper ) {
23+ super ( $options , $platformsData , $platformService , $projectData ) ;
2224 }
2325
2426 public async execute ( args : string [ ] ) : Promise < void > {
27+ await this . $devicesService . initialize ( {
28+ platform : this . platform ,
29+ deviceId : this . $options . device ,
30+ emulator : this . $options . emulator ,
31+ skipDeviceDetectionInterval : true
32+ } ) ;
33+
2534 const debugOptions = < IDebugOptions > _ . cloneDeep ( this . $options . argv ) ;
2635
2736 const debugData = this . $debugDataService . createDebugData ( this . $projectData , this . $options ) ;
@@ -99,7 +108,7 @@ export class DebugPlatformCommand implements ICommand {
99108 this . $errors . failWithoutHelp ( DebugCommandErrors . NO_DEVICES_EMULATORS_FOUND_FOR_OPTIONS ) ;
100109 }
101110
102- public async canExecute ( args : string [ ] ) : Promise < boolean > {
111+ public async canExecute ( args : string [ ] ) : Promise < ICanExecuteCommandOutput > {
103112 if ( ! this . $platformService . isPlatformSupportedForOS ( this . platform , this . $projectData ) ) {
104113 this . $errors . fail ( `Applications for platform ${ this . platform } can not be built on this OS` ) ;
105114 }
@@ -108,18 +117,8 @@ export class DebugPlatformCommand implements ICommand {
108117 this . $errors . fail ( "--release flag is not applicable to this command" ) ;
109118 }
110119
111- const platformData = this . $platformsData . getPlatformData ( this . platform , this . $projectData ) ;
112- const platformProjectService = platformData . platformProjectService ;
113- await platformProjectService . validate ( this . $projectData ) ;
114-
115- await this . $devicesService . initialize ( {
116- platform : this . platform ,
117- deviceId : this . $options . device ,
118- emulator : this . $options . emulator ,
119- skipDeviceDetectionInterval : true
120- } ) ;
121-
122- return true ;
120+ const result = await super . canExecuteCommandBase ( this . platform , { validateOptions : true , notConfiguredEnvOptions : { hideCloudBuildOption : true } } ) ;
121+ return result ;
123122 }
124123}
125124
@@ -138,7 +137,6 @@ export class DebugIOSCommand implements ICommand {
138137 private $options : IOptions ,
139138 private $injector : IInjector ,
140139 private $projectData : IProjectData ,
141- private $platformsData : IPlatformsData ,
142140 $iosDeviceOperations : IIOSDeviceOperations ,
143141 $iOSSimulatorLogProvider : Mobile . IiOSSimulatorLogProvider ) {
144142 this . $projectData . initializeProjectData ( ) ;
@@ -154,7 +152,7 @@ export class DebugIOSCommand implements ICommand {
154152 return this . debugPlatformCommand . execute ( args ) ;
155153 }
156154
157- public async canExecute ( args : string [ ] ) : Promise < boolean > {
155+ public async canExecute ( args : string [ ] ) : Promise < ICanExecuteCommandOutput > {
158156 if ( ! this . $platformService . isPlatformSupportedForOS ( this . $devicePlatformsConstants . iOS , this . $projectData ) ) {
159157 this . $errors . fail ( `Applications for platform ${ this . $devicePlatformsConstants . iOS } can not be built on this OS` ) ;
160158 }
@@ -164,7 +162,8 @@ export class DebugIOSCommand implements ICommand {
164162 this . $errors . fail ( `Timeout option specifies the seconds NativeScript CLI will wait to find the inspector socket port from device's logs. Must be a number.` ) ;
165163 }
166164
167- return await this . debugPlatformCommand . canExecute ( args ) && await this . $platformService . validateOptions ( this . $options . provision , this . $options . teamId , this . $projectData , this . $platformsData . availablePlatforms . iOS ) ;
165+ const result = await this . debugPlatformCommand . canExecute ( args ) ;
166+ return result ;
168167 }
169168
170169 private isValidTimeoutOption ( ) {
@@ -200,19 +199,17 @@ export class DebugAndroidCommand implements ICommand {
200199
201200 constructor ( protected $errors : IErrors ,
202201 private $devicePlatformsConstants : Mobile . IDevicePlatformsConstants ,
203- private $platformService : IPlatformService ,
204- private $options : IOptions ,
205202 private $injector : IInjector ,
206- private $projectData : IProjectData ,
207- private $platformsData : IPlatformsData ) {
208- this . $projectData . initializeProjectData ( ) ;
203+ private $projectData : IProjectData ) {
204+ this . $projectData . initializeProjectData ( ) ;
209205 }
210206
211207 public execute ( args : string [ ] ) : Promise < void > {
212208 return this . debugPlatformCommand . execute ( args ) ;
213209 }
214- public async canExecute ( args : string [ ] ) : Promise < boolean > {
215- return await this . debugPlatformCommand . canExecute ( args ) && await this . $platformService . validateOptions ( this . $options . provision , this . $options . teamId , this . $projectData , this . $platformsData . availablePlatforms . Android ) ;
210+ public async canExecute ( args : string [ ] ) : Promise < ICanExecuteCommandOutput > {
211+ const result = await this . debugPlatformCommand . canExecute ( args ) ;
212+ return result ;
216213 }
217214
218215 public platform = this . $devicePlatformsConstants . Android ;
0 commit comments