Skip to content

Commit b3b7df8

Browse files
author
Dimitar Kerezov
committed
Remove device-path-provider
1 parent 2c4d0c9 commit b3b7df8

13 files changed

+90
-92
lines changed

lib/bootstrap.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ $injector.require("infoService", "./services/info-service");
100100
$injector.requireCommand("info", "./commands/info");
101101

102102
$injector.require("androidToolsInfo", "./android-tools-info");
103+
$injector.require("devicePathProvider", "./device-path-provider");
103104

104105
$injector.requireCommand("platform|clean", "./commands/platform-clean");
105106

lib/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export const ItunesConnectApplicationTypes = new ItunesConnectApplicationTypesCl
6969
export const SYNC_DIR_NAME = "sync";
7070
export const REMOVEDSYNC_DIR_NAME = "removedsync";
7171
export const FULLSYNC_DIR_NAME = "fullsync";
72+
export const IOS_DEVICE_PROJECT_ROOT_PATH = "Library/Application Support/LiveSync/app";
7273
export const ANGULAR_NAME = "angular";
7374
export const TYPESCRIPT_NAME = "typescript";
7475
export const BUILD_OUTPUT_EVENT_NAME = "buildOutput";

lib/device-path-provider.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { fromWindowsRelativePathToUnix } from "./common/helpers";
2+
import { IOS_DEVICE_PROJECT_ROOT_PATH, SYNC_DIR_NAME, FULLSYNC_DIR_NAME } from "./constants";
3+
import { AndroidDeviceLiveSyncService } from "./services/livesync/android-device-livesync-service";
4+
import * as path from "path";
5+
6+
export class DevicePathProvider implements Mobile.IDevicePathProvider {
7+
constructor(private $mobileHelper: Mobile.IMobileHelper,
8+
private $injector: IInjector,
9+
private $iOSSimResolver: Mobile.IiOSSimResolver) {
10+
}
11+
12+
public async getDeviceBuildInfoDirname(device: Mobile.IDevice, appIdentifier: string): Promise<string> {
13+
let result = "";
14+
if (this.$mobileHelper.isiOSPlatform(device.deviceInfo.platform)) {
15+
result = path.basename(await this.getDeviceProjectRootPath(device, { appIdentifier }));
16+
} else if (this.$mobileHelper.isAndroidPlatform(device.deviceInfo.platform)) {
17+
result = `/data/local/tmp/${appIdentifier}`;
18+
}
19+
20+
return result;
21+
}
22+
23+
public async getDeviceProjectRootPath(device: Mobile.IDevice, options: Mobile.IDeviceProjectRootOptions): Promise<string> {
24+
let projectRoot = "";
25+
if (this.$mobileHelper.isiOSPlatform(device.deviceInfo.platform)) {
26+
if (device.isEmulator) {
27+
let applicationPath = this.$iOSSimResolver.iOSSim.getApplicationPath(device.deviceInfo.identifier, options.appIdentifier);
28+
projectRoot = path.join(applicationPath, "app");
29+
} else {
30+
projectRoot = IOS_DEVICE_PROJECT_ROOT_PATH;
31+
}
32+
} else if (this.$mobileHelper.isAndroidPlatform(device.deviceInfo.platform)) {
33+
const deviceLiveSyncService = this.$injector.resolve<AndroidDeviceLiveSyncService>(AndroidDeviceLiveSyncService, { _device: device });
34+
const hashService = deviceLiveSyncService.getDeviceHashService(options.appIdentifier);
35+
const hashFile = options.syncAllFiles ? null : await hashService.doesShasumFileExistsOnDevice();
36+
const syncFolderName = options.watch || hashFile ? SYNC_DIR_NAME : FULLSYNC_DIR_NAME;
37+
projectRoot = `/data/local/tmp/${options.appIdentifier}/${syncFolderName}`;
38+
}
39+
40+
return fromWindowsRelativePathToUnix(projectRoot);
41+
}
42+
}
43+
44+
$injector.register("devicePathProvider", DevicePathProvider);

lib/providers/device-app-data-provider.ts

