import SystemRegExpConfig from "@/utils/SystemRegExpConfig";
import commonApi from './commonApi'

let services = {};

let path = require("path");
function setAllHttp(files) {
  files.keys().forEach((item) => {
    let name = path.basename(item, ".js");
    if (SystemRegExpConfig.services.test(item)) {
      // console.log("name===", name);
      let exportDefault = files(item).default || files(item);
      if (exportDefault) {
        // 以国际化文件的名称做为key值
        services[name] = exportDefault;
      }
    }
  });
  services['common'] = commonApi;
}

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

export function initHttp(files) {
  // const files = require.context("@", true, /\/services(.*)\/*\.js$/);
  setAllHttp(files);
  console.log('initHttp services', services);
  return services;
}

export default {
  ...services,
};
