From e0841a89e1db6be9a438200b972314cd342bc9c6 Mon Sep 17 00:00:00 2001 From: Ethan Neff Date: Wed, 1 Feb 2017 15:05:06 -0800 Subject: [PATCH] refactor: removed class level variables --- hooks/lib/npm/nodeDependencies.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/hooks/lib/npm/nodeDependencies.js b/hooks/lib/npm/nodeDependencies.js index a7e9cb31..027882eb 100644 --- a/hooks/lib/npm/nodeDependencies.js +++ b/hooks/lib/npm/nodeDependencies.js @@ -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 = { @@ -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) @@ -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() @@ -88,7 +84,7 @@ } // if the Branch SDK package has already been installed - function getPackageInstalled () { + function getPackageInstalled (installFlagLocation) { try { fs.readFileSync(installFlagLocation) return true @@ -98,7 +94,7 @@ } // set that the Branch SDK package has been installed - function setPackageInstalled () { + function setPackageInstalled (installFlagLocation) { fs.closeSync(fs.openSync(installFlagLocation, 'w')) }