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

Remove ios native dependencies #889

Merged
merged 8 commits into from
Mar 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 26 additions & 17 deletions appbuilder/services/livesync/ios-livesync-service.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import iOSProxyServices = require("../../../mobile/ios/device/ios-proxy-services");
import * as path from "path";
import * as shell from "shelljs";
let osenv = require("osenv");
import { LiveSyncConstants } from "../../../constants";
import { TARGET_FRAMEWORK_IDENTIFIERS } from "../../../constants";
import * as constants from "../../../constants";

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

constructor(private _device: Mobile.IiOSDevice,
constructor(private _device: Mobile.IDevice,
private $fs: IFileSystem,
private $injector: IInjector,
private $logger: ILogger,
private $errors: IErrors) { }
private $errors: IErrors,
private $options: ICommonOptions,
private $iosDeviceOperations: IIOSDeviceOperations) {
// If we execute livesync with --watch we do not want to dispose the $iosDeviceOperations.
this.$iosDeviceOperations.setShouldDispose(!this.$options.watch);
}

private get device(): Mobile.IiOSDevice {
private get device(): Mobile.IDevice {
return this._device;
}

Expand All @@ -34,6 +37,7 @@ export class IOSLiveSyncService implements IDeviceLiveSyncService {
if (!parsed) {
break;
}

guid = parsed[1];
}

Expand All @@ -42,26 +46,31 @@ export class IOSLiveSyncService implements IDeviceLiveSyncService {
}

let sourcePath = await deviceAppData.getDeviceProjectRootPath();
let destinationPath = path.join(simulatorCachePath, guid, LiveSyncConstants.IOS_PROJECT_PATH);
let destinationPath = path.join(simulatorCachePath, guid, constants.LiveSyncConstants.IOS_PROJECT_PATH);

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

let cfBundleExecutable = `${this.$project.projectData.Framework}${this.$project.projectData.FrameworkVersion.split(".").join("")}`;
await this.device.applicationManager.restartApplication(deviceAppData.appIdentifier, cfBundleExecutable);
await this.device.applicationManager.restartApplication(deviceAppData.appIdentifier);
} else {
this.device.fileSystem.deleteFile("/Documents/AppBuilder/ServerInfo.plist", deviceAppData.appIdentifier);
let notificationProxyClient = this.$injector.resolve(iOSProxyServices.NotificationProxyClient, { device: this.device });
let notification = this.$project.projectData.Framework === TARGET_FRAMEWORK_IDENTIFIERS.NativeScript ? "com.telerik.app.refreshApp" : "com.telerik.app.refreshWebView";
notificationProxyClient.postNotification(notification);
notificationProxyClient.closeSocket();
await this.device.fileSystem.deleteFile("/Documents/AppBuilder/ServerInfo.plist", deviceAppData.appIdentifier);
let notification = this.$project.projectData.Framework === constants.TARGET_FRAMEWORK_IDENTIFIERS.NativeScript ? "com.telerik.app.refreshApp" : "com.telerik.app.refreshWebView";
const notificationData = {
deviceId: this.device.deviceInfo.identifier,
notificationName: notification,
commandType: constants.IOS_POST_NOTIFICATION_COMMAND_TYPE
};
await this.$iosDeviceOperations.postNotification([notificationData]);
}
}

public async removeFiles(appIdentifier: string, localToDevicePaths: Mobile.ILocalToDevicePathData[]): Promise<void> {
localToDevicePaths
.map(localToDevicePath => localToDevicePath.getDevicePath())
.forEach(deviceFilePath => this.device.fileSystem.deleteFile(deviceFilePath, appIdentifier));
const devicePaths = localToDevicePaths.map(localToDevicePath => localToDevicePath.getDevicePath());

for (let deviceFilePath of devicePaths) {
await this.device.fileSystem.deleteFile(deviceFilePath, appIdentifier);
}
}
}

$injector.register("iosLiveSyncServiceLocator", { factory: IOSLiveSyncService });
10 changes: 1 addition & 9 deletions bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,7 @@ $injector.requireCommand("device|list-files", "./commands/device/list-files");
$injector.requireCommand("device|get-file", "./commands/device/get-file");
$injector.requireCommand("device|put-file", "./commands/device/put-file");

$injector.require("iOSCore", "./mobile/ios/device/ios-core");
$injector.require("coreFoundation", "./mobile/ios/device/ios-core");
$injector.require("mobileDevice", "./mobile/ios/device/ios-core");
$injector.require("plistService", "./mobile/ios/device/ios-core");

