Skip to content

Commit 18692d6

Browse files
committed
output optionally specify a function
1 parent dfcf69a commit 18692d6

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

index.js

+18-10
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,17 @@ module.exports = function f (b, opts) {
2828
var needRecords = !files.length;
2929

3030
var outopt = defined(opts.outputs, opts.output, opts.o);
31-
if (outopt && !isarray(outopt)) outopt = [outopt];
32-
var outputs = defined(outopt, []).map(function (o) {
33-
if (isStream(o)) return o;
34-
else return fs.createWriteStream(o);
35-
});
36-
if (!isarray(outputs) && isStream(outputs)) outputs = [ outputs ];
37-
else if (!isarray(outputs)) outputs = [];
31+
if (typeof outopt === 'function') {
32+
var outputs = outopt
33+
} else {
34+
if (outopt && !isarray(outopt)) outopt = [outopt];
35+
var outputs = defined(outopt, []).map(function (o) {
36+
if (isStream(o)) return o;
37+
else return fs.createWriteStream(o);
38+
});
39+
if (!isarray(outputs) && isStream(outputs)) outputs = [ outputs ];
40+
else if (!isarray(outputs)) outputs = [];
41+
}
3842

3943
function moreOutputs (file) {
4044
if (isarray(outopt)) return [];
@@ -68,10 +72,14 @@ module.exports = function f (b, opts) {
6872
'pack', [ pack(packOpts) ],
6973
'wrap', []
7074
]);
71-
if (ix >= outputs.length) {
72-
outputs.push.apply(outputs, moreOutputs(x));
75+
if (typeof outputs === 'function') {
76+
pipeline.pipe(outputs(x))
77+
} else {
78+
if (ix >= outputs.length) {
79+
outputs.push.apply(outputs, moreOutputs(x));
80+
}
81+
if (outputs[ix]) pipeline.pipe(outputs[ix]);
7382
}
74-
if (outputs[ix]) pipeline.pipe(outputs[ix]);
7583

7684
acc[path.resolve(cwd, x)] = pipeline;
7785
return acc;

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "factor-bundle",
3-
"version": "2.4.1",
3+
"version": "2.4.2",
44
"description": "factor browser-pack bundles into common shared bundles",
55
"main": "index.js",
66
"bin": "bin/cmd.js",

readme.markdown

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ where OPTIONS are:
140140
141141
-o Output FILE or CMD that maps to a corresponding entry file at the same
142142
index. CMDs are executed with $FILE set to the corresponding input file.
143+
Optionally specify a function that return a writable stream.
143144
144145
-e Entry file to use, overriding the entry files listed in the original
145146
bundle.

0 commit comments

Comments
 (0)