UNPKG

923 BJavaScriptView Raw
1'use strict';
2
3var {pipeline} = require('stream');
4const {createTransform} = require('../util');
5
6module.exports = function (filters, stream, cb) {
7 var self = this;
8
9 if (typeof filters === 'function') {
10 cb = filters;
11 filters = [];
12 stream = undefined;
13 } else if (typeof stream === 'function') {
14 cb = stream;
15 stream = undefined;
16 }
17
18 stream = stream || this.store.stream();
19 var modifiedFilter = createTransform(function (file, _enc, cb) {
20 // Don't process deleted file who haven't been commited yet.
21 if (file.state === 'modified' || (file.state === 'deleted' && !file.isNew)) {
22 this.push(file);
23 }
24
25 cb();
26 });
27
28 var commitFilter = createTransform(function (file, _enc, cb) {
29 self.commitFileAsync(file).then(() => cb()).catch(error => cb(error));
30 });
31
32 pipeline(
33 stream,
34 modifiedFilter,
35 ...filters,
36 commitFilter,
37 (...args) => cb(...args)
38 );
39};