-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathlivesync-provider.ts
52 lines (44 loc) · 2.07 KB
/
livesync-provider.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
///<reference path="../.d.ts"/>
"use strict";
import * as path from "path";
export class LiveSyncProvider implements ILiveSyncProvider {
constructor(private $androidLiveSyncServiceLocator: {factory: Function},
private $iosLiveSyncServiceLocator: {factory: Function},
private $platformService: IPlatformService,
private $platformsData: IPlatformsData,
private $logger: ILogger) { }
private static FAST_SYNC_FILE_EXTENSIONS = [".css", ".xml"];
public get platformSpecificLiveSyncServices(): IDictionary<any> {
return {
android: (_device: Mobile.IDevice, $injector: IInjector): IPlatformLiveSyncService => {
return $injector.resolve(this.$androidLiveSyncServiceLocator.factory, {_device: _device});
},
ios: (_device: Mobile.IDevice, $injector: IInjector) => {
return $injector.resolve(this.$iosLiveSyncServiceLocator.factory, {_device: _device});
}
};
}
public buildForDevice(device: Mobile.IDevice): IFuture<string> {
return (() => {
this.$platformService.buildPlatform(device.deviceInfo.platform, {buildForDevice: !device.isEmulator}).wait();
let platformData = this.$platformsData.getPlatformData(device.deviceInfo.platform);
if (device.isEmulator) {
return this.$platformService.getLatestApplicationPackageForEmulator(platformData).wait().packageName;
}
return this.$platformService.getLatestApplicationPackageForDevice(platformData).wait().packageName;
}).future<string>()();
}
public preparePlatformForSync(platform: string): IFuture<void> {
return (() => {
if (!this.$platformService.preparePlatform(platform).wait()) {
this.$logger.out("Verify that listed files are well-formed and try again the operation.");
}
}).future<void>()();
}
public canExecuteFastSync(filePath: string, platform: string): boolean {
let platformData = this.$platformsData.getPlatformData(platform);
let fastSyncFileExtensions = LiveSyncProvider.FAST_SYNC_FILE_EXTENSIONS.concat(platformData.fastLivesyncFileExtensions);
return _.contains(fastSyncFileExtensions, path.extname(filePath));
}
}
$injector.register("liveSyncProvider", LiveSyncProvider);