$injector.require("installationProxyClient", "./mobile/ios/device/ios-proxy-services");
$injector.require("notificationProxyClient", "./mobile/ios/device/ios-proxy-services");
$injector.require("houseArrestClient", "./mobile/ios/device/ios-proxy-services");
$injector.require("gdbServer", "./mobile/ios/device/ios-core");
$injector.require("iosDeviceOperations", "./mobile/ios/device/ios-device-operations");

$injector.require("deviceFound", "./mobile/mobile-core/device-discovery");
$injector.require("deviceLost", "./mobile/mobile-core/device-discovery");
Expand Down
1 change: 1 addition & 0 deletions commands/device/device-log-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ export class OpenDeviceLogStreamCommand implements ICommand {
await this.$devicesService.execute(action);
}
}

$injector.registerCommand("device|log", OpenDeviceLogStreamCommand);
14 changes: 12 additions & 2 deletions commands/device/get-file.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
export class GetFileCommand implements ICommand {
constructor(private $devicesService: Mobile.IDevicesService,
private $stringParameter: ICommandParameter,
private $project: Project.IProjectBase,
private $errors: IErrors,
private $options: ICommonOptions) { }

allowedParameters: ICommandParameter[] = [this.$stringParameter];
public allowedParameters: ICommandParameter[] = [this.$stringParameter, this.$stringParameter];

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as we modify the command, shouldn't we delete the $options.app that has been used before (not in the command itself, but in the service behind it. If I understand correctly, we'll support getting of file only from application sandbox, so the $options.app is a mandatory argument now. So... let's remove $options.app


let action = (device: Mobile.IDevice) => device.fileSystem.getFile(args[0], this.$options.file);
if (!appIdentifier && !this.$project.projectData) {
this.$errors.failWithoutHelp("Please enter application identifier or execute this command in project.");
}

appIdentifier = appIdentifier || this.$project.projectData.AppIdentifier;

let action = (device: Mobile.IDevice) => device.fileSystem.getFile(args[0], appIdentifier, this.$options.file);
await this.$devicesService.execute(action);
}
}

$injector.registerCommand("device|get-file", GetFileCommand);
9 changes: 6 additions & 3 deletions commands/device/list-devices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class ListDevicesCommand implements ICommand {
private $stringParameter: ICommandParameter,
private $options: ICommonOptions) { }

allowedParameters = [this.$stringParameter];
public allowedParameters = [this.$stringParameter];

public async execute(args: string[]): Promise<void> {
let index = 1;
Expand Down Expand Up @@ -34,32 +34,35 @@ export class ListDevicesCommand implements ICommand {
}
}
}

$injector.registerCommand("device|*list", ListDevicesCommand);

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

allowedParameters: ICommandParameter[] = [];
public allowedParameters: ICommandParameter[] = [];

public async execute(args: string[]): Promise<void> {
let listDevicesCommand: ICommand = this.$injector.resolve(ListDevicesCommand);
let platform = this.$devicePlatformsConstants.Android;
await listDevicesCommand.execute([platform]);
}
}

$injector.registerCommand("device|android", ListAndroidDevicesCommand);

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

allowedParameters: ICommandParameter[] = [];
public allowedParameters: ICommandParameter[] = [];

public async execute(args: string[]): Promise<void> {
let listDevicesCommand: ICommand = this.$injector.resolve(ListDevicesCommand);
let platform = this.$devicePlatformsConstants.iOS;
await listDevicesCommand.execute([platform]);
}
}

$injector.registerCommand("device|ios", ListiOSDevicesCommand);
17 changes: 14 additions & 3 deletions commands/device/list-files.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
export class ListFilesCommand implements ICommand {
constructor(private $devicesService: Mobile.IDevicesService,
private $stringParameter: ICommandParameter,
private $options: ICommonOptions) { }
private $options: ICommonOptions,
private $project: Project.IProjectBase,
private $errors: IErrors) { }

allowedParameters: ICommandParameter[] = [this.$stringParameter];
public allowedParameters: ICommandParameter[] = [this.$stringParameter, this.$stringParameter];

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

let action = (device: Mobile.IDevice) => device.fileSystem.listFiles(args[0]);
if (!appIdentifier && !this.$project.projectData) {
this.$errors.failWithoutHelp("Please enter application identifier or execute this command in project.");
}

