From d81817a47681d4c8b5f4290967358056fe12da59 Mon Sep 17 00:00:00 2001 From: Fatme Havaluova Date: Thu, 19 Nov 2015 17:51:27 +0200 Subject: [PATCH] Show application output from livesync command https://github.com/NativeScript/nativescript-cli/issues/1130 --- lib/commands/livesync.ts | 1 - lib/common | 2 +- lib/providers/device-log-provider.ts | 34 +++++++++++++++++++++++++--- lib/services/platform-service.ts | 4 ---- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/lib/commands/livesync.ts b/lib/commands/livesync.ts index 3e0fb4f98f..96a766d516 100644 --- a/lib/commands/livesync.ts +++ b/lib/commands/livesync.ts @@ -9,7 +9,6 @@ export class LivesyncCommand implements ICommand { private $errors: IErrors) { } public execute(args: string[]): IFuture { - this.$options.justlaunch = true; return this.$usbLiveSyncService.liveSync(args[0]); } diff --git a/lib/common b/lib/common index 86217092ba..dae8c836e0 160000 --- a/lib/common +++ b/lib/common @@ -1 +1 @@ -Subproject commit 86217092ba00e2600103291e1e62c16e9d2f3c54 +Subproject commit dae8c836e0fb529cf5c2f61009fa801a071d02d4 diff --git a/lib/providers/device-log-provider.ts b/lib/providers/device-log-provider.ts index b140afa715..746a60cd65 100644 --- a/lib/providers/device-log-provider.ts +++ b/lib/providers/device-log-provider.ts @@ -2,10 +2,38 @@ "use strict"; export class DeviceLogProvider implements Mobile.IDeviceLogProvider { - constructor(private $logger: ILogger) { } + //sample line is "I/Web Console( 4438): Received Event: deviceready at file:///storage/emulated/0/Icenium/com.telerik.TestApp/js/index.js:48" + private static LINE_REGEX = /.\/(.+?)\s*\(\s*(\d+?)\): (.*)/; - public logData(line: string, platform: string, deviceIdentifier: string): void { - this.$logger.out(line); + constructor(private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants, + private $logger: ILogger) { } + + public logData(lineText: string, platform: string, deviceIdentifier: string): void { + if (!platform || platform.toLowerCase() === this.$devicePlatformsConstants.iOS.toLowerCase()) { + this.$logger.out(lineText); + } else if (platform === this.$devicePlatformsConstants.Android) { + let log = this.getConsoleLogFromLine(lineText); + if (log) { + if (log.tag) { + this.$logger.out(`${log.tag}: ${log.message}`); + } else { + this.$logger.out(log.message); + } + } + } + } + + private getConsoleLogFromLine(lineText: String): any { + let acceptedTags = ["chromium", "Web Console", "JS"]; + let match = lineText.match(DeviceLogProvider.LINE_REGEX); + if (match) { + if(acceptedTags.indexOf(match[1]) !== -1) { + return {tag: match[1], message: match[3]}; + } + } else if (_.any(acceptedTags, (tag: string) => { return lineText.indexOf(tag) !== -1; })) { + return {message: match[3]}; + } + return null; } } $injector.register("deviceLogProvider", DeviceLogProvider); diff --git a/lib/services/platform-service.ts b/lib/services/platform-service.ts index 3afe67c7f3..5b7b510829 100644 --- a/lib/services/platform-service.ts +++ b/lib/services/platform-service.ts @@ -353,10 +353,6 @@ export class PlatformService implements IPlatformService { return (() => { platformData.platformProjectService.deploy(device.deviceInfo.identifier).wait(); device.deploy(packageFile, this.$projectData.projectId).wait(); - - if (!this.$options.justlaunch) { - device.openDeviceLogStream(); - } }).future()(); }; this.$devicesService.execute(action).wait();