// 通过 mode 接口拿到 src/components 下的所有文件夹名作为打包后的模块
const fs = require('fs');
const path = require('path');
const componentDir = 'src/components';
const cModuleNames = fs.readdirSync(path.resolve(componentDir));
const cModuleMap = cModuleNames.reduce((prev, name) => {
  if (fs.statSync(path.resolve(`${componentDir}/${name}`)).isDirectory()) {
    prev[name] = `${componentDir}/${name}/index.js`;
  }
  return prev;
}, {});

const themecomponentDir = 'src/themeComponents';
const tcModuleNames = fs.readdirSync(path.resolve(themecomponentDir));

const tcModuleMap = tcModuleNames.reduce((prev, name) => {
  if (fs.statSync(path.resolve(`${themecomponentDir}/${name}`)).isDirectory()) {
    prev[name] = `${themecomponentDir}/${name}/index.js`;
  }
  return prev;
}, {});

const businesscomponentDir = 'src/businessComponents';
const bcModuleNames = fs.readdirSync(path.resolve(businesscomponentDir));

const bcModuleMap = bcModuleNames.reduce((prev, name) => {
  if (fs.statSync(path.resolve(`${businesscomponentDir}/${name}`)).isDirectory()) {
    prev[name] = `${businesscomponentDir}/${name}/index.js`;
  }
  return prev;
}, {});

export default {
  cModuleMap,
  tcModuleMap,
  bcModuleMap
};
