diff --git a/package.json b/package.json index f06947528..c4a8914d4 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ }, "dependencies": { "xcode": "^2.0.0", - "xml2js": "^0.4.16" + "xml2js": "^0.4.16", + "q": "^1.5.1" } } diff --git a/scripts/after_prepare.js b/scripts/after_prepare.js index e12c13636..6bb8fa3a7 100644 --- a/scripts/after_prepare.js +++ b/scripts/after_prepare.js @@ -9,13 +9,18 @@ */ var fs = require('fs'); var path = require('path'); +var Q = require('q'); +var parser = new (require('xml2js')).Parser(); + var utilities = require("./lib/utilities"); var config = fs.readFileSync('config.xml').toString(); var name = utilities.getValue(config, 'name'); +var pluginVariables = {}; var IOS_DIR = 'platforms/ios'; var ANDROID_DIR = 'platforms/android'; +var PLUGIN_ID = 'cordova-plugin-firebasex'; var PLATFORM = { IOS: { @@ -43,10 +48,56 @@ var PLATFORM = { } }; +var parsePluginVariables = function(){ + const deferred = Q.defer(); + var parseConfigXml = function () { + parser.parseString(config, function (err, data) { + if (data.widget.platform) { + (data.widget.plugin || []).forEach(function (plugin) { + (plugin.variable || []).forEach(function (variable) { + if((plugin.$.name === PLUGIN_ID || plugin.$.id === PLUGIN_ID) && variable.$.name && variable.$.value){ + pluginVariables[variable.$.name] = variable.$.value; + } + }); + }); + deferred.resolve(); + } + }); + return deferred.promise; + }; + + var parsePackageJson = function(){ + const deferred = Q.defer(); + var packageJSON = JSON.parse(fs.readFileSync('./package.json')); + if(packageJSON.cordova && packageJSON.cordova.plugins){ + for(const pluginId in packageJSON.cordova.plugins){ + if(pluginId === PLUGIN_ID){ + for(const varName in packageJSON.cordova.plugins[pluginId]){ + var varValue = packageJSON.cordova.plugins[pluginId][varName]; + pluginVariables[varName] = varValue; + } + } + } + } + deferred.resolve(); + return deferred.promise; + }; + + return parseConfigXml().then(parsePackageJson); +}; + module.exports = function (context) { + const deferred = Q.defer(); + //get platform from the context supplied by cordova var platforms = context.opts.platforms; + // Copy key files to their platform specific folders + if (platforms.indexOf('android') !== -1 && utilities.directoryExists(ANDROID_DIR)) { + console.log('Preparing Firebase on Android'); + utilities.copyKey(PLATFORM.ANDROID); + } + if (platforms.indexOf('ios') !== -1 && utilities.directoryExists(IOS_DIR)) { console.log('Preparing Firebase on iOS'); utilities.copyKey(PLATFORM.IOS); @@ -55,9 +106,16 @@ module.exports = function (context) { helper.getXcodeProjectPath(function(xcodeProjectPath){ helper.ensureRunpathSearchPath(context, xcodeProjectPath); }); + + parsePluginVariables().then(function(){ + if(pluginVariables['IOS_STRIP_DEBUG'] && pluginVariables['IOS_STRIP_DEBUG'] === 'true'){ + helper.stripDebugSymbols(); + deferred.resolve(); + } + }); + }else{ + deferred.resolve(); } - if (platforms.indexOf('android') !== -1 && utilities.directoryExists(ANDROID_DIR)) { - console.log('Preparing Firebase on Android'); - utilities.copyKey(PLATFORM.ANDROID); - } + + return deferred.promise; }; diff --git a/scripts/ios/helper.js b/scripts/ios/helper.js index 7e9b0fd3f..e405590d2 100644 --- a/scripts/ios/helper.js +++ b/scripts/ios/helper.js @@ -166,5 +166,20 @@ module.exports = { // Finally, write the .pbxproj back out to disk. fs.writeFileSync(xcodeProjectPath, xcodeProject.writeSync()); + }, + stripDebugSymbols: function(){ + var podFilePath = 'platforms/ios/Podfile', + podFile = fs.readFileSync(podFilePath).toString(); + if(!podFile.match('DEBUG_INFORMATION_FORMAT')){ + podFile += "\npost_install do |installer|\n" + + " installer.pods_project.targets.each do |target|\n" + + " target.build_configurations.each do |config|\n" + + " config.build_settings['DEBUG_INFORMATION_FORMAT'] = 'dwarf'\n" + + " end\n" + + " end\n" + + "end"; + fs.writeFileSync(podFilePath, podFile); + console.log('cordova-plugin-firebasex: Applied IOS_STRIP_DEBUG to Podfile'); + } } };