Skip to content

Commit

Permalink
refactor: removed class level variables
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanneff committed Feb 1, 2017
1 parent 1fc2ec6 commit e0841a8
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions hooks/lib/npm/nodeDependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
var path = require('path')
var exec = require('child_process').exec
var installFlagName = '.installed'
var installFlagLocation
var dependencies
var deferral
var q

// entry
module.exports = {
Expand All @@ -19,13 +15,13 @@
// install the node dependencies for Branch SDK
function install (context) {
// set properties
q = context.requireCordovaModule('q')
deferral = new q.defer() // eslint-disable-line
installFlagLocation = path.join(context.opts.projectRoot, 'plugins', context.opts.plugin.id, installFlagName)
dependencies = require(path.join(context.opts.projectRoot, 'plugins', context.opts.plugin.id, 'package.json')).dependencies
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 dependencies = require(path.join(context.opts.projectRoot, 'plugins', context.opts.plugin.id, 'package.json')).dependencies

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

// install node modules
var modules = getNodeModulesToInstall(dependencies)
Expand All @@ -38,7 +34,7 @@
throw new Error('BRANCH SDK: Failed to install the Branch SDK')
} else {
// only run once
setPackageInstalled()
setPackageInstalled(installFlagLocation)
removeEtcDirectory()
}
deferral.resolve()
Expand Down Expand Up @@ -88,7 +84,7 @@
}

// if the Branch SDK package has already been installed
function getPackageInstalled () {
function getPackageInstalled (installFlagLocation) {
try {
fs.readFileSync(installFlagLocation)
return true
Expand All @@ -98,7 +94,7 @@
}

// set that the Branch SDK package has been installed
function setPackageInstalled () {
function setPackageInstalled (installFlagLocation) {
fs.closeSync(fs.openSync(installFlagLocation, 'w'))
}

Expand Down

0 comments on commit e0841a8

Please sign in to comment.