1
1
import { EOL } from "os" ;
2
+ import { LiveSyncService } from "../services/livesync/livesync-service" ;
3
+ export class DebugLiveSyncService extends LiveSyncService {
2
4
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
+ }
3
74
export abstract class DebugPlatformCommand implements ICommand {
4
75
public allowedParameters : ICommandParameter [ ] = [ ] ;
76
+ public platform : string ;
5
77
6
78
constructor ( private debugService : IPlatformDebugService ,
7
79
private $devicesService : Mobile . IDevicesService ,
8
80
private $injector : IInjector ,
9
- private $config : IConfiguration ,
10
- private $usbLiveSyncService : ILiveSyncService ,
11
81
private $debugDataService : IDebugDataService ,
12
82
protected $platformService : IPlatformService ,
13
83
protected $projectData : IProjectData ,
@@ -19,16 +89,16 @@ export abstract class DebugPlatformCommand implements ICommand {
19
89
20
90
public async execute ( args : string [ ] ) : Promise < void > {
21
91
const 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
+ // };
32
102
33
103
let debugData = this . $debugDataService . createDebugData ( this . $projectData , this . $options ) ;
34
104
@@ -38,26 +108,67 @@ export abstract class DebugPlatformCommand implements ICommand {
38
108
return this . printDebugInformation ( await this . debugService . debug < string [ ] > ( debugData , debugOptions ) ) ;
39
109
}
40
110
41
- const appFilesUpdaterOptions : IAppFilesUpdaterOptions = { bundle : this . $options . bundle , release : this . $options . release } ;
111
+ // const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
42
112
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");
47
117
48
- await this . debugService . debugStop ( ) ;
118
+ // await this.debugService.debugStop();
49
119
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);
52
122
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);
55
125
56
- this . printDebugInformation ( await this . debugService . debug < string [ ] > ( debugData , debugOptions ) ) ;
57
- } ;
126
+ // this.printDebugInformation(await this.debugService.debug<string[]>(debugData, debugOptions));
127
+ // };
58
128
59
129
// 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 ) ;
61
172
}
62
173
63
174
public async canExecute ( args : string [ ] ) : Promise < boolean > {
@@ -92,14 +203,14 @@ export class DebugIOSCommand extends DebugPlatformCommand {
92
203
$devicesService : Mobile . IDevicesService ,
93
204
$injector : IInjector ,
94
205
$config : IConfiguration ,
95
- $usbLiveSyncService : ILiveSyncService ,
206
+ $liveSyncService : ILiveSyncService ,
96
207
$debugDataService : IDebugDataService ,
97
208
$platformService : IPlatformService ,
98
209
$options : IOptions ,
99
210
$projectData : IProjectData ,
100
211
$platformsData : IPlatformsData ,
101
212
$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 ) ;
103
214
// 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.
104
215
// 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.
105
216
// That's why the `$ tns debug ios --justlaunch` command will not release the terminal.
@@ -120,6 +231,8 @@ export class DebugIOSCommand extends DebugPlatformCommand {
120
231
super . printDebugInformation ( information ) ;
121
232
}
122
233
}
234
+
235
+ public platform = "iOS" ;
123
236
}
124
237
125
238
$injector . registerCommand ( "debug|ios" , DebugIOSCommand ) ;
@@ -132,13 +245,13 @@ export class DebugAndroidCommand extends DebugPlatformCommand {
132
245
$devicesService : Mobile . IDevicesService ,
133
246
$injector : IInjector ,
134
247
$config : IConfiguration ,
135
- $usbLiveSyncService : ILiveSyncService ,
248
+ $liveSyncService : ILiveSyncService ,
136
249
$debugDataService : IDebugDataService ,
137
250
$platformService : IPlatformService ,
138
251
$options : IOptions ,
139
252
$projectData : IProjectData ,
140
253
$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 ) ;
142
255
}
143
256
144
257
public async canExecute ( args : string [ ] ) : Promise < boolean > {
@@ -148,6 +261,8 @@ export class DebugAndroidCommand extends DebugPlatformCommand {
148
261
149
262
return await super . canExecute ( args ) && await this . $platformService . validateOptions ( this . $options . provision , this . $projectData , this . $platformsData . availablePlatforms . Android ) ;
150
263
}
264
+
265
+ public platform = "Android" ;
151
266
}
152
267
153
268
$injector . registerCommand ( "debug|android" , DebugAndroidCommand ) ;
0 commit comments