forked from sqhtiamo/webpack-sftp-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
84 lines (64 loc) · 2.16 KB
/
index.js
File metadata and controls
84 lines (64 loc) · 2.16 KB
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
/*!
* A plugin for webpack as an scp client
* Licensed under the MIT License.
*/
'use strict';
var ClientLib = require('scp2');
function WebpackScpClient(options) {
this.options = options;
}
WebpackScpClient.prototype.apply = function (compiler) {
var self = this;
compiler.plugin('done', function (compilation) {
var client = new ClientLib.Client();
var remotePath = self.options.remotePath;
var path = self.options.path;
var username = self.options.username;
var host = self.options.host;
var password = self.options.password;
var port = self.options.port || '22';
var verbose = self.options.verbose;
var startTime;
var endTime;
client.on('ready', function () {
startTime = new Date();
console.log(host + ' [Start Uploading] ' + startTime);
});
client.on('transfer', function (buf, up, total) {
});
client.on('write', function (p) {
if (verbose) {
console.log('Transfer ' + p.source + ' => ' + host + '@' + p.destination);
}
});
client.on('end', function () {
endTime = new Date();
console.log(host + ' [End Uploading] ' + new Date());
});
client.on('error', function (err) {
console.log('[Error] ' + err);
});
client.on('close', function () {
console.log(host + ' Transfer Completed in [' + (+endTime - +startTime) / 1000 + '] seconds!');
});
var srcPath = path;
var destPath = username + ':' + password + '@' + host + ':' + port + ':' + remotePath;
uploadByDir(srcPath, destPath, client);
});
};
/**
* [uploadByDir: Upload Directory Directory & Cannot Get Detailed Uploading Info for Files]
* @param {[String]} src [description]
* @param {[String]} dest [description]
* @param {[Object]} client [description]
*/
function uploadByDir(src, dest, client) {
ClientLib.scp(src, dest, client,
function (err) {
if (err) {
console.log(err);
}
}
);
}
module.exports = WebpackScpClient;