run-on-ssh
Version:
Run a node.js script on a given ssh server
30 lines (25 loc) • 934 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = copy;
var _promise = require('promise');
var _promise2 = _interopRequireDefault(_promise);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function copy(ssh, entries, destinationDirectory) {
return ssh.exec('mkdir ' + destinationDirectory).then(function () {
return new _promise2.default(function (resolve, reject) {
function next(i) {
if (i >= entries.length) {
return resolve();
}
var entry = entries[i];
var result = entry.type === 'directory' ? ssh.exec('mkdir ' + destinationDirectory + entry.path.substr(1)) : ssh.exec('cat > ' + destinationDirectory + entry.path.substr(1), { stdin: entry.content });
result.done(function () {
return next(i + 1);
}, reject);
}
next(0);
});
});
}