import mergeStream from '../../utilities/merge-stream' ; import { RenameOptions , TemplateOption } from '@balm-core/index' ; class PublishTask extends BalmJS . BalmTask { constructor ( ) { super ( 'publish' ) ; this . defaultInput = [ BalmJS . file . matchAllFiles ( BalmJS . config . dest . static ) , path . join ( `!${ BalmJS . config . dest . base }` , '*.*' ) ] ; this . defaultOutput = BalmJS . config . assets . static ; } #release = ( input , output , renameOptions = { } ) : any => { if ( input && output ) { this . init ( path . join ( BalmJS . config . dest . base , input ) , path . join ( BalmJS . config . assets . root , output ) ) ; } else { this . init ( ) ; } return this . src . pipe ( $ . if ( ! BalmJS . utils . isArray ( this . input ) , BalmJS . plugins . rename ( renameOptions ) ) ) . pipe ( gulp . dest ( this . output ) ) ; } ; recipe ( input , output , renameOptions ) { const balmPublish = ( callback ) : any => { if ( BalmJS . config . env . isProd ) { if ( BalmJS . utils . isArray ( input ) ) { const tasks = ( input as TemplateOption [ ] ) . map ( ( template ) => this . #release ( template . input , template . output , template . renameOptions ) ) ; return mergeStream ( ... tasks ) ; } else { return this . #release ( input as string , output , renameOptions ) ; } } else { BalmJS . logger . warn ( `${ this . name } task` , '`mix.publish()` is only supported for production' ) ; callback ( ) ; } } ; return balmPublish ; } fn ( callback ) { callback ( ) ; } } export default PublishTask ;