1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | 'use strict';
|
7 |
|
8 | const path = require( 'path' );
|
9 | const PassThrough = require( 'stream' ).PassThrough;
|
10 | const through = require( 'through2' );
|
11 |
|
12 | const stream = {
|
13 | |
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | noop( callback ) {
|
21 | if ( !callback ) {
|
22 | return new PassThrough( { objectMode: true } );
|
23 | }
|
24 |
|
25 | return through( { objectMode: true }, ( chunk, encoding, throughCallback ) => {
|
26 | const callbackResult = callback( chunk );
|
27 |
|
28 | if ( callbackResult instanceof Promise ) {
|
29 | callbackResult
|
30 | .then( () => {
|
31 | throughCallback( null, chunk );
|
32 | } )
|
33 | .catch( err => {
|
34 | throughCallback( err );
|
35 | } );
|
36 | } else {
|
37 | throughCallback( null, chunk );
|
38 | }
|
39 | } );
|
40 | },
|
41 |
|
42 | |
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | isTestFile( file ) {
|
49 |
|
50 | if ( !file.relative.startsWith( 'tests' + path.sep ) ) {
|
51 | return false;
|
52 | }
|
53 |
|
54 | const dirFrags = file.relative.split( path.sep );
|
55 |
|
56 | return !dirFrags.some( dirFrag => {
|
57 | return dirFrag.startsWith( '_' ) && dirFrag != '_utils-tests';
|
58 | } );
|
59 | },
|
60 |
|
61 | |
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 | isSourceFile( file ) {
|
68 | return !stream.isTestFile( file );
|
69 | },
|
70 |
|
71 | |
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 | isJSFile( file ) {
|
78 | return file.path.endsWith( '.js' );
|
79 | }
|
80 | };
|
81 |
|
82 | module.exports = stream;
|