-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
81 lines (75 loc) · 2.41 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
/* eslint-env node */
'use strict';
var DeployPluginBase = require('ember-cli-deploy-plugin');
var Sftp = require('sftp-upload');
var fs = require('fs');
var RSVP = require('rsvp');
module.exports = {
name: 'ember-cli-deploy-sftp',
createDeployPlugin: function(options) {
var DeployPlugin = DeployPluginBase.extend({
name: options.name,
defaultConfig: {
host: function(context) {
return context.host;
},
port: function(context) {
return context.port || 22;
},
remoteUser: function(context) {
return context.remoteUser || 'root';
},
remoteDir: function(context) {
return context.remoteDir;
},
distDir: function(context) {
return context.distDir;
},
privateKey: function(context) {
return context.privateKey;
},
passphrase: function(context) {
return context.passphrase;
},
agent: function(context) {
return context.agent;
},
password: function(context) {
return context.password;
}
},
upload: function(/* context */) {
this.log('Start Upload', { color: 'green' });
var promise = new RSVP.Promise(function(resolve, reject) {
var options = {
host: this.readConfig('host'),
port: this.readConfig('port'),
username: this.readConfig('remoteUser'),
path: this.readConfig('distDir'),
remoteDir: this.readConfig('remoteDir'),
privateKey: this.readConfig('privateKey') && fs.readFileSync(this.readConfig('privateKey')),
agent: this.readConfig('agent'),
password: this.readConfig('password'),
passphrase: this.readConfig('passphrase')
},
sftp = new Sftp(options);
sftp.on('error', function(err){
this.log(err);
reject(err);
}.bind(this))
.on('uploading', function(pgs){
this.log('Uploading '+ pgs.file);
this.log(pgs.percent+'% completed');
}.bind(this))
.on('completed', function(){
this.log('Upload Completed', { color: 'green' });
resolve('OK');
}.bind(this))
.upload();
}.bind(this));
return promise;
},
});
return new DeployPlugin();
}
};