forked from yuanqing/gulp-tape
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (36 loc) · 1.04 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
'use strict';
var tape = require('tape');
var through = require('through2');
var forEach = require('lodash.foreach');
var PluginError = require('gulp-util').PluginError;
var requireUncached = require('require-uncached');
var PLUGIN_NAME = 'gulp-tape';
var gulpTape = function(opts) {
opts = opts || {};
var outputStream = opts.outputStream || process.stdout;
var reporter = opts.reporter || through.obj();
var files = [];
var transform = function(file, encoding, cb) {
if (file.isNull()) {
return cb(null, file);
}
if (file.isStream()) {
return cb(new PluginError(PLUGIN_NAME, 'Streaming is not supported'));
}
files.push(file.path);
cb(null, file);
};
var flush = function(cb) {
try {
tape.createStream().pipe(reporter).pipe(outputStream);
forEach(files, function(file) {
requireUncached(file);
});
cb();
} catch (err) {
cb(new PluginError(PLUGIN_NAME, err));
}
};
return through.obj(transform, flush);
};
module.exports = gulpTape;