import CluiStore from '@store/cluiStore' ; import React , { useEffect , useState } from 'react' ; import { CommandType } from './commands' ; const CustomComp = ( props ) => { const [ count , setCount ] = useState ( 0 ) ; useEffect ( ( ) => { setCount ( count + 1 ) ; CluiStore . updateRun ( true ) ; } , [ ] ) ; useEffect ( ( ) => { if ( count ) { props . item . next ( ) ; } } , [ count ] ) ; return props . ui || 'No ui was provided' ; } ; const generateCommands = ( array ) => array . reduce ( ( cur , nex ) => { cur [ nex . command ] = { description : nex . description } ; if ( nex . child && nex . child . length ) { cur [ nex . command ] . commands = ( ) => generateCommands ( nex . child as Array < CommandType > ) ; } else { cur [ nex . command ] . run = ( ) => < CustomComp ui = { nex . ui } />; } return cur ; } , { } ) ; const getFormattedOutput = ( data ) => ( { commands : generateCommands ( data ) } ) ; export default getFormattedOutput ;