cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nikhilkh <...@git.apache.org>
Subject [GitHub] cordova-paramedic pull request: Code changes for Collecting Device...
Date Wed, 13 Apr 2016 23:52:12 GMT
Github user nikhilkh commented on a diff in the pull request:

    https://github.com/apache/cordova-paramedic/pull/4#discussion_r59645737
  
    --- Diff: lib/ParamedicLog.js ---
    @@ -0,0 +1,154 @@
    +#!/usr/bin/env node
    +
    +/* jshint node: true */
    +
    +"use strict";
    +
    +var shelljs  = require("shelljs");
    +var fs       = require("fs");
    +var path     = require("path");
    +var util     = require('./utils').utilities;
    +var logger   = require('./utils').logger;
    +
    +
    +function ParamedicLog(platform, appPath, logPath){
    +    this.platform = platform;
    +    this.appPath = appPath;
    +    this.logPath = logPath;
    +}
    +
    +ParamedicLog.prototype.logIOS = function (appPath) {
    +    // We need to print out the system log for the simulator app. In order to figure
    +    // out the path to that file, we need to find the ID of the simulator running
    +    // mobilespec
    +
    +    // First, figure out the simulator that ran mobilespec. "cordova run"" just chooses
    +    // the last simulator in this list that starts with the word "iPhone"
    +    shelljs.pushd(appPath);
    +
    +    var findSimCommand = this.getLocalCLI() + " 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 <device> (<version>) [<simulator-id>]
    +    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]);
    +        }
    +    });
    +
    +    if (simId) {
    +        // Now we can print out the log file
    +        var logPath = path.join("~", "Library", "Logs", "CoreSimulator", simId, "system.log");
    +        var logCommand = "cat " + logPath;
    +        this.generateLogs(logCommand);
    +    } else {
    +        logger.error("Failed to find ID of mobilespec simulator");
    +    }
    +}
    +
    +ParamedicLog.prototype.logWindows = function (appPath, logMins) {
    +    var logScriptPath = path.join(appPath, "platforms", "windows", "cordova", "log.bat");
    +    if (fs.existsSync(logScriptPath)) {
    +        var mins = util.DEFAULT_LOG_TIME;
    +        if (logMins) {
    +            mins = logMins + util.DEFAULT_LOG_TIME_ADDITIONAL;
    +        }
    +        var logCommand = logScriptPath + " --dump --mins " + mins;
    +        this.generateLogs(logCommand);
    +    }
    +}
    +
    +ParamedicLog.prototype.logAndroid = function (){
    +    var logCommand = "adb logcat -d";
    +
    +    var numDevices = util.countAndroidDevices();
    +    if (numDevices != 1) {
    +        logger.error("there must be exactly one emulator/device attached");
    +        return;
    +    }
    +    this.generateLogs(logCommand);
    +}
    +
    +ParamedicLog.prototype.generateLogs = function(logCommand) {
    +    var logFile = this.getLogFileName();
    +    logger.info('Running Command: ' + logCommand);
    +
    +    var result = shelljs.exec(logCommand, {silent: true, async: false});
    +    if (result.code > 0) {
    +        logger.error("Failed to run command: " + logCommand);
    +        return;
    +    }
    +
    +    try {
    +        fs.writeFileSync(logFile, result.output);
    +    } catch (ex) {
    +        logger.error("Cannot write the log results to the file. " + ex);
    +    }
    +}
    +
    +ParamedicLog.prototype.getLogFileName = function() {
    +    return path.join(this.logPath, this.platform+"_logs.txt");
    +}
    +
    +ParamedicLog.prototype.getLocalCLI = function (){
    --- End diff --
    
    Consider just using "cordova" inline instead of this method.


---
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


Mime
View raw message