Github user tony-- commented on a diff in the pull request:

    https://github.com/apache/cordova-lib/pull/395#discussion_r53622685
  
    --- Diff: cordova-lib/src/cordova/platform.js ---
    @@ -79,148 +79,156 @@ function addHelper(cmd, hooksRunner, projectRoot, 
targets, opts) {
         var platformsDir = path.join(projectRoot, 'platforms');
         shell.mkdir('-p', platformsDir);
     
    -    return hooksRunner.fire('before_platform_' + cmd, opts)
    -    .then(function() {
    -        return promiseutil.Q_chainmap(targets, function(target) {
    -            // For each platform, download it and call its helper script.
    -            var parts = target.split('@');
    -            var platform = parts[0];
    -            var spec = parts[1];
    -
    -            return Q.when().then(function() {
    -                if (!(platform in platforms)) {
    -                    spec = platform;
    -                    platform = null;
    -                }
    +    return promiseutil.Q_chainmap(targets, function(target) {
    +        // For each platform, download it and call its helper script.
    +        var parts = target.split('@');
    +        var platform = parts[0];
    +        var spec = parts[1];
    +        var platDetails = '';
    +
    +        return Q.when().then(function() {
    +            if (!(platform in platforms)) {
    +                spec = platform;
    +                platform = null;
    +            }
     
    -                if(platform === 'amazon-fireos') {
    -                    events.emit('warn', 'amazon-fireos has been 
deprecated. Please use android instead.');
    -                }
    -                if(platform === 'wp8') {
    -                    events.emit('warn', 'wp8 has been deprecated. Please 
use windows instead.');
    -                }
    -                if (platform && !spec && cmd == 'add') {
    -                    events.emit('verbose', 'No version supplied. 
Retrieving version from config.xml...');
    -                    spec = getVersionFromConfigFile(platform, cfg);
    -                }
    +            if(platform === 'amazon-fireos') {
    +                events.emit('warn', 'amazon-fireos has been deprecated. 
Please use android instead.');
    +            }
    +            if(platform === 'wp8') {
    +                events.emit('warn', 'wp8 has been deprecated. Please use 
windows instead.');
    +            }
    +            if (platform && !spec && cmd == 'add') {
    +                events.emit('verbose', 'No version supplied. Retrieving 
version from config.xml...');
    +                spec = getVersionFromConfigFile(platform, cfg);
    +            }
    +
    +            // If --save/autosave on && no version specified, use the 
pinned version
    +            // e.g: 'cordova platform add android --save', 'cordova 
platform update android --save'
    +            if( (opts.save || autosave) && !spec ){
    +                spec = platforms[platform].version;
    +            }
     
    -                // If --save/autosave on && no version specified, use the 
pinned version
    -                // e.g: 'cordova platform add android --save', 'cordova 
platform update android --save'
    -                if( (opts.save || autosave) && !spec ){
    -                    spec = platforms[platform].version;
    +            if (spec) {
    +                var maybeDir = cordova_util.fixRelativePath(spec);
    +                if (cordova_util.isDirectory(maybeDir)) {
    +                    return getPlatformDetailsFromDir(maybeDir, platform);
    +                }
    +            }
    +            return downloadPlatform(projectRoot, platform, spec, opts);
    +        }).then(function(platformDetails) {
    +            platDetails = platformDetails;
    +            var hookOpts = {
    +                platforms :[platDetails.platform],
    +                nohooks :[opts.nohooks]
    +            };
    +            return hooksRunner.fire('before_platform_' + cmd, hookOpts);
    --- End diff --
    
    Thanks for this feedback - that's a good point - I was focused on the 
platform-specific case.
    Instead of firing the hook once per platform, I could retain the once per 
operation behavior.
    I would move the hooksRunner.fire back out of the loop 
(`promiseutil.Q_chainmap`), but exit the first loop after the targets are 
resolved and place `hooksRunner.fire` for `before_platform_`.
    Then I would start a second loop (`promiseutil.Q_chainmap`) that actually 
adds the platforms.
    I'll make this change ASAP and update the review.


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