Commit a25f17a2 authored by hewenhao's avatar hewenhao

feat: production config

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