import { toKebabCase } from '../utils' ; import { STATE_MANAGEMENT } from '../constants' ; import { Extensions , ScaffoldConfig } from '../types' ; import { mobxTemplate , storeTemplate , reduxTemplate , sliceTemplate , routerTemplate , componentTemplate , stylesheetTemplate , rootExportTemplate , } from '../templates' ; type StateType = { storesOrReducers : string [ ] ; type : keyof typeof STATE_MANAGEMENT ; } ; export const generateScaffoldConfig = ( ts , routes , folders , sagaUsed , useLogger , namedExport , fileExtensions , stateManagement ? ) : ScaffoldConfig [ ] => { const { cmpExt , fileExt , stylesExt } = fileExtensions ; return [ ... routes . length ? [ { name : 'router' , children : [ { name : `index.${ cmpExt }` , children : routerTemplate ( routes , ts , namedExport ) , } ] , } , { name : 'routes' , children : [ ... routes . map ( route => ( { name : route , children : [ { name : `index.${ cmpExt }` , children : componentTemplate ( route , ts , namedExport , stylesExt ) , } , { name : `styles.${ stylesExt }` , children : stylesheetTemplate ( route ) , } ] , } ) ) , ... namedExport ? [ { name : `index.${ fileExt }` , children : rootExportTemplate ( 'routes' , routes ) , } ] : [ ] , ] , } , ] : [ ] , ... folders . length ? folders . map ( name => ( { name , children : namedExport ? [ { name : `index.${ fileExt }` , children : rootExportTemplate ( name ) , } ] : undefined , } ) ) : [ ] , ... stateManagement ?. type === STATE_MANAGEMENT . MobX . label ? [ { name : 'store' , children : [ { name : `index.${ fileExt }` , children : mobxTemplate ( stateManagement . storesOrReducers , namedExport ) , } , ... stateManagement ?. storesOrReducers . length ? stateManagement . storesOrReducers . map ( name => ( { name : `${ toKebabCase ( name ) }.${ fileExt }` , children : storeTemplate ( name , ts , namedExport ) , } ) ) : [ ] ] , } ] : [ ] , ... stateManagement ?. type === STATE_MANAGEMENT . Redux . label ? [ { name : 'store' , children : [ { name : `index.${ fileExt }` , children : reduxTemplate ( ts , sagaUsed , useLogger , namedExport , stateManagement . storesOrReducers ) , } , ... stateManagement ?. storesOrReducers . length ? [ { name : 'features' , children : [ ... stateManagement . storesOrReducers . map ( name => ( { name : toKebabCase ( name ) , children : [ { name : `index.${ fileExt }` , children : sliceTemplate ( name , ts , namedExport , sagaUsed ) , } ] , } ) ) , ... namedExport ? [ { name : `index.${ fileExt }` , children : rootExportTemplate ( 'reducers' , stateManagement . storesOrReducers . map ( name => toKebabCase ( name ) ) ) , } ] : [ ] ] , } ] : [ ] ] , } ] : [ ] , ] ; } ;