/* eslint-disable */
let xlsx = require('node-xlsx')
let fs = require('fs')
if (!fs.existsSync('./i18n.xlsx')) {
  console.log('缺少国际化文件\<i18n.xlsx\>,请检查')
  return
}
let sheets = xlsx.parse('./i18n.xlsx')
let xfsheets = xlsx.parse('./xfi18n.xlsx')
let varoptions = process.argv
let lang = varoptions[2].split('=')[1]
let keyCol = parseInt(varoptions[3].split('=')[1]) - 1
let valCol = parseInt(varoptions[4].split('=')[1]) - 1

async function init () {
  try {
    if (!fs.existsSync('./src/lang')) {
      fs.mkdirSync('./src/lang')
    } else {
    }
    let txt = '/* eslint-disable */\nexport default {\n'
    let xftxt = '/* eslint-disable */\nexport default {\n'
    sheets[0].data.forEach((v, i) => {
      if (!i) return
      if (!v[keyCol]) return
      txt += `\t\t'${v[keyCol]}': \`${v[valCol]}\`,\n`
    })
    xfsheets[0].data.forEach((v, i) => {
      if (!i) return
      if (!v[keyCol]) return
      xftxt += `\t\t'${v[keyCol]}': \`${v[valCol]}\`,\n`
    })
    txt = txt + '}'
    xftxt = xftxt + '}'
    fs.writeFileSync(`./src/lang/${lang}.js`, txt, {
      encoding: 'utf8'
    })
    fs.writeFileSync(`./src/lang/xf${lang}.js`, xftxt, {
      encoding: 'utf8'
    })
    console.log(`${lang}语言国际化配置生成成功`)
  } catch (e) {
    console.log(e)
  }
}

init()



