You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
shop-pc/env.config.js

45 lines
1.2 KiB

3 years ago
/*
* @Author: ch
* @Date: 2022-05-05 14:40:00
* @LastEditors: ch
* @LastEditTime: 2022-05-27 18:25:28
3 years ago
* @Description: 根据git分支生成对应环境的环境变量
* 开发时如果环境变量换了可以不用重启服务直接运行node env.config.js即可
3 years ago
*/
const fs = require('fs');
const path = require('path');
const getRepoInfo = require('git-repo-info');
const envConfig = {
dev : {
base_url: 'https://k8s-horse-gateway.mashibing.cn',
imUrl : 'wss://k8s-horse-gateway.mashibing.cn'
3 years ago
},
test : {
base_url: 'https://k8s-horse-gateway.mashibing.cn',
imUrl : 'wss://k8s-horse-gateway.mashibing.cn'
3 years ago
},
beta : {
base_url: 'https://you-gateway.mashibing.com',
imUrl : 'wss://you-gateway.mashibing.com'
3 years ago
},
prod : {
base_url: 'https://you-gateway.mashibing.com',
imUrl : 'wss://you-gateway.mashibing.com'
3 years ago
}
}
const branch = getRepoInfo().branch; // 调用获取git信息
let curEnvConfig = null;
const argv = global.process.argv;
for(key in envConfig){
if(argv.includes(`--ENV:${key}`)){
curEnvConfig = envConfig[key];
break;
}
}
if(!curEnvConfig){
curEnvConfig = envConfig.dev;
3 years ago
}
fs.writeFileSync(`${path.resolve(__dirname, './plugins/config')}/env.js`,
`const ENV = ${JSON.stringify(curEnvConfig)}; export default ENV;`);