Skip to content

Commit

Permalink
Port code to apply IOS_STRIP_DEBUG plugin variable to Podfile into th…
Browse files Browse the repository at this point in the history
…is plugin's hook scripts (from cordova-plugin-cocoapod-supportx).

Fixes #89
  • Loading branch information
Dave Alden committed Aug 16, 2019
1 parent a94af90 commit 4664cd5
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 5 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
},
"dependencies": {
"xcode": "^2.0.0",
"xml2js": "^0.4.16"
"xml2js": "^0.4.16",
"q": "^1.5.1"
}
}
66 changes: 62 additions & 4 deletions scripts/after_prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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);
Expand All @@ -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;
};
15 changes: 15 additions & 0 deletions scripts/ios/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
};

0 comments on commit 4664cd5

Please sign in to comment.