Skip to content

Commit e377340

Browse files
author
Dimitar Kerezov
committed
Implement tracking
1 parent 4e4197e commit e377340

File tree

7 files changed

+63
-10
lines changed

7 files changed

+63
-10
lines changed

lib/commands/run.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export class RunIosCommand extends RunCommandBase implements ICommand {
124124
}
125125

126126
public async canExecute(args: string[]): Promise<boolean> {
127-
return args.length === 0 && await this.$platformService.validateOptions(this.$options.provision, this.$projectData, this.$platformsData.availablePlatforms.iOS);
127+
return super.canExecute(args) && await this.$platformService.validateOptions(this.$options.provision, this.$projectData, this.$platformsData.availablePlatforms.iOS);
128128
}
129129
}
130130

@@ -156,14 +156,15 @@ export class RunAndroidCommand extends RunCommandBase implements ICommand {
156156
}
157157

158158
public async canExecute(args: string[]): Promise<boolean> {
159+
super.canExecute(args);
159160
if (!this.$platformService.isPlatformSupportedForOS(this.$devicePlatformsConstants.Android, this.$projectData)) {
160161
this.$errors.fail("Applications for platform %s can not be built on this OS - %s", this.$devicePlatformsConstants.Android, process.platform);
161162
}
162163

163164
if (this.$options.release && (!this.$options.keyStorePath || !this.$options.keyStorePassword || !this.$options.keyStoreAlias || !this.$options.keyStoreAliasPassword)) {
164165
this.$errors.fail("When producing a release build, you need to specify all --key-store-* options.");
165166
}
166-
return args.length === 0 && await this.$platformService.validateOptions(this.$options.provision, this.$projectData, this.$platformsData.availablePlatforms.Android);
167+
return this.$platformService.validateOptions(this.$options.provision, this.$projectData, this.$platformsData.availablePlatforms.Android);
167168
}
168169
}
169170

lib/constants.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ export class PackageVersion {
2323
static LATEST = "latest";
2424
}
2525

26+
const liveSyncOperation = "LiveSync Operation";
27+
export class LiveSyncTrackActionNames {
28+
static LIVESYNC_OPERATION = liveSyncOperation;
29+
static LIVESYNC_OPERATION_BUILD = `${liveSyncOperation} - Build`;
30+
static DEVICE_INFO = `Device Info for ${liveSyncOperation}`;
31+
}
32+
2633
export const PackageJsonKeysToKeep: Array<String> = ["name", "main", "android", "version"];
2734

