Commit 34bee68a authored by caimeng's avatar caimeng

修改环境配置,自动上传OSS

parent 98052e66
NODE_ENV=production NODE_ENV=dr
VUE_APP_ENV=production VUE_APP_ENV=production
VUE_APP_SIGN_URL=https://sign.taimedias.com/dr/index.html VUE_APP_SIGN_URL=https://sign.taimedias.com/dr/index.html
VUE_APP_API=https://drwater.dingrongxd.com VUE_APP_API=https://drwater.dingrongxd.com
NODE_ENV=production NODE_ENV=prod
VUE_APP_ENV=production VUE_APP_ENV=production
VUE_APP_SIGN_URL=https://sign.taimedias.com/index.html VUE_APP_SIGN_URL=https://sign.taimedias.com/index.html
VUE_APP_API=https://water.jqtianxia.com VUE_APP_API=https://water.jqtianxia.com
NODE_ENV=production NODE_ENV=staging
VUE_APP_ENV=test VUE_APP_ENV=test
VUE_APP_SIGN_URL=http://m.jqtianxia.cn/sign_agreement/index.html VUE_APP_SIGN_URL=http://m.jqtianxia.cn/sign_agreement/index.html
VUE_APP_API=http://47.99.245.36:8202 VUE_APP_API=http://47.99.245.36:8202
This diff is collapsed.
...@@ -7,11 +7,12 @@ ...@@ -7,11 +7,12 @@
"private": true, "private": true,
"scripts": { "scripts": {
"serve": "vue-cli-service serve", "serve": "vue-cli-service serve",
"build:test": "vue-cli-service build --mode test", "build:test": "vue-cli-service build --mode test && node ./upload_oss.js",
"build:dr": "vue-cli-service build --mode dr --modern", "build:dr": "vue-cli-service build --mode dr --modern",
"build:prod": "vue-cli-service build --mode production --modern" "build:prod": "vue-cli-service build --mode production --modern"
}, },
"dependencies": { "dependencies": {
"ali-oss": "^6.20.0",
"axios": "^0.21.1", "axios": "^0.21.1",
"element-ui": "^2.15.13", "element-ui": "^2.15.13",
"express": "^4.17.1", "express": "^4.17.1",
......
This diff is collapsed.
let fs = require("fs"); // node , fs 文件流控制
let path = require("path"); // node 什么方法忘了,路径方法
let OSS = require("ali-oss"); // oss 引入
const dirBasePath = path.join(process.cwd(), "/dist/1.0.0"); // 路径引导
const { COMPILE_ENV = "staging" } = process.env; // 获取环境变量,node版本失效,可饮用env作为判断,也可以手动执行修改
let bucket = "customer-vue-test"; // 对应oss文件,默认为预发环境
let accessKeyId = "LTAI5tAhrEnqLFtnWPwZbDue",
accessKeySecret = "z3S6J1yrc4JoGtkMJkb75oTUsCxdOD";
if (COMPILE_ENV === "prod") {
bucket = "customer-vue";
} else if (COMPILE_ENV === "dr") {
bucket = "mmyx-h5-gray";
accessKeyId = "";
accessKeySecret = "";
} else if (COMPILE_ENV === "staging") {
bucket = "customer-vue-test";
}
// oss 账号密码,地址
let client = new OSS({
region: "oss-cn-hangzhou",
bucket,
accessKeyId,
accessKeySecret,
});
// 上传的方法
// node 日志进度输入
async function put(file, filePath) {
try {
let r1 = await client.put(file, filePath);
console.log("当前进度: %j", r1);
} catch (e) {
console.error("上传文件报错", e);
}
}
// 遍历本地上传的目录文件夹
// node本地文件遍历,fs文档流控制
const fileList = [];
function listFile(dir) {
let arr = fs.readdirSync(dir);
arr.forEach(function(item) {
const o = {};
let fullPath = path.join(dir, item);
let stats = fs.statSync(fullPath);
if (stats.isDirectory()) {
listFile(fullPath);
} else {
const fileDir = fullPath.replace(`${dirBasePath}/`, "");
console.log(fileDir + "处理后的内容");
o.file = fileDir;
o.filePath = fullPath;
fileList.push(o);
}
});
return fileList;
}
listFile(dirBasePath).forEach(function(item) {
const { file, filePath } = item;
put(file, filePath);
});
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment