Skip to content

Commit

Permalink
chore: added comments and reordered functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanneff committed Jan 9, 2017
1 parent 099d70b commit 2983bf2
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 32 deletions.
2 changes: 2 additions & 0 deletions hooks/beforePluginInstall.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// before plugin install hooks
(function () {
// properties
'use strict'
Expand All @@ -6,6 +7,7 @@
// entry
module.exports = run

// methods
function run (context) {
nodeDependencies.install(context)
}
Expand Down
2 changes: 1 addition & 1 deletion hooks/lib/ios/associatedDomains.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
addAssociatedDomains: addAssociatedDomains
}

// methods
function addAssociatedDomains (preferences) {
var file = path.join(preferences.projectRoot, 'platforms', 'ios', preferences.bundleName, 'Resources', preferences.bundleName + '.entitlements')
var entitlements = getEntitlements(file)
Expand All @@ -22,7 +23,6 @@
setEntitlements(file, entitlements)
}

// helper methods
function setEntitlements (file, entitlements) {
var plistContent = plist.build(entitlements)

Expand Down
2 changes: 2 additions & 0 deletions hooks/lib/ios/developmentTeam.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO: does not work
// update the development team for Universal Links
(function () {
// properties
Expand All @@ -12,6 +13,7 @@
addDevelopmentTeam: addDevelopmentTeam
}

// methods
function addDevelopmentTeam (context, preferences) {
if (context.opts.cordova.platforms.indexOf('ios') === -1) return
if (!context.opts.options) return
Expand Down
2 changes: 1 addition & 1 deletion hooks/lib/ios/plist.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
addBranchSettings: addBranchSettings
}

// methods
function addBranchSettings (preferences) {
var filePath = 'platforms/ios/' + preferences.bundleName + '/' + preferences.bundleName + '-Info.plist'
var xml = readPlist(filePath)
Expand All @@ -22,7 +23,6 @@
writePList(filePath, xml)
}

// helper methods
function convertXmlToObject (xml) {
return plist.parse(xml)
}
Expand Down
9 changes: 5 additions & 4 deletions hooks/lib/ios/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
enableAssociatedDomains: enableAssociatedDomains
}

// methods
function enableAssociatedDomains (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'))
Expand Down Expand Up @@ -45,21 +46,21 @@
}

if (deploymentTargetIsUpdated) {
console.log('IOS project now has deployment target set as: ' + IOS_DEPLOYMENT_TARGET)
console.warn('IOS project now has deployment target set as: ' + IOS_DEPLOYMENT_TARGET)
}

console.log('IOS project Code Sign Entitlements now set to: ' + entitlementsFile)
console.warn('IOS project Code Sign Entitlements now set to: ' + entitlementsFile)
}

function addPbxReference (xcodeProject, entitlementsFile) {
var fileReferenceSection = removeComments(xcodeProject.pbxFileReferenceSection())

if (isPbxReferenceAlreadySet(fileReferenceSection, entitlementsFile)) {
console.log('Entitlements file is in reference section.')
console.warn('Entitlements file is in reference section.')
return
}

console.log('Entitlements file is not in references section, adding it')
console.warn('Entitlements file is not in references section, adding it')
xcodeProject.addResourceFile(path.basename(entitlementsFile))
}

Expand Down
3 changes: 2 additions & 1 deletion hooks/lib/npm/nodeDependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
var deferral
var q

// hook entry
// entry
module.exports = {
install: install
}

// methods
function install (context) {
// set properties
q = context.requireCordovaModule('q')
Expand Down
55 changes: 30 additions & 25 deletions hooks/lib/sdk/configXml.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,39 @@
function read (context) {
var configXml = getConfigXml(context)
var branchXml = getBranchXml(configXml)
var branchPreferences = getBranchPerferences(context, configXml, branchXml)
var branchPreferences = getBranchPreferences(context, configXml, branchXml)

validateBranchPreferences(branchPreferences)

return branchPreferences
}

function getBranchPerferences (context, configXml, branchXml) {
// read config.xml
function getConfigXml (context) {
var projectRoot = getProjectRoot(context)
var pathToConfigXml = path.join(projectRoot, 'config.xml')
var configXml = xmlHelper.readXmlAsJson(pathToConfigXml)

if (configXml == null) {
throw new Error('config.xml not found! Please, check that it exist in your project\'s root directory.')
}

return configXml
}

// read <branch-config> within config.xml
function getBranchXml (configXml) {
var branchConfig = configXml.widget['branch-config']

if (branchConfig == null || branchConfig.length === 0) {
throw new Error('<branch-config> tag is not set in the config.xml. The Branch SDK is not properly installed.')
}

return branchConfig[0]
}

// read <branch-config> 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
Expand All @@ -45,10 +70,12 @@
}
}

// read app project location
function getProjectRoot (context) {
return context.opts.projectRoot
}

// read project platform
function getProjectPlatform (context) {
// pre-5.0 cordova structure
try {
Expand All @@ -58,29 +85,7 @@
}
}

function getConfigXml (context) {
// read data from projects root config.xml file
var projectRoot = getProjectRoot(context)
var pathToConfigXml = path.join(projectRoot, 'config.xml')
var configXml = xmlHelper.readXmlAsJson(pathToConfigXml)

if (configXml == null) {
throw new Error('config.xml not found! Please, check that it exist in your project\'s root directory.')
}

return configXml
}

function getBranchXml (configXml) {
var branchConfig = configXml.widget['branch-config']

if (branchConfig == null || branchConfig.length === 0) {
throw new Error('<branch-config> tag is not set in the config.xml. The Branch SDK is not properly installed.')
}

return branchConfig[0]
}

// validate <branch-config> properties within config.xml
function validateBranchPreferences (preferences) {
if (preferences.bundleId === null) {
throw new Error('Branch SDK plugin is missing "widget id" in your config.xml')
Expand Down

0 comments on commit 2983bf2

Please sign in to comment.