You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cordova.apache.org by tony-- <gi...@git.apache.org> on 2016/02/19 22:53:29 UTC

[GitHub] cordova-lib pull request: CB-10654 make hooks fire when platforms ...

GitHub user tony-- opened a pull request:

    https://github.com/apache/cordova-lib/pull/395

    CB-10654 make hooks fire when platforms added from repo or dir

    move `hooksRunner.fire('before_platform_'...) ` till after platform has been resolved, pass resolved platform instead of target.
    move `hooksRunner.fire('after_platform_'...) ` into platform loop, pass resolved platform instead of target.
    


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/tony--/cordova-lib CB-10654

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/cordova-lib/pull/395.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #395
    
----
commit 045ab1ace5666a7d06752d9691e3e8298ec032bd
Author: Tony Homer <to...@intel.com>
Date:   2016-02-19T21:43:09Z

    CB-10654 make hooks fire when platforms added from repo or dir

----


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


[GitHub] cordova-lib pull request: CB-10654 make hooks fire when platforms ...

Posted by bso-intel <gi...@git.apache.org>.
Github user bso-intel commented on the pull request:

    https://github.com/apache/cordova-lib/pull/395#issuecomment-186517246
  
    It looks great assuming that before_platform_add and after_platform_add hooks could be platform specific.
    My understanding about the current convention is a little different, though.
    Thanks, Tony.


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


[GitHub] cordova-lib pull request: CB-10654 make hooks fire when platforms ...

Posted by tony-- <gi...@git.apache.org>.
Github user tony-- commented on the pull request:

    https://github.com/apache/cordova-lib/pull/395#issuecomment-186428877
  
    @bso-intel will you take a look, please?


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


[GitHub] cordova-lib pull request: CB-10654 make hooks fire when platforms ...

Posted by tony-- <gi...@git.apache.org>.
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 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


[GitHub] cordova-lib pull request: CB-10654 make hooks fire when platforms ...

Posted by bso-intel <gi...@git.apache.org>.
Github user bso-intel commented on a diff in the pull request:

    https://github.com/apache/cordova-lib/pull/395#discussion_r53545261
  
    --- 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 --
    
    Now, the behavior is a little different than before.
    Previously, the before_platform_add hook ran only once for all target platforms.
    This hook could be platform agnostic.
    However, by moving the hookRunner inside per platform, this hook will run every time each platform is added.
    Not sure whether this is an issue or not, though.


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


[GitHub] cordova-lib pull request: CB-10654 make hooks fire when platforms ...

Posted by tony-- <gi...@git.apache.org>.
Github user tony-- commented on a diff in the pull request:

    https://github.com/apache/cordova-lib/pull/395#discussion_r53677145
  
    --- 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 --
    
    I was only providing the opts that are used by HooksRunner and scriptFinder, but I was planning to switch to cloning opts and replacing the platform in my copy.  Seems less brittle than my current approach.


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


[GitHub] cordova-lib pull request: CB-10654 make hooks fire when platforms ...

Posted by bso-intel <gi...@git.apache.org>.
Github user bso-intel commented on a diff in the pull request:

    https://github.com/apache/cordova-lib/pull/395#discussion_r53545185
  
    --- 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]
    --- End diff --
    
    opts.nohooks is already an array.
    So you can change this line to the following
    nohooks: opts.nohooks


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


[GitHub] cordova-lib pull request: CB-10654 make hooks fire when platforms ...