appIdentifier = appIdentifier || this.$project.projectData.AppIdentifier;

let action = (device: Mobile.IDevice) => device.fileSystem.listFiles(pathToList, appIdentifier);
await this.$devicesService.execute(action);
}
}

$injector.registerCommand("device|list-files", ListFilesCommand);
14 changes: 11 additions & 3 deletions commands/device/put-file.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
export class PutFileCommand implements ICommand {
constructor(private $devicesService: Mobile.IDevicesService,
private $stringParameter: ICommandParameter,
private $options: ICommonOptions) { }
private $options: ICommonOptions,
private $project: Project.IProjectBase,
private $errors: IErrors) { }

allowedParameters: ICommandParameter[] = [this.$stringParameter, this.$stringParameter];
allowedParameters: ICommandParameter[] = [this.$stringParameter, this.$stringParameter, this.$stringParameter];

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

let action = (device: Mobile.IDevice) => device.fileSystem.putFile(args[0], args[2], args[1]);
if (!appIdentifier && !this.$project.projectData) {
this.$errors.failWithoutHelp("Please enter application identifier or execute this command in project.");
}

appIdentifier = appIdentifier || this.$project.projectData.AppIdentifier;
let action = (device: Mobile.IDevice) => device.fileSystem.putFile(args[0], args[1], appIdentifier);
await this.$devicesService.execute(action);
}
}
Expand Down
4 changes: 2 additions & 2 deletions commands/device/run-application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class RunApplicationOnDeviceCommand implements ICommand {
private $staticConfig: Config.IStaticConfig,
private $options: ICommonOptions) { }

allowedParameters: ICommandParameter[] = [this.$stringParameter];
public allowedParameters: ICommandParameter[] = [this.$stringParameter];

public async execute(args: string[]): Promise<void> {
await this.$devicesService.initialize({ deviceId: this.$options.device, skipInferPlatform: true });
Expand All @@ -15,7 +15,7 @@ export class RunApplicationOnDeviceCommand implements ICommand {
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());
}

this.$devicesService.execute(async (device: Mobile.IDevice) => await device.applicationManager.startApplication(args[0]));
await this.$devicesService.execute(async (device: Mobile.IDevice) => await device.applicationManager.startApplication(args[0]));
}
}

Expand Down
18 changes: 11 additions & 7 deletions constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ export class ProvisionType {
static Enterprise = "Enterprise";
}

export let APP_RESOURCES_FOLDER_NAME = "App_Resources";
export const APP_RESOURCES_FOLDER_NAME = "App_Resources";

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

export let UNREACHABLE_STATUS = "Unreachable";
export let CONNECTED_STATUS = "Connected";
export const UNREACHABLE_STATUS = "Unreachable";
export const CONNECTED_STATUS = "Connected";

export class LiveSyncConstants {
static VERSION_2 = 2;
Expand All @@ -24,7 +24,7 @@ export class LiveSyncConstants {
static IOS_PROJECT_PATH = "/Documents/AppBuilder/LiveSync";
}

export let TARGET_FRAMEWORK_IDENTIFIERS = {
export const TARGET_FRAMEWORK_IDENTIFIERS = {
Cordova: "Cordova",
NativeScript: "NativeScript"
};
Expand All @@ -34,12 +34,16 @@ export class Configurations {
static Release = "Release";
}

export let NODE_MODULES_DIR_NAME = "node_modules";
export let TNS_CORE_MODULES = "tns-core-modules";
export const NODE_MODULES_DIR_NAME = "node_modules";
export const TNS_CORE_MODULES = "tns-core-modules";

export class FileExtensions {
static TYPESCRIPT_DEFINITION_FILE = ".d.ts";
static TYPESCRIPT_FILE = ".ts";
static PNG_FILE = ".png";
static NINE_PATCH_PNG_FILE = ".9.png";
}

export const IOS_POST_NOTIFICATION_COMMAND_TYPE = "PostNotification";
export const IOS_OBSERVE_NOTIFICATION_COMMAND_TYPE = "ObserveNotification";
export const IOS_RELAY_NOTIFICATION_COMMAND_TYPE = "RelayNotification";
1 change: 0 additions & 1 deletion declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,6 @@ interface ICommonOptions extends IRelease, IDeviceIdentifier, IJustLaunch, IAvd,
stop: boolean;
ddi: string; // the path to developer disk image
skipRefresh: boolean;
app: string;
file: string;
analyticsClient: string;
force: boolean;
Expand Down
Loading