-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (44 loc) · 1.35 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
'use strict';
var through2 = require('through2');
var sourcemaps = require('gulp-sourcemaps');
var duplexify = require('duplexify');
var sink = require('./lib/sink');
var prepareWrite = require('./lib/prepare-write');
var writeContents = require('./lib/write-contents');
function store(outFolder, opt) {
if (!opt) {
opt = {};
}
function saveFile(file, enc, cb) {
prepareWrite(outFolder, file, opt, function(err, writePath) {
if (err) {
return cb(err);
}
writeContents(writePath, file, cb);
});
}
var saveStream = through2.obj(opt, saveFile);
if (!opt.sourcemaps) {
// Sink the save stream to start flowing
// Do this on nextTick, it will flow at slowest speed of piped streams
process.nextTick(sink(saveStream));
return saveStream;
}
var sourcemapOpt = opt.sourcemaps;
if (typeof sourcemapOpt === 'boolean') {
sourcemapOpt = {};
}
if (typeof sourcemapOpt === 'string') {
sourcemapOpt = {
path: sourcemapOpt,
};
}
var mapStream = sourcemaps.write(sourcemapOpt.path, sourcemapOpt);
var outputStream = duplexify.obj(mapStream, saveStream);
mapStream.pipe(saveStream);
// Sink the output stream to start flowing
// Do this on nextTick, it will flow at slowest speed of piped streams
process.nextTick(sink(outputStream));
return outputStream;
}
module.exports = store;