1
|
|
|
var path = require('path'); |
2
|
|
|
var fs = require('fs'); |
3
|
|
|
var JSZip = require("jszip"); |
4
|
|
|
var node_ssh = require('node-ssh'); |
5
|
|
|
var ssh = new node_ssh(); |
|
|
|
|
6
|
|
|
var zip = new JSZip(); |
7
|
|
|
|
8
|
|
|
zip.file("Hello.txt", "Hello World\n"); |
9
|
|
|
|
10
|
|
|
//var img = zip.folder("images"); |
11
|
|
|
//img.file("smile.gif", imgData, {base64: true}); |
12
|
|
|
|
13
|
|
|
zip.generateNodeStream({type:'nodebuffer',streamFiles:true}) |
14
|
|
|
.pipe(fs.createWriteStream('example.zip')) |
15
|
|
|
.on('finish', function () { |
16
|
|
|
// JSZip generates a readable stream with a "end" event, |
17
|
|
|
// but is piped here in a writable stream which emits a "finish" event. |
18
|
|
|
console.log("example.zip written."); |
|
|
|
|
19
|
|
|
}); |
20
|
|
|
|
21
|
|
|
var activeConnection = ssh.connect({ |
22
|
|
|
host: 'www.d1b0.local', |
23
|
|
|
username: 'developer', |
24
|
|
|
privateKey: '../../server/play/ssh/developer.key' |
25
|
|
|
}); |
26
|
|
|
|
27
|
|
|
activeConnection.then(function() { |
28
|
|
|
|
29
|
|
|
// Array<Shape('local' => string, 'remote' => string)> |
30
|
|
|
ssh.putFiles([ |
31
|
|
|
{ local: '../../applications/workspace/composer.json', remote: '/var/www/workspace.local/composer.json' } |
32
|
|
|
]).then(function() { |
33
|
|
|
console.log("The File thing is done"); |
|
|
|
|
34
|
|
|
}, function(error) { |
35
|
|
|
console.log("Something's wrong"); |
|
|
|
|
36
|
|
|
console.log(error); |
37
|
|
|
}); |
38
|
|
|
|
39
|
|
|
// Putting entire directories |
40
|
|
|
var failed = []; |
41
|
|
|
var successful = []; |
42
|
|
|
ssh.putDirectory('../../applications/workspace/src/', '/var/www/workspace.local/src/', { |
43
|
|
|
recursive: true, |
44
|
|
|
validate: function(itemPath) { |
45
|
|
|
var baseName = path.basename(itemPath); |
46
|
|
|
return baseName.substr(0, 1) !== '.' && baseName !== 'node_modules' && baseName !== 'vendor'; |
47
|
|
|
}, |
48
|
|
|
tick: function(localPath, remotePath, error) { |
49
|
|
|
if (error) { |
50
|
|
|
failed.push(localPath); |
51
|
|
|
} else { |
52
|
|
|
successful.push(localPath); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
}).then(function(successful) { |
56
|
|
|
console.log('the directory transfer was', successful ? 'successful' : 'unsuccessful'); |
|
|
|
|
57
|
|
|
console.log('failed transfers', failed.join(', ')); |
58
|
|
|
console.log('successful transfers', successful.join(', ')); |
59
|
|
|
}); |
60
|
|
|
|
61
|
|
|
// Command with escaped params |
62
|
|
|
ssh.exec('composer', ['install', '--no-dev', '--optimize-autoloader', '--no-interaction', '--no-progress', '--no-scripts'], { cwd: '/var/www/workspace.local/' }).then(function(result) { |
63
|
|
|
console.log('STDOUT: ' + result); |
|
|
|
|
64
|
|
|
}); |
65
|
|
|
|
66
|
|
|
}); |
67
|
|
|
|