const BLOCKLIST_IN_PROD = [ 'serve' ] ; let compiling = false ; function ban ( name ) { const BLOCKLIST_IN_DEV = [ 'publish' , ... ( BalmJS . config . useDefaults ? BLOCKLIST_IN_PROD : [ ] ) ] ; const banInProd = BalmJS . config . env . isProd && BLOCKLIST_IN_PROD . includes ( name ) ; const banInDev = BalmJS . config . env . isDev && BLOCKLIST_IN_DEV . includes ( name ) ; const isBan = banInProd || banInDev ; const api = name === 'postcss' ? 'css' : name ; if ( isBan ) { const message = BalmJS . config . useDefaults && BalmJS . config . env . isDev && BLOCKLIST_IN_PROD . includes ( name ) ? `'mix.${ api }()' can only be used for 'balm.config.useDefaults = false;'` : `There is no 'mix.${ api }()' hook in ${ banInProd ? 'production' : 'development' } mode` ; BalmJS . logger . warn ( 'balm hook' , message ) ; } return isBan ; } class Maker { static generate ( name , args = [ ] ) { if ( ban ( name ) ) { return ; } const customTask = BalmJS . tasks . get ( name ) ; const taskName = [ 'sprite' , ... BLOCKLIST_IN_PROD ] . includes ( customTask . name ) ? customTask . name : `${ customTask . name }:${ BalmJS . recipeIndex }` ; let balmTask = ( callback ) : void => { callback ( ) ; } ; switch ( customTask . name ) { case 'sprite' : customTask . recipe ( ... args ) ; if ( customTask . deps . length ) { balmTask = gulp . series ( ... BalmJS . toNamespace ( customTask . deps ) ) ; } else { BalmJS . logger . warn ( 'balm hook' , '`mix.sprite()` is missing `input` parameters' ) ; } break ; case 'modernizr' : balmTask = customTask . fn ; break ; default : balmTask = customTask . recipe ( ... args ) ; } if ( BalmJS . watching ) { if ( ! compiling ) { compiling = true ; gulp . series ( balmTask , ( done ) : void => { compiling = false ; done ( ) ; } ) ( ) ; } } else { gulp . task ( BalmJS . toNamespace ( taskName ) as string , balmTask ) ; BalmJS . recipes . push ( taskName ) ; BalmJS . recipeIndex ++ ; } } } export default Maker ;