Skip to content
This repository has been archived by the owner on Jul 8, 2020. It is now read-only.

patcher.js breaks when either one of the platform is not added on livereload #416

Closed
nirus opened this issue Jul 27, 2016 · 2 comments
Closed

Comments

@nirus
Copy link

nirus commented Jul 27, 2016

When ever there's no either of platforms available patchConfigXml breaks because it tries to read the config.xml of that non available platform

--Fix

Patcher.prototype.patchConfigXml = function (externalUrl) {
  var platforms = ['android', 'ios'];
  platforms.forEach(function (platform) {

    var CONFIG_LOCATION = {
      android: 'res/xml',
      // retrieve project name which is necessary for ios config.xml path
      ios: this.getProjectName()
    };

    // retrieve platform's path to config.xml & parse it
    var configXmlPath = path.join(this.projectRoot, 'platforms', platform, CONFIG_LOCATION[platform], 'config.xml'), configXml;
    try{
      configXml = this.parseXml(configXmlPath);
      console.log(chalk.green('[Patching]: ') + configXmlPath);
      // set content src attrib to externalUrl
      var contentTag = configXml.find('content[@src]');
      contentTag.attrib.src = externalUrl;

      // Add allow-navigation element so it's possible to navigate to externalUrl
      var allowNavTag = et.SubElement(configXml.find('.'), 'allow-navigation');
      allowNavTag.set('href', '*');

      fs.writeFileSync(configXmlPath, configXml.write({
        indent: 4
      }), 'utf-8');

    }catch(e){
      console.log(chalk.yellow('[Patching Warn]: ') + chalk.bold(platform) + chalk.yellow(' is Not Available. Please add it via Cordova command'));
    }
  }, this);
};
@gruppjo gruppjo added this to the 1.10.0 milestone Aug 3, 2016
@gruppjo
Copy link
Contributor

gruppjo commented Aug 3, 2016

I'll look into it. Thank you!

@gruppjo
Copy link
Contributor

gruppjo commented Aug 24, 2016

@nirus, thanks for your contribution and sorry for my delay in working on this.

I thought about this a little bit and decided to implement it without try{}catch{} rather by tracking what platform the command is run for. That way we still get error messages if something else goes wrong.

You can see the changes in the commit linked above. Additionally I'll probably release a new version in the next days.

@gruppjo gruppjo closed this as completed Aug 24, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants