Github user TimBarham commented on a diff in the pull request:

    https://github.com/apache/cordova-lib/pull/363#discussion_r53298645
  
    --- Diff: cordova-lib/src/cordova/util.js ---
    @@ -185,6 +187,31 @@ function listPlatforms(project_dir) {
         });
     }
     
    +function getInstalledPlatformsWithVersions(project_dir) {
    +    var platforms_on_fs = listPlatforms(project_dir);
    +
    +    return Q.all(platforms_on_fs.map(function(p) {
    +        return superspawn.maybeSpawn(path.join(project_dir, 'platforms', 
p, 'cordova', 'version'), [], { chmod: true })
    +        .then(function(v) {
    +            return {
    +                platform: p,
    +                version: v ? v : null
    +            };
    +        }, function(v) {
    +            return {
    +                platform: p,
    +                version: 'broken'
    +            };
    +        });
    +    })).then(function(platformVersions) {
    +        var result = {};
    +        for(var i = 0; i < platformVersions.length; i++) {
    +            result[platformVersions[i].platform] = 
platformVersions[i].version;
    +        }
    +        return result;
    +    });
    +}
    --- End diff --
    
    The above method would be simplified if you just accumulated the `result` 
object as you go... As in... initialize `result` before the `Q.all()` call, 
then instead of, for example, `return { platform: p, version: v ? v : null };` 
you would just do `result[p] = v || null;`. In the final then, you would ignore 
the parameter and just return `result`.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@cordova.apache.org
For additional commands, e-mail: dev-h...@cordova.apache.org

Reply via email to