From 4507dd06c4a4bb46bc18c2c8bb73c90b6789dc63 Mon Sep 17 00:00:00 2001 From: Ethan Neff Date: Mon, 6 Mar 2017 21:16:19 -0800 Subject: [PATCH 1/7] style: renamed bundlename to projectname --- src/scripts/ios/associatedDomains.js | 4 ++-- src/scripts/ios/capabilities.js | 2 +- src/scripts/ios/plist.js | 2 +- src/scripts/sdk/configXml.js | 8 ++++++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/scripts/ios/associatedDomains.js b/src/scripts/ios/associatedDomains.js index 40ff3a1a..7eee0405 100644 --- a/src/scripts/ios/associatedDomains.js +++ b/src/scripts/ios/associatedDomains.js @@ -30,12 +30,12 @@ // get the xcode .entitlements and provisioning profile .plist function getEntitlementFiles (preferences) { var files = [] - var entitlements = path.join(preferences.projectRoot, 'platforms', 'ios', preferences.bundleName, 'Resources', preferences.bundleName + '.entitlements') + var entitlements = path.join(preferences.projectRoot, 'platforms', 'ios', preferences.projectName, 'Resources', preferences.projectName + '.entitlements') files.push(entitlements) for (var i = 0; i < BUILD_TYPES.length; i++) { var buildType = BUILD_TYPES[i] - var plist = path.join(preferences.projectRoot, 'platforms', 'ios', preferences.bundleName, 'Entitlements-' + buildType + '.plist') + var plist = path.join(preferences.projectRoot, 'platforms', 'ios', preferences.projectName, 'Entitlements-' + buildType + '.plist') files.push(plist) } diff --git a/src/scripts/ios/capabilities.js b/src/scripts/ios/capabilities.js index 757b33a6..fc5440e8 100755 --- a/src/scripts/ios/capabilities.js +++ b/src/scripts/ios/capabilities.js @@ -15,8 +15,8 @@ function enableAssociatedDomains (preferences) { console.log('BRANCH SDK: Updating iOS Xcode preferences') - var entitlementsFile = path.join(preferences.projectRoot, 'platforms', 'ios', preferences.bundleName, 'Resources', preferences.bundleName + '.entitlements') var projectFile = preferences.projectPlatform.parseProjectFile(path.join(preferences.projectRoot, 'platforms', 'ios')) + var entitlementsFile = path.join(preferences.projectRoot, 'platforms', 'ios', preferences.projectName, 'Resources', preferences.projectName + '.entitlements') activateAssociativeDomains(projectFile.xcode, entitlementsFile) addPbxReference(projectFile.xcode, entitlementsFile) diff --git a/src/scripts/ios/plist.js b/src/scripts/ios/plist.js index fc7bc898..6472b023 100644 --- a/src/scripts/ios/plist.js +++ b/src/scripts/ios/plist.js @@ -14,7 +14,7 @@ function addBranchSettings (preferences) { console.log('BRANCH SDK: Updating iOS info.plist') - var filePath = 'platforms/ios/' + preferences.bundleName + '/' + preferences.bundleName + '-Info.plist' + var filePath = 'platforms/ios/' + preferences.projectName + '/' + preferences.projectName + '-Info.plist' var xml = readPlist(filePath) var obj = convertXmlToObject(xml) diff --git a/src/scripts/sdk/configXml.js b/src/scripts/sdk/configXml.js index 0563ed39..1eb87dd0 100644 --- a/src/scripts/sdk/configXml.js +++ b/src/scripts/sdk/configXml.js @@ -62,7 +62,6 @@ 'projectRoot': projectRoot, 'projectPlatform': projectPlatform, 'bundleId': bundleId, - 'bundleName': bundleName, 'branchKey': branchKey, 'uriScheme': uriScheme, 'linkDomain': linkDomain, @@ -70,12 +69,17 @@ 'iosTeamDebug': iosTeamDebug, // optional 'androidPrefix': androidPrefix, // optional 'androidTestMode': androidTestMode // optional + 'projectName': getProjectName(configXml), } } // read app project location function getProjectRoot (context) { return context.opts.projectRoot + // read project name from config.xml + function getProjectName (configXml) { + return (configXml.widget.hasOwnProperty('name')) ? configXml.widget.name[0] : null + } } // read project platform @@ -93,7 +97,7 @@ if (preferences.bundleId === null) { throw new Error('BRANCH SDK: Invalid "widget id" in your config.xml. Docs https://goo.gl/GijGKP') } - if (preferences.bundleName === null) { + if (preferences.projectName === null) { throw new Error('BRANCH SDK: Invalid "name" in your config.xml. Docs https://goo.gl/GijGKP') } if (preferences.branchKey === null) { From ec5f7db64cbbb50c6b8cd3336d6df1d0605799fc Mon Sep 17 00:00:00 2001 From: Ethan Neff Date: Mon, 6 Mar 2017 21:17:35 -0800 Subject: [PATCH 2/7] style: renamed projectplatform to iosprojectmodule --- src/scripts/ios/capabilities.js | 2 +- src/scripts/sdk/configXml.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/scripts/ios/capabilities.js b/src/scripts/ios/capabilities.js index fc5440e8..3842143a 100755 --- a/src/scripts/ios/capabilities.js +++ b/src/scripts/ios/capabilities.js @@ -15,8 +15,8 @@ function enableAssociatedDomains (preferences) { console.log('BRANCH SDK: Updating iOS Xcode preferences') - var projectFile = preferences.projectPlatform.parseProjectFile(path.join(preferences.projectRoot, 'platforms', 'ios')) var entitlementsFile = path.join(preferences.projectRoot, 'platforms', 'ios', preferences.projectName, 'Resources', preferences.projectName + '.entitlements') + var projectFile = preferences.iosProjectModule.parseProjectFile(path.join(preferences.projectRoot, 'platforms', 'ios')) activateAssociativeDomains(projectFile.xcode, entitlementsFile) addPbxReference(projectFile.xcode, entitlementsFile) diff --git a/src/scripts/sdk/configXml.js b/src/scripts/sdk/configXml.js index 1eb87dd0..c5a172ec 100644 --- a/src/scripts/sdk/configXml.js +++ b/src/scripts/sdk/configXml.js @@ -60,7 +60,6 @@ return { 'projectRoot': projectRoot, - 'projectPlatform': projectPlatform, 'bundleId': bundleId, 'branchKey': branchKey, 'uriScheme': uriScheme, @@ -70,6 +69,7 @@ 'androidPrefix': androidPrefix, // optional 'androidTestMode': androidTestMode // optional 'projectName': getProjectName(configXml), + 'iosProjectModule': getProjectModule(context), } } @@ -82,8 +82,8 @@ } } - // read project platform - function getProjectPlatform (context) { + // read iOS project module from cordova context + function getProjectModule (context) { // try pre-5.0 cordova structure try { return context.requireCordovaModule('cordova-lib/src/plugman/platforms').ios From f05ae3022866383c701c0c67ccc2aac89eda4b46 Mon Sep 17 00:00:00 2001 From: Ethan Neff Date: Mon, 6 Mar 2017 21:19:13 -0800 Subject: [PATCH 3/7] fix: added support for iOS and Android bundle ids --- README.md | 4 ++++ src/scripts/sdk/configXml.js | 29 ++++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1ef387e3..5c8ae0fb 100644 --- a/README.md +++ b/README.md @@ -597,6 +597,10 @@ ``` + ```xml + + ``` + - #### Testing: Sample Testing App - [Branch Testing App](https://github.com/BranchMetrics/cordova-ionic-phonegap-branch-deep-linking/tree/master/testbed) diff --git a/src/scripts/sdk/configXml.js b/src/scripts/sdk/configXml.js index c5a172ec..ac744b25 100644 --- a/src/scripts/sdk/configXml.js +++ b/src/scripts/sdk/configXml.js @@ -60,7 +60,6 @@ return { 'projectRoot': projectRoot, - 'bundleId': bundleId, 'branchKey': branchKey, 'uriScheme': uriScheme, 'linkDomain': linkDomain, @@ -69,7 +68,9 @@ 'androidPrefix': androidPrefix, // optional 'androidTestMode': androidTestMode // optional 'projectName': getProjectName(configXml), + 'iosBundleId': getBundleId(configXml, 'ios'), 'iosProjectModule': getProjectModule(context), + 'androidBundleId': getBundleId(configXml, 'android'), // optional } } @@ -80,6 +81,24 @@ function getProjectName (configXml) { return (configXml.widget.hasOwnProperty('name')) ? configXml.widget.name[0] : null } + + // read branch value from + function getBranchValue (branchXml, key) { + return (branchXml.hasOwnProperty(key)) ? branchXml[key][0]['$']['value'] : null + } + + // read bundle id from config.xml (optional values override widget-id) + function getBundleId (configXml, platform) { + var output = null + var key = platform === 'ios' ? 'ios-CFBundleIdentifier' : 'android-packageName' + + if (configXml.widget['$'].hasOwnProperty(key)) { + output = configXml.widget['$'][key] + } else if (configXml.widget['$'].hasOwnProperty('id')) { + output = configXml.widget['$']['id'] + } + + return output } // read iOS project module from cordova context @@ -94,8 +113,6 @@ // validate properties within config.xml function validateBranchPreferences (preferences) { - if (preferences.bundleId === null) { - throw new Error('BRANCH SDK: Invalid "widget id" in your config.xml. Docs https://goo.gl/GijGKP') } if (preferences.projectName === null) { throw new Error('BRANCH SDK: Invalid "name" in your config.xml. Docs https://goo.gl/GijGKP') @@ -109,12 +126,18 @@ if (preferences.linkDomain === null || !/^(?!.*?www).*([a-zA-Z0-9]+(\.[a-zA-Z0-9]+)+.*)$/.test(preferences.linkDomain)) { throw new Error('BRANCH SDK: Invalid "link-domain" in in your config.xml. Docs https://goo.gl/GijGKP') } + if (preferences.iosBundleId === null || !/^[a-zA-Z0-9.]*$/.test(preferences.iosBundleId)) { + throw new Error('BRANCH SDK: Invalid "id" or "ios-CFBundleIdentifier" in in your config.xml. Docs https://goo.gl/GijGKP') + } if (preferences.iosTeamRelease === null || !/^[a-zA-Z0-9]{10}$/.test(preferences.iosTeamRelease)) { throw new Error('BRANCH SDK: Invalid "ios-team-release" in in your config.xml. Docs https://goo.gl/GijGKP') } if (preferences.iosTeamDebug !== null && !/^[a-zA-Z0-9]{10}$/.test(preferences.iosTeamDebug)) { throw new Error('BRANCH SDK: Invalid "ios-team-debug" in in your config.xml. Docs https://goo.gl/GijGKP') } + if (preferences.androidBundleId !== null && !/^[a-zA-Z0-9.]*$/.test(preferences.androidBundleId)) { + throw new Error('BRANCH SDK: Invalid "id" or "android-packageName" in in your config.xml. Docs https://goo.gl/GijGKP') + } if (preferences.androidPrefix !== null && !/^[/].[a-zA-Z0-9]{3}$/.test(preferences.androidPrefix)) { throw new Error('BRANCH SDK: Invalid "android-prefix" in in your config.xml. Docs https://goo.gl/GijGKP') } From 3792c180552f00c76f4e2c2f36987edab15cdc7a Mon Sep 17 00:00:00 2001 From: Ethan Neff Date: Mon, 6 Mar 2017 21:19:44 -0800 Subject: [PATCH 4/7] refactor: added validation to config.xml and cleaned up code --- src/scripts/android/androidManifest.js | 2 +- src/scripts/sdk/configXml.js | 47 ++++++++++++-------------- 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/scripts/android/androidManifest.js b/src/scripts/android/androidManifest.js index 079ded0d..38f34894 100644 --- a/src/scripts/android/androidManifest.js +++ b/src/scripts/android/androidManifest.js @@ -35,7 +35,7 @@ var metadatas = manifest['manifest']['application'][0]['meta-data'] || [] var metadata = [] var keys = ['io.branch.sdk.BranchKey', 'io.branch.sdk.TestMode'] - var vals = [preferences.branchKey, preferences.androidTestMode] + var vals = [preferences.branchKey, preferences.androidTestMode || 'false'] // remove old for (var i = 0; i < keys.length; i++) { diff --git a/src/scripts/sdk/configXml.js b/src/scripts/sdk/configXml.js index ac744b25..52eee7b2 100644 --- a/src/scripts/sdk/configXml.js +++ b/src/scripts/sdk/configXml.js @@ -11,7 +11,8 @@ // read branch config from config.xml function read (context) { - var configXml = getConfigXml(context) + var projectRoot = getProjectRoot(context) + var configXml = getConfigXml(projectRoot) var branchXml = getBranchXml(configXml) var branchPreferences = getBranchPreferences(context, configXml, branchXml) @@ -21,8 +22,7 @@ } // read config.xml - function getConfigXml (context) { - var projectRoot = getProjectRoot(context) + function getConfigXml (projectRoot) { var pathToConfigXml = path.join(projectRoot, 'config.xml') var configXml = xmlHelper.readXmlAsJson(pathToConfigXml) @@ -46,37 +46,27 @@ // read properties within config.xml function getBranchPreferences (context, configXml, branchXml) { - var projectRoot = getProjectRoot(context) - var projectPlatform = getProjectPlatform(context) - 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 linkDomain = (branchXml.hasOwnProperty('link-domain')) ? branchXml['link-domain'][0]['$']['value'] : null - var uriScheme = (branchXml.hasOwnProperty('uri-scheme')) ? branchXml['uri-scheme'][0]['$']['value'] : null - var iosTeamRelease = (branchXml.hasOwnProperty('ios-team-release')) ? branchXml['ios-team-release'][0]['$']['value'] : null - var iosTeamDebug = (branchXml.hasOwnProperty('ios-team-debug')) ? branchXml['ios-team-debug'][0]['$']['value'] : null - var androidPrefix = (branchXml.hasOwnProperty('android-prefix')) ? branchXml['android-prefix'][0]['$']['value'] : null - var androidTestMode = (branchXml.hasOwnProperty('android-testmode')) ? branchXml['android-testmode'][0]['$']['value'] : 'false' - return { - 'projectRoot': projectRoot, - 'branchKey': branchKey, - 'uriScheme': uriScheme, - 'linkDomain': linkDomain, - 'iosTeamRelease': iosTeamRelease, - 'iosTeamDebug': iosTeamDebug, // optional - 'androidPrefix': androidPrefix, // optional - 'androidTestMode': androidTestMode // optional + 'projectRoot': getProjectRoot(context), 'projectName': getProjectName(configXml), + 'branchKey': getBranchValue(branchXml, 'branch-key'), + 'linkDomain': getBranchValue(branchXml, 'link-domain'), + 'uriScheme': getBranchValue(branchXml, 'uri-scheme'), 'iosBundleId': getBundleId(configXml, 'ios'), 'iosProjectModule': getProjectModule(context), + 'iosTeamRelease': getBranchValue(branchXml, 'ios-team-release'), + 'iosTeamDebug': getBranchValue(branchXml, 'ios-team-debug'), // optional 'androidBundleId': getBundleId(configXml, 'android'), // optional + 'androidPrefix': getBranchValue(branchXml, 'android-prefix'), // optional + 'androidTestMode': getBranchValue(branchXml, 'android-testmode') // optional } } - // read app project location + // read project root from cordova context function getProjectRoot (context) { - return context.opts.projectRoot + return context.opts.projectRoot || null + } + // read project name from config.xml function getProjectName (configXml) { return (configXml.widget.hasOwnProperty('name')) ? configXml.widget.name[0] : null @@ -113,6 +103,11 @@ // validate properties within config.xml function validateBranchPreferences (preferences) { + if (preferences.projectRoot === null) { + throw new Error('BRANCH SDK: Invalid "root" in your config.xml. Docs https://goo.gl/GijGKP') + } + if (preferences.projectPlatform === null) { + throw new Error('BRANCH SDK: Invalid "platform" in your config.xml. Docs https://goo.gl/GijGKP') } if (preferences.projectName === null) { throw new Error('BRANCH SDK: Invalid "name" in your config.xml. Docs https://goo.gl/GijGKP') @@ -141,7 +136,7 @@ if (preferences.androidPrefix !== null && !/^[/].[a-zA-Z0-9]{3}$/.test(preferences.androidPrefix)) { throw new Error('BRANCH SDK: Invalid "android-prefix" in in your config.xml. Docs https://goo.gl/GijGKP') } - if (!(preferences.androidTestMode === 'true' || preferences.androidTestMode === 'false')) { + if (!(preferences.androidTestMode === 'true' || preferences.androidTestMode === 'false' || preferences.androidTestMode === null)) { throw new Error('BRANCH SDK: Invalid "android-testmode" in in your config.xml. Docs https://goo.gl/GijGKP') } } From c8e539194849fbbded592dfd886b7407356260ef Mon Sep 17 00:00:00 2001 From: Ethan Neff Date: Tue, 7 Mar 2017 00:03:26 -0800 Subject: [PATCH 5/7] chore: updated npm version --- package.json | 9 +++++---- plugin.template.xml | 2 +- plugin.xml | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 7dad8756..ff0d3a32 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "branch-cordova-sdk", "description": "Branch Metrics Cordova SDK", "main": "www/branch.js", - "version": "2.5.3", + "version": "2.5.5", "homepage": "https://github.com/BranchMetrics/cordova-ionic-phonegap-branch-deep-linking", "repository": { "type": "git", @@ -37,8 +37,9 @@ }, "scripts": { "commitmsg": "validate-commit-msg", + "precommit": "semantic-release pre --verifyRelease='./src/scripts/npm/nodeVersion'", "prerelease": "gulp prod", - "semantic-release": "semantic-release pre --verifyRelease='./src/scripts/npm/nodeVersion' && npm publish && semantic-release post" + "semantic-release": "semantic-release pre && npm publish && semantic-release post" }, "dependencies": { "mkpath": "^1.0.0", @@ -53,8 +54,8 @@ "mkpath": "^1.0.0", "node-version-compare": "^1.0.1", "plist": "^1.2.0", - "semantic-release": "^4.3.5", + "semantic-release": "^6.3.6", "validate-commit-msg": "^2.8.2", "xml2js": "^0.4.17" } -} +} \ No newline at end of file diff --git a/plugin.template.xml b/plugin.template.xml index 68d4da5e..00cd666f 100644 --- a/plugin.template.xml +++ b/plugin.template.xml @@ -24,7 +24,7 @@ SOFTWARE. + version="2.5.5"> diff --git a/plugin.xml b/plugin.xml index 5ecadd04..e60d16db 100644 --- a/plugin.xml +++ b/plugin.xml @@ -24,7 +24,7 @@ SOFTWARE. + version="2.5.5"> From cf94144ccff8a670b001112cc002c490d926b61d Mon Sep 17 00:00:00 2001 From: Ethan Neff Date: Tue, 7 Mar 2017 08:37:31 -0800 Subject: [PATCH 6/7] test: precommit to postcommit --- package.json | 2 +- src/scripts/sdk/configXml.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index ff0d3a32..b318d648 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ }, "scripts": { "commitmsg": "validate-commit-msg", - "precommit": "semantic-release pre --verifyRelease='./src/scripts/npm/nodeVersion'", + "postcommit": "semantic-release pre --verifyRelease='./src/scripts/npm/nodeVersion'", "prerelease": "gulp prod", "semantic-release": "semantic-release pre && npm publish && semantic-release post" }, diff --git a/src/scripts/sdk/configXml.js b/src/scripts/sdk/configXml.js index 52eee7b2..76df7e4c 100644 --- a/src/scripts/sdk/configXml.js +++ b/src/scripts/sdk/configXml.js @@ -136,7 +136,7 @@ if (preferences.androidPrefix !== null && !/^[/].[a-zA-Z0-9]{3}$/.test(preferences.androidPrefix)) { throw new Error('BRANCH SDK: Invalid "android-prefix" in in your config.xml. Docs https://goo.gl/GijGKP') } - if (!(preferences.androidTestMode === 'true' || preferences.androidTestMode === 'false' || preferences.androidTestMode === null)) { + if (!(preferences.androidTestMode === 'true' || preferences.androidTestMode === 'false' || preferences.androidTestMode === null)) { throw new Error('BRANCH SDK: Invalid "android-testmode" in in your config.xml. Docs https://goo.gl/GijGKP') } } From 326d1825d5e0d6e593ded026ab707766943bd3d6 Mon Sep 17 00:00:00 2001 From: Ethan Neff Date: Tue, 7 Mar 2017 08:52:28 -0800 Subject: [PATCH 7/7] fix: iOS spotlight disable on android --- src/branch.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/branch.js b/src/branch.js index 24e3f623..d2f7fb6c 100644 --- a/src/branch.js +++ b/src/branch.js @@ -153,7 +153,7 @@ Branch.prototype.createBranchUniversalObject = function (options) { } obj.listOnSpotlight = function () { - if (deviceVendor.indexOf('Apple') < 0) { + if (!(deviceVendor.indexOf('Apple') < 0)) { return execute('listOnSpotlight', [obj.instanceId]) } else { return new Promise(function (resolve, reject) {