Skip to content

Commit

Permalink
chore: relocated actions outside of main hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanneff committed Jan 9, 2017
1 parent 2600c2a commit f540a1e
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 119 deletions.
34 changes: 34 additions & 0 deletions hooks/afterPrepare.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// read the app/config.xml
// read the sdk/package.json
(function () {
// properties
'use strict'
var configPrefrences = require('./lib/sdk/configXml.js')
var iosPlist = require('./lib/ios/plist.js')
var iosPreferences = require('./lib/ios/xcodePreferences.js')
var iosAssociatedDomains = require('./lib/ios/associatedDomains.js')
var iosDevelopmentTeam = require('./lib/ios/developmentTeam.js')
// var androidManifest = require('.lib/android/androidManifest.js')
var IOS = 'ios'
var ANDROID = 'android'

// entry
module.exports = run

function run (context) {
var preferences = configPrefrences.read(context)
var platforms = context.opts.platforms

platforms.forEach(function (platform) {
if (platform === ANDROID) {

}
if (platform === IOS) {
iosPlist.addBranchSettings(preferences)
iosPreferences.enableAssociatedDomains(preferences)
iosAssociatedDomains.addAssociatedDomains(preferences)
iosDevelopmentTeam.addDevelopmentTeam(context, preferences)
}
})
}
})()
113 changes: 0 additions & 113 deletions hooks/after_prepare.js

This file was deleted.

12 changes: 12 additions & 0 deletions hooks/beforePluginInstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(function () {
// properties
'use strict'
var nodeDependencies = require('./lib/npm/nodeDependencies.js')

// entry
module.exports = run

function run (context) {
nodeDependencies.install(context)
}
})()
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
var q

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

function install (context) {
// set properties
q = context.requireCordovaModule('q')
deferral = new q.defer() // eslint-disable-line
installFlagLocation = path.join(context.opts.projectRoot, 'plugins', context.opts.plugin.id, installFlagName)
Expand Down Expand Up @@ -44,7 +47,6 @@
}

// installs the node modules via npm install one at a time
// @return {callback(error)}
function installNodeModules (modules, callback) {
// base case
if (modules.length <= 0) {
Expand All @@ -68,8 +70,7 @@
})
}

// checks to see which node modules need to be installed
// @return {[string]} of node modules from package.json.dependencies
// checks to see which node modules need to be installed from package.json.dependencies
function getNodeModulesToInstall (dependencies) {
var modules = []
for (var module in dependencies) {
Expand All @@ -85,7 +86,6 @@
}

// if the Branch SDK package has already been installed
// @return {boolean} based on .installed file is found
function getPackageInstalled () {
try {
fs.readFileSync(installFlagLocation)
Expand All @@ -96,7 +96,6 @@
}

// set that the Branch SDK package has been installed
// @return {void} based on .installed file is created
function setPackageInstalled () {
fs.closeSync(fs.openSync(installFlagLocation, 'w'))
}
Expand Down
104 changes: 104 additions & 0 deletions hooks/lib/sdk/configXml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// read branch config from config.xml
(function () {
// properties
'use strict'
var path = require('path')
var xmlHelper = require('./xmlHelper.js')

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

// methods
function read (context) {
var configXml = getConfigXml(context)
var branchXml = getBranchXml(configXml)
var branchPreferences = getBranchPerferences(context, configXml, branchXml)

validateBranchPreferences(branchPreferences)

return branchPreferences
}

function getBranchPerferences (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 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 androidPrefix = (branchXml.hasOwnProperty('android-prefix')) ? branchXml['android-prefix'][0]['$']['value'] : null

return {
'projectRoot': projectRoot,
'projectPlatform': projectPlatform,
'bundleId': bundleId,
'bundleName': bundleName,
'branchKey': branchKey,
'uriScheme': uriScheme,
'linkDomain': linkDomain,
'iosTeamId': iosTeamId,
'androidPrefix': androidPrefix
}
}

function getProjectRoot (context) {
return context.opts.projectRoot
}

function getProjectPlatform (context) {
// pre-5.0 cordova structure
try {
return context.requireCordovaModule('cordova-lib/src/plugman/platforms').ios
} catch (e) {
return context.requireCordovaModule('cordova-lib/src/plugman/platforms/ios')
}
}

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]
}

function validateBranchPreferences (preferences) {
if (preferences.bundleId === null) {
throw new Error('Branch SDK plugin is missing "widget id" in your config.xml')
}
if (preferences.bundleName === null) {
throw new Error('Branch SDK plugin is missing "name" in your config.xml')
}
if (preferences.branchKey === null) {
throw new Error('Branch SDK plugin is missing "branch-key" in <branch-config> in your config.xml')
}
if (preferences.uriScheme === null) {
throw new Error('Branch SDK plugin is missing "uri-scheme" in <branch-config> in your config.xml')
}
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')
}
}
})()

0 comments on commit f540a1e

Please sign in to comment.