|
1
|
|
|
var path = require('path'); |
|
|
|
|
|
|
2
|
|
|
var fs = require('fs'); |
|
3
|
|
|
var JSZip = require("jszip"); |
|
4
|
|
|
var rsync = require("rsyncwrapper"); |
|
5
|
|
|
var chalk = require('chalk'); |
|
6
|
|
|
var node_ssh = require('node-ssh'); |
|
7
|
|
|
var ssh = new node_ssh(); |
|
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
process.stdout.write("Deploy workspace on DEV.\n"); |
|
10
|
|
|
|
|
11
|
|
|
ssh.connect({ |
|
12
|
|
|
host: 'www.d1b0.local', |
|
13
|
|
|
username: 'developer', |
|
14
|
|
|
privateKey: './server/plays/ssh/developer.key', |
|
15
|
|
|
port: 2222 |
|
16
|
|
|
}).then(function() { |
|
17
|
|
|
var nextCommand = ssh.mkdir('/var/www/workspace.local/src/'); |
|
18
|
|
|
// @see: https://github.com/steelbrain/node-ssh/blob/master/src/index.js |
|
19
|
|
|
nextCommand.then( function(){ |
|
20
|
|
|
ssh.exec('rm', ['-rf', 'public'], { cwd: '/var/www/workspace.local', stream: 'both' }).then( function(both){ |
|
|
|
|
|
|
21
|
|
|
ssh.exec('ln', ['-s','web','public'], { cwd: '/var/www/workspace.local', stream: 'both' }).then( function(both){ |
|
|
|
|
|
|
22
|
|
|
ssh.dispose(); |
|
23
|
|
|
process.stdout.write("prepare dir COMPLETED.\n"); |
|
24
|
|
|
|
|
25
|
|
|
process.stdout.write("Start rsync src.\n"); |
|
26
|
|
|
|
|
27
|
|
|
rsync({ |
|
28
|
|
|
src: "./applications/workspace/", |
|
29
|
|
|
dest: "[email protected]:/var/www/workspace.local/", |
|
30
|
|
|
ssh: true, |
|
31
|
|
|
privateKey: './server/plays/ssh/developer.key', |
|
32
|
|
|
port: 2222, |
|
33
|
|
|
exclude: [ 'test', '.DS_Store', 'phpunit.xml', 'README.md', 'vendor' ], |
|
34
|
|
|
recursive: true, |
|
35
|
|
|
deleteAll: false //senno elimina log! |
|
36
|
|
|
},function (error,stdout,stderr,cmd) { |
|
37
|
|
|
if ( error ) { |
|
38
|
|
|
process.stderr.write('CMD: '+cmd+"\n"); |
|
39
|
|
|
process.stderr.write(chalk.red(error.message)+"\n"); |
|
40
|
|
|
process.exit(1); |
|
|
|
|
|
|
41
|
|
|
} |
|
42
|
|
|
}); |
|
43
|
|
|
|
|
44
|
|
|
process.stdout.write("Composer install.\n"); |
|
45
|
|
|
|
|
46
|
|
|
ssh.connect({ |
|
47
|
|
|
host: 'www.d1b0.local', |
|
48
|
|
|
username: 'developer', |
|
49
|
|
|
privateKey: './server/plays/ssh/developer.key', |
|
50
|
|
|
port: 2222 |
|
51
|
|
|
}).then(function() { |
|
52
|
|
|
ssh.exec('composer', ['install', '--no-dev', '--optimize-autoloader', '--no-interaction', '--no-progress', '--no-scripts'], { cwd: '/var/www/workspace.local/', stream: 'both' }).then(function(both) { |
|
53
|
|
|
process.stdout.write(chalk.cyan(both.stdout)+"\n"); |
|
54
|
|
|
if ( both.code === 0 ){ |
|
55
|
|
|
process.stdout.write(chalk.cyan(both.stderr)+"\n"); |
|
56
|
|
|
} else { |
|
57
|
|
|
process.stdout.write(chalk.red(both.stderr)+"\n"); |
|
58
|
|
|
process.exit(1); |
|
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
process.stdout.write("Deploy COMPLETED.\n"); |
|
61
|
|
|
ssh.dispose(); |
|
62
|
|
|
}); |
|
63
|
|
|
}); |
|
64
|
|
|
|
|
65
|
|
|
}); |
|
66
|
|
|
}); |
|
67
|
|
|
}); |
|
68
|
|
|
}); |
|
69
|
|
|
|