forked from NativeScript/nativescript-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathandroid-device-livesync-service-base.ts
137 lines (129 loc) · 4.29 KB
/
android-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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import { DeviceLiveSyncServiceBase } from "./device-livesync-service-base";
import { IPlatformsDataService } from "../../definitions/platform";
import { IProjectData } from "../../definitions/project";
import { IFilesHashService } from "../../definitions/files-hash-service";
import { IStringDictionary } from "../../common/declarations";
import { IInjector } from "../../common/definitions/yok";
import * as _ from "lodash";
export abstract class AndroidDeviceLiveSyncServiceBase extends DeviceLiveSyncServiceBase {
constructor(
protected $injector: IInjector,
protected $platformsDataService: IPlatformsDataService,
protected $filesHashService: IFilesHashService,
protected $logger: ILogger,
protected device: Mobile.IAndroidDevice
) {
super($platformsDataService, device);
}
public abstract transferFilesOnDevice(
deviceAppData: Mobile.IDeviceAppData,
localToDevicePaths: Mobile.ILocalToDevicePathData[]
): Promise<void>;
public abstract transferDirectoryOnDevice(
deviceAppData: Mobile.IDeviceAppData,
localToDevicePaths: Mobile.ILocalToDevicePathData[],
projectFilesPath: string
): Promise<void>;
public async transferFiles(
deviceAppData: Mobile.IDeviceAppData,
localToDevicePaths: Mobile.ILocalToDevicePathData[],
projectFilesPath: string,
projectData: IProjectData,
liveSyncDeviceDescriptor: ILiveSyncDeviceDescriptor,
options: ITransferFilesOptions
): Promise<Mobile.ILocalToDevicePathData[]> {
const deviceHashService = this.device.fileSystem.getDeviceHashService(
deviceAppData.appIdentifier
);
const currentHashes = await deviceHashService.generateHashesFromLocalToDevicePaths(
localToDevicePaths
);
const transferredFiles = await this.transferFilesCore(
deviceAppData,
localToDevicePaths,
projectFilesPath,
currentHashes,
options
);
await this.device.fileSystem.updateHashesOnDevice(
currentHashes,
deviceAppData.appIdentifier
);
return transferredFiles;
}
private async transferFilesCore(
deviceAppData: Mobile.IDeviceAppData,
localToDevicePaths: Mobile.ILocalToDevicePathData[],
projectFilesPath: string,
currentHashes: IStringDictionary,
options: ITransferFilesOptions
): Promise<Mobile.ILocalToDevicePathData[]> {
if (options.force && options.isFullSync) {
const hashFileDevicePath = this.device.fileSystem.getDeviceHashService(
deviceAppData.appIdentifier
).hashFileDevicePath;
await this.device.fileSystem.deleteFile(
hashFileDevicePath,
deviceAppData.appIdentifier
);
this.$logger.trace(
"Before transfer directory on device ",
localToDevicePaths
);
await this.transferDirectoryOnDevice(
deviceAppData,
localToDevicePaths,
projectFilesPath
);
return localToDevicePaths;
}
const localToDevicePathsToTransfer = await this.getLocalToDevicePathsToTransfer(
deviceAppData,
localToDevicePaths,
currentHashes,
options
);
this.$logger.trace("Files to transfer: ", localToDevicePathsToTransfer);
await this.transferFilesOnDevice(
deviceAppData,
localToDevicePathsToTransfer
);
return localToDevicePathsToTransfer;
}
private async getLocalToDevicePathsToTransfer(
deviceAppData: Mobile.IDeviceAppData,
localToDevicePaths: Mobile.ILocalToDevicePathData[],
currentHashes: IStringDictionary,
options: ITransferFilesOptions
): Promise<Mobile.ILocalToDevicePathData[]> {
if (options.force || !options.isFullSync) {
return localToDevicePaths;
}
const changedLocalToDevicePaths = await this.getChangedLocalToDevicePaths(
deviceAppData.appIdentifier,
localToDevicePaths,
currentHashes
);
return changedLocalToDevicePaths;
}
private async getChangedLocalToDevicePaths(
appIdentifier: string,
localToDevicePaths: Mobile.ILocalToDevicePathData[],
currentHashes: IStringDictionary
): Promise<Mobile.ILocalToDevicePathData[]> {
const deviceHashService = this.device.fileSystem.getDeviceHashService(
appIdentifier
);
const oldHashes = (await deviceHashService.getShasumsFromDevice()) || {};
const changedHashes = deviceHashService.getChangedShasums(
oldHashes,
currentHashes
);
const changedFiles = _.keys(changedHashes);
const changedLocalToDevicePaths = localToDevicePaths.filter(
(localToDevicePathData) =>
changedFiles.indexOf(localToDevicePathData.getLocalPath()) >= 0
);
return changedLocalToDevicePaths;
}
}