addseed-ux-admin/devops/deploy.js

36 lines
1019 B
JavaScript

/* eslint-disable */
var aliOss = require('ali-oss');
var fs = require('fs');
var path = require('path');
var accessKeySecret = require('./config').ossSecret;
const adseedOssManager = new aliOss({
region: 'oss-cn-shanghai',
accessKeyId: 'LTAI5tEday8PJNaMTz5mp8g4',
accessKeySecret,
bucket: 'adseed-admin-ux',
});
const distDir = path.resolve(__dirname, '../dist');
const distFiles = traverseFiles(distDir, []);
console.log('start deploying');
Promise.all(distFiles.map((fileName) => adseedOssManager.put(fileName.slice(distDir.length), fileName)))
.then(() => console.log('deployment succeed'))
.catch((e) => console.log('deployment failed:', e));
function traverseFiles(dir, distFiles) {
const dirents = fs.readdirSync(dir, { withFileTypes: true });
for (const dirent of dirents) {
const res = `${dir}/${dirent.name}`;
const file = fs.statSync(res);
if (file.isDirectory()) {
traverseFiles(res, distFiles);
} else {
distFiles.push(res);
}
}
return distFiles;
}