From 49c39fd41d101536f2e49a43b0eb5e1346c1e623 Mon Sep 17 00:00:00 2001 From: Benjamin Reed Date: Mon, 10 Apr 2017 17:02:55 -0400 Subject: [PATCH] chore(): add a hook to make builds work nicely with xcode8+ --- hooks/before_compile/xcode8.js | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 hooks/before_compile/xcode8.js diff --git a/hooks/before_compile/xcode8.js b/hooks/before_compile/xcode8.js new file mode 100755 index 0000000..ec405f4 --- /dev/null +++ b/hooks/before_compile/xcode8.js @@ -0,0 +1,39 @@ +#!/usr/bin/env node + +"use strict"; + +var fs = require('fs'); +var path = require('path'); + +module.exports = function(context) { + var encoding = 'utf-8'; + var filepath = 'platforms/ios/cordova/build.xcconfig'; + + if (context.opts.cordova.platforms.indexOf('ios') === -1) return; + if (!context.opts.options) return; + if (!context.opts.options.buildConfig) return; + + + var buildType = context.opts.options.release ? 'release' : 'debug'; + + var buildConfigPath = context.opts.options.buildConfig; + if (!path.isAbsolute(buildConfigPath)) { + buildConfigPath = path.join(context.opts.projectRoot, context.opts.options.buildConfig); + } + var config = require(buildConfigPath); + + + if (!config.ios) return; + if (!config.ios[buildType]) return; + if (!config.ios[buildType].developmentTeam) return; + + + var xcconfig = fs.readFileSync(filepath, encoding); + + if (xcconfig.indexOf('DEVELOPMENT_TEAM') === -1) { + var content = '\nDEVELOPMENT_TEAM = ' + config.ios[buildType].developmentTeam; + + xcconfig += content; + fs.writeFileSync(filepath, xcconfig, encoding); + } +};