Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit 6bcc88c

Browse files
Merge pull request #889 from telerik/milanov/remove-ios-native-dependencies
Remove ios native dependencies
2 parents abaed01 + 32ecf38 commit 6bcc88c

28 files changed

+511
-2837
lines changed
Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1-
import iOSProxyServices = require("../../../mobile/ios/device/ios-proxy-services");
21
import * as path from "path";
32
import * as shell from "shelljs";
43
let osenv = require("osenv");
5-
import { LiveSyncConstants } from "../../../constants";
6-
import { TARGET_FRAMEWORK_IDENTIFIERS } from "../../../constants";
4+
import * as constants from "../../../constants";
75

86
export class IOSLiveSyncService implements IDeviceLiveSyncService {
97
private get $project(): any {
108
return this.$injector.resolve("project");
119
}
1210

13-
constructor(private _device: Mobile.IiOSDevice,
11+
constructor(private _device: Mobile.IDevice,
1412
private $fs: IFileSystem,
1513
private $injector: IInjector,
1614
private $logger: ILogger,
17-
private $errors: IErrors) { }
15+
private $errors: IErrors,
16+
private $options: ICommonOptions,
17+
private $iosDeviceOperations: IIOSDeviceOperations) {
18+
// If we execute livesync with --watch we do not want to dispose the $iosDeviceOperations.
19+
this.$iosDeviceOperations.setShouldDispose(!this.$options.watch);
20+
}
1821

19-
private get device(): Mobile.IiOSDevice {
22+
private get device(): Mobile.IDevice {
2023
return this._device;
2124
}
2225

@@ -34,6 +37,7 @@ export class IOSLiveSyncService implements IDeviceLiveSyncService {
3437
if (!parsed) {
3538
break;
3639
}
40+
3741
guid = parsed[1];
3842
}
3943

@@ -42,26 +46,31 @@ export class IOSLiveSyncService implements IDeviceLiveSyncService {
4246
}
4347

4448
let sourcePath = await deviceAppData.getDeviceProjectRootPath();
45-
let destinationPath = path.join(simulatorCachePath, guid, LiveSyncConstants.IOS_PROJECT_PATH);
49+
let destinationPath = path.join(simulatorCachePath, guid, constants.LiveSyncConstants.IOS_PROJECT_PATH);
4650

4751
this.$logger.trace(`Transferring from ${sourcePath} to ${destinationPath}`);
4852
shell.cp("-Rf", path.join(sourcePath, "*"), destinationPath);
4953

50-
let cfBundleExecutable = `${this.$project.projectData.Framework}${this.$project.projectData.FrameworkVersion.split(".").join("")}`;
51-
await this.device.applicationManager.restartApplication(deviceAppData.appIdentifier, cfBundleExecutable);
54+
await this.device.applicationManager.restartApplication(deviceAppData.appIdentifier);
5255
} else {
53-
this.device.fileSystem.deleteFile("/Documents/AppBuilder/ServerInfo.plist", deviceAppData.appIdentifier);
54-
let notificationProxyClient = this.$injector.resolve(iOSProxyServices.NotificationProxyClient, { device: this.device });
55-
let notification = this.$project.projectData.Framework === TARGET_FRAMEWORK_IDENTIFIERS.NativeScript ? "com.telerik.app.refreshApp" : "com.telerik.app.refreshWebView";
56-
notificationProxyClient.postNotification(notification);
57-
notificationProxyClient.closeSocket();
56+
await this.device.fileSystem.deleteFile("/Documents/AppBuilder/ServerInfo.plist", deviceAppData.appIdentifier);
57+
let notification = this.$project.projectData.Framework === constants.TARGET_FRAMEWORK_IDENTIFIERS.NativeScript ? "com.telerik.app.refreshApp" : "com.telerik.app.refreshWebView";
58+
const notificationData = {
59+
deviceId: this.device.deviceInfo.identifier,
60+
notificationName: notification,
61+
commandType: constants.IOS_POST_NOTIFICATION_COMMAND_TYPE
62+
};
63+
await this.$iosDeviceOperations.postNotification([notificationData]);
5864
}
5965
}
6066

