|
|
@@ -200,20 +200,37 @@ require( [ 'tests' ], bender.defer(), function( err ) {
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
- * Allows us to pick one of files suffixed with the format (`__esnext`, `__amd`, or `__cjs`).
|
|
|
+ * Allows us to pick one of files suffixed with the format (`__esnext`, `__amd`, or `__cjs`) and removes
|
|
|
+ * files with other suffixes from the stream.
|
|
|
*
|
|
|
* For example: we have `load__esnext.js`, `load__amd.js` and `load__cjs.js`. After applying this
|
|
|
* transformation when compiling code for a specific format the proper file will be renamed to `load.js`.
|
|
|
+ * Files not matching a specific format will be removed.
|
|
|
*
|
|
|
* @param {String} format
|
|
|
* @returns {Stream}
|
|
|
*/
|
|
|
pickVersionedFile( format ) {
|
|
|
- return rename( ( path ) => {
|
|
|
+ const pick = rename( ( path ) => {
|
|
|
const regexp = new RegExp( `__${ format }$` );
|
|
|
|
|
|
path.basename = path.basename.replace( regexp, '' );
|
|
|
} );
|
|
|
+
|
|
|
+ const remove = gulpFilter( ( file ) => {
|
|
|
+ return [ 'esnext', 'amd', 'cjs' ]
|
|
|
+ .filter( ( item ) => item !== format )
|
|
|
+ .reduce( ( prev, item ) => {
|
|
|
+ // If file was already matched, skip next checking.
|
|
|
+ if ( !prev ) {
|
|
|
+ return prev;
|
|
|
+ }
|
|
|
+
|
|
|
+ return !( new RegExp( `__${ item }\.js$` ).test( file.path ) );
|
|
|
+ }, true );
|
|
|
+ } );
|
|
|
+
|
|
|
+ return multipipe( pick, remove );
|
|
|
},
|
|
|
|
|
|
/**
|