Posted by bso-intel <gi...@git.apache.org>.
Github user bso-intel commented on a diff in the pull request:

    https://github.com/apache/cordova-lib/pull/395#discussion_r53545199
  
    --- 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);
    +        }).then(function() {
    +            platform = platDetails.platform;
    +            var platformPath = path.join(projectRoot, 'platforms', platform);
    +            var platformAlreadyAdded = fs.existsSync(platformPath);
    +
    +            if (cmd == 'add') {
    +                if (platformAlreadyAdded) {
    +                    throw new CordovaError('Platform ' + platform + ' already added.');
                     }
     
    -                if (spec) {
    -                    var maybeDir = cordova_util.fixRelativePath(spec);
    -                    if (cordova_util.isDirectory(maybeDir)) {
    -                        return getPlatformDetailsFromDir(maybeDir, platform);
    -                    }
    +                // Remove the <platform>.json file from the plugins directory, so we start clean (otherwise we
    +                // can get into trouble not installing plugins if someone deletes the platform folder but
    +                // <platform>.json still exists).
    +                removePlatformPluginsJson(projectRoot, target);
    +            } else if (cmd == 'update') {
    +                if (!platformAlreadyAdded) {
    +                    throw new CordovaError('Platform "' + platform + '" is not yet added. See `' +
    +                        cordova_util.binname + ' platform list`.');
                     }
    -                return downloadPlatform(projectRoot, platform, spec, opts);
    -            }).then(function(platDetails) {
    -                platform = platDetails.platform;
    -                var platformPath = path.join(projectRoot, 'platforms', platform);
    -                var platformAlreadyAdded = fs.existsSync(platformPath);
    +            }
     
    -                if (cmd == 'add') {
    -                    if (platformAlreadyAdded) {
    -                        throw new CordovaError('Platform ' + platform + ' already added.');
    -                    }
    +            var options = {
    +                // We need to pass a platformDetails into update/create
    +                // since PlatformApiPoly needs to know something about
    +                // platform, it is going to create.
    +                platformDetails: platDetails,
    +                link: opts.link
    +            };
     
    -                    // Remove the <platform>.json file from the plugins directory, so we start clean (otherwise we
    -                    // can get into trouble not installing plugins if someone deletes the platform folder but
    -                    // <platform>.json still exists).
    -                    removePlatformPluginsJson(projectRoot, target);
    -                } else if (cmd == 'update') {
    -                    if (!platformAlreadyAdded) {
    -                        throw new CordovaError('Platform "' + platform + '" is not yet added. See `' +
    -                            cordova_util.binname + ' platform list`.');
    -                    }
    -                }
    +            if (config_json && config_json.lib && config_json.lib[platform] &&
    +                config_json.lib[platform].template) {
    +                options.customTemplate = config_json.lib[platform].template;
    +            }
     
    -                var options = {
    -                    // We need to pass a platformDetails into update/create
    -                    // since PlatformApiPoly needs to know something about
    -                    // platform, it is going to create.
    -                    platformDetails: platDetails,
    -                    link: opts.link
    -                };
    +            events.emit('log', (cmd === 'add' ? 'Adding ' : 'Updating ') + platform + ' project...');
     
    -                if (config_json && config_json.lib && config_json.lib[platform] &&
    -                    config_json.lib[platform].template) {
    -                    options.customTemplate = config_json.lib[platform].template;
    +            var PlatformApi;
    +            try {
    +                // Try to get PlatformApi class from platform
    +                // Get an entry point for platform package
    +                var apiEntryPoint = require.resolve(platDetails.libDir);
    +                // Validate entry point filename. This is required since most of platforms
    +                // defines 'main' entry in package.json pointing to bin/create which is
    +                // basically a valid NodeJS script but intended to be used as a regular
    +                // executable script.
    +                if (path.basename(apiEntryPoint) === 'Api.js') {
    +                    PlatformApi = require(apiEntryPoint);
    +                    events.emit('verbose', 'PlatformApi successfully found for platform ' + platform);
                     }
    -
    -                events.emit('log', (cmd === 'add' ? 'Adding ' : 'Updating ') + platform + ' project...');
    -
    -                var PlatformApi;
    -                try {
    -                    // Try to get PlatformApi class from platform
    -                    // Get an entry point for platform package
    -                    var apiEntryPoint = require.resolve(platDetails.libDir);
    -                    // Validate entry point filename. This is required since most of platforms
    -                    // defines 'main' entry in package.json pointing to bin/create which is
    -                    // basically a valid NodeJS script but intended to be used as a regular
    -                    // executable script.
    -                    if (path.basename(apiEntryPoint) === 'Api.js') {
    -                        PlatformApi = require(apiEntryPoint);
    -                        events.emit('verbose', 'PlatformApi successfully found for platform ' + platform);
    -                    }
    -                } catch (e) {
    -                } finally {
    -                    if (!PlatformApi) {
    -                        events.emit('verbose', 'Failed to require PlatformApi instance for platform "' + platform +
    -                            '". Using polyfill instead.');
    -                        PlatformApi = require('../platforms/PlatformApiPoly');
    -                    }
    +            } catch (e) {
    +            } finally {
    +                if (!PlatformApi) {
    +                    events.emit('verbose', 'Failed to require PlatformApi instance for platform "' + platform +
    +                        '". Using polyfill instead.');
    +                    PlatformApi = require('../platforms/PlatformApiPoly');
                     }
    +            }
     
    -                var destination = path.resolve(projectRoot, 'platforms', platform);
    -                var promise = cmd === 'add' ?
    -                    PlatformApi.createPlatform.bind(null, destination, cfg, options, events) :
    -                    PlatformApi.updatePlatform.bind(null, destination, options, events);
    +            var destination = path.resolve(projectRoot, 'platforms', platform);
    +            var promise = cmd === 'add' ?
    +                PlatformApi.createPlatform.bind(null, destination, cfg, options, events) :
    +                PlatformApi.updatePlatform.bind(null, destination, options, events);
     
    -                return promise()
    -                .then(function() {
    -                    if (cmd == 'add') {
    -                        return installPluginsForNewPlatform(platform, projectRoot, opts);
    -                    }
    -                })
    -                .then(function () {
    -                    // Call prepare for the current platform.
    -                    var prepOpts = {
    -                        platforms :[platform],
    -                        searchpath :opts.searchpath
    -                    };
    -                    return require('./cordova').raw.prepare(prepOpts);
    +            return promise()
    +            .then(function() {
    +                if (cmd == 'add') {
    +                    return installPluginsForNewPlatform(platform, projectRoot, opts);
    +                }
    +            })
    +            .then(function () {
    +                // Call prepare for the current platform.
    +                var prepOpts = {
    +                    platforms :[platform],
    +                    searchpath :opts.searchpath
    +                };
    +                return require('./cordova').raw.prepare(prepOpts);
                     })
                     .then(function() {
    -                    var saveVersion = !spec || semver.validRange(spec, true);
    -
    -                    // Save platform@spec into platforms.json, where 'spec' is a version or a soure location. If a
    -                    // source location was specified, we always save that. Otherwise we save the version that was
    -                    // actually installed.
    -                    var versionToSave = saveVersion ? platDetails.version : spec;
    -                    events.emit('verbose', 'saving ' + platform + '@' + versionToSave + ' into platforms.json');
    -                    platformMetadata.save(projectRoot, platform, versionToSave);
    -
    -                    if(opts.save || autosave){
    -                        // Similarly here, we save the source location if that was specified, otherwise the version that
    -                        // was installed. However, we save it with the "~" attribute (this allows for patch updates).
    -                        spec = saveVersion ? '~' + platDetails.version : spec;
    -
    -                        // Save target into config.xml, overriding already existing settings
    -                        events.emit('log', '--save flag or autosave detected');
    -                        events.emit('log', 'Saving ' + platform + '@' + spec + ' into config.xml file ...');
    -                        cfg.removeEngine(platform);
    -                        cfg.addEngine(platform, spec);
    -                        cfg.write();
    -                    }
    -                });
    +                var saveVersion = !spec || semver.validRange(spec, true);
    +
    +                // Save platform@spec into platforms.json, where 'spec' is a version or a soure location. If a
    +                // source location was specified, we always save that. Otherwise we save the version that was
    +                // actually installed.
    +                var versionToSave = saveVersion ? platDetails.version : spec;
    +                events.emit('verbose', 'saving ' + platform + '@' + versionToSave + ' into platforms.json');
    +                platformMetadata.save(projectRoot, platform, versionToSave);
    +
    +                if(opts.save || autosave){
    +                    // Similarly here, we save the source location if that was specified, otherwise the version that
    +                    // was installed. However, we save it with the "~" attribute (this allows for patch updates).
    +                    spec = saveVersion ? '~' + platDetails.version : spec;
    +
    +                    // Save target into config.xml, overriding already existing settings
    +                    events.emit('log', '--save flag or autosave detected');
    +                    events.emit('log', 'Saving ' + platform + '@' + spec + ' into config.xml file ...');
    +                    cfg.removeEngine(platform);
    +                    cfg.addEngine(platform, spec);
    +                    cfg.write();
    +                }
    +                var hookOpts = {
    +                    platforms :[platDetails.platform],
    +                    nohooks :[opts.nohooks]
    --- End diff --
    
    The same thing. Please remove bracket [ ] here.


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


[GitHub] cordova-lib pull request: CB-10654 make hooks fire when platforms ...

Posted by nikhilkh <gi...@git.apache.org>.
Github user nikhilkh commented on a diff in the pull request:

    https://github.com/apache/cordova-lib/pull/395#discussion_r53669157
  
    --- 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 --
    
    Do we end up losing some of the original `opts` - as I do not see us copying them over.


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


[GitHub] cordova-lib pull request: CB-10654 make hooks fire when platforms ...

Posted by tony-- <gi...@git.apache.org>.
Github user tony-- commented on the pull request:

    https://github.com/apache/cordova-lib/pull/395#issuecomment-186425912
  
    I'd like to see this get fixed, so I thought I'd submit a PR, but I'm a node noob - this definitely needs to be reviewed before being merged in.



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