import generateDoc from './doc'

interface GenerateHandler {
  doc: (options: object)=>void,
}

async function generate(type: string, options: object) {
  const generateHandler:GenerateHandler = {
    doc: generateDoc, // 处理文档生成
  }
  if (Object.prototype.hasOwnProperty.call(generateHandler, type)) {
    await generateHandler[type as 'doc'](options)
  }
}

async function execGenerate(options: object) {
  // 理论上这里的options永远只会有一个key。之所以用Object.keys加forEach的组合，是为了应对key为任何值的情况，便于扩展
  Object.keys(options).forEach(async (type) => {
    await generate(type, options)
  })
}

export default execGenerate
