Skip to content

Commit f45f1e3

Browse files
rosen-vladimirovDimitar Kerezov
authored andcommitted
Add correct events for LiveSync
1 parent 823f1c5 commit f45f1e3

File tree

7 files changed

+193
-188
lines changed

7 files changed

+193
-188
lines changed

lib/commands/debug.ts

Lines changed: 12 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,24 @@
11
import { EOL } from "os";
2-
import { LiveSyncService } from "../services/livesync/livesync-service";
3-
export class DebugLiveSyncService extends LiveSyncService {
42

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-
}
743
export abstract class DebugPlatformCommand implements ICommand {
754
public allowedParameters: ICommandParameter[] = [];
765
public platform: string;
776

787
constructor(private debugService: IPlatformDebugService,
798
private $devicesService: Mobile.IDevicesService,
80-
private $injector: IInjector,
819
private $debugDataService: IDebugDataService,
8210
protected $platformService: IPlatformService,
8311
protected $projectData: IProjectData,
8412
protected $options: IOptions,
8513
protected $platformsData: IPlatformsData,
86-
protected $logger: ILogger) {
14+
protected $logger: ILogger,
15+
private $debugLiveSyncService: ILiveSyncService,
16+
private $config: IConfiguration) {
8717
this.$projectData.initializeProjectData();
8818
}
8919

9020
public async execute(args: string[]): Promise<void> {
9121
const debugOptions = this.$options;
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-
// };
10222

10323
let debugData = this.$debugDataService.createDebugData(this.$projectData, this.$options);
10424

@@ -108,23 +28,7 @@ export abstract class DebugPlatformCommand implements ICommand {
10828
return this.printDebugInformation(await this.debugService.debug<string[]>(debugData, debugOptions));
10929
}
11030

111-
// const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
112-
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");
117-
118-
// await this.debugService.debugStop();
119-
120-
// let applicationId = deviceAppData.appIdentifier;
121-
// await deviceAppData.device.applicationManager.stopApplication(applicationId, projectData.projectName);
122-
123-
// const buildConfig: IBuildConfig = _.merge({ buildForDevice: !deviceAppData.device.isEmulator }, deployOptions);
124-
// debugData.pathToAppPackage = this.$platformService.lastOutputPath(this.debugService.platform, buildConfig, projectData);
125-
126-
// this.printDebugInformation(await this.debugService.debug<string[]>(debugData, debugOptions));
127-
// };
31+
this.$config.debugLivesync = true;
12832

12933
// TODO: Fix this call
13034
await this.$devicesService.initialize({ deviceId: this.$options.device, platform: this.platform, skipDeviceDetectionInterval: true, skipInferPlatform: true });
@@ -153,10 +57,9 @@ export abstract class DebugPlatformCommand implements ICommand {
15357

15458
await this.$platformService.buildPlatform(d.deviceInfo.platform, buildConfig, this.$projectData);
15559
const pathToBuildResult = await this.$platformService.lastOutputPath(d.deviceInfo.platform, buildConfig, this.$projectData);
156-
console.log("3##### return path to buildResult = ", pathToBuildResult);
15760
return pathToBuildResult;
15861
}
159-
}
62+
};
16063

16164
return info;
16265
});
@@ -167,8 +70,7 @@ export abstract class DebugPlatformCommand implements ICommand {
16770
watchAllFiles: this.$options.syncAllFiles
16871
};
16972

170-
const debugLiveSyncService = this.$injector.resolve<ILiveSyncService>(DebugLiveSyncService, { debugService: this.debugService });
171-
await debugLiveSyncService.liveSync(deviceDescriptors, liveSyncInfo);
73+
await this.$debugLiveSyncService.liveSync(deviceDescriptors, liveSyncInfo);
17274
}
17375

