Skip to content

Commit

Permalink
feat: added build.json for iOS development team
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanneff committed Feb 9, 2017
1 parent c9a04d9 commit 6b43823
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
testbed/platforms
testbed/plugins
testbed/hooks
testbed/build.json
node_modules
.installed
.gradle/
Expand Down
2 changes: 1 addition & 1 deletion hooks/afterPrepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
iosPlist.addBranchSettings(preferences)
iosCapabilities.enableAssociatedDomains(preferences)
iosAssociatedDomains.addAssociatedDomains(preferences)
iosDevelopmentTeam.addDevelopmentTeam(context, preferences) // does not work
iosDevelopmentTeam.addDevelopmentTeam(preferences) // does not work, still needs to run through Xcode
}
})
}
Expand Down
95 changes: 74 additions & 21 deletions hooks/lib/ios/developmentTeam.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,97 @@
// TODO: does not work
// TODO: does not work. Automatic Signing of Provisioning Profile is not updating (https://pewpewthespells.com/blog/migrating_code_signing.html#automatic-signing-xcode-7)
// TODO: users will have to bypass by always opening up Xcode
(function () {
// properties
'use strict'
var fs = require('fs')
var path = require('path')
var encoding = 'utf-8'
var filepath = 'platforms/ios/cordova/build.xcconfig'

var fileName = 'build.json'

// entry
module.exports = {
addDevelopmentTeam: addDevelopmentTeam
}

// updates the development team for Universal Links
function addDevelopmentTeam (context, preferences) {
console.log('BRANCH SDK: Updating Development Team')
function addDevelopmentTeam (preferences) {
console.log('BRANCH SDK: Updating iOS development team')

var file = path.join(preferences.projectRoot, fileName)
var content = getBuildJson(file)
content = convertStringToJson(content)

if (context.opts.cordova.platforms.indexOf('ios') === -1) return
if (!context.opts.options) return
if (!context.opts.options.buildConfig) return
createDefaultBuildJson(content)
updateDevelopmentTeam(content, preferences)

var buildType = context.opts.options.release ? 'release' : 'debug'
content = convertJsonToString(content)
setBuildJson(file, content)
}

var buildConfigPath = context.opts.options.buildConfig
if (!path.isAbsolute(buildConfigPath)) {
buildConfigPath = path.join(context.opts.projectRoot, context.opts.options.buildConfig)
// json helper functions
function convertJsonToString (content) {
try {
// pretty-json
return JSON.stringify(content, null, 2)
} catch (err) {
throw new Error('Branch SDK cannot write build.json within your root directory.')
}
var config = require(buildConfigPath)
}

if (!config.ios) return
if (!config.ios[buildType]) return
if (!config.ios[buildType].developmentTeam) return
function convertStringToJson (content) {
// handle blank file
content = !content ? '{}' : content
try {
return JSON.parse(content)
} catch (err) {
throw new Error('Branch SDK cannot read build.json within your root directory.')
}
}

var xcconfig = fs.readFileSync(filepath, encoding)
// read build.json
function getBuildJson (file) {
try {
return fs.readFileSync(file, 'utf8')
} catch (err) {
// handle no file
return '{}'
}
}

if (xcconfig.indexOf('DEVELOPMENT_TEAM') === -1) {
var content = '\nDEVELOPMENT_TEAM = ' + config.ios[buildType].developmentTeam
// write build.json
function setBuildJson (file, content) {
fs.writeFileSync(file, content, 'utf8')
}

xcconfig += content
fs.writeFileSync(filepath, xcconfig, encoding)
// creates basic build.json if key-value pairs are missing
// {
// "ios": {
// "debug": {
// "developmentTeam": "FG35JLLMXX4A"
// },
// "release": {
// "developmentTeam": "FG35JLLMXX4A"
// }
// }
// }
function createDefaultBuildJson (content) {
if (!content.ios) {
content.ios = {}
}
if (!content.ios.debug) {
content.ios.debug = {}
}
if (!content.ios.release) {
content.ios.release = {}
}
}

// update build.json with developmentTeam from config.xml
function updateDevelopmentTeam (content, preferences) {
var release = preferences.iosTeamProd
var debug = (preferences.iosTeamDev) ? preferences.iosTeamDev : preferences.iosTeamProd

content.ios.release.developmentTeam = release
content.ios.debug.developmentTeam = debug
}
})()
14 changes: 8 additions & 6 deletions hooks/lib/sdk/configXml.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@
var bundleId = (configXml.widget['$'].hasOwnProperty('id')) ? configXml.widget['$']['id'] : null
var bundleName = (configXml.widget.hasOwnProperty('name')) ? configXml.widget.name[0] : null
var branchKey = (branchXml.hasOwnProperty('branch-key')) ? branchXml['branch-key'][0]['$']['value'] : null
var uriScheme = (branchXml.hasOwnProperty('uri-scheme')) ? branchXml['uri-scheme'][0]['$']['value'] : null
var linkDomain = (branchXml.hasOwnProperty('link-domain')) ? branchXml['link-domain'][0]['$']['value'] : null
var iosTeamId = (branchXml.hasOwnProperty('ios-team-id')) ? branchXml['ios-team-id'][0]['$']['value'] : null
var uriScheme = (branchXml.hasOwnProperty('uri-scheme')) ? branchXml['uri-scheme'][0]['$']['value'] : null
var iosTeamProd = (branchXml.hasOwnProperty('ios-team-prod')) ? branchXml['ios-team-prod'][0]['$']['value'] : null
var iosTeamDev = (branchXml.hasOwnProperty('ios-team-dev')) ? branchXml['ios-team-dev'][0]['$']['value'] : null
var androidPrefix = (branchXml.hasOwnProperty('android-prefix')) ? branchXml['android-prefix'][0]['$']['value'] : null

return {
Expand All @@ -64,8 +65,9 @@
'branchKey': branchKey,
'uriScheme': uriScheme,
'linkDomain': linkDomain,
'iosTeamId': iosTeamId,
'androidPrefix': androidPrefix
'iosTeamProd': iosTeamProd,
'iosTeamDev': iosTeamDev, // optional
'androidPrefix': androidPrefix // optional
}
}

Expand Down Expand Up @@ -101,8 +103,8 @@
if (preferences.linkDomain === null) {
throw new Error('Branch SDK plugin is missing "uri-scheme" in <branch-config> in your config.xml')
}
if (preferences.iosTeamId === null) {
throw new Error('Branch SDK plugin is missing "ios-team-id" in <branch-config> in your config.xml')
if (preferences.iosTeamProd === null) {
throw new Error('Branch SDK plugin is missing "ios-team-prod" in <branch-config> in your config.xml')
}
}
})()
2 changes: 1 addition & 1 deletion testbed/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<plugin name="branch-cordova-sdk" />
<branch-config>
<branch-key value="key_live_icCccJIpd7GlYY5oOmoEtpafuDiuyXhT" />
<ios-team-id value="PW4Q8885U7" />
<uri-scheme value="enefftest" />
<link-domain value="eneff.app.link" />
<ios-team-prod value="PW4Q8885U7" />
</branch-config>

<name>Branch Testing</name>
Expand Down

0 comments on commit 6b43823

Please sign in to comment.