Return-Path: X-Original-To: apmail-cordova-dev-archive@www.apache.org Delivered-To: apmail-cordova-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4ECB619DCB for ; Wed, 27 Apr 2016 20:55:18 +0000 (UTC) Received: (qmail 1601 invoked by uid 500); 27 Apr 2016 20:55:18 -0000 Delivered-To: apmail-cordova-dev-archive@cordova.apache.org Received: (qmail 1561 invoked by uid 500); 27 Apr 2016 20:55:18 -0000 Mailing-List: contact dev-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cordova.apache.org Delivered-To: mailing list dev@cordova.apache.org Received: (qmail 1550 invoked by uid 99); 27 Apr 2016 20:55:17 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 27 Apr 2016 20:55:17 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 90F7DDFDE3; Wed, 27 Apr 2016 20:55:17 +0000 (UTC) From: sarangan12 To: dev@cordova.apache.org Reply-To: dev@cordova.apache.org References: In-Reply-To: Subject: [GitHub] cordova-paramedic pull request: Code changes for Collecting Device... Content-Type: text/plain Message-Id: <20160427205517.90F7DDFDE3@git1-us-west.apache.org> Date: Wed, 27 Apr 2016 20:55:17 +0000 (UTC) Github user sarangan12 commented on a diff in the pull request: https://github.com/apache/cordova-paramedic/pull/4#discussion_r61334311 --- Diff: lib/utils/utilities.js --- @@ -0,0 +1,123 @@ +#!/usr/bin/env node + +var shelljs = require('shelljs'); +var verbose = undefined; +var fs = require('fs'); +var os = require("os"); +var util = require('util'); +var path = require("path-extra"); +var logger = require('cordova-common').CordovaLogger.get(); + +var HEADING_LINE_PATTERN = /List of devices/m; +var DEVICE_ROW_PATTERN = /(emulator|device|host)/m; + +function isWindows () { + return /^win/.test(os.platform()); +} + +function countAndroidDevices() { + var listCommand = "adb devices"; + + logger.info("running:"); + logger.info(" " + listCommand); + + var numDevices = 0; + var result = shelljs.exec(listCommand, {silent: false, async: false}); + result.output.split('\n').forEach(function (line) { + if (!HEADING_LINE_PATTERN.test(line) && DEVICE_ROW_PATTERN.test(line)) { + numDevices += 1; + } + }); + return numDevices; +} + +function secToMin (seconds) { + return Math.ceil(seconds / 60); +} + +function getSimulatorsFolder() { + var simulatorsFolderPath = path.join(path.homedir(), "Library", "Developer", "CoreSimulator", "Devices"); + return simulatorsFolderPath; +} + +function getSimId() { + var findSimCommand = "cordova run --list --emulator | grep ^iPhone | tail -n1"; + + logger.info("running:"); + logger.info(" " + findSimCommand); + + var findSimResult = shelljs.exec(findSimCommand, {silent: true, async: false}); + + if (findSimResult.code > 0) { + logger.error("Failed to find simulator we deployed to"); + return; + } + + var split = findSimResult.output.split(", "); + + // Format of the output is "iPhone-6s-Plus, 9.1" + // Extract the device name and the version number + var device = split[0].replace(/-/g, " ").trim(); + var version = split[1].trim(); + + // Next, figure out the ID of the simulator we found + var instrCommand = "instruments -s devices | grep ^iPhone"; + logger.info("running:"); + logger.info(" " + instrCommand); + + var instrResult = shelljs.exec(instrCommand, {silent: true, async: false}); + + if (instrResult.code > 0) { + logger.error("Failed to get the list of simulators"); + return; + } + + // This matches () [] + var simIdRegex = /^([a-zA-Z\d ]+) \(([\d.]+)\) \[([a-zA-Z\d\-]*)\]$/; + + var simId = null; + var lines = instrResult.output.split(/\n/); + lines.forEach(function(line) { + var simIdMatch = simIdRegex.exec(line); + if (simIdMatch && simIdMatch.length === 4 && simIdMatch[1] === device && simIdMatch[2] === version) { + simId = encodeURIComponent(simIdMatch[3]); + } + }); + + return simId; +} --- End diff -- Done --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org For additional commands, e-mail: dev-help@cordova.apache.org