-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.js
88 lines (75 loc) · 2.52 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
76
77
78
79
80
81
82
83
84
85
86
87
88
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,
displayCommands: false
},
requiredConfig: ['username', 'path', 'host'],
build: function(context) {
this.log('Building...');
},
fetchRevisions: function(keyPrefix) {
var self = this;
return Promise.resolve(function(){
return [
{
revision: 'abc123', // mandatory
version: 'v1',
timestamp: 1438232435000, // milliseconds since epoch
deployer: 'cats'
},
{
revision: 'def456',
version: 'v2',
timestamp: 1032123128000,
deployer: 'dogs',
active: true // indicate whether this revision is activated
}
]
}())
.then(function(revisions){
return { revisions: revisions };
})
.catch(function(err) {
self.log(err);
});
},
rsync: function (destination){
var rsync = new Rsync()
.shell('ssh')
.flags('rtvu')
.source(this.readConfig('directory'))
.destination(destination);
if (this.readConfig('exclude')){
rsync.set('exclude', this.readConfig('exclude'));
}
if (this.readConfig('displayCommands')){
this.log(rsync.command())
}
rsync.execute(function(error, code, cmd) {
this.log('Done !');
});
},
upload: function(context) {
this.log('Uploading...');
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);
this.rsync(generatedPath);
this.log('Done !');
}
});
return new DeployPlugin();
}
};