Lines changed: 0 additions & 50 deletions
This file was deleted.

lib/services/livesync/android-livesync-service.ts

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import * as path from "path";
22
import { AndroidDeviceLiveSyncService } from "./android-device-livesync-service";
3-
import { APP_FOLDER_NAME, SYNC_DIR_NAME, FULLSYNC_DIR_NAME } from "../../constants";
3+
import { APP_FOLDER_NAME } from "../../constants";
4+
import { PlatformLiveSyncServiceBase } from "./platform-livesync-service-base";
45

5-
export class AndroidLiveSyncService implements IPlatformLiveSyncService {
6+
export class AndroidLiveSyncService extends PlatformLiveSyncServiceBase implements IPlatformLiveSyncService {
67
constructor(private $projectFilesManager: IProjectFilesManager,
78
private $platformsData: IPlatformsData,
89
private $logger: ILogger,
910
private $projectFilesProvider: IProjectFilesProvider,
1011
private $fs: IFileSystem,
11-
private $injector: IInjector) {
12+
private $injector: IInjector,
13+
$devicePathProvider: Mobile.IDevicePathProvider) {
14+
super($devicePathProvider);
1215
}
1316

1417
public async fullSync(syncInfo: IFullSyncInfo): Promise<ILiveSyncResultInfo> {
@@ -17,7 +20,7 @@ export class AndroidLiveSyncService implements IPlatformLiveSyncService {
1720
const deviceLiveSyncService = this.$injector.resolve<AndroidDeviceLiveSyncService>(AndroidDeviceLiveSyncService, { _device: device });
1821
const platformData = this.$platformsData.getPlatformData(device.deviceInfo.platform, projectData);
1922

20-
const deviceAppData = await this.getAppData(syncInfo, deviceLiveSyncService);
23+
const deviceAppData = await this.getAppData(syncInfo);
2124
await deviceLiveSyncService.beforeLiveSyncAction(deviceAppData);
2225

2326
const projectFilesPath = path.join(platformData.appDestinationDirectoryPath, APP_FOLDER_NAME);
@@ -34,8 +37,7 @@ export class AndroidLiveSyncService implements IPlatformLiveSyncService {
3437
public async liveSyncWatchAction(device: Mobile.IDevice, liveSyncInfo: ILiveSyncWatchInfo): Promise<ILiveSyncResultInfo> {
3538
const projectData = liveSyncInfo.projectData;
3639
const syncInfo = _.merge<IFullSyncInfo>({ device, watch: true }, liveSyncInfo);
37-
const deviceLiveSyncService = this.$injector.resolve<AndroidDeviceLiveSyncService>(AndroidDeviceLiveSyncService, { _device: device });
38-
const deviceAppData = await this.getAppData(syncInfo, deviceLiveSyncService);
40+
const deviceAppData = await this.getAppData(syncInfo);
3941

4042
let modifiedLocalToDevicePaths: Mobile.ILocalToDevicePathData[] = [];
4143
if (liveSyncInfo.filesToSync.length) {
@@ -95,20 +97,5 @@ export class AndroidLiveSyncService implements IPlatformLiveSyncService {
9597
await deviceAppData.device.fileSystem.transferFiles(deviceAppData, localToDevicePaths);
9698
}
9799
}
98-
99-
private async getAppData(syncInfo: IFullSyncInfo, deviceLiveSyncService: IAndroidNativeScriptDeviceLiveSyncService): Promise<Mobile.IDeviceAppData> {
100-
return {
101-
appIdentifier: syncInfo.device.deviceInfo.identifier,
102-
device: syncInfo.device,
103-
platform: syncInfo.device.deviceInfo.platform,
104-
getDeviceProjectRootPath: async () => {
105-
const hashService = deviceLiveSyncService.getDeviceHashService(syncInfo.device.deviceInfo.identifier);
106-
const hashFile = syncInfo.syncAllFiles ? null : await hashService.doesShasumFileExistsOnDevice();
107-
const syncFolderName = syncInfo.watch || hashFile ? SYNC_DIR_NAME : FULLSYNC_DIR_NAME;
108-
return `/data/local/tmp/${syncInfo.device.deviceInfo.identifier}/${syncFolderName}`;
109-
},
110-
isLiveSyncSupported: async () => true
111-
};
112-
}
113100
}
114101
$injector.register("androidLiveSyncService", AndroidLiveSyncService);

lib/services/livesync/ios-livesync-service.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
import * as deviceAppDataIdentifiers from "../../providers/device-app-data-provider";
21
import * as path from "path";
32
import * as iosdls from "./ios-device-livesync-service";
43
import * as temp from "temp";
4+
import { PlatformLiveSyncServiceBase } from "./platform-livesync-service-base";
55
// import * as uuid from "uuid";
66

7-
export class IOSLiveSyncService implements IPlatformLiveSyncService {
8-
constructor(
9-
private $devicesService: Mobile.IDevicesService,
7+
export class IOSLiveSyncService extends PlatformLiveSyncServiceBase implements IPlatformLiveSyncService {
8+
constructor(private $devicesService: Mobile.IDevicesService,
109
private $projectFilesManager: IProjectFilesManager,
1110
private $platformsData: IPlatformsData,
1211
private $logger: ILogger,
1312
private $projectFilesProvider: IProjectFilesProvider,
1413
private $fs: IFileSystem,
15-
private $injector: IInjector) {
14+
private $injector: IInjector,
15+
$devicePathProvider: Mobile.IDevicePathProvider) {
16+
super($devicePathProvider);
1617
}
1718

1819
/*
@@ -25,8 +26,7 @@ export class IOSLiveSyncService implements IPlatformLiveSyncService {
2526
const projectData = syncInfo.projectData;
2627
const device = syncInfo.device;
2728
const platformData = this.$platformsData.getPlatformData(device.deviceInfo.platform, projectData);
28-
const deviceAppData = this.$injector.resolve(deviceAppDataIdentifiers.IOSAppIdentifier,
29-
{ _appIdentifier: projectData.projectId, device, platform: device.deviceInfo.platform });
29+
const deviceAppData = await this.getAppData(syncInfo);
3030
const projectFilesPath = path.join(platformData.appDestinationDirectoryPath, "app");
3131

3232
if (device.isEmulator) {
@@ -70,8 +70,8 @@ export class IOSLiveSyncService implements IPlatformLiveSyncService {
7070

7171
public async liveSyncWatchAction(device: Mobile.IDevice, liveSyncInfo: ILiveSyncWatchInfo): Promise<ILiveSyncResultInfo> {
7272
const projectData = liveSyncInfo.projectData;
73-
const deviceAppData = this.$injector.resolve(deviceAppDataIdentifiers.IOSAppIdentifier,
74-
{ _appIdentifier: projectData.projectId, device, platform: device.deviceInfo.platform });
73+
const syncInfo = _.merge<IFullSyncInfo>({ device, watch: true }, liveSyncInfo);
74+
const deviceAppData = await this.getAppData(syncInfo);
7575
let modifiedLocalToDevicePaths: Mobile.ILocalToDevicePathData[] = [];
7676

7777
if (liveSyncInfo.isRebuilt) {

lib/services/livesync/livesync-service.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,12 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
185185

186186
await this.ensureLatestAppPackageIsInstalledOnDevice(device, preparedPlatforms, rebuiltInformation, projectData, deviceDescriptor);
187187

188-
const liveSyncResultInfo = await this.getLiveSyncService(platform).fullSync({ projectData, device, syncAllFiles: liveSyncData.watchAllFiles, useLiveEdit: liveSyncData.useLiveEdit });
188+
const liveSyncResultInfo = await this.getLiveSyncService(platform).fullSync({
189+
projectData, device,
190+
syncAllFiles: liveSyncData.watchAllFiles,
191+
useLiveEdit: liveSyncData.useLiveEdit,
192+
watch: !liveSyncData.skipWatcher
193+
});
189194
await this.refreshApplication(projectData, liveSyncResultInfo);
190195
} catch (err) {
191196
this.$logger.warn(`Unable to apply changes on device: ${err.deviceIdentifier}. Error is: ${err.message}.`);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export class PlatformLiveSyncServiceBase {
2+
constructor(
3+
private $devicePathProvider: Mobile.IDevicePathProvider,
4+
) {
5+
}
6+
7+
protected async getAppData(syncInfo: IFullSyncInfo): Promise<Mobile.IDeviceAppData> {
8+
const deviceProjectRootOptions: Mobile.IDeviceProjectRootOptions = _.assign({ appIdentifier: syncInfo.projectData.projectId }, syncInfo);
9+
return {
10+
appIdentifier: syncInfo.projectData.projectId,
11+
device: syncInfo.device,
12+
platform: syncInfo.device.deviceInfo.platform,
13+
getDeviceProjectRootPath: () => this.$devicePathProvider.getDeviceProjectRootPath(syncInfo.device, deviceProjectRootOptions),
14+
isLiveSyncSupported: async () => true
15+
};
16+
}
17+
}

lib/services/platform-service.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ export class PlatformService extends EventEmitter implements IPlatformService {
3434
private $projectFilesManager: IProjectFilesManager,
3535
private $mobileHelper: Mobile.IMobileHelper,
3636
private $hostInfo: IHostInfo,
37+
private $devicePathProvider: Mobile.IDevicePathProvider,
3738
private $xmlValidator: IXmlValidator,
3839
private $npm: INodePackageManager,
3940
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
40-
private $deviceAppDataFactory: Mobile.IDeviceAppDataFactory,
4141
private $projectChangesService: IProjectChangesService,
4242
private $analyticsService: IAnalyticsService) {
4343
super();
@@ -547,8 +547,9 @@ export class PlatformService extends EventEmitter implements IPlatformService {
547547
}
548548

549549
private async getDeviceBuildInfoFilePath(device: Mobile.IDevice, projectData: IProjectData): Promise<string> {
550-
let deviceAppData = this.$deviceAppDataFactory.create(projectData.projectId, device.deviceInfo.platform, device);
551-
let deviceRootPath = path.dirname(await deviceAppData.getDeviceProjectRootPath());
550+
// let deviceAppData = this.$deviceAppDataFactory.create(projectData.projectId, device.deviceInfo.platform, device);
551+
// let deviceRootPath = path.dirname(await deviceAppData.getDeviceProjectRootPath());
552+
const deviceRootPath = await this.$devicePathProvider.getDeviceBuildInfoDirname(device, projectData.projectId);
552553
return helpers.fromWindowsRelativePathToUnix(path.join(deviceRootPath, buildInfoFileName));
553554
}
554555

test/npm-support.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { DeviceAppDataFactory } from "../lib/common/mobile/device-app-data/devic
2020
import { LocalToDevicePathDataFactory } from "../lib/common/mobile/local-to-device-path-data-factory";
2121
import { MobileHelper } from "../lib/common/mobile/mobile-helper";
2222
import { ProjectFilesProvider } from "../lib/providers/project-files-provider";
23-
import { DeviceAppDataProvider } from "../lib/providers/device-app-data-provider";
2423
import { MobilePlatformsCapabilities } from "../lib/mobile-platforms-capabilities";
2524
import { DevicePlatformsConstants } from "../lib/common/mobile/device-platforms-constants";
2625
import { XmlValidator } from "../lib/xml-validator";
@@ -74,7 +73,6 @@ function createTestInjector(): IInjector {
7473
testInjector.register("localToDevicePathDataFactory", LocalToDevicePathDataFactory);
7574
testInjector.register("mobileHelper", MobileHelper);
7675
testInjector.register("projectFilesProvider", ProjectFilesProvider);
77-
testInjector.register("deviceAppDataProvider", DeviceAppDataProvider);
7876
testInjector.register("mobilePlatformsCapabilities", MobilePlatformsCapabilities);
7977
testInjector.register("devicePlatformsConstants", DevicePlatformsConstants);
8078
testInjector.register("xmlValidator", XmlValidator);

0 commit comments

Comments
 (0)