hussh
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -1,4 +0,4 @@ | ||
// Generated by CoffeeScript 1.9.3 | ||
// Generated by CoffeeScript 1.10.0 | ||
(function() { | ||
var Client, WHEN, assign, envEscape, envPrefix, fs, hussh, | ||
var Client, Promise, assign, envEscape, envPrefix, fs, hussh, | ||
slice = [].slice; | ||
@@ -12,3 +12,3 @@ | ||
WHEN = require("when"); | ||
Promise = require("bluebird"); | ||
@@ -52,16 +52,36 @@ module.exports = function(sshOpts, opts) { | ||
} | ||
this.ssh = null; | ||
this.sftp = null; | ||
this._ssh = null; | ||
this._sshPromise = null; | ||
this._sftp = null; | ||
this._sftpPromise = null; | ||
} | ||
hussh.prototype.connect = function() { | ||
return this.ssh != null ? this.ssh : this.ssh = WHEN.promise((function(_this) { | ||
return function(resolve, reject) { | ||
var client; | ||
client = new Client(); | ||
client.once("ready", function() { | ||
return resolve(client); | ||
return Promise["try"]((function(_this) { | ||
return function() { | ||
if (_this._ssh) { | ||
return _this._ssh; | ||
} | ||
return _this._sshPromise != null ? _this._sshPromise : _this._sshPromise = new Promise(function(resolve, reject) { | ||
var cleanup, client, onError, onReady; | ||
client = new Client(); | ||
cleanup = function() { | ||
_this._sshPromise = null; | ||
client.removeListener("ready", onReady); | ||
client.removeListener("error", onError); | ||
client.removeListener("ready", cleanup); | ||
return client.removeListener("error", cleanup); | ||
}; | ||
onReady = function() { | ||
return resolve(_this._ssh = client); | ||
}; | ||
onError = function(e) { | ||
return reject(e); | ||
}; | ||
client.on("ready", cleanup); | ||
client.on("error", cleanup); | ||
client.on("ready", onReady); | ||
client.on("error", onError); | ||
return client.connect(_this.sshOpts); | ||
}); | ||
client.once("error", reject); | ||
return client.connect(_this.sshOpts); | ||
}; | ||
@@ -72,3 +92,3 @@ })(this)); | ||
hussh.prototype.disconnect = function(done) { | ||
if (!this.ssh) { | ||
if (!this._ssh && !this._sshPromise) { | ||
return typeof done === "function" ? done() : void 0; | ||
@@ -81,6 +101,10 @@ } | ||
return function(ssh) { | ||
ssh.once("close", function() { | ||
_this.ssh = null; | ||
return _this.sftp = null; | ||
}); | ||
var cleanup; | ||
cleanup = function() { | ||
_this._ssh = null; | ||
_this._sftp = null; | ||
_this._sshPromise = null; | ||
return _this._sftpPromise = null; | ||
}; | ||
ssh.once("close", cleanup); | ||
return ssh.once("close", done).end(); | ||
@@ -108,13 +132,18 @@ }; | ||
hussh.prototype.sftpSession = function() { | ||
return this.sftp != null ? this.sftp : this.sftp = WHEN.promise((function(_this) { | ||
return function(resolve, reject) { | ||
return _this.connect().then(function(ssh) { | ||
return ssh.sftp(function(err, sftp) { | ||
if (err) { | ||
return reject(err); | ||
} else { | ||
return resolve(sftp); | ||
} | ||
return Promise["try"]((function(_this) { | ||
return function() { | ||
if (_this._sftp) { | ||
return _this._sftp; | ||
} | ||
return _this._sftpPromise != null ? _this._sftpPromise : _this._sftpPromise = _this.connect().then(function(ssh) { | ||
var doit; | ||
doit = Promise.promisify(ssh.sftp, { | ||
context: ssh | ||
}); | ||
})["catch"](reject); | ||
return doit().then(function(sftp) { | ||
return _this._sftp = sftp; | ||
}); | ||
})["finally"](function() { | ||
return _this._sftpPromise = null; | ||
}); | ||
}; | ||
@@ -121,0 +150,0 @@ })(this)); |
{ | ||
"name": "hussh", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "SSH2 wrapper", | ||
@@ -17,11 +17,11 @@ "main": "js/hussh.js", | ||
"dependencies": { | ||
"lodash.assign": "^3.2.0", | ||
"ssh2": "^0.4.10", | ||
"when": "^3.7.3" | ||
"bluebird": "^3.2.2", | ||
"lodash.assign": "^4.0.2", | ||
"ssh2": "^0.4.13" | ||
}, | ||
"devDependencies": { | ||
"coffee-script": "^1.9.3", | ||
"coffee-script": "^1.10.0", | ||
"convig": "^1.2.0", | ||
"mocha": "^2.2.5", | ||
"should": "^7.0.3" | ||
"mocha": "^2.4.5", | ||
"should": "^8.2.2" | ||
}, | ||
@@ -33,3 +33,3 @@ "repository": { | ||
"author": "Ruquay K Calloway", | ||
"license": "MIT License" | ||
"license": "MIT" | ||
} |
@@ -25,3 +25,3 @@ # HuSSH | ||
privateKey: require("fs").readFileSync("./my-secret.key") | ||
}, {encoding: "utf-8}); | ||
}, {encoding: "utf-8"}); | ||
@@ -28,0 +28,0 @@ // upload a string to a remote file |
14423
269
+ Addedbluebird@^3.2.2
+ Addedbluebird@3.7.2(transitive)
+ Addedlodash.assign@4.2.0(transitive)
- Removedwhen@^3.7.3
- Removedlodash._baseassign@3.2.0(transitive)
- Removedlodash._basecopy@3.0.1(transitive)
- Removedlodash._bindcallback@3.0.1(transitive)
- Removedlodash._createassigner@3.1.1(transitive)
- Removedlodash._getnative@3.9.1(transitive)
- Removedlodash._isiterateecall@3.0.9(transitive)
- Removedlodash.assign@3.2.0(transitive)
- Removedlodash.isarguments@3.1.0(transitive)
- Removedlodash.isarray@3.0.4(transitive)
- Removedlodash.keys@3.1.2(transitive)
- Removedlodash.restparam@3.6.1(transitive)
- Removedwhen@3.7.8(transitive)
Updatedlodash.assign@^4.0.2
Updatedssh2@^0.4.13