2835
export class SaveOptions {

lib/definitions/livesync.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ interface ILiveSyncInfo {
116116
useLiveEdit?: boolean;
117117
}
118118

119+
interface ILatestAppPackageInstalledSettings {
120+
[key: string]: {
121+
[key: string]: boolean;
122+
}
123+
}
124+
119125
interface ILiveSyncBuildInfo {
120126
platform: string;
121127
isEmulator: boolean;

lib/services/emulator-platform-service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createTable, deferPromise } from "../common/helpers";
2+
import { DeviceTypes } from "../common/constants";
23

34
export class EmulatorPlatformService implements IEmulatorPlatformService {
45

@@ -70,7 +71,7 @@ export class EmulatorPlatformService implements IEmulatorPlatformService {
7071
name: device.deviceInfo.displayName,
7172
version: device.deviceInfo.version,
7273
platform: "Android",
73-
type: "emulator",
74+
type: DeviceTypes.Emulator,
7475
isRunning: true
7576
};
7677
}

lib/services/livesync/debug-livesync-service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export class DebugLiveSyncService extends LiveSyncService {
77
$projectDataService: IProjectDataService,
88
protected $devicesService: Mobile.IDevicesService,
99
$mobileHelper: Mobile.IMobileHelper,
10+
$devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
1011
$nodeModulesDependenciesBuilder: INodeModulesDependenciesBuilder,
1112
protected $logger: ILogger,
1213
$processService: IProcessService,
@@ -22,6 +23,7 @@ export class DebugLiveSyncService extends LiveSyncService {
2223
$projectDataService,
2324
$devicesService,
2425
$mobileHelper,
26+
$devicePlatformsConstants,
2527
$nodeModulesDependenciesBuilder,
2628
$logger,
2729
$processService,

lib/services/livesync/livesync-service.ts

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import * as path from "path";
22
import * as choki from "chokidar";
33
import { EventEmitter } from "events";
44
import { hook } from "../../common/helpers";
5-
import { FileExtensions } from "../../common/constants";
5+
import { APP_FOLDER_NAME, PACKAGE_JSON_FILE_NAME, LiveSyncTrackActionNames } from "../../constants";
6+
import { FileExtensions, DeviceTypes } from "../../common/constants";
67

78
const LiveSyncEvents = {
89
liveSyncStopped: "liveSyncStopped",
@@ -22,6 +23,7 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
2223
private $projectDataService: IProjectDataService,
2324
protected $devicesService: Mobile.IDevicesService,
2425
private $mobileHelper: Mobile.IMobileHelper,
26+
protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
2527
private $nodeModulesDependenciesBuilder: INodeModulesDependenciesBuilder,
2628
protected $logger: ILogger,
2729
private $processService: IProcessService,
@@ -152,8 +154,8 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
152154
rebuiltInformation: ILiveSyncBuildInfo[],
153155
projectData: IProjectData,
154156
deviceBuildInfoDescriptor: ILiveSyncDeviceInfo,
157+
settings: ILatestAppPackageInstalledSettings,
155158
modifiedFiles?: string[]): Promise<void> {
156-
157159
const platform = device.deviceInfo.platform;
158160
if (preparedPlatforms.indexOf(platform) === -1) {
159161
preparedPlatforms.push(platform);
@@ -176,12 +178,29 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
176178
// TODO: fix args cast to any
177179
const shouldBuild = await this.$platformService.shouldBuild(platform, projectData, <any>{ buildForDevice: !device.isEmulator }, deviceBuildInfoDescriptor.outputPath);
178180
let pathToBuildItem = null;
181+
let action = LiveSyncTrackActionNames.LIVESYNC_OPERATION;
179182
if (shouldBuild) {
180183
pathToBuildItem = await deviceBuildInfoDescriptor.buildAction();
181184
// Is it possible to return shouldBuild for two devices? What about android device and android emulator?
182185
rebuiltInformation.push({ isEmulator: device.isEmulator, platform, pathToBuildItem });
186+
action = LiveSyncTrackActionNames.LIVESYNC_OPERATION_BUILD;
187+
}
188+
189+
if (!settings[platform][device.deviceInfo.type]) {
190+
let isForDevice = !device.isEmulator;
191+
settings[platform][device.deviceInfo.type] = true;
192+
if (this.$mobileHelper.isAndroidPlatform(platform)) {
193+
settings[platform][DeviceTypes.Emulator] = true;
194+
settings[platform][DeviceTypes.Device] = true;
195+
isForDevice = null;
196+
}
197+
198+
await this.$platformService.trackActionForPlatform({ action, platform, isForDevice });
183199
}
184200

201+
await this.$platformService.trackActionForPlatform({ action: LiveSyncTrackActionNames.DEVICE_INFO, platform, isForDevice: !device.isEmulator, deviceOsVersion: device.deviceInfo.version });
202+
203+
185204
const shouldInstall = await this.$platformService.shouldInstall(device, projectData, deviceBuildInfoDescriptor.outputPath);
186205
if (shouldInstall) {
187206
await this.$platformService.installApplication(device, { release: false }, projectData, pathToBuildItem, deviceBuildInfoDescriptor.outputPath);
@@ -192,6 +211,7 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
192211
const preparedPlatforms: string[] = [];
193212
const rebuiltInformation: ILiveSyncBuildInfo[] = [];
194213

214+
const settings = this.getDefaultLatestAppPackageInstalledSettings();
195215
// Now fullSync
196216
const deviceAction = async (device: Mobile.IDevice): Promise<void> => {
197217
try {
@@ -204,14 +224,15 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
204224
const platform = device.deviceInfo.platform;
205225
const deviceDescriptor = _.find(deviceDescriptors, dd => dd.identifier === device.deviceInfo.identifier);
206226

207-
await this.ensureLatestAppPackageIsInstalledOnDevice(device, preparedPlatforms, rebuiltInformation, projectData, deviceDescriptor);
227+
await this.ensureLatestAppPackageIsInstalledOnDevice(device, preparedPlatforms, rebuiltInformation, projectData, deviceDescriptor, settings);
208228

209229
const liveSyncResultInfo = await this.getLiveSyncService(platform).fullSync({
210230
projectData, device,
211231
syncAllFiles: liveSyncData.watchAllFiles,
212232
useLiveEdit: liveSyncData.useLiveEdit,
213233
watch: !liveSyncData.skipWatcher
214234
});
235+
await this.$platformService.trackActionForPlatform({ action: "LiveSync", platform: device.deviceInfo.platform, isForDevice: !device.isEmulator, deviceOsVersion: device.deviceInfo.version });
215236
await this.refreshApplication(projectData, liveSyncResultInfo);
216237
} catch (err) {
217238
this.$logger.warn(`Unable to apply changes on device: ${device.deviceInfo.identifier}. Error is: ${err.message}.`);
@@ -232,14 +253,27 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
232253
await this.addActionToChain(projectData.projectDir, () => this.$devicesService.execute(deviceAction, (device: Mobile.IDevice) => _.some(deviceDescriptors, deviceDescriptor => deviceDescriptor.identifier === device.deviceInfo.identifier)));
233254
}
234255

256+
private getDefaultLatestAppPackageInstalledSettings(): ILatestAppPackageInstalledSettings {
257+
return {
258+
[this.$devicePlatformsConstants.Android]: {
259+
[DeviceTypes.Device]: false,
260+
[DeviceTypes.Emulator]: false
261+
},
262+
[this.$devicePlatformsConstants.iOS]: {
263+
[DeviceTypes.Device]: false,
264+
[DeviceTypes.Emulator]: false
265+
}
266+
}
267+
}
268+
235269
private async startWatcher(projectData: IProjectData,
236270
liveSyncData: ILiveSyncInfo): Promise<void> {
237271

238-
let pattern = ["app"];
272+
let pattern = [APP_FOLDER_NAME];
239273

240274
if (liveSyncData.watchAllFiles) {
241275
const productionDependencies = this.$nodeModulesDependenciesBuilder.getProductionDependencies(projectData.projectDir);
242-
pattern.push("package.json");
276+
pattern.push(PACKAGE_JSON_FILE_NAME);
243277

244278
// watch only production node_module/packages same one prepare uses
245279
for (let index in productionDependencies) {
@@ -274,11 +308,13 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
274308
const preparedPlatforms: string[] = [];
275309
const rebuiltInformation: ILiveSyncBuildInfo[] = [];
276310

311+
const latestAppPackageInstalledSettings = this.getDefaultLatestAppPackageInstalledSettings();
312+
277313
await this.$devicesService.execute(async (device: Mobile.IDevice) => {
278314
const liveSyncProcessInfo = this.liveSyncProcessesInfo[projectData.projectDir];
279315
const deviceDescriptor = _.find(liveSyncProcessInfo.deviceDescriptors, dd => dd.identifier === device.deviceInfo.identifier);
280316

281-
await this.ensureLatestAppPackageIsInstalledOnDevice(device, preparedPlatforms, rebuiltInformation, projectData, deviceDescriptor, allModifiedFiles);
317+
await this.ensureLatestAppPackageIsInstalledOnDevice(device, preparedPlatforms, rebuiltInformation, projectData, deviceDescriptor, latestAppPackageInstalledSettings, allModifiedFiles);
282318

283319
const service = this.getLiveSyncService(device.deviceInfo.platform);
284320
const settings: ILiveSyncWatchInfo = {

0 commit comments

Comments
 (0)