Skip to content

Commit 060e2ab

Browse files
authored
Merge pull request #296 from BranchMetrics/fix--continual-improvements
Fix: continual improvements
2 parents e52f750 + 682dbfe commit 060e2ab

File tree

7 files changed

+43
-22
lines changed

7 files changed

+43
-22
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,6 @@
452452

453453
- Sets the identity of a user (email, ID, UUID, etc) for events, deep links, and referrals
454454

455-
- Must be a `string`
456-
457455
```js
458456
var userId = '123456'
459457
Branch.setIdentity(userId).then(function (res) {

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "branch-cordova-sdk",
33
"description": "Branch Metrics Cordova SDK",
44
"main": "www/branch.js",
5-
"version": "2.5.5",
5+
"version": "2.5.6",
66
"homepage": "https://github.com/BranchMetrics/cordova-ionic-phonegap-branch-deep-linking",
77
"repository": {
88
"type": "git",
@@ -37,6 +37,7 @@
3737
},
3838
"scripts": {
3939
"commitmsg": "validate-commit-msg",
40+
"precommit": "gulp prod",
4041
"postcommit": "semantic-release pre --verifyRelease='./src/scripts/npm/nodeVersion'",
4142
"prerelease": "gulp prod",
4243
"semantic-release": "semantic-release pre && npm publish && semantic-release post"

plugin.template.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SOFTWARE.
2424
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
2525
xmlns:android="http://schemas.android.com/apk/res/android"
2626
id="branch-cordova-sdk"
27-
version="2.5.5">
27+
version="2.5.6">
2828

2929
<!-- DO NOT EDIT THIS FILE. MAKE ALL CHANGES TO plugin.template.xml INSTEAD -->
3030

plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SOFTWARE.
2424
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
2525
xmlns:android="http://schemas.android.com/apk/res/android"
2626
id="branch-cordova-sdk"
27-
version="2.5.5">
27+
version="2.5.6">
2828

2929
<!-- DO NOT EDIT THIS FILE. MAKE ALL CHANGES TO plugin.template.xml INSTEAD -->
3030

src/branch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Branch.prototype.getLatestReferringParams = function () {
8181

8282
Branch.prototype.setIdentity = function (identity) {
8383
if (identity) {
84-
return execute('setIdentity', [identity])
84+
return execute('setIdentity', [String(identity)])
8585
} else {
8686
return new Promise(function (resolve, reject) {
8787
reject('Please set an identity')

src/scripts/npm/nodeDependencies.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
var fs = require('fs')
66
var path = require('path')
77
var exec = require('child_process').exec
8-
var installFlagName = '.installed'
8+
var INSTALLFLAGNAME = '.installed'
99

1010
// entry
1111
module.exports = {
@@ -16,16 +16,16 @@
1616
function install (context) {
1717
// set properties
1818
var q = context.requireCordovaModule('q')
19-
var deferral = new q.defer() // eslint-disable-line
20-
var installFlagLocation = path.join(context.opts.projectRoot, 'plugins', context.opts.plugin.id, installFlagName)
19+
var async = new q.defer() // eslint-disable-line
20+
var installFlagLocation = path.join(context.opts.projectRoot, 'plugins', context.opts.plugin.id, INSTALLFLAGNAME)
2121
var dependencies = require(path.join(context.opts.projectRoot, 'plugins', context.opts.plugin.id, 'package.json')).dependencies
2222

2323
// only run once
2424
if (getPackageInstalled(installFlagLocation)) return
2525

2626
// install node modules
2727
var modules = getNodeModulesToInstall(dependencies)
28-
if (modules.length === 0) return deferral.promise
28+
if (modules.length === 0) return async.promise
2929

3030
installNodeModules(modules, function (err) {
3131
if (err) {
@@ -36,11 +36,11 @@
3636
setPackageInstalled(installFlagLocation)
3737
removeEtcDirectory()
3838
}
39-
deferral.resolve()
39+
async.resolve()
4040
})
4141

4242
// wait until callbacks from the all the npm install complete
43-
return deferral.promise
43+
return async.promise
4444
}
4545

4646
// installs the node modules via npm install one at a time

src/scripts/npm/nodeVersion.js

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(function () {
22
var path = require('path')
3+
var exec = require('child_process').exec
34
var fileHelper = require('../lib/fileHelper.js')
45
var FILES = ['package.json', 'plugin.xml', 'plugin.template.xml']
56

@@ -9,20 +10,38 @@
910
function updateNpmVersion (pluginConfig, config, callback) {
1011
var files = readFilePaths(FILES)
1112
var version = config.nextRelease.version
13+
var git = ''
1214

1315
for (var i = 0; i < files.length; i++) {
16+
// update
1417
var file = files[i]
1518
var content = readContent(file)
19+
var updated = updateVersion(file, content, version)
1620

17-
content = updateVersion(file, content, version)
18-
saveContent(file, content)
21+
// early exit (made no changes)
22+
if (content === updated) return
23+
24+
// save
25+
git += 'git add ' + file + ' && '
26+
saveContent(file, updated)
1927
}
28+
commitChanges(git, version)
2029
}
2130

31+
// handle content
2232
function readContent (file) {
2333
return isFileXml(file) ? fileHelper.readFile(file) : JSON.parse(fileHelper.readFile(file))
2434
}
2535

36+
function saveContent (file, content) {
37+
return isFileXml(file) ? fileHelper.writeFile(file, content) : fileHelper.writeFile(file, JSON.stringify(content, null, 2))
38+
}
39+
40+
function isFileXml (file) {
41+
return file.indexOf('xml') > 0
42+
}
43+
44+
// update content based on xml or json
2645
function updateVersion (file, content, version) {
2746
var prev = /id="branch-cordova-sdk"[\s]*version="\d+\.\d+\.\d+"/mgi
2847
var next = 'id="branch-cordova-sdk"\n version="' + version + '"'
@@ -39,14 +58,7 @@
3958
return content
4059
}
4160

42-
function saveContent (file, content) {
43-
return isFileXml(file) ? fileHelper.writeFile(file, content) : fileHelper.writeFile(file, JSON.stringify(content, null, 2))
44-
}
45-
46-
function isFileXml (file) {
47-
return file.indexOf('xml') > 0
48-
}
49-
61+
// get the absolute path of the files within the root directory
5062
function readFilePaths (files) {
5163
var locations = []
5264
for (var i = 0; i < files.length; i++) {
@@ -56,4 +68,14 @@
5668
}
5769
return locations
5870
}
71+
72+
// push file code changes to github
73+
function commitChanges (git, version) {
74+
git += 'git commit -m "chore: updated npm version to ' + version + '" && git push'
75+
exec(git, function (err, stdout, stderr) {
76+
if (err) {
77+
throw new Error('BRANCH SDK: Failed commit git changes to npm version. Docs https://goo.gl/GijGKP')
78+
}
79+
})
80+
}
5981
})()

0 commit comments

Comments
 (0)