From f51608de15f65546fd4dbf5793d8d39562cdd17f Mon Sep 17 00:00:00 2001 From: Tsvetan Raikov Date: Fri, 17 Jun 2016 16:10:43 +0300 Subject: [PATCH] Fixed slow livesync --- lib/common | 2 +- lib/providers/device-app-data-provider.ts | 8 ++++++++ lib/providers/livesync-provider.ts | 24 ++++++++++++++++++++++- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/lib/common b/lib/common index e4f5e0eff7..b24e3a8a1a 160000 --- a/lib/common +++ b/lib/common @@ -1 +1 @@ -Subproject commit e4f5e0eff7ebfaa96d3ab5ee189ee651fe2ac690 +Subproject commit b24e3a8a1a9349e1a222853031d06968751f36eb diff --git a/lib/providers/device-app-data-provider.ts b/lib/providers/device-app-data-provider.ts index aa20c83ff6..2d36663348 100644 --- a/lib/providers/device-app-data-provider.ts +++ b/lib/providers/device-app-data-provider.ts @@ -31,6 +31,14 @@ export class IOSAppIdentifier extends deviceAppDataBaseLib.DeviceAppDataBase imp return this.getDeviceProjectRootPath(this._deviceProjectRootPath); } + public get deviceSyncZipPath(): string { + if (this.device.isEmulator) { + return undefined; + } else { + return "Library/Application Support/LiveSync/sync.zip"; + } + } + public isLiveSyncSupported(): IFuture { return Future.fromResult(true); } diff --git a/lib/providers/livesync-provider.ts b/lib/providers/livesync-provider.ts index 01aef925f5..99dad8349d 100644 --- a/lib/providers/livesync-provider.ts +++ b/lib/providers/livesync-provider.ts @@ -1,11 +1,13 @@ import * as path from "path"; +import * as temp from "temp"; export class LiveSyncProvider implements ILiveSyncProvider { constructor(private $androidLiveSyncServiceLocator: {factory: Function}, private $iosLiveSyncServiceLocator: {factory: Function}, private $platformService: IPlatformService, private $platformsData: IPlatformsData, - private $logger: ILogger) { } + private $logger: ILogger, + private $childProcess: IChildProcess) { } private static FAST_SYNC_FILE_EXTENSIONS = [".css", ".xml"]; @@ -54,5 +56,25 @@ export class LiveSyncProvider implements ILiveSyncProvider { let fastSyncFileExtensions = LiveSyncProvider.FAST_SYNC_FILE_EXTENSIONS.concat(platformData.fastLivesyncFileExtensions); return _.contains(fastSyncFileExtensions, path.extname(filePath)); } + + public transferFiles(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string, isFullSync: boolean): IFuture { + return (() => { + if (deviceAppData.platform.toLowerCase() === "android" || !deviceAppData.deviceSyncZipPath || !isFullSync) { + deviceAppData.device.fileSystem.transferFiles(deviceAppData, localToDevicePaths).wait(); + } else { + temp.track(); + let tempZip = temp.path({prefix: "sync", suffix: ".zip"}); + this.$logger.trace("Creating zip file: " + tempZip); + this.$childProcess.spawnFromEvent("zip", [ "-r", "-0", tempZip, "app" ], "close", { cwd: path.dirname(projectFilesPath) }).wait(); + + deviceAppData.device.fileSystem.transferFiles(deviceAppData, [{ + getLocalPath: () => tempZip, + getDevicePath: () => deviceAppData.deviceSyncZipPath, + getRelativeToProjectBasePath: () => "../sync.zip", + deviceProjectRootPath: deviceAppData.deviceProjectRootPath + }]).wait(); + } + }).future()(); + } } $injector.register("liveSyncProvider", LiveSyncProvider);