6167
public async removeFiles(appIdentifier: string, localToDevicePaths: Mobile.ILocalToDevicePathData[]): Promise<void> {
62-
localToDevicePaths
63-
.map(localToDevicePath => localToDevicePath.getDevicePath())
64-
.forEach(deviceFilePath => this.device.fileSystem.deleteFile(deviceFilePath, appIdentifier));
68+
const devicePaths = localToDevicePaths.map(localToDevicePath => localToDevicePath.getDevicePath());
69+
70+
for (let deviceFilePath of devicePaths) {
71+
await this.device.fileSystem.deleteFile(deviceFilePath, appIdentifier);
72+
}
6573
}
6674
}
75+
6776
$injector.register("iosLiveSyncServiceLocator", { factory: IOSLiveSyncService });

bootstrap.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,7 @@ $injector.requireCommand("device|list-files", "./commands/device/list-files");
5454
$injector.requireCommand("device|get-file", "./commands/device/get-file");
5555
$injector.requireCommand("device|put-file", "./commands/device/put-file");
5656

57-
$injector.require("iOSCore", "./mobile/ios/device/ios-core");
58-
$injector.require("coreFoundation", "./mobile/ios/device/ios-core");
59-
$injector.require("mobileDevice", "./mobile/ios/device/ios-core");
60-
$injector.require("plistService", "./mobile/ios/device/ios-core");
61-
62-
$injector.require("installationProxyClient", "./mobile/ios/device/ios-proxy-services");
63-
$injector.require("notificationProxyClient", "./mobile/ios/device/ios-proxy-services");
64-
$injector.require("houseArrestClient", "./mobile/ios/device/ios-proxy-services");
65-
$injector.require("gdbServer", "./mobile/ios/device/ios-core");
57+
$injector.require("iosDeviceOperations", "./mobile/ios/device/ios-device-operations");
6658

6759
$injector.require("deviceFound", "./mobile/mobile-core/device-discovery");
6860
$injector.require("deviceLost", "./mobile/mobile-core/device-discovery");

commands/device/device-log-stream.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ export class OpenDeviceLogStreamCommand implements ICommand {
2424
await this.$devicesService.execute(action);
2525
}
2626
}
27+
2728
$injector.registerCommand("device|log", OpenDeviceLogStreamCommand);

commands/device/get-file.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
export class GetFileCommand implements ICommand {
22
constructor(private $devicesService: Mobile.IDevicesService,
33
private $stringParameter: ICommandParameter,
4+
private $project: Project.IProjectBase,
5+
private $errors: IErrors,
46
private $options: ICommonOptions) { }
57

6-
allowedParameters: ICommandParameter[] = [this.$stringParameter];
8+
public allowedParameters: ICommandParameter[] = [this.$stringParameter, this.$stringParameter];
79

810
public async execute(args: string[]): Promise<void> {
911
await this.$devicesService.initialize({ deviceId: this.$options.device, skipInferPlatform: true });
12+
let appIdentifier = args[1];
1013

11-
let action = (device: Mobile.IDevice) => device.fileSystem.getFile(args[0], this.$options.file);
14+
if (!appIdentifier && !this.$project.projectData) {
15+
this.$errors.failWithoutHelp("Please enter application identifier or execute this command in project.");
16+
}
17+
18+
appIdentifier = appIdentifier || this.$project.projectData.AppIdentifier;
19+
20+
let action = (device: Mobile.IDevice) => device.fileSystem.getFile(args[0], appIdentifier, this.$options.file);
1221
await this.$devicesService.execute(action);
1322
}
1423
}
24+
1525
$injector.registerCommand("device|get-file", GetFileCommand);

commands/device/list-devices.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export class ListDevicesCommand implements ICommand {
66
private $stringParameter: ICommandParameter,
77
private $options: ICommonOptions) { }
88

9-
allowedParameters = [this.$stringParameter];
9+
public allowedParameters = [this.$stringParameter];
1010

