11import { EOL } from "os" ;
2+ import { LiveSyncService } from "../services/livesync/livesync-service" ;
3+ export class DebugLiveSyncService extends LiveSyncService {
24
5+ constructor ( protected $platformService : IPlatformService ,
6+ $projectDataService : IProjectDataService ,
7+ protected $devicesService : Mobile . IDevicesService ,
8+ $mobileHelper : Mobile . IMobileHelper ,
9+ $nodeModulesDependenciesBuilder : INodeModulesDependenciesBuilder ,
10+ protected $logger : ILogger ,
11+ $processService : IProcessService ,
12+ $hooksService : IHooksService ,
13+ $projectChangesService : IProjectChangesService ,
14+ protected $injector : IInjector ,
15+ private $options : IOptions ,
16+ private $debugDataService : IDebugDataService ,
17+ private $projectData : IProjectData ,
18+ private debugService : IPlatformDebugService ,
19+ private $config : IConfiguration ) {
20+
21+ super ( $platformService ,
22+ $projectDataService ,
23+ $devicesService ,
24+ $mobileHelper ,
25+ $nodeModulesDependenciesBuilder ,
26+ $logger ,
27+ $processService ,
28+ $hooksService ,
29+ $projectChangesService ,
30+ $injector ) ;
31+ }
32+
33+ protected async refreshApplication ( projectData : IProjectData , liveSyncResultInfo : ILiveSyncResultInfo ) : Promise < void > {
34+ const debugOptions = this . $options ;
35+ const deployOptions : IDeployPlatformOptions = {
36+ clean : this . $options . clean ,
37+ device : this . $options . device ,
38+ emulator : this . $options . emulator ,
39+ platformTemplate : this . $options . platformTemplate ,
40+ projectDir : this . $options . path ,
41+ release : this . $options . release ,
42+ provision : this . $options . provision ,
43+ teamId : this . $options . teamId
44+ } ;
45+
46+ let debugData = this . $debugDataService . createDebugData ( this . $projectData , this . $options ) ;
47+
48+ await this . $platformService . trackProjectType ( this . $projectData ) ;
49+
50+ if ( this . $options . start ) {
51+ return this . printDebugInformation ( await this . debugService . debug < string [ ] > ( debugData , debugOptions ) ) ;
52+ }
53+
54+ const deviceAppData = liveSyncResultInfo . deviceAppData ;
55+ this . $config . debugLivesync = true ;
56+
57+ await this . debugService . debugStop ( ) ;
58+
59+ let applicationId = deviceAppData . appIdentifier ;
60+ await deviceAppData . device . applicationManager . stopApplication ( applicationId , projectData . projectName ) ;
61+
62+ const buildConfig : IBuildConfig = _ . merge ( { buildForDevice : ! deviceAppData . device . isEmulator } , deployOptions ) ;
63+ debugData . pathToAppPackage = this . $platformService . lastOutputPath ( this . debugService . platform , buildConfig , projectData ) ;
64+
65+ this . printDebugInformation ( await this . debugService . debug < string [ ] > ( debugData , debugOptions ) ) ;
66+ }
67+
68+ protected printDebugInformation ( information : string [ ] ) : void {
69+ _ . each ( information , i => {
70+ this . $logger . info ( `To start debugging, open the following URL in Chrome:${ EOL } ${ i } ${ EOL } ` . cyan ) ;
71+ } ) ;
72+ }
73+ }
374export abstract class DebugPlatformCommand implements ICommand {
475public allowedParameters : ICommandParameter [ ] = [ ] ;
76+ public platform : string ;
577
678constructor ( private debugService : IPlatformDebugService ,
779private $devicesService : Mobile . IDevicesService ,
880private $injector : IInjector ,
9- private $config : IConfiguration ,
10- private $usbLiveSyncService : ILiveSyncService ,
1181private $debugDataService : IDebugDataService ,
1282protected $platformService : IPlatformService ,
1383protected $projectData : IProjectData ,
@@ -19,16 +89,16 @@ export abstract class DebugPlatformCommand implements ICommand {
1989
2090public async execute ( args : string [ ] ) : Promise < void > {
2191const debugOptions = this . $options ;
22- const deployOptions : IDeployPlatformOptions = {
23- clean : this . $options . clean ,
24- device : this . $options . device ,
25- emulator : this . $options . emulator ,
26- platformTemplate : this . $options . platformTemplate ,
27- projectDir : this . $options . path ,
28- release : this . $options . release ,
29- provision : this . $options . provision ,
30- teamId : this . $options . teamId
31- } ;
92+ // const deployOptions: IDeployPlatformOptions = {
93+ // clean: this.$options.clean,
94+ // device: this.$options.device,
95+ // emulator: this.$options.emulator,
96+ // platformTemplate: this.$options.platformTemplate,
97+ // projectDir: this.$options.path,
98+ // release: this.$options.release,
99+ // provision: this.$options.provision,
100+ // teamId: this.$options.teamId
101+ // };
32102
33103let debugData = this . $debugDataService . createDebugData ( this . $projectData , this . $options ) ;
34104
@@ -38,26 +108,67 @@ export abstract class DebugPlatformCommand implements ICommand {
38108return this . printDebugInformation ( await this . debugService . debug < string [ ] > ( debugData , debugOptions ) ) ;
39109}
40110
41- const appFilesUpdaterOptions : IAppFilesUpdaterOptions = { bundle : this . $options . bundle , release : this . $options . release } ;
111+ // const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
42112
43- await this . $platformService . deployPlatform ( this . $devicesService . platform , appFilesUpdaterOptions , deployOptions , this . $projectData , this . $options ) ;
44- this . $config . debugLivesync = true ;
45- let applicationReloadAction = async ( deviceAppData : Mobile . IDeviceAppData ) : Promise < void > => {
46- let projectData : IProjectData = this . $injector . resolve ( "projectData" ) ;
113+ // await this.$platformService.deployPlatform(this.$devicesService.platform, appFilesUpdaterOptions, deployOptions, this.$projectData, this.$options);
114+ // this.$config.debugLivesync = true;
115+ // let applicationReloadAction = async (deviceAppData: Mobile.IDeviceAppData): Promise<void> => {
116+ // let projectData: IProjectData = this.$injector.resolve("projectData");
47117
48- await this . debugService . debugStop ( ) ;
118+ // await this.debugService.debugStop();
49119
50- let applicationId = deviceAppData . appIdentifier ;
51- await deviceAppData . device . applicationManager . stopApplication ( applicationId , projectData . projectName ) ;
120+ // let applicationId = deviceAppData.appIdentifier;
121+ // await deviceAppData.device.applicationManager.stopApplication(applicationId, projectData.projectName);
52122
53- const buildConfig : IBuildConfig = _ . merge ( { buildForDevice : ! deviceAppData . device . isEmulator } , deployOptions ) ;
54- debugData . pathToAppPackage = this . $platformService . lastOutputPath ( this . debugService . platform , buildConfig , projectData ) ;
123+ // const buildConfig: IBuildConfig = _.merge({ buildForDevice: !deviceAppData.device.isEmulator }, deployOptions);
124+ // debugData.pathToAppPackage = this.$platformService.lastOutputPath(this.debugService.platform, buildConfig, projectData);
55125
56- this . printDebugInformation ( await this . debugService . debug < string [ ] > ( debugData , debugOptions ) ) ;
57- } ;
126+ // this.printDebugInformation(await this.debugService.debug<string[]>(debugData, debugOptions));
127+ // };
58128
59129// TODO: Fix this call
60- return this . $usbLiveSyncService . liveSync ( this . $devicesService . platform , this . $projectData , applicationReloadAction , this . $options ) ;
130+ await this . $devicesService . initialize ( { deviceId : this . $options . device , platform : this . platform , skipDeviceDetectionInterval : true , skipInferPlatform : true } ) ;
131+ await this . $devicesService . detectCurrentlyAttachedDevices ( ) ;
132+
133+ const devices = this . $devicesService . getDeviceInstances ( ) ;
134+ // Now let's take data for each device:
135+ const deviceDescriptors : ILiveSyncDeviceInfo [ ] = devices . filter ( d => ! this . platform || d . deviceInfo . platform === this . platform )
136+ . map ( d => {
137+ const info : ILiveSyncDeviceInfo = {
138+ identifier : d . deviceInfo . identifier ,
139+ buildAction : async ( ) : Promise < string > => {
140+ const buildConfig : IBuildConfig = {
141+ buildForDevice : ! d . isEmulator , // this.$options.forDevice,
142+ projectDir : this . $options . path ,
143+ clean : this . $options . clean ,
144+ teamId : this . $options . teamId ,
145+ device : this . $options . device ,
146+ provision : this . $options . provision ,
147+ release : this . $options . release ,
148+ keyStoreAlias : this . $options . keyStoreAlias ,
149+ keyStorePath : this . $options . keyStorePath ,
150+ keyStoreAliasPassword : this . $options . keyStoreAliasPassword ,
151+ keyStorePassword : this . $options . keyStorePassword
152+ } ;
153+
154+ await this . $platformService . buildPlatform ( d . deviceInfo . platform , buildConfig , this . $projectData ) ;
155+ const pathToBuildResult = await this . $platformService . lastOutputPath ( d . deviceInfo . platform , buildConfig , this . $projectData ) ;
156+ console . log ( "3##### return path to buildResult = " , pathToBuildResult ) ;
157+ return pathToBuildResult ;
158+ }
159+ }
160+
161+ return info ;
162+ } ) ;
163+
164+ const liveSyncInfo : ILiveSyncInfo = {
165+ projectDir : this . $projectData . projectDir ,
166+ shouldStartWatcher : this . $options . watch ,
167+ syncAllFiles : this . $options . syncAllFiles
168+ } ;
169+
170+ const debugLiveSyncService = this . $injector . resolve < ILiveSyncService > ( DebugLiveSyncService , { debugService : this . debugService } ) ;
171+ await debugLiveSyncService . liveSync ( deviceDescriptors , liveSyncInfo ) ;
61172}
62173
63174public async canExecute ( args : string [ ] ) : Promise < boolean > {
@@ -92,14 +203,14 @@ export class DebugIOSCommand extends DebugPlatformCommand {
92203$devicesService : Mobile . IDevicesService ,
93204$injector : IInjector ,
94205$config : IConfiguration ,
95- $usbLiveSyncService : ILiveSyncService ,
206+ $liveSyncService : ILiveSyncService ,
96207$debugDataService : IDebugDataService ,
97208$platformService : IPlatformService ,
98209$options : IOptions ,
99210$projectData : IProjectData ,
100211$platformsData : IPlatformsData ,
101212$iosDeviceOperations : IIOSDeviceOperations ) {
102- super ( $iOSDebugService , $devicesService , $injector , $config , $usbLiveSyncService , $ debugDataService, $platformService , $projectData , $options , $platformsData , $logger ) ;
213+ super ( $iOSDebugService , $devicesService , $injector , $debugDataService , $platformService , $projectData , $options , $platformsData , $logger ) ;
103214// Do not dispose ios-device-lib, so the process will remain alive and the debug application (NativeScript Inspector or Chrome DevTools) will be able to connect to the socket.
104215// In case we dispose ios-device-lib, the socket will be closed and the code will fail when the debug application tries to read/send data to device socket.
105216// That's why the `$ tns debug ios --justlaunch` command will not release the terminal.
@@ -120,6 +231,8 @@ export class DebugIOSCommand extends DebugPlatformCommand {
120231super . printDebugInformation ( information ) ;
121232}
122233}
234+
235+ public platform = "iOS" ;
123236}
124237
125238$injector . registerCommand ( "debug|ios" , DebugIOSCommand ) ;
@@ -132,13 +245,13 @@ export class DebugAndroidCommand extends DebugPlatformCommand {
132245$devicesService : Mobile . IDevicesService ,
133246$injector : IInjector ,
134247$config : IConfiguration ,
135- $usbLiveSyncService : ILiveSyncService ,
248+ $liveSyncService : ILiveSyncService ,
136249$debugDataService : IDebugDataService ,
137250$platformService : IPlatformService ,
138251$options : IOptions ,
139252$projectData : IProjectData ,
140253$platformsData : IPlatformsData ) {
141- super ( $androidDebugService , $devicesService , $injector , $config , $usbLiveSyncService , $ debugDataService, $platformService , $projectData , $options , $platformsData , $logger ) ;
254+ super ( $androidDebugService , $devicesService , $injector , $debugDataService , $platformService , $projectData , $options , $platformsData , $logger ) ;
142255}
143256
144257public async canExecute ( args : string [ ] ) : Promise < boolean > {
@@ -148,6 +261,8 @@ export class DebugAndroidCommand extends DebugPlatformCommand {
148261
149262return await super . canExecute ( args ) && await this . $platformService . validateOptions ( this . $options . provision , this . $projectData , this . $platformsData . availablePlatforms . Android ) ;
150263}
264+
265+ public platform = "Android" ;
151266}
152267
153268$injector . registerCommand ( "debug|android" , DebugAndroidCommand ) ;
0 commit comments