/*
 * @Author: 莫靓仔
 * @description: node执行该文件，修改全局配置
 * @Date: 2021-09-02 09:40:29
 * @LastEditors: 莫靓仔
 * @LastEditTime: 2021-09-03 11:09:45
 */
let fs = require('fs')
let chalk = require('chalk')
let apiMap = {
    dev: 'https://apidev.sycdev.com',
    test: 'https://api.sycdev.com',
    pre: 'https://apipre.sycdev.com',
    prod: 'https://slmapi.shengyc.com',
    tx: 'https://apitx.shengyc.com',
    newDev: 'https://apidev-alpha.sycdev.com',
    newTest: 'https://api-alpha.sycdev.com'
}
let urlMap = {
    dev: 'https://slmdev.sycdev.com',
    test: 'https://slm.sycdev.com',
    pre: 'https://slmpre.sycdev.com',
    prod: 'https://slm.shengyc.com',
    tx: '',
    newDev: '',
    newTest: ''
}
let textMap = {
    test: '测试环境',
    dev: '开发环境',
    pre: '预发布环境',
    prod: '正式环境',
    newDev: '新开发环境',
    newTest: '新测试环境'
}
let domainMap = {
    test: 'sycdev.com',
    dev: 'sycdev.com',
    pre: 'sycdev.com',
    prod: 'shengyc.com',
    newDev: 'sycdev.com',
    newTest: 'sycdev.com'
}
function changeEnv() {
    let env_ = process.argv[2]
    let res = {
        apiUrl: apiMap[env_],
        baseUrl: urlMap[env_],
        domain: domainMap[env_],
        name: textMap[env_]
    }
    fs.writeFile('./config/config.json', JSON.stringify(res), function (err) {
        if (err) {
            throw err
        }
        console.log(chalk.green(`成功切换到【${textMap[env_]}】！`))
    })
}
changeEnv()
