From 2983bf2a1bf6314aaa084496d2bcbd808e086430 Mon Sep 17 00:00:00 2001 From: Ethan Neff Date: Mon, 9 Jan 2017 15:02:40 -0800 Subject: [PATCH] chore: added comments and reordered functions --- hooks/beforePluginInstall.js | 2 ++ hooks/lib/ios/associatedDomains.js | 2 +- hooks/lib/ios/developmentTeam.js | 2 ++ hooks/lib/ios/plist.js | 2 +- hooks/lib/ios/preferences.js | 9 ++--- hooks/lib/npm/nodeDependencies.js | 3 +- hooks/lib/sdk/configXml.js | 55 ++++++++++++++++-------------- 7 files changed, 43 insertions(+), 32 deletions(-) diff --git a/hooks/beforePluginInstall.js b/hooks/beforePluginInstall.js index b28c2c13..204a7db6 100644 --- a/hooks/beforePluginInstall.js +++ b/hooks/beforePluginInstall.js @@ -1,3 +1,4 @@ +// before plugin install hooks (function () { // properties 'use strict' @@ -6,6 +7,7 @@ // entry module.exports = run + // methods function run (context) { nodeDependencies.install(context) } diff --git a/hooks/lib/ios/associatedDomains.js b/hooks/lib/ios/associatedDomains.js index 2c3df163..5c63e72f 100644 --- a/hooks/lib/ios/associatedDomains.js +++ b/hooks/lib/ios/associatedDomains.js @@ -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) @@ -22,7 +23,6 @@ setEntitlements(file, entitlements) } - // helper methods function setEntitlements (file, entitlements) { var plistContent = plist.build(entitlements) diff --git a/hooks/lib/ios/developmentTeam.js b/hooks/lib/ios/developmentTeam.js index 5a1cc80b..bd5fb660 100644 --- a/hooks/lib/ios/developmentTeam.js +++ b/hooks/lib/ios/developmentTeam.js @@ -1,3 +1,4 @@ +// TODO: does not work // update the development team for Universal Links (function () { // properties @@ -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 diff --git a/hooks/lib/ios/plist.js b/hooks/lib/ios/plist.js index db658737..28aef272 100644 --- a/hooks/lib/ios/plist.js +++ b/hooks/lib/ios/plist.js @@ -11,6 +11,7 @@ addBranchSettings: addBranchSettings } + // methods function addBranchSettings (preferences) { var filePath = 'platforms/ios/' + preferences.bundleName + '/' + preferences.bundleName + '-Info.plist' var xml = readPlist(filePath) @@ -22,7 +23,6 @@ writePList(filePath, xml) } - // helper methods function convertXmlToObject (xml) { return plist.parse(xml) } diff --git a/hooks/lib/ios/preferences.js b/hooks/lib/ios/preferences.js index 2b6e151f..cfed4595 100755 --- a/hooks/lib/ios/preferences.js +++ b/hooks/lib/ios/preferences.js @@ -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')) @@ -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)) } diff --git a/hooks/lib/npm/nodeDependencies.js b/hooks/lib/npm/nodeDependencies.js index f1cd3369..d3b973c9 100644 --- a/hooks/lib/npm/nodeDependencies.js +++ b/hooks/lib/npm/nodeDependencies.js @@ -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') diff --git a/hooks/lib/sdk/configXml.js b/hooks/lib/sdk/configXml.js index b0311926..77b30ab2 100644 --- a/hooks/lib/sdk/configXml.js +++ b/hooks/lib/sdk/configXml.js @@ -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 within config.xml + function getBranchXml (configXml) { + var branchConfig = configXml.widget['branch-config'] + + if (branchConfig == null || branchConfig.length === 0) { + throw new Error(' tag is not set in the config.xml. The Branch SDK is not properly installed.') + } + + return branchConfig[0] + } + + // 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 @@ -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 { @@ -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(' tag is not set in the config.xml. The Branch SDK is not properly installed.') - } - - return branchConfig[0] - } - + // validate 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')