17476
public async canExecute(args: string[]): Promise<boolean> {
@@ -201,16 +103,15 @@ export class DebugIOSCommand extends DebugPlatformCommand {
201103
$logger: ILogger,
202104
$iOSDebugService: IPlatformDebugService,
203105
$devicesService: Mobile.IDevicesService,
204-
$injector: IInjector,
205106
$config: IConfiguration,
206-
$liveSyncService: ILiveSyncService,
207107
$debugDataService: IDebugDataService,
208108
$platformService: IPlatformService,
209109
$options: IOptions,
210110
$projectData: IProjectData,
211111
$platformsData: IPlatformsData,
212-
$iosDeviceOperations: IIOSDeviceOperations) {
213-
super($iOSDebugService, $devicesService, $injector, $debugDataService, $platformService, $projectData, $options, $platformsData, $logger);
112+
$iosDeviceOperations: IIOSDeviceOperations,
113+
$debugLiveSyncService: ILiveSyncService) {
114+
super($iOSDebugService, $devicesService, $debugDataService, $platformService, $projectData, $options, $platformsData, $logger, $debugLiveSyncService, $config);
214115
// 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.
215116
// 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.
216117
// That's why the `$ tns debug ios --justlaunch` command will not release the terminal.
@@ -243,15 +144,14 @@ export class DebugAndroidCommand extends DebugPlatformCommand {
243144
$logger: ILogger,
244145
$androidDebugService: IPlatformDebugService,
245146
$devicesService: Mobile.IDevicesService,
246-
$injector: IInjector,
247147
$config: IConfiguration,
248-
$liveSyncService: ILiveSyncService,
249148
$debugDataService: IDebugDataService,
250149
$platformService: IPlatformService,
251150
$options: IOptions,
252151
$projectData: IProjectData,
253-
$platformsData: IPlatformsData) {
254-
super($androidDebugService, $devicesService, $injector, $debugDataService, $platformService, $projectData, $options, $platformsData, $logger);
152+
$platformsData: IPlatformsData,
153+
$debugLiveSyncService: ILiveSyncService) {
154+
super($androidDebugService, $devicesService, $debugDataService, $platformService, $projectData, $options, $platformsData, $logger, $debugLiveSyncService, $config);
255155
}
256156

257157
public async canExecute(args: string[]): Promise<boolean> {

lib/commands/run.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class RunCommandBase implements ICommand {
5959
console.log("3##### return path to buildResult = ", pathToBuildResult);
6060
return pathToBuildResult;
6161
}
62-
}
62+
};
6363

6464
return info;
6565
});

lib/definitions/livesync.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ interface ILiveSyncProcessInfo {
6060
watcher: IFSWatcher;
6161
actionsChain: Promise<any>;
6262
isStopped: boolean;
63+
deviceDescriptors: ILiveSyncDeviceInfo[];
6364
}
6465

6566
/**
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { EOL } from "os";
2+
import { LiveSyncService } from "./livesync-service";
3+
4+
export class DebugLiveSyncService extends LiveSyncService {
5+
6+
constructor(protected $platformService: IPlatformService,
7+
$projectDataService: IProjectDataService,
8+
protected $devicesService: Mobile.IDevicesService,
9+
$mobileHelper: Mobile.IMobileHelper,
10+
$nodeModulesDependenciesBuilder: INodeModulesDependenciesBuilder,
11+
protected $logger: ILogger,
12+
$processService: IProcessService,
13+
$hooksService: IHooksService,
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+
$injector);
30+
}
31+
32+
protected async refreshApplication(projectData: IProjectData, liveSyncResultInfo: ILiveSyncResultInfo): Promise<void> {
33+
const debugOptions = this.$options;
34+
const deployOptions: IDeployPlatformOptions = {
35+
clean: this.$options.clean,
36+
device: this.$options.device,
37+
emulator: this.$options.emulator,
38+
platformTemplate: this.$options.platformTemplate,
39+
projectDir: this.$options.path,
40+
release: this.$options.release,
41+
provision: this.$options.provision,
42+
teamId: this.$options.teamId
43+
};
44+
45+
let debugData = this.$debugDataService.createDebugData(this.$projectData, this.$options);
46+
47+
await this.$platformService.trackProjectType(this.$projectData);
48+
49+
if (this.$options.start) {
50+
return this.printDebugInformation(await this.debugService.debug<string[]>(debugData, debugOptions));
51+
}
52+
53+
const deviceAppData = liveSyncResultInfo.deviceAppData;
54+
this.$config.debugLivesync = true;
55+
56+
await this.debugService.debugStop();
57+
58+
let applicationId = deviceAppData.appIdentifier;
59+
await deviceAppData.device.applicationManager.stopApplication(applicationId, projectData.projectName);
60+
61+
const buildConfig: IBuildConfig = _.merge({ buildForDevice: !deviceAppData.device.isEmulator }, deployOptions);
62+
debugData.pathToAppPackage = this.$platformService.lastOutputPath(this.debugService.platform, buildConfig, projectData);
63+
64+
this.printDebugInformation(await this.debugService.debug<string[]>(debugData, debugOptions));
65+
}
66+
67+
protected printDebugInformation(information: string[]): void {
68+
_.each(information, i => {
69+
this.$logger.info(`To start debugging, open the following URL in Chrome:${EOL}${i}${EOL}`.cyan);
70+
});
71+
}
72+
}
73+
74+
$injector.register("debugLiveSyncService", DebugLiveSyncService);

0 commit comments

Comments
 (0)