import Mock from 'mockjs'
// 设置全局延时
Mock.setup({
  timeout: '200-400'
});
import SystemRegExpConfig from "@/utils/SystemRegExpConfig";

let mocks = {};

function setAllMocks(files) {
  let path = require('path');
  files.keys().forEach(item => {
    let name = path.basename(item, '.js');
    if (SystemRegExpConfig.mocks.test(item)) {
      let exportDefault = files(item) || files(item);
      if (exportDefault) {
        mocks[name] = exportDefault;
      }
    }
  });
  console.log("mocks：", mocks);
}

/**
 * 需要修改成对应的模块
 */
const files = require.context('@', true, /\/mock(.*)\/*.js$/);
setAllMocks(files);

export function initMocks(files) {
  setAllMocks(files);
  console.log("initMocks mocks：", mocks);
  return mocks;
}

export default mocks;
