From a5bd04b227fc30b79953a9828481b976072f72c2 Mon Sep 17 00:00:00 2001 From: Ethan Neff Date: Fri, 16 Dec 2016 14:59:06 -0800 Subject: [PATCH] feat: hook to update development team for ios --- hooks/lib/ios/developmentTeam.js | 41 ++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 hooks/lib/ios/developmentTeam.js diff --git a/hooks/lib/ios/developmentTeam.js b/hooks/lib/ios/developmentTeam.js new file mode 100644 index 00000000..5a1cc80b --- /dev/null +++ b/hooks/lib/ios/developmentTeam.js @@ -0,0 +1,41 @@ +// update the development team for Universal Links +(function () { + // properties + 'use strict' + var fs = require('fs') + var path = require('path') + var encoding = 'utf-8' + var filepath = 'platforms/ios/cordova/build.xcconfig' + + // entry + module.exports = { + addDevelopmentTeam: addDevelopmentTeam + } + + function addDevelopmentTeam (context, preferences) { + 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) + } + } +})()