-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathdevice-livesync-service-base.ts
49 lines (40 loc) · 2.19 KB
/
device-livesync-service-base.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
import { cache } from "../../common/decorators";
import * as path from "path";
export abstract class DeviceLiveSyncServiceBase {
private static FAST_SYNC_FILE_EXTENSIONS = [".css", ".xml", ".html"];
constructor(
protected $platformsData: IPlatformsData,
protected device: Mobile.IDevice
) { }
public canExecuteFastSync(liveSyncResult: ILiveSyncResultInfo, filePath: string, projectData: IProjectData, platform: string): boolean {
const fastSyncFileExtensions = this.getFastLiveSyncFileExtensions(platform, projectData);
return liveSyncResult.useHotModuleReload || _.includes(fastSyncFileExtensions, path.extname(filePath));
}
protected canExecuteFastSyncForPaths(liveSyncResult: ILiveSyncResultInfo, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectData: IProjectData, platform: string) {
return !_.some(localToDevicePaths,
(localToDevicePath: Mobile.ILocalToDevicePathData) =>
!this.canExecuteFastSync(liveSyncResult, localToDevicePath.getLocalPath(), projectData, this.device.deviceInfo.platform));
}
@cache()
private getFastLiveSyncFileExtensions(platform: string, projectData: IProjectData): string[] {
const platformData = this.$platformsData.getPlatformData(platform, projectData);
const fastSyncFileExtensions = DeviceLiveSyncServiceBase.FAST_SYNC_FILE_EXTENSIONS.concat(platformData.fastLivesyncFileExtensions);
return fastSyncFileExtensions;
}
public async transferFiles(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string, isFullSync: boolean): Promise<Mobile.ILocalToDevicePathData[]> {
let transferredFiles: Mobile.ILocalToDevicePathData[] = [];
if (isFullSync) {
transferredFiles = await this.device.fileSystem.transferDirectory(deviceAppData, localToDevicePaths, projectFilesPath);
} else {
transferredFiles = await this.device.fileSystem.transferFiles(deviceAppData, localToDevicePaths);
}
return transferredFiles;
}
public async finalizeSync(liveSyncInfo: ILiveSyncResultInfo, projectData: IProjectData): Promise<IAndroidLivesyncSyncOperationResult> {
//implement in case a sync point for all remove/create operation is needed
return {
didRefresh: true,
operationId: ""
};
}
}