@@ -9,13 +9,24 @@ const fullTarget = (dir, file, options) => join(dir, template(file, options))
99
1010// given an obj of files, return the full target/source paths and associated parser
1111const getParsers = ( dir , files , options ) => Object . entries ( files ) . map ( ( [ t , s ] ) => {
12- let { file, parser : fileParser } = typeof s === 'string' ? { file : s } : s
13- const target = fullTarget ( dir , t , options )
12+ let {
13+ file,
14+ parser : fileParser ,
15+ filter,
16+ } = typeof s === 'string' ? { file : s } : s
17+
1418 file = join ( options . config . sourceDir , file )
19+ const target = fullTarget ( dir , t , options )
20+
21+ if ( typeof filter === 'function' && ! filter ( options ) ) {
22+ return null
23+ }
24+
1525 if ( fileParser ) {
1626 // allow files to extend base parsers or create new ones
1727 return new ( fileParser ( Parser . Parsers ) ) ( target , file , options )
1828 }
29+
1930 return new ( Parser ( file ) ) ( target , file , options )
2031} )
2132
@@ -32,7 +43,9 @@ const rmEach = async (dir, files, options, fn) => {
3243const parseEach = async ( dir , files , options , fn ) => {
3344 const res = [ ]
3445 for ( const parser of getParsers ( dir , files , options ) ) {
35- res . push ( await fn ( parser ) )
46+ if ( parser ) {
47+ res . push ( await fn ( parser ) )
48+ }
3649 }
3750 return res . filter ( Boolean )
3851}
0 commit comments