-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathios-livesync-service.ts
78 lines (65 loc) · 3.19 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
77
78
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, TNS_MODULES_FOLDER_NAME } from "../../constants";
export class IOSLiveSyncService extends PlatformLiveSyncServiceBase implements IPlatformLiveSyncService {
constructor(protected $fs: IFileSystem,
protected $platformsData: IPlatformsData,
protected $projectFilesManager: IProjectFilesManager,
private $injector: IInjector,
$devicePathProvider: IDevicePathProvider,
$logger: ILogger,
$projectFilesProvider: IProjectFilesProvider,
private $iOSDebuggerPortService: IIOSDebuggerPortService,
) {
super($fs, $logger, $platformsData, $projectFilesManager, $devicePathProvider, $projectFilesProvider);
}
public async fullSync(syncInfo: IFullSyncInfo): Promise<ILiveSyncResultInfo> {
const device = syncInfo.device;
if (device.isEmulator) {
return super.fullSync(syncInfo);
}
this.$iOSDebuggerPortService.attachToDebuggerPortFoundEvent(device);
const projectData = syncInfo.projectData;
const platformData = this.$platformsData.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" });
const tempApp = temp.mkdirSync("app");
this.$logger.trace("Creating zip file: " + tempZip);
this.$fs.copyFile(path.join(path.dirname(projectFilesPath), `${APP_FOLDER_NAME}/*`), tempApp);
if (!syncInfo.syncAllFiles) {
this.$logger.info("Skipping node_modules folder! Use the syncAllFiles option to sync files from this folder.");
this.$fs.deleteDirectory(path.join(tempApp, TNS_MODULES_FOLDER_NAME));
}
await this.$fs.zipFiles(tempZip, this.$fs.enumerateFilesInDirectorySync(tempApp), (res) => {
return path.join(APP_FOLDER_NAME, path.relative(tempApp, res));
});
await device.fileSystem.transferFiles(deviceAppData, [{
getLocalPath: () => tempZip,
getDevicePath: () => deviceAppData.deviceSyncZipPath,
getRelativeToProjectBasePath: () => "../sync.zip",
deviceProjectRootPath: await deviceAppData.getDeviceProjectRootPath()
}]);
return {
deviceAppData,
isFullSync: true,
modifiedFilesData: []
};
}
public liveSyncWatchAction(device: Mobile.IDevice, liveSyncInfo: ILiveSyncWatchInfo): Promise<ILiveSyncResultInfo> {
if (liveSyncInfo.isReinstalled) {
// 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.
return this.fullSync({ projectData: liveSyncInfo.projectData, device, syncAllFiles: liveSyncInfo.syncAllFiles, watch: true });
} else {
return super.liveSyncWatchAction(device, liveSyncInfo);
}
}
protected _getDeviceLiveSyncService(device: Mobile.IDevice): INativeScriptDeviceLiveSyncService {
const service = this.$injector.resolve<INativeScriptDeviceLiveSyncService>(IOSDeviceLiveSyncService, { _device: device });
return service;
}
}
$injector.register("iOSLiveSyncService", IOSLiveSyncService);