Commit ae47e7cd authored by 郝聪敏's avatar 郝聪敏

feature: 区分测试和线上环境

parent cea40be8
const COS = require('cos-nodejs-sdk-v5');
const path = require('path');
const fs = require('fs');
const prefix = process.env.NODE_ENV === 'production' ? 'qb' : 'qb-test';
const cdnPrefix = `https://misc.lkbang.net/${prefix}/`;
class upload2Cos {
filesPath = [];
instance = null;
constructor() {
this.filesPath = [];
this.instance = new COS({
SecretId: 'AKIDVlxtVqOK9i0wc0m0e7C5saATZnl2xvUx',
SecretKey: 'NWQ3VlmWeFtIQHrDI6F9oCheMq41lGVV'
});
}
getFilesPath() {
this._readFileList(path.resolve(__dirname, './public'), this.filesPath);
}
upload() {
this.getFilesPath();
const filesList = this.filesPath.map(filepath => {
return {
Bucket: 'misc-1258270469',
Region: 'ap-beijing',
Key: `${prefix}${filepath.split('quantum-blocks-h5')[1]}`,
FilePath: filepath
}
});
this.instance.uploadFiles({
files: filesList,
SliceSize: 1024 * 1024,
onProgress: function (info) {
var percent = parseInt(info.percent * 10000) / 100;
var speed = parseInt(info.speed / 1024 / 1024 * 100) / 100;
console.log('进度:' + percent + '%; 速度:' + speed + 'Mb/s;');
},
onFileFinish: function (err, data, options) {
console.log(options.Key + '上传' + (err ? '失败' : '完成'));
},
}, function (err, data) {
console.log(err || data);
});
}
_isValid (path) {
const format = ['.ico', '.html', '.ttf', '.woff', '.woff2'];
return !format.some(v => path.endsWith(v))
}
_readFileList(dir, filesPath = []) {
  const files = fs.readdirSync(dir);
  files.forEach((item, index) => {
    var fullPath = path.join(dir, item);
    const stat = fs.statSync(fullPath);
    if (stat.isDirectory()) {  
      this._readFileList(path.join(dir, item), filesPath);
    } else if(this._isValid(fullPath)) {       
      filesPath.push(fullPath);          
    }   
  });
  return filesPath;
}
}
module.exports = {
upload2Cos,
cdnPrefix
};
\ No newline at end of file
'use strict';
const path = require('path');
const fs = require('fs');
const SentryPlugin = require("webpack-sentry-plugin");
const resolve = filepath => path.resolve(__dirname, filepath);
const SentryConfig = require("./app/web/.sentryclirc.ts");
const { upload2Cos, cdnPrefix } = require("./upload-cos.js");
module.exports = {
entry: {
// 'login': 'app/web/page/login/index.vue',
// 'editor': 'app/web/page/editor/index.ts',
'activity': 'app/web/page/activity/index.ts',
},
resolve: {
......@@ -20,10 +16,7 @@ module.exports = {
'@asset': resolve('app/web/asset'),
'@framework': resolve('app/web/framework'),
'@component': resolve('app/web/component'),
'@store': resolve('app/web/page/store'),
// '@router': resolve('app/web/page/admin/home/router'),
// '@view': resolve('app/web/page/admin/home/view'),
// '@editor': resolve('app/web/page/editor')
'@store': resolve('app/web/page/store')
}
},
nodeExternals: {
......@@ -162,66 +155,16 @@ module.exports = {
}
},
externals: {
// 'vue': 'Vue',
// 'vue-router': 'VueRouter',
// 'vuex': 'Vuex',
'axios': 'axios',
'sa-sdk-javascript': 'sensorsDataAnalytic201505',
'swiper': 'Swiper',
},
// mode: 'development',
devtool:'source-map',
cdn: 'https://misc.lkbang.net/qb/',
cdn: cdnPrefix,
done(){
const COS = require('cos-nodejs-sdk-v5');
const cos = new COS({
SecretId: 'AKIDVlxtVqOK9i0wc0m0e7C5saATZnl2xvUx',
SecretKey: 'NWQ3VlmWeFtIQHrDI6F9oCheMq41lGVV'
});
const filesPath = [];
function isValid (path) {
const format = ['.ico', '.html', '.ttf', '.woff', '.woff2'];
return !format.some(v => path.endsWith(v))
}
function readFileList(dir, filesPath = []) {
  const files = fs.readdirSync(dir);
  files.forEach((item, index) => {
    var fullPath = path.join(dir, item);
    const stat = fs.statSync(fullPath);
    if (stat.isDirectory()) {  
      readFileList(path.join(dir, item), filesPath); //递归读取文件
    } else if(isValid(fullPath)) {       
      filesPath.push(fullPath);          
    }   
  });
  return filesPath;
}
readFileList(path.resolve(__dirname, './public'), filesPath);
const filesList = filesPath.map(filepath => {
const publicPath = filepath.split('public')[1];
const Key = `qb/public${publicPath}`;
console.log('filepath', filepath, Key);
return {
Bucket: 'misc-1258270469',
Region: 'ap-beijing',
Key,
FilePath: filepath
}
});
cos.uploadFiles({
files: filesList,
SliceSize: 1024 * 1024,
onProgress: function (info) {
var percent = parseInt(info.percent * 10000) / 100;
var speed = parseInt(info.speed / 1024 / 1024 * 100) / 100;
console.log('进度:' + percent + '%; 速度:' + speed + 'Mb/s;');
},
onFileFinish: function (err, data, options) {
console.log(options.Key + '上传' + (err ? '失败' : '完成'));
},
}, function (err, data) {
console.log(err || data);
});
const instance = new upload2Cos();
instance.upload();
},
customize(webpackConfig){
// 此外 webpackConfig 为原生生成的 webpack config,可以进行自定义处理
......
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