-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (43 loc) · 977 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
40
41
42
43
44
45
46
47
48
49
50
var fs = require('fs');
var path = require('path');
var mkdirp = require('mkdirp');
var vfs = require('vinyl-fs');
var es = require('event-stream');
var queue = require('queue');
function createSymlink(dest, symlink, cb) {
mkdirp(path.dirname(dest), function (err) {
if (err) { return cb(err); }
fs.symlink(symlink, dest, cb);
});
}
module.exports = function (out) {
var pass = es.through();
var symlinks = [];
return es.duplex(pass,
pass.pipe(es.mapSync(function (f) {
if (!f.symlink) {
return f;
}
symlinks.push(f);
}))
.pipe(vfs.dest(out))
.pipe(es.through(null, function () {
var q = queue();
q.concurrency = 1;
q.timeout = 1000;
var that = this;
symlinks.forEach(function (f) {
q.push(function (cb) {
createSymlink(path.join(out, f.relative), f.symlink, cb);
});
});
q.start(function (err) {
if (err) {
that.emit('error', err);
} else {
that.emit('end');
}
});
}))
);
};