-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
68 lines (58 loc) · 1.95 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
var path = require('path');
var gutil = require('gulp-util');
var through = require('through2');
var plur = require('plur');
var exec = require('child_process').exec;
function copy(container, localPath, containerPath, callback) {
if (process.argv.indexOf('--verbose') !== -1) {
gutil.log('gulp-docker-sync:', 'copy [' + localPath + '] to [' + container + ':' + containerPath + ']');
}
exec('docker cp ' + localPath + ' ' + container + ':' + containerPath, callback);
};
module.exports = {
cp: copy,
dest: (options = {}) => {
options.verbose = process.argv.indexOf('--verbose') !== -1;
if (options.container === undefined) {
throw new gutil.PluginError('gulp-docker-sync', '`container` required');
}
if (options.remotePath === undefined) {
throw new gutil.PluginError('gulp-docker-sync', '`remotePath` required');
}
let dirCount = 0;
let fileCount = 0;
let stream = through.obj((file, enc, callback) => {
if (file.isStream()) {
throw new gutil.PluginError('gulp-docker-sync', 'Streaming not supported');
}
let finalRemotePath = path.join(options.remotePath, file.relative).replace(/\\/g, '/');
// remove name from remote path when syncing dirs
if (file.isDirectory()) {
finalRemotePath = finalRemotePath.substr(0, finalRemotePath.lastIndexOf('/') + 1);
}
copy(options.container, file.path, finalRemotePath, (err) => {
if (err) {
throw new gutil.PluginError('gulp-docker-sync', err, { fileName: file.path });
}
if (file.isDirectory) {
dirCount++;
} else {
fileCount++;
}
callback();
});
}, (callback) => {
if (fileCount > 0 || dirCount > 0) {
gutil.log('gulp-docker-sync:', gutil.colors.green(
dirCount + ' ' + plur('directory', dirCount),
'and',
fileCount + ' ' + plur('file', fileCount),
'copied successfully'));
} else {
gutil.log('gulp-docker-sync:', gutil.colors.yellow('No files uploaded'));
}
callback();
});
return stream;
}
};