/**
 * Automatically import all module files named with suffix '.store.js' and export them
 * as single module objects. Modules will be named according to file structure, however,
 * the first directory level will be ignored.
 */
const requireModule = require.context('.', true, /\.store\.js$/)
const modules = {}

requireModule.keys().forEach(fileName => {
  // create the module name from fileName
  // remove the store.js extension and capitalize
  const moduleName = fileName.replace(/(\.\/|\.store\.js)/g, '')
  // create a dynamic object with all modules
  modules[moduleName] = {
    namespaced: true,
    ...requireModule(fileName)
  }
})

export default modules