1111
public async execute(args: string[]): Promise<void> {
1212
let index = 1;
@@ -34,32 +34,35 @@ export class ListDevicesCommand implements ICommand {
3434
}
3535
}
3636
}
37+
3738
$injector.registerCommand("device|*list", ListDevicesCommand);
3839

3940
class ListAndroidDevicesCommand implements ICommand {
4041
constructor(private $injector: IInjector,
4142
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants) { }
4243

43-
allowedParameters: ICommandParameter[] = [];
44+
public allowedParameters: ICommandParameter[] = [];
4445

4546
public async execute(args: string[]): Promise<void> {
4647
let listDevicesCommand: ICommand = this.$injector.resolve(ListDevicesCommand);
4748
let platform = this.$devicePlatformsConstants.Android;
4849
await listDevicesCommand.execute([platform]);
4950
}
5051
}
52+
5153
$injector.registerCommand("device|android", ListAndroidDevicesCommand);
5254

5355
class ListiOSDevicesCommand implements ICommand {
5456
constructor(private $injector: IInjector,
5557
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants) { }
5658

57-
allowedParameters: ICommandParameter[] = [];
59+
public allowedParameters: ICommandParameter[] = [];
5860

5961
public async execute(args: string[]): Promise<void> {
6062
let listDevicesCommand: ICommand = this.$injector.resolve(ListDevicesCommand);
6163
let platform = this.$devicePlatformsConstants.iOS;
6264
await listDevicesCommand.execute([platform]);
6365
}
6466
}
67+
6568
$injector.registerCommand("device|ios", ListiOSDevicesCommand);

commands/device/list-files.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
export class ListFilesCommand implements ICommand {
22
constructor(private $devicesService: Mobile.IDevicesService,
33
private $stringParameter: ICommandParameter,
4-
private $options: ICommonOptions) { }
4+
private $options: ICommonOptions,
5+
private $project: Project.IProjectBase,
6+
private $errors: IErrors) { }
57

6-
allowedParameters: ICommandParameter[] = [this.$stringParameter];
8+
public allowedParameters: ICommandParameter[] = [this.$stringParameter, this.$stringParameter];
79

810
public async execute(args: string[]): Promise<void> {
911
await this.$devicesService.initialize({ deviceId: this.$options.device, skipInferPlatform: true });
12+
const pathToList = args[0];
13+
let appIdentifier = args[1];
1014

11-
let action = (device: Mobile.IDevice) => device.fileSystem.listFiles(args[0]);
15+
if (!appIdentifier && !this.$project.projectData) {
16+
this.$errors.failWithoutHelp("Please enter application identifier or execute this command in project.");
17+
}
18+
19+
appIdentifier = appIdentifier || this.$project.projectData.AppIdentifier;
20+
21+
let action = (device: Mobile.IDevice) => device.fileSystem.listFiles(pathToList, appIdentifier);
1222
await this.$devicesService.execute(action);
1323
}
1424
}
25+
1526
$injector.registerCommand("device|list-files", ListFilesCommand);

commands/device/put-file.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
export class PutFileCommand implements ICommand {
22
constructor(private $devicesService: Mobile.IDevicesService,
33
private $stringParameter: ICommandParameter,
4-
private $options: ICommonOptions) { }
4+
private $options: ICommonOptions,
5+
private $project: Project.IProjectBase,
6+
private $errors: IErrors) { }
57

6-
allowedParameters: ICommandParameter[] = [this.$stringParameter, this.$stringParameter];
8+
allowedParameters: ICommandParameter[] = [this.$stringParameter, this.$stringParameter, this.$stringParameter];
79

810
public async execute(args: string[]): Promise<void> {
911
await this.$devicesService.initialize({ deviceId: this.$options.device, skipInferPlatform: true });
12+
let appIdentifier = args[2];
1013

11-
let action = (device: Mobile.IDevice) => device.fileSystem.putFile(args[0], args[2], args[1]);
14+
if (!appIdentifier && !this.$project.projectData) {
15+
this.$errors.failWithoutHelp("Please enter application identifier or execute this command in project.");
16+
}
17+
18+
appIdentifier = appIdentifier || this.$project.projectData.AppIdentifier;
19+
let action = (device: Mobile.IDevice) => device.fileSystem.putFile(args[0], args[1], appIdentifier);
1220
await this.$devicesService.execute(action);
1321
}
1422
}

