From 1e6cb103939c42e978b2850458b6ada1e62e47cc Mon Sep 17 00:00:00 2001 From: Ethan Neff Date: Wed, 14 Dec 2016 14:19:24 -0800 Subject: [PATCH] fix: added hooks for after_prepare and before_plugin_install --- hooks/after_prepare.js | 107 +++++++++++++++++++++++++++++++++ hooks/before_plugin_install.js | 14 +++++ 2 files changed, 121 insertions(+) create mode 100644 hooks/after_prepare.js create mode 100644 hooks/before_plugin_install.js diff --git a/hooks/after_prepare.js b/hooks/after_prepare.js new file mode 100644 index 00000000..422f31c4 --- /dev/null +++ b/hooks/after_prepare.js @@ -0,0 +1,107 @@ +'use strict'; + +// read the app/config.xml +// read the sdk/package.json + +(function () { + // properties + var configXmlHelper = require('./lib/sdk/configXmlHelper.js'); + var iosPlist = require('./lib/ios/plist.js'); + var iosPreferences = require('./lib/ios/preferences.js'); + var iosAssociatedDomains = require('./lib/ios/associatedDomains.js'); + var androidManifest = require('.lib/android/androidManifest.js'); + var IOS = 'ios'; + var ANDROID = 'android'; + var SDK = 'branch-cordova-sdk'; + + // entry + module.exports = install; + + function install(context) { + var preferences = readPreferences(context); + var platforms = context.opts.platforms; + + validatePreferences(preferences); + updatePlatforms(context, preferences, platforms); + } + + // helper methods + function updatePlatforms(context, preferences, platforms) { + platforms.forEach(function (platform) { + switch (platform) { + case ANDROID: + { + } + case IOS: + { + iosPlist.update(preferences); + iosPreferences.enableAssociatedDomains(context); + iosAssociatedDomains.addAssociatedDomains(preferences); + } + } + }); + } + + function readPreferences(context) { + // read data from projects root config.xml file + var configXml = new configXmlHelper(context).read(); + validateConfigXml(configXml); + + var branchXml = configXml.widget['branch-config']; + validateBranchXml(branchXml); + + var branchXmlPerferences = branchXml[0]; + + var bundleId = (configXml.widget['$'].hasOwnProperty('id')) ? configXml.widget['$']['id'] : null; + var bundleName = (configXml.widget.hasOwnProperty('name')) ? configXml.widget.name[0] : null; + var branchKey = (branchXmlPerferences.hasOwnProperty('branch-key')) ? branchXmlPerferences['branch-key'][0]['$']['value'] : null; + var uriScheme = (branchXmlPerferences.hasOwnProperty('uri-scheme')) ? branchXmlPerferences['uri-scheme'][0]['$']['value'] : null; + var linkDomain = (branchXmlPerferences.hasOwnProperty('link-domain')) ? branchXmlPerferences['link-domain'][0]['$']['value'] : null; + var iosTeamId = (branchXmlPerferences.hasOwnProperty('ios-team-id')) ? branchXmlPerferences['ios-team-id'][0]['$']['value'] : null; + var androidPrefix = (branchXmlPerferences.hasOwnProperty('android-prefix')) ? branchXmlPerferences['android-prefix'][0]['$']['value'] : null; + + return { + 'projectRoot': context.opts.projectRoot, + 'bundleId': bundleId, + 'bundleName': bundleName, + 'branchKey': branchKey, + 'uriScheme': uriScheme, + 'linkDomain': linkDomain, + 'iosTeamId': iosTeamId, + 'androidPrefix': androidPrefix + }; + } + + function validateConfigXml(configXml) { + if (configXml == null) { + throw new Error('config.xml not found! Please, check that it exist in your project\'s root directory.'); + } + } + + function validateBranchXml(branchXml) { + if (branchXml == null || branchXml.length == 0) { + throw new Error(' tag is not set in the config.xml. The Branch SDK is not properly installed.'); + } + } + + function validatePreferences(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 in your config.xml'); + } + if (preferences.uriScheme === null) { + throw new Error('Branch SDK plugin is missing "uri-scheme" in in your config.xml'); + } + if (preferences.linkDomain === null) { + throw new Error('Branch SDK plugin is missing "uri-scheme" in in your config.xml'); + } + if (preferences.iosTeamId === null) { + throw new Error('Branch SDK plugin is missing "ios-team-id" in in your config.xml'); + } + } +})(); diff --git a/hooks/before_plugin_install.js b/hooks/before_plugin_install.js new file mode 100644 index 00000000..ee68cac9 --- /dev/null +++ b/hooks/before_plugin_install.js @@ -0,0 +1,14 @@ +'use strict'; + +// before Branch SDK install hooks + +(function () { + // properties + var nodeDependencies = require('./lib/sdk/nodeDependencies.js'); + + // entry + module.exports = function(context) { + nodeDependencies.install(context); + }; +})(); +