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YACpB,EAAQ,QAER,YAAW,KACT,GAAG,UAAU,GAAG,EAAM,OAAO,WAAW,KAAK,OAAmB,GAAO,SAAU,GAC3E,EACF,QAAQ,IAAI,GAEZ,QAAQ,IAAI,MAAM,MAAM,OAAO,EAAM,OAAO,WAAW,KAAK,YAE9D,EAAQ,MACV,GAAC,GACA,IAAI,GACR,GACF,GAEL,CAGA,oBAAA,CAAqB,EAAS,GAC5B,GAAG,OAAO,GAAS,IACZ,IAEH,KAAK,OAAO,GACR,GACF,KAAK,gBAAgB,GAEzB,GAEJ,CAGA,MAAA,CAAO,GACL,QAAI,GAAG,WAAW,KAGZ,KAAK,OAAO,KAAK,QAAQ,KAC3B,GAAG,UAAU,IACN,QAFT,EAKJ,EAGF,OAAO,QAAU","file":"/npm/build-i8n-lang-config@1.0.6/lib/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/build-i8n-lang-config@1.0.6/lib/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/*\n * @Author: shoestrong\n * @Date: 2019-09-19 15:13:28\n * @Description: build-i8n-lang-config 为i18n而生\n * @LastEditTime: 2019-09-23 16:29:05\n * @LastEditors: shoestrong\n */\nconst fs = require('fs');\nconst path = require('path')\nconst inquirer = require('inquirer')\nconst chalk = require('chalk')\nconst ora = require('ora');\n\nconst {join} = path\n\n\nclass BuildI18nLangConfig {\n  constructor(props = {}) {\n    this.dirCache = {}\n    this.config = {\n      langs: ['zh_CN', 'zh_TW', 'en'],\n      defaultLangs: ['zh_CN', 'en'],\n      outPath: './lang',\n      entryPath: './local',\n      ...props\n    }\n    this._init()\n  }\n\n  setLangs(lang, isDefault) {\n    const lg = isDefault ? 'defaultLangs' : 'langs'\n    this.config[lg].push(lang)\n  }\n\n  setPath(path, isWhere) {\n    if (isWhere !== 'outPath' || isWhere !== 'entryPath') return;\n    this.config[isWhere] = path\n  }\n\n  _init() {\n    this._isHasDirectoryMkdir(this.config.entryPath, true)\n    this._filterLangs().then(res => {\n      this.defaultLangs = res\n      const spinner = ora('检测是否存在local文件夹和配置文件...')\n      spinner.start()\n      setTimeout(() => {\n        spinner.stop()\n        // 交互式提示\n        inquirer.prompt([{\n            type: 'checkbox',\n            choices: this.config.langs,\n            name: 'checked',\n            message: '选择要输出的语言，空格可多选',\n            default: this.config.defaultLangs\n          },\n          {\n            type: 'list',\n            choices: this._findSync(this.config.entryPath),\n            name: 'select',\n            message: '选择一个需要编译的文件',\n            default: false\n          }\n        ]).then(res => {\n          console.log(chalk.cyan('选择的输出语言是：' + res.checked))\n          console.log(chalk.cyan('选择的文件是：' + res.select))\n          let obj = {}\n          res.checked.length > 0 && res.checked.map(lang => {\n            obj[lang] = {}\n          })\n          this._writeJson(res.select, obj)\n        })\n      }, 1000)\n    }).catch(err => {\n      console.log(chalk.cyan(err))\n    })\n  }\n\n  _filterLangs() {\n    return new Promise((resolve, reject) => {\n      if (this.config.langs && this.config.langs.length === 0) {\n        reject('默认参数langs不能为空')\n      } else {\n        let newLangs = []\n        this.config.defaultLangs.forEach(dlang => {\n          this.config.langs.forEach(lang => {\n            if (dlang === lang) {\n              newLangs.push(lang)\n            }\n          })\n        })\n        resolve(newLangs)\n      }\n    })\n  }\n\n  _writeLocalFile(path) {\n    const defaultJson = `{\n      \"message\": {\n        \"zh_CN\": \"为i18n而生\",\n        \"en\": \"Born to i18n\",\n        \"zh_TW\": \"為i18n而生\"\n      }\n    }\n    `\n\n    fs.writeFile(`${path}/demo.json`, defaultJson, function (err) {\n      if (err) {\n        return new Error(err);\n      }\n      console.log(chalk.green(`生成${path}/demo.json`))\n    })\n  }\n\n  // 查找文件下文件名列表\n  _findSync(startPath) {\n    let result = [];\n    function finder(path) {\n      const files = fs.readdirSync(path);\n      files.forEach((val) => {\n        const fPath = join(path, val);\n        const stats = fs.statSync(fPath);\n        if (stats.isDirectory()) finder(fPath);\n        if (stats.isFile()) result.push(fPath);\n      });\n    }\n    finder(startPath);\n    return result;\n  }\n\n  // 写入数据\n  _writeJson(url, newObj) {\n    const _this = this;\n    const selectedName = url.split('/').pop().split('.').shift()\n    fs.readFile(url, 'utf8', (err, data) => {\n      if (err) {\n        return new Error(err);\n      }\n      let person = JSON.parse(data);\n      person = Object.assign({}, person);\n      // 是否存在文件夹\n      _this._isHasDirectoryMkdir(_this.config.outPath)\n\n      // 遍历文件反编译\n      Object.keys(newObj).map(o => {\n        Object.keys(person).map(r => {\n          if (!person[r][o]) {\n            console.log(chalk.italic.yellowBright(`::${o}格式不正确，请核对！不影响其他文件编译::`))\n            return false\n          }\n\n          newObj[o][r] = person[r][o];\n          const jsStr = 'export default ' + JSON.stringify(newObj[o], null, '\\t');\n\n          // 是否存在要编译后的en/zh_CN\n          _this._isHasDirectoryMkdir(`${_this.config.outPath}/${o}`)\n\n          const spinner = ora('生成文件中...')\n          spinner.start()\n          // 写入文件目录\n          setTimeout(() => {\n            fs.writeFile(`${_this.config.outPath}/${o}/${selectedName}.js`, jsStr, function (err) {\n              if (err) {\n                console.log(err)\n              } else {\n                console.log(chalk.green(`已生成 ${_this.config.outPath}/${o}/${selectedName}.js 完毕`))\n              }\n              spinner.stop()\n            })\n          }, 1000)\n        })\n      })\n    })\n  }\n  \n  // 是否已经创建过文件夹\n  _isHasDirectoryMkdir(outPath, is) {\n    fs.exists(outPath, exists => {\n      if (!exists) {\n        // fs.mkdirSync(outPath)\n        this._mkdir(outPath)\n        if (is) {\n          this._writeLocalFile(outPath)\n        }\n      }\n    });\n  }\n\n  // 递归创建文件夹\n  _mkdir(dirname) {\n    if (fs.existsSync(dirname)) {\n      return true;\n    } else {\n      if (this._mkdir(path.dirname(dirname))) {\n        fs.mkdirSync(dirname);\n        return true;\n      }\n    }\n  }\n}\n\nmodule.exports = BuildI18nLangConfig\n"]}