|
|
@@ -28,6 +28,11 @@ require( [ 'tests' ], bender.defer(), function( err ) {
|
|
|
} );
|
|
|
`,
|
|
|
|
|
|
+ /**
|
|
|
+ * Module formats supported by the builder.
|
|
|
+ */
|
|
|
+ SUPPORTED_FORMATS: [ 'esnext', 'amd', 'cjs' ],
|
|
|
+
|
|
|
/**
|
|
|
* Creates a simple duplex stream.
|
|
|
*
|
|
|
@@ -200,20 +205,28 @@ 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 specified format will be removed.
|
|
|
*
|
|
|
* @param {String} format
|
|
|
* @returns {Stream}
|
|
|
*/
|
|
|
pickVersionedFile( format ) {
|
|
|
- return rename( ( path ) => {
|
|
|
- const regexp = new RegExp( `__${ format }$` );
|
|
|
+ const rejectedFormats = utils.SUPPORTED_FORMATS
|
|
|
+ .filter( ( item ) => item !== format );
|
|
|
+ const pickRegexp = new RegExp( `__${ format }$` );
|
|
|
+ const rejectRegexp = new RegExp( `__(${ rejectedFormats.join( '|' ) }).js$` );
|
|
|
|
|
|
- path.basename = path.basename.replace( regexp, '' );
|
|
|
+ const pick = rename( ( path ) => {
|
|
|
+ path.basename = path.basename.replace( pickRegexp, '' );
|
|
|
} );
|
|
|
+ const remove = gulpFilter( ( file ) => !rejectRegexp.test( file.path ) );
|
|
|
+
|
|
|
+ return multipipe( pick, remove );
|
|
|
},
|
|
|
|
|
|
/**
|