-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
39 lines (33 loc) · 918 Bytes
/
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
/* jshint node: true */
var PLUGIN_NAME = 'gulp-multi-dest';
var through = require('through2');
var gulp = require('gulp');
var async = require('async');
module.exports = function (paths, options) {
options = options || {};
var writtenFiles = [];
if (typeof (paths) === 'string') {
paths = [paths];
}
var dests = paths.map(function (path) {
return gulp.dest(path, options);
});
function writeFileToMultipleDestinations(file, encoding, done) {
async.each(dests, function (dest, wroteFileToDest) {
var fileClone = file.clone();
dest.write(fileClone, function () {
writtenFiles.push(fileClone);
wroteFileToDest();
});
}, done);
}
function flushCreatedFiles(done) {
var stream = this;
for(var i = 0; i < writtenFiles.length; i++){
var file = writtenFiles[i];
stream.push(file);
}
done();
}
return through.obj(writeFileToMultipleDestinations, flushCreatedFiles);
};