import './foundation' ; import requireDir from 'require-dir' ; import DefaultTask from './default' ; import BalmHooks from '../hooks' ; import { BalmError } from '@balm-core/index' ; const PRIVATE_TASKS = requireDir ( './private' ) ; const PUBLIC_TASKS = requireDir ( './public' ) ; function registerTasks ( recipe ) { const AwesomeTasks = BalmJS . utils . deepMerge ( PRIVATE_TASKS , PUBLIC_TASKS ) ; const depsTasks = [ ] ; const nonDepsTasks = [ ] ; Object . values ( AwesomeTasks ) . forEach ( ( AwesomeTask ) => { const awesomeTask = new AwesomeTask . default ( ) ; awesomeTask . deps ? depsTasks . push ( awesomeTask ) : nonDepsTasks . push ( awesomeTask ) ; } ) ; nonDepsTasks . forEach ( ( task ) => { const taskName = task . taskName ; const taskFunction = task . fn ; gulp . task ( taskName , taskFunction ) ; BalmJS . tasks . set ( task . name , task ) ; } ) ; depsTasks . forEach ( ( task ) => { const taskName = task . taskName ; const taskFunction = task . deps . length ? gulp . series ( ... BalmJS . toNamespace ( task . deps ) ) : ( callback ) : void => { callback ( ) ; } ; gulp . task ( taskName , taskFunction ) ; BalmJS . tasks . set ( task . name , task ) ; } ) ; try { recipe ( new BalmHooks ( ) ) ; } catch ( error ) { const { message } = error as BalmError ; BalmJS . logger . error ( 'balm hook' , message ) ; } const defaultTask = new DefaultTask ( ) ; gulp . task ( defaultTask . taskName , gulp . series ( ... defaultTask . startTask , ... defaultTask . mainTasks , ... defaultTask . subTasks , ... defaultTask . endTask ) ) ; } export default registerTasks ;