Skip to content

Commit c2434a0

Browse files
Fatme HavaluovaFatme Havaluova
authored andcommitted
Integrate iOS simulator with device discovery
1 parent 0b77553 commit c2434a0

26 files changed

+482
-626
lines changed

lib/bootstrap.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ $injector.require("analyticsSettingsService", "./services/analytics-settings-ser
2525

2626
$injector.require("emulatorSettingsService", "./services/emulator-settings-service");
2727

28-
$injector.require("usbLiveSyncService", "./services/usb-livesync-service");
29-
3028
$injector.require("platformCommandParameter", "./platform-command-param");
3129
$injector.requireCommand("create", "./commands/create-project");
3230
$injector.requireCommand("platform|*list", "./commands/list-platforms");
@@ -64,6 +62,8 @@ $injector.require("commandsServiceProvider", "./providers/commands-service-provi
6462
$injector.require("deviceAppDataProvider", "./providers/device-app-data-provider");
6563

6664
$injector.require("deviceLogProvider", "./common/mobile/device-log-provider");
65+
$injector.require("liveSyncProvider", "./providers/livesync-provider");
66+
$injector.require("projectFilesProvider", "./providers/project-files-provider");
6767

6868
$injector.require("broccoliBuilder", "./tools/broccoli/builder");
6969
$injector.require("nodeModulesTree", "./tools/broccoli/trees/node-modules-tree");
@@ -80,12 +80,13 @@ $injector.requireCommand("install", "./commands/install");
8080
$injector.require("initService", "./services/init-service");
8181
$injector.requireCommand("init", "./commands/init");
8282

83-
$injector.require("projectFilesManager", "./services/project-files-manager");
84-
$injector.requireCommand("livesync", "./commands/livesync");
8583
$injector.require("androidToolsInfo", "./android-tools-info");
8684

87-
$injector.require("iosUsbLiveSyncServiceLocator", "./services/usb-livesync-service");
88-
$injector.require("androidUsbLiveSyncServiceLocator", "./services/usb-livesync-service");
85+
$injector.requireCommand("livesync", "./commands/livesync");
86+
$injector.require("usbLiveSyncService", "./services/livesync/livesync-service"); // The name is used in https://github.com/NativeScript/nativescript-dev-typescript
87+
$injector.require("iosLiveSyncServiceLocator", "./services/livesync/ios-livesync-service");
88+
$injector.require("androidLiveSyncServiceLocator", "./services/livesync/android-livesync-service");
89+
8990
$injector.require("sysInfo", "./sys-info");
9091

9192
$injector.require("iOSNotificationService", "./services/ios-notification-service");

lib/commands/livesync.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
export class LivesyncCommand implements ICommand {
55
constructor(private $logger: ILogger,
6-
private $usbLiveSyncService: IUsbLiveSyncService,
6+
private $usbLiveSyncService: ILiveSyncService,
77
private $mobileHelper: Mobile.IMobileHelper,
88
private $options: IOptions,
99
private $errors: IErrors) { }

lib/common

Submodule common updated 38 files

lib/declarations.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,10 @@ interface IOpener {
5454
open(target: string, appname: string): void;
5555
}
5656

57-
interface IUsbLiveSyncService {
57+
interface ILiveSyncService {
5858
liveSync(platform: string): IFuture<void>;
5959
}
6060

61-
interface IiOSUsbLiveSyncService extends IPlatformSpecificUsbLiveSyncService {
62-
sendPageReloadMessageToSimulator(): IFuture<void>;
63-
}
64-
6561
interface IOptions extends ICommonOptions {
6662
frameworkPath: string;
6763
frameworkName: string;
@@ -90,10 +86,6 @@ interface IOptions extends ICommonOptions {
9086
baseConfig: string;
9187
}
9288

93-
interface IProjectFilesManager {
94-
processPlatformSpecificFiles(directoryPath: string, platform: string, excludedDirs?: string[]): IFuture<void>;
95-
}
96-
9789
interface IInitService {
9890
initialize(): IFuture<void>;
9991
}

lib/definitions/project.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ interface IPlatformProjectServiceBase {
4848

4949
interface IBuildConfig {
5050
runSbGenerator?: boolean;
51+
buildForDevice?: boolean;
5152
}
5253

5354
interface IPlatformProjectService {

lib/device-sockets/ios/socket-request-executor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"use strict";
33

44
import * as helpers from "../../common/helpers";
5-
import * as iOSProxyServices from "../../common/mobile/ios/ios-proxy-services";
5+
import * as iOSProxyServices from "../../common/mobile/ios/device/ios-proxy-services";
66

77
export class IOSSocketRequestExecutor implements IiOSSocketRequestExecutor {
88
constructor(private $errors: IErrors,

lib/platforms-data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class PlatformsData implements IPlatformsData {
1818
}
1919

2020
public getPlatformData(platform: string): IPlatformData {
21-
return this.platformsData[platform];
21+
return this.platformsData[platform.toLowerCase()];
2222
}
2323

2424
public get availablePlatforms(): any {

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

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,63 @@
22
"use strict";
33
import * as deviceAppDataBaseLib from "../common/mobile/device-app-data/device-app-data-base";
44
import Future = require("fibers/future");
5+
import * as path from "path";
56

67
export class IOSAppIdentifier extends deviceAppDataBaseLib.DeviceAppDataBase implements Mobile.IDeviceAppData {
7-
private static DEVICE_PROJECT_ROOT_PATH = "Library/Application Support/LiveSync";
8+
private static DEVICE_PROJECT_ROOT_PATH = "Library/Application Support/LiveSync/app";
9+
private _deviceProjectRootPath: string = null;
810

9-
constructor(_appIdentifier: string) {
11+
constructor(_appIdentifier: string,
12+
public device: Mobile.IDevice,
13+
public platform: string,
14+
private $iOSSimResolver: Mobile.IiOSSimResolver) {
1015
super(_appIdentifier);
1116
}
1217

1318
public get deviceProjectRootPath(): string {
14-
return this.getDeviceProjectRootPath(IOSAppIdentifier.DEVICE_PROJECT_ROOT_PATH);
19+
if (!this._deviceProjectRootPath) {
20+
if (this.device.isEmulator) {
21+
let applicationPath = this.$iOSSimResolver.iOSSim.getApplicationPath(this.device.deviceInfo.identifier, this.appIdentifier);
22+
this._deviceProjectRootPath = path.join(applicationPath, "app");
23+
} else {
24+
this._deviceProjectRootPath = IOSAppIdentifier.DEVICE_PROJECT_ROOT_PATH;
25+
}
26+
}
27+
28+
return this.getDeviceProjectRootPath(this._deviceProjectRootPath);
1529
}
1630

17-
public isLiveSyncSupported(device: Mobile.IDevice): IFuture<boolean> {
31+
public isLiveSyncSupported(): IFuture<boolean> {
1832
return Future.fromResult(true);
1933
}
2034
}
2135

2236
export class AndroidAppIdentifier extends deviceAppDataBaseLib.DeviceAppDataBase implements Mobile.IDeviceAppData {
23-
constructor(_appIdentifier: string) {
37+
constructor(_appIdentifier: string,
38+
public device: Mobile.IDevice,
39+
public platform: string,
40+
private $options: IOptions) {
2441
super(_appIdentifier);
2542
}
2643

2744
public get deviceProjectRootPath(): string {
28-
let options: IOptions = $injector.resolve("options");
29-
let syncFolderName = options.watch ? "sync" : "fullsync";
45+
let syncFolderName = this.$options.watch ? "sync" : "fullsync";
3046
return `/data/local/tmp/${this.appIdentifier}/${syncFolderName}`;
3147
}
3248

33-
public isLiveSyncSupported(device: Mobile.IDevice): IFuture<boolean> {
49+
public isLiveSyncSupported(): IFuture<boolean> {
3450
return Future.fromResult(true);
3551
}
3652
}
3753

38-
export class AndroidCompanionAppIdentifier extends deviceAppDataBaseLib.CompanionDeviceAppDataBase implements Mobile.IDeviceAppData {
39-
private static APP_IDENTIFIER = "com.telerik.NativeScript";
40-
41-
constructor() {
42-
super(AndroidCompanionAppIdentifier.APP_IDENTIFIER);
43-
}
44-
45-
public get deviceProjectRootPath(): string {
46-
return `/mnt/sdcard/Android/data/${this.appIdentifier}/files/12590FAA-5EDD-4B12-856D-F52A0A1599F2`;
47-
}
48-
}
49-
5054
export class DeviceAppDataProvider implements Mobile.IDeviceAppDataProvider {
5155
public createFactoryRules(): IDictionary<Mobile.IDeviceAppDataFactoryRule> {
5256
return {
5357
iOS: {
5458
vanilla: IOSAppIdentifier
5559
},
5660
Android: {
57-
vanilla: AndroidAppIdentifier,
58-
companion: AndroidCompanionAppIdentifier
61+
vanilla: AndroidAppIdentifier
5962
}
6063
};
6164
}

lib/providers/livesync-provider.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
///<reference path="../.d.ts"/>
2+
"use strict";
3+
4+
import * as path from "path";
5+
6+
export class LiveSyncProvider implements ILiveSyncProvider {
7+
constructor(private $androidLiveSyncServiceLocator: {factory: Function},
8+
private $iosLiveSyncServiceLocator: {factory: Function},
9+
private $platformService: IPlatformService,
10+
private $platformsData: IPlatformsData,
11+
private $logger: ILogger) { }
12+
13+
private static FAST_SYNC_FILE_EXTENSIONS = [".css", ".xml"];
14+
15+
public get platformSpecificLiveSyncServices(): IDictionary<any> {
16+
return {
17+
android: (_device: Mobile.IDevice, $injector: IInjector): IPlatformLiveSyncService => {
18+
return $injector.resolve(this.$androidLiveSyncServiceLocator.factory, {_device: _device});
19+
},
20+
ios: (_device: Mobile.IDevice, $injector: IInjector) => {
21+
return $injector.resolve(this.$iosLiveSyncServiceLocator.factory, {_device: _device});
22+
}
23+
};
24+
}
25+
26+
public buildForDevice(device: Mobile.IDevice): IFuture<string> {
27+
return (() => {
28+
this.$platformService.buildPlatform(device.deviceInfo.platform, {buildForDevice: !device.isEmulator}).wait();
29+
let platformData = this.$platformsData.getPlatformData(device.deviceInfo.platform);
30+
if (device.isEmulator) {
31+
return this.$platformService.getLatestApplicationPackageForEmulator(platformData).wait().packageName;
32+
}
33+
34+
return this.$platformService.getLatestApplicationPackageForDevice(platformData).wait().packageName;
35+
}).future<string>()();
36+
}
37+
38+
public preparePlatformForSync(platform: string): IFuture<void> {
39+
return (() => {
40+
if (!this.$platformService.preparePlatform(platform).wait()) {
41+
this.$logger.out("Verify that listed files are well-formed and try again the operation.");
42+
}
43+
}).future<void>()();
44+
}
45+
46+
public canExecuteFastSync(filePath: string): boolean {
47+
return _.contains(LiveSyncProvider.FAST_SYNC_FILE_EXTENSIONS, path.extname(filePath));
48+
}
49+
}
50+
$injector.register("liveSyncProvider", LiveSyncProvider);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
///<reference path="../.d.ts"/>
2+
"use strict";
3+
4+
import minimatch = require("minimatch");
5+
import * as constants from "../constants";
6+
import * as path from "path";
7+
8+
export class ProjectFilesProvider implements IProjectFilesProvider {
9+
constructor(private $platformsData: IPlatformsData,
10+
private $projectData: IProjectData) { }
11+
12+
private static INTERNAL_NONPROJECT_FILES = [ "**/*.ts" ];
13+
14+
public mapFilePath(filePath: string, platform: string): string {
15+
let platformData = this.$platformsData.getPlatformData(platform.toLowerCase());
16+
let projectFilesPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME);
17+
let mappedFilePath = path.join(projectFilesPath, path.relative(path.join(this.$projectData.projectDir, constants.APP_FOLDER_NAME), filePath));
18+
19+
let appResourcesDirectoryPath = path.join(constants.APP_FOLDER_NAME, constants.APP_RESOURCES_FOLDER_NAME);
20+
let platformSpecificAppResourcesDirectoryPath = path.join(appResourcesDirectoryPath, platformData.normalizedPlatformName);
21+
if (filePath.indexOf(appResourcesDirectoryPath) > -1 && filePath.indexOf(platformSpecificAppResourcesDirectoryPath) === -1) {
22+
return null;
23+
}
24+
if (filePath.indexOf(platformSpecificAppResourcesDirectoryPath) > -1) {
25+
let appResourcesRelativePath = path.relative(path.join(this.$projectData.projectDir, constants.APP_FOLDER_NAME, constants.APP_RESOURCES_FOLDER_NAME,
26+
platformData.normalizedPlatformName), filePath);
27+
mappedFilePath = path.join(platformData.platformProjectService.getAppResourcesDestinationDirectoryPath().wait(), appResourcesRelativePath);
28+
}
29+
30+
return mappedFilePath;
31+
}
32+
33+
public isFileExcluded(filePath: string): boolean {
34+
return !!_.find(ProjectFilesProvider.INTERNAL_NONPROJECT_FILES, (pattern) => minimatch(filePath, pattern, { nocase: true }));
35+
}
36+
}
37+
$injector.register("projectFilesProvider", ProjectFilesProvider);

0 commit comments

Comments
 (0)