Skip to content

Commit

Permalink
refactor(plugin.xml): generate ios references based on build target
Browse files Browse the repository at this point in the history
  • Loading branch information
amit-bansil committed Aug 3, 2016
1 parent cac6a12 commit 67d70cf
Show file tree
Hide file tree
Showing 3 changed files with 176 additions and 19 deletions.
49 changes: 49 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
var gulp = require('gulp');
var fs = require('fs');

//generate plugin.xml for use as a cordova plugin
//here we explode the contents of the frameworks
gulp.task('gen-npm-plugin-xml', function(){
var xml = fs.readFileSync('plugin.template.xml', 'utf-8');

var files = [];
var root = 'src/ios/dependencies/';
files = files.concat(emitFiles(root + 'Fabric/'));
files = files.concat(emitFiles(root + 'Branch-SDK/'));
files = files.concat(emitFiles(root + 'Branch-SDK/Requests/'));

var newLineIndent = '\n ';
xml = xml.replace('<!--[Branch Framework Reference]-->', newLineIndent
+ files.join(newLineIndent));

fs.writeFileSync('plugin.xml', xml);
});

//generate plugin.xml for local development
//here we reference the frameworks instead of all the files directly
gulp.task('gen-dev-plugin-xml', function(){
var xml = fs.readFileSync('plugin.template.xml', 'utf-8');

xml = xml.replace('<!--[Branch Framework Reference]-->',
'<framework custom="true" src="src/ios/dependencies/Branch.framework" />');

fs.writeFileSync('plugin.xml', xml);
});

//emit array of cordova file references for all .h/.m files in path
function emitFiles(path){
var ret = [];
for(filename of fs.readdirSync(path)){
var fileType = null;
if(filename.match(/\.m$/)){
fileType = 'source';
}else if(filename.match(/\.h$/) || filename.match(/\.pch$/)){
fileType = 'header';
}
if(fileType){
ret.push('<' + fileType + '-file src="' + path + filename + '" />');
}
}
ret.push('');
return ret;
}
108 changes: 108 additions & 0 deletions plugin.template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The MIT License (MIT)
Copyright (c) 2015 Branch Metrics, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="io.branch.sdk"
version="2.1.10">

<name>branch-cordova-sdk</name>
<description>Branch SDK Plugin</description>
<license>Apache 2.0</license>
<keywords>cordova,branch</keywords>
<repo>https://github.com/BranchMetrics/Cordova-Ionic-PhoneGap-Deferred-Deep-Linking-SDK.git</repo>
<issue>https://github.com/BranchMetrics/Cordova-Ionic-PhoneGap-Deferred-Deep-Linking-SDK/issues</issue>

<dependency
id="es6-promise-plugin"
url="https://github.com/vstirbu/PromisesPlugin.git">
</dependency>

<js-module src="www/branch.js" name="Branch">
<clobbers target="Branch" />
</js-module>

<preference name="BRANCH_KEY" />
<preference name="URI_SCHEME" />

<!-- Hooks -->
<hook src="hooks/afterPrepareHook.js" type="after_prepare" />
<hook src="hooks/beforePluginInstallHook.js" type="before_plugin_install" />

<engines>
<engine name="cordova" version=">=3.5.0" />
</engines>

<!-- android -->
<platform name="android">
<config-file target="config.xml" parent="/*">
<feature name="BranchSDK">
<param name="android-package" value="io.branch.BranchSDK" />
<param name="onload" value="true" />
</feature>
</config-file>
<config-file target="AndroidManifest.xml" parent="/manifest/application">
<meta-data android:name="io.branch.sdk.BranchKey" android:value="$BRANCH_KEY" />
</config-file>
<config-file target="AndroidManifest.xml" parent="/manifest/application/activity">
<!-- Non AppLink example -->
<intent-filter>
<data android:scheme="$URI_SCHEME" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</config-file>
<source-file src="src/android/io/branch/BranchSDK.java" target-dir="src/io/branch" />
<framework src="io.branch.sdk.android:library:1+" />
</platform>

<!-- ios -->
<platform name="ios">
<config-file target="config.xml" parent="/*">
<feature name="BranchSDK">
<param name="ios-package" value="BranchSDK" />
</feature>
</config-file>
<config-file target="*-Info.plist" parent="branch_key">
<string>$BRANCH_KEY</string>
</config-file>
<config-file target="*-Info.plist" parent="CFBundleURLTypes">
<array>
<dict>
<key>CFBundleURLName</key>
<string>io.branch.sdk</string>
<key>CFBundleURLSchemes</key>
<array>
<string>$URI_SCHEME</string>
</array>
</dict>
</array>
</config-file>
<header-file src="src/ios/BranchSDK.h" />
<source-file src="src/ios/BranchSDK.m" />
<source-file src="src/ios/AppDelegate+BranchSdk.m" />
<!--[Branch Framework Reference]-->
</platform>
</plugin>
38 changes: 19 additions & 19 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,24 +103,26 @@ SOFTWARE.
<header-file src="src/ios/BranchSDK.h" />
<source-file src="src/ios/BranchSDK.m" />
<source-file src="src/ios/AppDelegate+BranchSdk.m" />
<!-- COMMENT if building for NPM -->
<framework custom="true" src="src/ios/dependencies/Branch.framework" />
<!-- UNCOMMENT if building for NPM -->
<!-- <header-file src="src/ios/dependencies/Fabric/ANSCompatibility.h" />
<header-file src="src/ios/dependencies/Fabric/Answers.h" />
<header-file src="src/ios/dependencies/Fabric/FABAttributes.h" />
<header-file src="src/ios/dependencies/Fabric/FABKitProtocol.h" />
<header-file src="src/ios/dependencies/Fabric/Fabric.h" />
<header-file src="src/ios/dependencies/Fabric/Fabric+FABKits.h" />

