Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cmfsotelo/355d8020e2bf830ac1ec11f53dd79463 to your computer and use it in GitHub Desktop.
Save cmfsotelo/355d8020e2bf830ac1ec11f53dd79463 to your computer and use it in GitHub Desktop.
Cordova hook to add build settings to ios platform to use with plugins
module.exports = function (ctx) {
var fs = ctx.requireCordovaModule("fs");
var path = ctx.requireCordovaModule("path");
var xcode = ctx.requireCordovaModule("xcode");
var deferral = ctx.requireCordovaModule('q').defer();
/**
* Recursively search for file with the tiven filter starting on startPath
*/
function searchRecursiveFromPath(startPath, filter, rec, multiple) {
if (!fs.existsSync(startPath)) {
console.log("no dir ", startPath);
return;
}
var files = fs.readdirSync(startPath);
var resultFiles = []
for (var i = 0; i < files.length; i++) {
var filename = path.join(startPath, files[i]);
var stat = fs.lstatSync(filename);
if (stat.isDirectory() && rec) {
fromDir(filename, filter); //recurse
}
if (filename.indexOf(filter) >= 0) {
if (multiple) {
resultFiles.push(filename);
} else {
return filename;
}
}
}
if (multiple) {
return resultFiles;
}
}
var xcodeProjPath = searchRecursiveFromPath('platforms/ios', '.xcodeproj', false);
var projectPath = xcodeProjPath + '/project.pbxproj';
console.log("Found", projectPath);
var proj = xcode.project(projectPath);
var mXCBuildConfigurationSections = proj.parseSync().pbxXCBuildConfigurationSection()
//create the new BuildConfig
var newBuildConfig = {}
for(prop in mXCBuildConfigurationSections) {
var value = mXCBuildConfigurationSections[prop];
if(!(typeof value === 'string')) {
/*
* ADD BUILD SETTINGS HERE
*/
value.buildSettings['EMBEDDED_CONTENT_CONTAINS_SWIFT'] = "YES"
/*
* END
*/
}
newBuildConfig[prop] = value;
}
//Change BuildConfigs
proj.hash.project.objects['XCBuildConfiguration'] = newBuildConfig
fs.writeFile(proj.filepath, proj.writeSync(), 'utf8', function (err) {
if (err) {
deferral.reject(err);
return;
}
console.log("finished writing xcodeproj");
deferral.resolve();
});
return deferral.promise;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment