Skip to content
This repository has been archived by the owner on Jul 24, 2019. It is now read-only.

Commit

Permalink
Merge pull request #415 from Medium/nick-md5
Browse files Browse the repository at this point in the history
Check to see if phantomjs is already installed in lib. Fixes #255
  • Loading branch information
nicks committed Nov 24, 2015
2 parents 87a2473 + 43970b4 commit ba33446
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions install.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,10 @@ var npmConfPromise = kew.nfcall(npmconf.load)
// https://github.com/Obvious/phantomjs/issues/85
// https://github.com/Medium/phantomjs/pull/184
kew.resolve(true)
.then(function () {
return tryPhantomjsOnPath()
})
.then(function () {
return downloadPhantomjs()
})
.then(function (downloadedFile) {
return extractDownload(downloadedFile)
})
.then(tryPhantomjsInLib)
.then(tryPhantomjsOnPath)
.then(downloadPhantomjs)
.then(extractDownload)
.then(function (extractedPath) {
return copyIntoPlace(extractedPath, pkgPath)
})
Expand Down Expand Up @@ -304,6 +299,23 @@ function copyIntoPlace(extractedPath, targetPath) {
})
}

/**
* Check to see if the binary in lib is OK to use. If successful, exit the process.
*/
function tryPhantomjsInLib() {
return kew.fcall(function () {
var libModule = require('./lib/location.js')
if (libModule.location &&
getTargetPlatform() == libModule.platform &&
getTargetArch() == libModule.arch) {
console.log('PhantomJS is previously installed at ' + libModule.location)
exit(0)
}
}).fail(function () {
// silently swallow any errors
})
}

/**
* Check to see if the binary on PATH is OK to use. If successful, exit the process.
*/
Expand Down Expand Up @@ -332,7 +344,7 @@ function tryPhantomjsOnPath() {
return checkPhantomjsVersion(phantomPath).then(function (matches) {
if (matches) {
writeLocationFile(phantomPath)
console.log('PhantomJS is already installed at', phantomPath + '.')
console.log('PhantomJS is already installed on PATH at', phantomPath)
exit(0)
}
})
Expand Down

0 comments on commit ba33446

Please sign in to comment.