forked from rtablada/ember-cli-deploy-scp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
75 lines (63 loc) · 2.19 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
var BasePlugin = require('ember-cli-deploy-plugin');
var Rsync = require('rsync');
module.exports = {
name: 'ember-cli-deploy-scp',
createDeployPlugin: function(options) {
var DeployPlugin = BasePlugin.extend({
name: options.name,
defaultConfig: {
port: '22',
directory: 'tmp/deploy-dist/.',
exclude: false,
flags: 'rtvu',
displayCommands: false,
beforeBuild: function(){},
beforeUpload: function(){}
},
requiredConfig: ['username', 'path', 'host'],
willBuild: function(context) {
this.readConfig('beforeBuild');
},
willUpload: function(context) {
this.readConfig('beforeUpload');
},
build: function(context) {
},
rsync: function (destination) {
var _this = this;
var rsync = new Rsync()
.shell('ssh -p '+this.readConfig('port'))
.flags(this.readConfig('flags'))
.source(this.readConfig('directory'))
.destination(destination);
if (this.readConfig('exclude')){
rsync.exclude(this.readConfig('exclude'));
}
if (this.readConfig('displayCommands')) {
this.log(rsync.command())
}
return new Promise(function(resolve, reject) {
rsync.execute(function(error, code, cmd) {
if(error) {
reject(_this.log(error));
} else {
_this.log('Done !');
resolve();
}
});
});
},
upload: function(context) {
var MyDate = new Date(),
MyDateString,
generatedPath = this.readConfig('username') + '@' + this.readConfig('host') + ':' + this.readConfig('path'),
parentPath = generatedPath.substr(0, generatedPath.lastIndexOf("/"));
MyDate.setDate(MyDate.getDate());
MyDateString = ('0' + MyDate.getDate()).slice(-2) + ('0' + (MyDate.getMonth()+1)).slice(-2) + MyDate.getFullYear() + ('0' + MyDate.getHours()).slice(-2) + ('0' + MyDate.getMinutes()).slice(-2);
this.rsync(parentPath + '/' + MyDateString);
return this.rsync(generatedPath);
}
});
return new DeployPlugin();
}
};