commands/device/run-application.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export class RunApplicationOnDeviceCommand implements ICommand {
66
private $staticConfig: Config.IStaticConfig,
77
private $options: ICommonOptions) { }
88

9-
allowedParameters: ICommandParameter[] = [this.$stringParameter];
9+
public allowedParameters: ICommandParameter[] = [this.$stringParameter];
1010

1111
public async execute(args: string[]): Promise<void> {
1212
await this.$devicesService.initialize({ deviceId: this.$options.device, skipInferPlatform: true });
@@ -15,7 +15,7 @@ export class RunApplicationOnDeviceCommand implements ICommand {
1515
this.$errors.failWithoutHelp("More than one device found. Specify device explicitly with --device option. To discover device ID, use $%s device command.", this.$staticConfig.CLIENT_NAME.toLowerCase());
1616
}
1717

18-
this.$devicesService.execute(async (device: Mobile.IDevice) => await device.applicationManager.startApplication(args[0]));
18+
await this.$devicesService.execute(async (device: Mobile.IDevice) => await device.applicationManager.startApplication(args[0]));
1919
}
2020
}
2121

constants.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ export class ProvisionType {
66
static Enterprise = "Enterprise";
77
}
88

9-
export let APP_RESOURCES_FOLDER_NAME = "App_Resources";
9+
export const APP_RESOURCES_FOLDER_NAME = "App_Resources";
1010

11-
export let ERROR_NO_DEVICES = "Cannot find connected devices. Reconnect any connected devices, verify that your system recognizes them, and run this command again.";
11+
export const ERROR_NO_DEVICES = "Cannot find connected devices. Reconnect any connected devices, verify that your system recognizes them, and run this command again.";
1212

13-
export let UNREACHABLE_STATUS = "Unreachable";
14-
export let CONNECTED_STATUS = "Connected";
13+
export const UNREACHABLE_STATUS = "Unreachable";
14+
export const CONNECTED_STATUS = "Connected";
1515

1616
export class LiveSyncConstants {
1717
static VERSION_2 = 2;
@@ -24,7 +24,7 @@ export class LiveSyncConstants {
2424
static IOS_PROJECT_PATH = "/Documents/AppBuilder/LiveSync";
2525
}
2626

27-
export let TARGET_FRAMEWORK_IDENTIFIERS = {
27+
export const TARGET_FRAMEWORK_IDENTIFIERS = {
2828
Cordova: "Cordova",
2929
NativeScript: "NativeScript"
3030
};
@@ -34,12 +34,16 @@ export class Configurations {
3434
static Release = "Release";
3535
}
3636

37-
export let NODE_MODULES_DIR_NAME = "node_modules";
38-
export let TNS_CORE_MODULES = "tns-core-modules";
37+
export const NODE_MODULES_DIR_NAME = "node_modules";
38+
export const TNS_CORE_MODULES = "tns-core-modules";
3939

4040
export class FileExtensions {
4141
static TYPESCRIPT_DEFINITION_FILE = ".d.ts";
4242
static TYPESCRIPT_FILE = ".ts";
4343
static PNG_FILE = ".png";
4444
static NINE_PATCH_PNG_FILE = ".9.png";
4545
}
46+
47+
export const IOS_POST_NOTIFICATION_COMMAND_TYPE = "PostNotification";
48+
export const IOS_OBSERVE_NOTIFICATION_COMMAND_TYPE = "ObserveNotification";
49+
export const IOS_RELAY_NOTIFICATION_COMMAND_TYPE = "RelayNotification";

declarations.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,6 @@ interface ICommonOptions extends IRelease, IDeviceIdentifier, IJustLaunch, IAvd,
989989
stop: boolean;
990990
ddi: string; // the path to developer disk image
991991
skipRefresh: boolean;
992-
app: string;
993992
file: string;
994993
analyticsClient: string;
995994
force: boolean;

0 commit comments

Comments
 (0)