
function getAppsMocks() {
  const modulesFiles = require.context('@/apps', true, /mock\.js$/)
  const modules = modulesFiles.keys().reduce((modules, modulePath) => {
    // const moduleName = modulePath.replace(/^\.\/(.*)\/(.*)mock\.\w+$/, '$1')
    const value = modulesFiles(modulePath)
    if (Array.isArray(modules)) {
      modules = [...modules, ...value.default]
    } else {
      return modules = value.default
    }
    return modules
  }, {})
  return modules
}

function getMockFiles() {
  const modulesFiles = require.context('@/mock/mockFiles', true, /\.js$/)
  const modules = modulesFiles.keys().reduce((modules, modulePath) => {
    const value = modulesFiles(modulePath)
    if (Array.isArray(modules)) {
      modules = [...modules, ...value.default]
    } else {
      return modules = value.default
    }
    return modules
  }, {})
  return modules
}

const mockFiles = getMockFiles()
const appsMocks = getAppsMocks()
let mocks = [
  ...appsMocks,
  ...mockFiles
]

mocks = mocks.map((item) => {
  item.url = "/mock" + item.url.replace(/^(\w)/, "/$1")
  return item
})

export default mocks