Skip to content

Commit

Permalink
refactor(ios): automatically set correct header paths based on deploy…
Browse files Browse the repository at this point in the history
…ment
  • Loading branch information
amit-bansil committed Jul 26, 2016
1 parent dbed3cc commit aa96258
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 200 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ testbed/hooks
node_modules
testbed/ul_web_hooks/
.installed

/plugin.xml
src/ios/BranchNPM.h
31 changes: 27 additions & 4 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
var gulp = require('gulp');
var fs = require('fs');

//setup for development use
gulp.task('setupDev', function(){
getDevPluginXML();
setIosNpmOrDev('dev');
})

//setup for npm deployment
gulp.task('setupNpm', function(){
genNpmPluginXML();
setIosNpmOrDev('npm');
});

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

var files = [];
Expand All @@ -17,18 +29,29 @@ gulp.task('gen-npm-plugin-xml', function(){
+ 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(){
function getDevPluginXML(){
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);
});
};

function setIosNpmOrDev(npmOrDev){
if(npmOrDev === 'npm'){
content = '#define BRANCH_NPM true';
}else if(npmOrDev === 'dev'){
content = '//empty';
}else{
throw new Error('expected deployed|local, not ' + deployedOrLocal);
}
fs.writeFileSync('src/ios/BranchNPM.h', content + '\n');
}

//emit array of cordova file references for all .h/.m files in path
function emitFiles(path){
Expand Down
6 changes: 6 additions & 0 deletions plugin.template.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@

<!------------------------------------------------------------------------------------>
<!--EDIT plugin.template.xml NOT plugin.xml. plugin.xml WILL BE OVERWRITTEN BY GULP -->
<!------------------------------------------------------------------------------------>

<?xml version="1.0" encoding="UTF-8"?>
<!--
The MIT License (MIT)
Expand Down Expand Up @@ -100,6 +105,7 @@ SOFTWARE.
</dict>
</array>
</config-file>
<header-file src="src/ios/BranchNPM.h" />
<header-file src="src/ios/BranchSDK.h" />
<source-file src="src/ios/BranchSDK.m" />
<source-file src="src/ios/AppDelegate+BranchSdk.m" />
Expand Down
192 changes: 0 additions & 192 deletions plugin.xml

This file was deleted.

9 changes: 8 additions & 1 deletion src/ios/AppDelegate+BranchSdk.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@
//

#import "AppDelegate.h"
#import <Branch/Branch.h>

#import "BranchNPM.h"

#ifdef BRANCH_NPM
#import "Branch.h"
#else
#import <Branch/Branch.h>
#endif

@interface AppDelegate (BranchSDK)

Expand Down
15 changes: 12 additions & 3 deletions src/ios/BranchSDK.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@
// Copyright © 2016 Branch Metrics. All rights reserved.
//

#import <Branch/Branch.h>
#import <Branch/BranchLinkProperties.h>
#import <Branch/BranchUniversalObject.h>
#import "BranchNPM.h"

#ifdef BRANCH_NPM
#import "Branch.h"
#import "BranchLinkProperties.h"
#import "BranchUniversalObject.h"
#else
#import <Branch/Branch.h>
#import <Branch/BranchLinkProperties.h>
#import <Branch/BranchUniversalObject.h>
#endif

#import <Cordova/CDV.h>

@interface BranchSDK : CDVPlugin
Expand Down

0 comments on commit aa96258

Please sign in to comment.