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

48 lines
946 B

/*
* @Author: ch
* @Date: 2022-05-05 14:40:00
* @LastEditors: ch
* @LastEditTime: 2022-05-05 15:40:42
* @Description: 根据git分支生成对应环境的环境变量
*/
const fs = require('fs');
const path = require('path');
const getRepoInfo = require('git-repo-info');
const envConfig = {
dev : {
base_url: 'dev'
},
test : {
base_url: 'xxx'
},
reslese : {
base_url: 'xxx'
},
prod : {
}
}
const branch = getRepoInfo().branch; // 调用获取git信息
const argv = global.process.argv;
let curEnvConfig = {};
switch (branch){
case 'msb_test':
curEnvConfig = envConfig.test;
break;
case 'msb_beta':
curEnvConfig = envConfig.release;
break;
case 'msb_prod':
curEnvConfig = envConfig.prod;
break;
default:
curEnvConfig = envConfig.dev;
break;
}
let codeStr = `const ENV = ${JSON.stringify(curEnvConfig)}; export default ENV;`;
fs.writeFileSync(`${path.resolve(__dirname, './plugins')}/env.js`, codeStr);