diff --git a/src/ios/local-receipt-validation/apply-module.js b/src/ios/local-receipt-validation/apply-module.js index afc861ac..52cccfd4 100644 --- a/src/ios/local-receipt-validation/apply-module.js +++ b/src/ios/local-receipt-validation/apply-module.js @@ -131,17 +131,19 @@ const parsePluginVariables = function(){ // Parse config.xml const config = parseConfigXml(); - (config.widget.plugin ? [].concat(config.widget.plugin) : []).forEach(function(plugin){ - (plugin.variable ? [].concat(plugin.variable) : []).forEach(function(variable){ - if((plugin._attributes.name === PLUGIN_ID || plugin._attributes.id === PLUGIN_ID) && variable._attributes.name && variable._attributes.value){ - pluginVariables[variable._attributes.name] = variable._attributes.value; - } + if(config) { + (config.widget.plugin ? [].concat(config.widget.plugin) : []).forEach(function (plugin) { + (plugin.variable ? [].concat(plugin.variable) : []).forEach(function (variable) { + if ((plugin._attributes.name === PLUGIN_ID || plugin._attributes.id === PLUGIN_ID) && variable._attributes.name && variable._attributes.value) { + pluginVariables[variable._attributes.name] = variable._attributes.value; + } + }); }); - }); + } // Parse package.json const packageJSON = parsePackageJson(); - if(packageJSON.cordova && packageJSON.cordova.plugins){ + if(packageJSON && packageJSON.cordova && packageJSON.cordova.plugins){ for(const pluginId in packageJSON.cordova.plugins){ if(pluginId === PLUGIN_ID){ for(const varName in packageJSON.cordova.plugins[pluginId]){ @@ -157,15 +159,23 @@ const parsePluginVariables = function(){ const parsePackageJson = function(){ if(projectPackageJsonData) return projectPackageJsonData; - projectPackageJsonData = JSON.parse(fs.readFileSync(projectPackageJsonPath)); - return projectPackageJsonData; + try{ + projectPackageJsonData = JSON.parse(fs.readFileSync(projectPackageJsonPath)); + return projectPackageJsonData; + }catch(e){ + console.warn("Failed to parse package.json: " + e.message); + } }; const parseConfigXml = function(){ if(configXmlData) return configXmlData; - data = parseXmlFileToJson(configXmlPath); - configXmlData = data.xml; - return configXmlData; + try{ + data = parseXmlFileToJson(configXmlPath); + configXmlData = data.xml; + return configXmlData; + }catch (e){ + console.warn("Failed to parse config.xml: " + e.message); + } }; const parsePluginXml = function(){