forked from Fjandin/gulp-scp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·72 lines (60 loc) · 2.02 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
'use strict';
var gutil = require('gulp-util');
var through = require('through2');
var assign = require('object-assign');
var scp = require('scp');
var path = require('path');
module.exports = function (options) {
options = assign({
port: 22,
user: ''
}, options);
if (options.host === undefined) {
throw new gutil.PluginError('gulp-scp', '`host` required.');
}
if (options.path === undefined) {
throw new gutil.PluginError('gulp-scp', '`path` required.');
}
var files = [];
var remotePath = options.remotePath || '';
delete options.remotePath;
return through.obj(function (file, enc, cb) {
if (file.isStream()) {
this.emit('error', new gutil.PluginError('gulp-scp', 'Streaming not supported'));
return cb();
}
//Folder mode does not allow files
if (!options.folder && file.isNull()) {
this.push(file);
return cb();
}
//Folder only allows 1 path
if (options.folder && files.length) {
return cb();
}
this.push(file);
var filePath = options.cygwin ? path.relative(process.cwd(), file.path) : file.path;
files.push(filePath);
return cb();
}, function (cb) {
if (files.length > 0) {
for (var i = 0; i < files.length; i++) {
options.file = files[i];
scp.send(options, function (err) {
if (err) {
gutil.log('gulp-scp:', gutil.colors.red(err));
} else {
gutil.log('gulp-scp:', gutil.colors.green(files.length, files.length === 1 ? 'file' : 'files', 'transferred successfully'));
}
cb();
if (options.cb) {
options.cb()
}
});
}
} else {
gutil.log('gulp-scp:', gutil.colors.green('No files transferred'));
cb();
}
});
};