Skip to content

Commit e865a5c

Browse files
authored
Merge pull request #658 from adrianyg7/sdk326
SDK-326 Evaluate and resurrect build and release scripts Looks good.
2 parents ed97bc9 + 9ee0000 commit e865a5c

File tree

16 files changed

+91
-563
lines changed

16 files changed

+91
-563
lines changed

package.json

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,38 @@
2222
"version": ">=8.0.0"
2323
}
2424
],
25+
"scripts": {
26+
"commitmsg": " echo 'validate commit messages'; commitlint -e $GIT_PARAMS",
27+
"precommit": " echo 'run prettier on commit'; lint-staged",
28+
"prettier": " echo 'run prettier'; prettier --write './{src,testbed,tests}/**/*.js'",
29+
"lint": " echo 'run code linter'; eslint --ext=js --fix ./src",
30+
"examples": " echo 'generate examples'; node ./src/scripts/examples"
31+
},
32+
"eslintConfig": {
33+
"extends": [
34+
"airbnb-base/legacy"
35+
],
36+
"rules": {
37+
"no-console": 0,
38+
"no-alert": 0,
39+
"no-use-before-define": 0
40+
},
41+
"globals": {
42+
"Promise": true,
43+
"Branch": true
44+
}
45+
},
46+
"commitlint": {
47+
"extends": [
48+
"@commitlint/config-conventional"
49+
]
50+
},
51+
"lint-staged": {
52+
"src/*.{js,json,css,md}": [
53+
"prettier --write",
54+
"git add"
55+
]
56+
},
2557
"dependencies": {
2658
"fs": "0.0.1-security",
2759
"glob": "^7.1.4",
@@ -33,5 +65,14 @@
3365
"xcode": "^2.0.0",
3466
"xml2js": "^0.4.19"
3567
},
36-
"devDependencies": {}
68+
"devDependencies": {
69+
"@commitlint/cli": "^8.3.5",
70+
"@commitlint/config-conventional": "^8.3.4",
71+
"eslint": "^6.8.0",
72+
"eslint-config-airbnb-base": "^14.1.0",
73+
"eslint-plugin-import": "^2.20.2",
74+
"husky": "^4.2.5",
75+
"lint-staged": "^10.1.7",
76+
"prettier": "^2.0.5"
77+
}
3778
}

src/__tests__/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Running Plugin Tests
2+
3+
1. Use your existing cordova app, or create a new one.
4+
2. Add this plugins:
5+
```
6+
cordova plugin add cordova-plugin-test-framework
7+
cordova plugin add plugins/branch-cordova-sdk/src/__tests__
8+
```
9+
3. Change the start page in `config.xml` with `<content src="cdvtests/index.html" />` or navigate to `cdvtests/index.html` from within your app.
10+
4. That's it.

src/__tests__/index.js

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ var _typeof =
1414
: typeof obj;
1515
};
1616

