Skip to content

Commit

Permalink
Merge pull request #296 from BranchMetrics/fix--continual-improvements
Browse files Browse the repository at this point in the history
Fix: continual improvements
  • Loading branch information
ethanneff authored Mar 7, 2017
2 parents e52f750 + 682dbfe commit 060e2ab
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 22 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,6 @@

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

- Must be a `string`

```js
var userId = '123456'
Branch.setIdentity(userId).then(function (res) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "branch-cordova-sdk",
"description": "Branch Metrics Cordova SDK",
"main": "www/branch.js",
"version": "2.5.5",
"version": "2.5.6",
"homepage": "https://github.com/BranchMetrics/cordova-ionic-phonegap-branch-deep-linking",
"repository": {
"type": "git",
Expand Down Expand Up @@ -37,6 +37,7 @@
},
"scripts": {
"commitmsg": "validate-commit-msg",
"precommit": "gulp prod",
"postcommit": "semantic-release pre --verifyRelease='./src/scripts/npm/nodeVersion'",
"prerelease": "gulp prod",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
Expand Down
2 changes: 1 addition & 1 deletion plugin.template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ SOFTWARE.
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="branch-cordova-sdk"
version="2.5.5">
version="2.5.6">

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

Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ SOFTWARE.
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="branch-cordova-sdk"
version="2.5.5">
version="2.5.6">

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

Expand Down
2 changes: 1 addition & 1 deletion src/branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Branch.prototype.getLatestReferringParams = function () {

Branch.prototype.setIdentity = function (identity) {
if (identity) {
return execute('setIdentity', [identity])
return execute('setIdentity', [String(identity)])
} else {
return new Promise(function (resolve, reject) {
reject('Please set an identity')
Expand Down
12 changes: 6 additions & 6 deletions src/scripts/npm/nodeDependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
var fs = require('fs')
var path = require('path')
var exec = require('child_process').exec
var installFlagName = '.installed'
var INSTALLFLAGNAME = '.installed'

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

// only run once
if (getPackageInstalled(installFlagLocation)) return

// install node modules
var modules = getNodeModulesToInstall(dependencies)
if (modules.length === 0) return deferral.promise
if (modules.length === 0) return async.promise

installNodeModules(modules, function (err) {
if (err) {
Expand All @@ -36,11 +36,11 @@
setPackageInstalled(installFlagLocation)
removeEtcDirectory()
}
deferral.resolve()
async.resolve()
})

// wait until callbacks from the all the npm install complete
return deferral.promise
return async.promise
}

// installs the node modules via npm install one at a time
Expand Down
42 changes: 32 additions & 10 deletions src/scripts/npm/nodeVersion.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(function () {
var path = require('path')
var exec = require('child_process').exec
var fileHelper = require('../lib/fileHelper.js')
var FILES = ['package.json', 'plugin.xml', 'plugin.template.xml']

Expand All @@ -9,20 +10,38 @@
function updateNpmVersion (pluginConfig, config, callback) {
var files = readFilePaths(FILES)
var version = config.nextRelease.version
var git = ''

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

content = updateVersion(file, content, version)
saveContent(file, content)
// early exit (made no changes)
if (content === updated) return

// save
git += 'git add ' + file + ' && '
saveContent(file, updated)
}
commitChanges(git, version)
}

// handle content
function readContent (file) {
return isFileXml(file) ? fileHelper.readFile(file) : JSON.parse(fileHelper.readFile(file))
}

function saveContent (file, content) {
return isFileXml(file) ? fileHelper.writeFile(file, content) : fileHelper.writeFile(file, JSON.stringify(content, null, 2))
}

function isFileXml (file) {
return file.indexOf('xml') > 0
}

// update content based on xml or json
function updateVersion (file, content, version) {
var prev = /id="branch-cordova-sdk"[\s]*version="\d+\.\d+\.\d+"/mgi
var next = 'id="branch-cordova-sdk"\n version="' + version + '"'
Expand All @@ -39,14 +58,7 @@
return content
}

function saveContent (file, content) {
return isFileXml(file) ? fileHelper.writeFile(file, content) : fileHelper.writeFile(file, JSON.stringify(content, null, 2))
}

function isFileXml (file) {
return file.indexOf('xml') > 0
}

// get the absolute path of the files within the root directory
function readFilePaths (files) {
var locations = []
for (var i = 0; i < files.length; i++) {
Expand All @@ -56,4 +68,14 @@
}
return locations
}

// push file code changes to github
function commitChanges (git, version) {
git += 'git commit -m "chore: updated npm version to ' + version + '" && git push'
exec(git, function (err, stdout, stderr) {
if (err) {
throw new Error('BRANCH SDK: Failed commit git changes to npm version. Docs https://goo.gl/GijGKP')
}
})
}
})()

0 comments on commit 060e2ab

Please sign in to comment.