const fs = require('fs')
const path = require('path')
const adminPath = 'apps'
// 获取 admins 目录下的后台管理系统文件名并指定公共文件目录命名
function resolve (dir) {
  return path.resolve(__dirname, '../', dir)
}
const files = fs.readdirSync(resolve(adminPath))
function copyToApps(dir, isFolder) {
  let r = []
    const cpFiles = fs.readdirSync(resolve(dir))
    if (!isFolder) {
      files.map(app => {
        console.log(`${adminPath}/${app}/${dir.replace('.tmp/', '').replace('im/', '')}`)
        r.push({
          from: resolve(dir),
          to: resolve(`${adminPath}/${app}/${dir.replace('.tmp/', '')}`)
        })
      })
    } else {
      const cpFiles = fs.readdirSync(resolve(dir))
      files.map(app => {
        cpFiles.forEach(item => {
          r.push({
            from: resolve(`${dir}/${item}`),
            to: resolve(`${adminPath}/${app}/${item.replace('.tmp/', '')}`)
          })
        })
      })
    }
    console.log(r)
  return r
}

module.exports = copyToApps