Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var pkgPath = path.join(libPath, 'phantom')
var phantomPath = null
var tmpPath = null
// If the user manually installed PhantomJS, we want
// to use the existing version.
//
// Do not re-use a manually-installed PhantomJS with
// a different version.
//
// Do not re-use an npm-installed PhantomJS, because
// that can lead to weird circular dependencies between
// local versions and global versions.
// https://github.com/Obvious/phantomjs/issues/85
// https://github.com/Medium/phantomjs/pull/184
var whichDeferred = kew.defer()
which('phantomjs', whichDeferred.makeNodeResolver())
whichDeferred.promise
.then(function (result) {
phantomPath = result
// Horrible hack to avoid problems during global install. We check to see if
// the file `which` found is our own bin script.
if (phantomPath.indexOf(path.join('npm', 'phantomjs')) !== -1) {
console.log('Looks like an `npm install -g` on windows; unable to check for already installed version.')
throw new Error('Global install')
}
var contents = fs.readFileSync(phantomPath, 'utf8')
if (/NPM_INSTALL_MARKER/.test(contents)) {
console.log('Looks like an `npm install -g`; unable to check for already installed version.')
throw new Error('Global install')
function extractDownload(filePath) {
var deferred = kew.defer()
// extract to a unique directory in case multiple processes are
// installing and extracting at once
var extractedPath = filePath + '-extract-' + Date.now()
var options = {cwd: extractedPath}
mkdirp.sync(extractedPath, '0777')
// Make double sure we have 0777 permissions; some operating systems
// default umask does not allow write by default.
fs.chmodSync(extractedPath, '0777')
if (filePath.substr(-4) === '.zip') {
console.log('Extracting zip contents')
try {
var zip = new AdmZip(filePath)
zip.extractAllTo(extractedPath, true)
.fail(function (err) {
// Trying to use a local file failed, so initiate download and install
// steps instead.
var npmconfDeferred = kew.defer()
npmconf.load(npmconfDeferred.makeNodeResolver())
return npmconfDeferred.promise
})
.then(function (conf) {
.fail(function (err) {
// Trying to use a local file failed, so initiate download and install
// steps instead.
var npmconfDeferred = kew.defer()
npmconf.load(npmconfDeferred.makeNodeResolver())
return npmconfDeferred.promise
})
.then(function (conf) {
function destroy(pgtable, key) {
var deferred = Q.defer();
//show we first check if there is a record to delete - does this matter?
pgclient.query("SELECT id FROM " + pgtable + " WHERE id='" + key + "'", function(err, result) {
if (err) {
//console.error(pgtable, err);
deferred.reject(err);
} else {
if (result.rows.length > 0) {
sql = "DELETE FROM " + pgtable + " WHERE id='" + key + "'";
pgclient.query(sql, function(err, result) {
if (err) {
console.err(pgtable + ": " + sql, err);
deferred.reject(err);
} else {
console.log(pgtable + ": " + key + " deleted");
deferred.resolve(result.rowCount);
function requestBinary(requestOptions, filePath) {
var deferred = kew.defer()
var writePath = filePath + '-download-' + Date.now()
console.log('Receiving...')
var bar = null
requestProgress(request(requestOptions, function (error, response, body) {
console.log('')
if (!error && response.statusCode === 200) {
fs.writeFileSync(writePath, body)
console.log('Received ' + Math.floor(body.length / 1024) + 'K total.')
fs.renameSync(writePath, filePath)
deferred.resolve(filePath)
} else if (response) {
console.error('Error requesting archive.\n' +
'Status: ' + response.statusCode + '\n' +
return function() {
var p = q.defer();
arguments[arguments.length++] = function(err, res) {
if (err) p.reject(err);
else p.resolve(res)
};
try {
nodefn.apply(this, arguments);
}
catch (e) {
p.reject(e);
}
return p;
}
}
UpnpInterface.prototype.getCurrentIP = function () {
var self = this;
var defer = libQ.defer();
var ipaddr = '';
ifconfig.status('wlan0', function(err, status) {
if (status != undefined) {
if (status.ipv4_address != undefined) {
ipaddr = status.ipv4_address;
defer.resolve(ipaddr);
} else {
ipaddr = ip.address();
defer.resolve(ipaddr);
}
}
});
return defer.promise;
};
CoreStateMachine.prototype.pushState = function () {
this.commandRouter.pushConsoleMessage('[' + Date.now() + '] ' + 'CoreStateMachine::pushState');
var promise = libQ.defer();
var state = this.getState();
var self = this;
self.commandRouter.volumioPushState(state)
.then(function (data) {
self.checkFavourites(state)
.then(function (a) {
promise.resolve({});
})
});
return promise.promise;
};