<header-file src="src/ios/dependencies/Branch-SDK/BNCConfig.h" />
<header-file src="src/ios/dependencies/Fabric/ANSCompatibility.h" />
<header-file src="src/ios/dependencies/Fabric/Answers.h" />
<header-file src="src/ios/dependencies/Fabric/FABAttributes.h" />
<header-file src="src/ios/dependencies/Fabric/FABKitProtocol.h" />
<header-file src="src/ios/dependencies/Fabric/Fabric+FABKits.h" />
<header-file src="src/ios/dependencies/Fabric/Fabric.h" />

<header-file src="src/ios/dependencies/Branch-SDK/BNCCallbacks.h" />
<header-file src="src/ios/dependencies/Branch-SDK/BNCConfig.h" />
<header-file src="src/ios/dependencies/Branch-SDK/BNCContentDiscoveryManager.h" />
<source-file src="src/ios/dependencies/Branch-SDK/BNCContentDiscoveryManager.m" />
<header-file src="src/ios/dependencies/Branch-SDK/BNCDeviceInfo.h" />
<source-file src="src/ios/dependencies/Branch-SDK/BNCDeviceInfo.m" />
<header-file src="src/ios/dependencies/Branch-SDK/BNCEncodingUtils.h" />
<source-file src="src/ios/dependencies/Branch-SDK/BNCEncodingUtils.m" />
<header-file src="src/ios/dependencies/Branch-SDK/BNCError.h" />
<source-file src="src/ios/dependencies/Branch-SDK/BNCError.m" />
<header-file src="src/ios/dependencies/Branch-SDK/BNCFabricAnswers.h" />
<source-file src="src/ios/dependencies/Branch-SDK/BNCFabricAnswers.m" />
<header-file src="src/ios/dependencies/Branch-SDK/BNCLinkCache.h" />
<source-file src="src/ios/dependencies/Branch-SDK/BNCLinkCache.m" />
<header-file src="src/ios/dependencies/Branch-SDK/BNCLinkData.h" />
Expand All @@ -142,10 +144,10 @@ SOFTWARE.
<source-file src="src/ios/dependencies/Branch-SDK/Branch.m" />
<header-file src="src/ios/dependencies/Branch-SDK/BranchActivityItemProvider.h" />
<source-file src="src/ios/dependencies/Branch-SDK/BranchActivityItemProvider.m" />
<header-file src="src/ios/dependencies/Branch-SDK/BranchConstants.h" />
<source-file src="src/ios/dependencies/Branch-SDK/BranchConstants.m" />
<header-file src="src/ios/dependencies/Branch-SDK/BranchCSSearchableItemAttributeSet.h" />
<source-file src="src/ios/dependencies/Branch-SDK/BranchCSSearchableItemAttributeSet.m" />
<header-file src="src/ios/dependencies/Branch-SDK/BranchConstants.h" />
<source-file src="src/ios/dependencies/Branch-SDK/BranchConstants.m" />
<header-file src="src/ios/dependencies/Branch-SDK/BranchDeepLinkingController.h" />
<header-file src="src/ios/dependencies/Branch-SDK/BranchLinkProperties.h" />
<source-file src="src/ios/dependencies/Branch-SDK/BranchLinkProperties.m" />
Expand All @@ -154,12 +156,8 @@ SOFTWARE.
<header-file src="src/ios/dependencies/Branch-SDK/BranchView.h" />
<source-file src="src/ios/dependencies/Branch-SDK/BranchView.m" />
<header-file src="src/ios/dependencies/Branch-SDK/BranchViewHandler.h" />
<source-file src="src/ios/dependencies/Branch-SDK/BranchViewHandler.m" />
<header-file src="src/ios/dependencies/Branch-SDK/BNCFabricAnswers.h" />
<source-file src="src/ios/dependencies/Branch-SDK/BNCFabricAnswers.m" />
<header-file src="src/ios/dependencies/Branch-SDK/BNCDeviceInfo.h" />
<source-file src="src/ios/dependencies/Branch-SDK/BNCDeviceInfo.m" />
<source-file src="src/ios/dependencies/Branch-SDK/BranchViewHandler.m" />

<header-file src="src/ios/dependencies/Branch-SDK/Requests/BNCServerRequest.h" />
<source-file src="src/ios/dependencies/Branch-SDK/Requests/BNCServerRequest.m" />
<header-file src="src/ios/dependencies/Branch-SDK/Requests/BranchCloseRequest.h" />
Expand Down Expand Up @@ -187,6 +185,8 @@ SOFTWARE.
<header-file src="src/ios/dependencies/Branch-SDK/Requests/BranchSpotlightUrlRequest.h" />
<source-file src="src/ios/dependencies/Branch-SDK/Requests/BranchSpotlightUrlRequest.m" />
<header-file src="src/ios/dependencies/Branch-SDK/Requests/BranchUserCompletedActionRequest.h" />
<source-file src="src/ios/dependencies/Branch-SDK/Requests/BranchUserCompletedActionRequest.m" /> -->
<source-file src="src/ios/dependencies/Branch-SDK/Requests/BranchUserCompletedActionRequest.m" />
<header-file src="src/ios/dependencies/Branch-SDK/Requests/PromoViewHandler.h" />

</platform>
</plugin>

0 comments on commit 67d70cf

Please sign in to comment.