Commit a25f17a2 authored by hewenhao's avatar hewenhao

feat: production config

parent 63dcf18a
......@@ -19,4 +19,5 @@ _staging
_production
_testing
/test.js
/product-config.js
/mock/static
\ No newline at end of file
module.exports = {
SecretId: 'AKIDmMhgQGAJbkjZ8bfpa5LNAoJfuvkJJuwh',
SecretKey: 'gCTs8h8btRo00mIcgYBZh16zd7YpvqRn',
Bucket: 'test-1257124244'
}
\ No newline at end of file
......@@ -7,28 +7,31 @@ const rawArgv = process.argv.slice(2);
const args = require("minimist")(rawArgv);
const getContentType = require('./utils');
const { f = 'reward-day', s = '\0_None' } = args;
const { f: folderName = 'reward-day', s: subFolder = '\0_None', env = 'development' } = args;
const isProduction = env === 'production';
const config = isProduction ? require('./product-config') : require('./config');
const cos = new COS({
SecretId: 'AKIDmMhgQGAJbkjZ8bfpa5LNAoJfuvkJJuwh',
SecretKey: 'gCTs8h8btRo00mIcgYBZh16zd7YpvqRn'
SecretId: config.SecretId,
SecretKey: config.SecretKey
});
const folderList = fastglob
.sync('**', { onlyFiles: false, deep: 1, cwd: `./${f}` })
.sync('**', { onlyFiles: false, deep: 1, cwd: `./${folderName}` })
.filter(item => {
return s === '*' || item === s
return subFolder === '*' || item === subFolder
});
if (folderList.length < 1) {
console.log('empty folder', f);
console.log('empty folder', folder);
}
const list = folderList
.map(item => {
const subFolderPath = `./${f}/${item}`
const subFolderPath = `./${folderName}/${item}`
const subList = fastglob.sync(`**`, { onlyFiles: true, deep: 1, cwd: subFolderPath })
const outputFileName = `./dist/${f}_${item}.js`;
const outputFileName = `./dist/${folderName}_${item}.js`;
return {
folderPath: subFolderPath,
outputFileName,
......@@ -71,7 +74,7 @@ function uploadFile ({ fileName, filePath, relativePath }) {
return new Promise((resolve, reject) => {
const dimensions = sizeOf(filePath);
cos.sliceUploadFile({
Bucket: 'test-1257124244', // Bucket 格式:test-1250000000
Bucket: config.Bucket,//'test-1257124244', // Bucket 格式:test-1250000000
Region: 'ap-chengdu',
Key: getFileName(relativePath, filePath),
ContentType: getContentType(filePath),
......@@ -86,7 +89,9 @@ function uploadFile ({ fileName, filePath, relativePath }) {
width: dimensions.width,
height: dimensions.height,
// originPath,
url: `https://${data.Location}`
url: isProduction ? `https://${data.Location}`
.replace(`${config.Bucket}.cos.ap-chengdu.myqcloud.com`, 'cdn.jkwljy.com')
: `https://${data.Location}`
})
}
});
......@@ -102,7 +107,7 @@ function getFileName(filePath, absolutPath) {
.update(fs.readFileSync(absolutPath, { encoding: 'binary' }))
.digest('base64')
.replace(/\.|\-|\=|\+|\//g, '_')
return `${str.substring(0, 4)}/${str.substring(4)}`
return `/${folderName}/${str}`;
}
// // 分片上传
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