-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathios-livesync-service.ts
76 lines (64 loc) · 2.92 KB
/
ios-livesync-service.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
import * as path from "path";
import * as temp from "temp";
import { IOSDeviceLiveSyncService } from "./ios-device-livesync-service";
import { PlatformLiveSyncServiceBase } from "./platform-livesync-service-base";
import { APP_FOLDER_NAME } from "../../constants";
import { performanceLog } from "../../common/decorators";
export class IOSLiveSyncService extends PlatformLiveSyncServiceBase implements IPlatformLiveSyncService {
constructor(protected $fs: IFileSystem,
protected $platformsDataService: IPlatformsDataService,
protected $projectFilesManager: IProjectFilesManager,
private $injector: IInjector,
$devicePathProvider: IDevicePathProvider,
$logger: ILogger) {
super($fs, $logger, $platformsDataService, $projectFilesManager, $devicePathProvider);
}
@performanceLog()
public async fullSync(syncInfo: IFullSyncInfo): Promise<ILiveSyncResultInfo> {
const device = syncInfo.device;
if (device.isEmulator) {
return super.fullSync(syncInfo);
}
const projectData = syncInfo.projectData;
const platformData = this.$platformsDataService.getPlatformData(device.deviceInfo.platform, projectData);
const deviceAppData = await this.getAppData(syncInfo);
const projectFilesPath = path.join(platformData.appDestinationDirectoryPath, APP_FOLDER_NAME);
temp.track();
const tempZip = temp.path({ prefix: "sync", suffix: ".zip" });
this.$logger.trace("Creating zip file: " + tempZip);
const filesToTransfer = this.$fs.enumerateFilesInDirectorySync(projectFilesPath);
await this.$fs.zipFiles(tempZip, filesToTransfer, (res) => {
return path.join(APP_FOLDER_NAME, path.relative(projectFilesPath, res));
});
await device.fileSystem.transferFiles(deviceAppData, [{
getLocalPath: () => tempZip,
getDevicePath: () => deviceAppData.deviceSyncZipPath,
getRelativeToProjectBasePath: () => "../sync.zip",
deviceProjectRootPath: await deviceAppData.getDeviceProjectRootPath()
}]);
await deviceAppData.device.applicationManager.setTransferredAppFiles(filesToTransfer);
return {
deviceAppData,
isFullSync: true,
modifiedFilesData: [],
useHotModuleReload: syncInfo.useHotModuleReload
};
}
public async syncAfterInstall(device: Mobile.IDevice, liveSyncInfo: ILiveSyncWatchInfo): Promise<void> {
if (!device.isEmulator) {
// In this case we should execute fullsync because iOS Runtime requires the full content of app dir to be extracted in the root of sync dir.
await this.fullSync({
projectData: liveSyncInfo.projectData,
device,
liveSyncDeviceData: liveSyncInfo.liveSyncDeviceData,
watch: true,
useHotModuleReload: liveSyncInfo.useHotModuleReload
});
}
}
protected _getDeviceLiveSyncService(device: Mobile.IDevice, data: IProjectDir): INativeScriptDeviceLiveSyncService {
const service = this.$injector.resolve<INativeScriptDeviceLiveSyncService>(IOSDeviceLiveSyncService, { device, data });
return service;
}
}
$injector.register("iOSLiveSyncService", IOSLiveSyncService);