52 lines
1.7 KiB
JavaScript
52 lines
1.7 KiB
JavaScript
const os = require("os");
|
|
|
|
const simpleGit = require("simple-git");
|
|
const GIT = simpleGit("./");
|
|
const fs = require("fs");
|
|
const { join } = require("path");
|
|
const packageFile = JSON.parse(fs.readFileSync("./package.json"));
|
|
const config = JSON.parse(fs.readFileSync(join(os.homedir(), ".cos.json")));
|
|
const domain = "//a.ebus.vip/";
|
|
const COS = require("cos-nodejs-sdk-v5");
|
|
const client = new COS({
|
|
SecretId: config.id,
|
|
SecretKey: config.key,
|
|
});
|
|
function send(dir, output) {
|
|
let files = fs.readdirSync(dir);
|
|
files.forEach((item) => {
|
|
if (item.indexOf(".") === 0 || item.indexOf(".html") > -1) {
|
|
return;
|
|
}
|
|
let fpath = join(dir, item);
|
|
let stat = fs.statSync(fpath);
|
|
if (stat.isDirectory()) {
|
|
send(fpath, join(output, item));
|
|
}
|
|
if (stat.isFile()) {
|
|
let target = join(output, item).replace(/\\/gi, "/");
|
|
client.putObject(
|
|
{
|
|
Bucket: config.bucket /* 必须 */,
|
|
Region: config.region /* 必须 */,
|
|
Key: target /* 必须 */,
|
|
StorageClass: "STANDARD",
|
|
Body: fs.createReadStream(fpath), // 上传文件对象
|
|
},
|
|
(err, data) => {
|
|
if (err) {
|
|
return console.log(err, data);
|
|
}
|
|
console.log(domain + target);
|
|
}
|
|
);
|
|
// client.putObject(join(output, item), fpath)
|
|
}
|
|
});
|
|
}
|
|
GIT.branchLocal((err, branch) => {
|
|
let name = packageFile.name,
|
|
version = branch.current;
|
|
send(join(__dirname, "../dist"), `${name}/${version}`);
|
|
});
|