17+
var sessionInitialized = false;
18+
19+
function initSession(done) {
20+
return new Promise(function promise(resolve, reject) {
21+
if (sessionInitialized) {
22+
return resolve();
23+
}
24+
25+
window.Branch.initSession().then(function() {
26+
sessionInitialized = true;
27+
resolve();
28+
});
29+
});
30+
}
31+
1732
/**
1833
* Branch.IO Cordova Plugin Unit-Test
1934
* ----------------------------------
@@ -67,7 +82,7 @@ exports.defineAutoTests = function() {
6782

6883
describe("Branch.getLatestReferringParams()", function() {
6984
beforeEach(function(done) {
70-
window.Branch.initSession().then(function() {
85+
initSession().then(function() {
7186
done();
7287
});
7388
}, 3000);
@@ -87,7 +102,7 @@ exports.defineAutoTests = function() {
87102

88103
describe("Branch.getFirstReferringParams()", function() {
89104
beforeEach(function(done) {
90-
window.Branch.initSession().then(function() {
105+
initSession().then(function() {
91106
done();
92107
});
93108
}, 3000);
@@ -106,7 +121,7 @@ exports.defineAutoTests = function() {
106121

107122
describe("Branch.setIdentity()", function() {
108123
beforeEach(function(done) {
109-
window.Branch.initSession().then(function() {
124+
initSession().then(function() {
110125
done();
111126
});
112127
}, 3000);
@@ -128,7 +143,7 @@ exports.defineAutoTests = function() {
128143
var branchUniversalObj;
129144

130145
beforeEach(function(done) {
131-
window.Branch.initSession().then(function() {
146+
initSession().then(function() {
132147
var properties = {
133148
canonicalIdentifier: "testbed",
134149
title: "testbed",
@@ -149,9 +164,7 @@ exports.defineAutoTests = function() {
149164
"should execute register view",
150165
function(done) {
151166
branchUniversalObj.registerView().then(function(res) {
152-
expect(typeof res === "undefined" ? "undefined" : _typeof(res)).toBe(
153-
"object"
154-
);
167+
expect(typeof res).not.toBe("undefined");
155168
done();
156169
});
157170
},
@@ -192,7 +205,7 @@ exports.defineAutoTests = function() {
192205

193206
describe("Branch.userCompletedAction()", function() {
194207
beforeEach(function(done) {
195-
window.Branch.initSession().then(function() {
208+
initSession().then(function() {
196209
done();
197210
});
198211
}, 3000);
@@ -209,7 +222,7 @@ exports.defineAutoTests = function() {
209222

210223
describe("Branch.loadRewards()", function() {
211224
beforeEach(function(done) {
212-
window.Branch.initSession().then(function() {
225+
initSession().then(function() {
213226
done();
214227
});
215228
}, 3000);
@@ -237,7 +250,7 @@ exports.defineAutoTests = function() {
237250

238251
describe("Branch.redeemRewards()", function() {
239252
beforeEach(function(done) {
240-
window.Branch.initSession().then(function() {
253+
initSession().then(function() {
241254
done();
242255
});
243256
}, 3000);
@@ -265,7 +278,7 @@ exports.defineAutoTests = function() {
265278

266279
describe("Branch.creditHistory()", function() {
267280
beforeEach(function(done) {
268-
window.Branch.initSession().then(function() {
281+
initSession().then(function() {
269282
done();
270283
});
271284
}, 3000);

src/__tests__/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "branch-cordova-sdk-tests",
3+
"version": "1.0.0",
4+
"description": "Branch Metrics Cordova SDK Tests",
5+
"cordova": {
6+
"id": "branch-cordova-sdk-tests",
7+
"platforms": []
8+
},
9+
"license": "MIT"
10+
}

src/__tests__/plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ SOFTWARE.
3131
<name>branch-cordova-sdk-tests</name>
3232
<license>Apache 2.0</license>
3333

34-
<js-module src="tests.js" name="tests"></js-module>
34+
<js-module src="index.js" name="tests"></js-module>
3535

3636
</plugin>

src/android/io/branch/BranchSDK.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,8 @@ private void registerView(int instanceIdx, CallbackContext callbackContext) {
570570

571571
branchUniversalWrapper.branchUniversalObj.registerView(new RegisterViewStatusListener(callbackContext));
572572

573+
callbackContext.success("Success");
574+
573575
}
574576

575577
/**

src/scripts/examples/index.js

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// yarn examples
66
// cd examples/cordova1
77
// (plug in devices)
8-
// (ionic build if ionic 3)
98
// cordova run ios
109
// cordova run android
1110

@@ -15,8 +14,6 @@ const DIR = "examples";
1514
const TMP = "tmp";
1615
const CORDOVA1 = "cordova1";
1716
const PHONEGAP1 = "phonegap1";
18-
const IONIC1 = "ionic1";
19-
const IONIC3 = "ionic3";
2017

2118
// promisfy bash execution with stout streaming
2219
const run = (args, dir = undefined) =>
@@ -78,58 +75,6 @@ const buildPhoneGap1 = async () => {
7875
await run(`phonegap platform add ios android`, `${DIR}/${PHONEGAP1}`);
7976
};
8077

81-
const buildIonic1 = async () => {
82-
await run(`ionic start ${IONIC1} tabs --cordova --type ionic1`, `${DIR}`);
83-
await run(
84-
`cp ./src/scripts/examples/templates/${IONIC1}/index.xml ./${DIR}/${IONIC1}/config.xml`
85-
);
86-
await run(
87-
`cp ./src/scripts/examples/templates/${IONIC1}/index.html ./${DIR}/${IONIC1}/www/templates/tab-dash.html`
88-
);
89-
await run(
90-
`cp ./src/scripts/examples/templates/${IONIC1}/app.js ./${DIR}/${IONIC1}/www/js/app.js`
91-
);
92-
await run(
93-
`cp ./src/scripts/examples/templates/${IONIC1}/controllers.js ./${DIR}/${IONIC1}/www/js/controllers.js`
94-
);
95-
await run(`rm -rf ./${DIR}/${IONIC1}/.git`);
96-
await run(`mkdir -p plugins/branch-cordova-sdk`, `${DIR}/${IONIC1}`);
97-
await run(
98-
`rsync -a ../../${TMP}/ plugins/branch-cordova-sdk`,
99-
`${DIR}/${IONIC1}`
100-
);
101-
await run(`ionic cordova platform add ios`, `${DIR}/${IONIC1}`);
102-
await run(`ionic cordova platform add android`, `${DIR}/${IONIC1}`);
103-
};
104-
105-
const buildIonic3 = async () => {
106-
await run(`ionic start ${IONIC3} tabs --cordova`, `${DIR}`);
107-
await run(`mkdir -p plugins/branch-cordova-sdk`, `${DIR}/${IONIC3}`);
108-
await run(
109-
`cp ./src/scripts/examples/templates/${IONIC3}/index.xml ./${DIR}/${IONIC3}/config.xml`
110-
);
111-
await run(
112-
`cp ./src/scripts/examples/templates/${IONIC3}/index.html ./${DIR}/${IONIC3}/src/pages/home/home.html`
113-
);
114-
await run(
115-
`cp ./src/scripts/examples/templates/${IONIC3}/app.js ./${DIR}/${IONIC3}/src/app/app.component.ts`
116-
);
117-
await run(
118-
`cp ./src/scripts/examples/templates/${IONIC3}/controllers.js ./${DIR}/${IONIC3}/src/pages/home/home.ts`
119-
);
120-
await run(`rm -rf ./${DIR}/${IONIC3}/.git`);
121-
await run(
122-
`rsync -a ../../${TMP}/ plugins/branch-cordova-sdk`,
123-
`${DIR}/${IONIC3}`
124-
);
125-
await run(`ionic cordova platform add ios`, `${DIR}/${IONIC3}`);
126-
await run(`ionic cordova platform add android`, `${DIR}/${IONIC3}`);
127-
};
128-
129-
const installDependencies = async () => {
130-
await run("yarn add -g cordova ionic phonegap");
131-
};
132-
13378
const copySdk = async () => {
13479
await run(
13580
`rsync -a ./ ./${TMP} --exclude node_modules --exclude .git --exclude ${DIR} --exclude ${TMP}`
@@ -142,12 +87,9 @@ const removeCopySdk = async () => {
14287

14388
const main = async () => {
14489
await cleanDirectory();
145-
// await installDependencies();
14690
await copySdk();
14791
await buildCordova1();
14892
await buildPhoneGap1();
149-
await buildIonic1();
150-
await buildIonic3();
15193
await removeCopySdk();
15294
};
15395

src/scripts/examples/templates/cordova1/index.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
<branch-key value="key_live_ndqptlgXNE4LHqIahH1WIpbiyFlb62J3" />
55
<uri-scheme value="branchcordova" />
66
<link-domain value="cordova.app.link" />
7+
<link-domain value="cordova-alternate.app.link" />
78
<ios-team-release value="PW4Q8885U7" />
89
</branch-config>
9-
<preference name="android-minSdkVersion" value="16" />
10+
<preference name="android-minSdkVersion" value="19" />
1011
<name>Cordova1</name>
1112
<description>Testing App For Branch Cordova</description>
1213
<author email="[email protected]" href="https://support.branch.io/support/tickets/new">Branch Support</author>
1314
<content src="index.html" />
14-
<plugin name="cordova-plugin-console" />
1515
<plugin name="cordova-plugin-whitelist" spec="1" />
1616
<access origin="*" />
1717
<allow-intent href="http://*/*" />

0 commit comments

Comments
 (0)