// 拆分语言配置文件
const fs = require('fs')
const path = require('path')
const lang = "en"
const model = require(`./src/static/lang/${lang}.js`)
const splitModelDir = `./src/static/lang/${lang}/`
if (!fs.existsSync(splitModelDir)) {
  fs.mkdirSync(splitModelDir)
}
let mainJsContent = "export default{ \n"
const importArr = []
for(const key in model) {
  console.log("拆分：" + key);
  const value = model[key]
  const filePath = path.resolve(splitModelDir, key + ".js")
  fs.writeFileSync(filePath, `export default ${JSON.stringify(value, null, 2)}`)
  mainJsContent += key + ",\n"
  importArr.push(`import ${key} from './${lang}/${key}.js'`)
}
mainJsContent += "}"
importArr.push(mainJsContent)
fs.writeFileSync(`src/static/lang/${lang}.js`,  importArr.join("\n"))
console.log("done!")
