x
This commit is contained in:
80
vue/release/cos.js
Normal file
80
vue/release/cos.js
Normal file
@@ -0,0 +1,80 @@
|
||||
const os = require("os");
|
||||
|
||||
const simpleGit = require("simple-git");
|
||||
const pako = require("pako");
|
||||
const GIT = simpleGit("./");
|
||||
const CWD = process.cwd();
|
||||
|
||||
const fs = require("fs");
|
||||
const { join, dirname } = require("path");
|
||||
const packageFile = JSON.parse(fs.readFileSync("./package.json"));
|
||||
const config = JSON.parse(fs.readFileSync(join(os.homedir(), ".cos.json")));
|
||||
const domain = "//a.zeto.me/";
|
||||
const COS = require("cos-nodejs-sdk-v5");
|
||||
function findRootDir(dir) {
|
||||
if (dir === "/") {
|
||||
return "/";
|
||||
}
|
||||
if (fs.existsSync(dir, "package.json")) {
|
||||
return dir;
|
||||
}
|
||||
return findRootDir(dirname(dir));
|
||||
}
|
||||
const ROOT = findRootDir(CWD);
|
||||
const DIST_DIR = join(ROOT, "dist");
|
||||
const LIB_DIR = join(ROOT, "public", "lib");
|
||||
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, "/");
|
||||
let cosTarget = {
|
||||
Bucket: config.bucket /* 必须 */,
|
||||
Region: config.region /* 必须 */,
|
||||
Key: target /* 必须 */,
|
||||
StorageClass: "STANDARD",
|
||||
};
|
||||
let isJS = target.indexOf(".js") > -1;
|
||||
if (isJS || target.indexOf(".css") > -1) {
|
||||
cosTarget.Headers = {
|
||||
"Content-Encoding": "gzip",
|
||||
"Content-Type": isJS
|
||||
? "application/javascript"
|
||||
: "text/css",
|
||||
};
|
||||
cosTarget.Body = Buffer.from(
|
||||
pako.gzip(fs.readFileSync(fpath, "utf8"))
|
||||
);
|
||||
} else {
|
||||
cosTarget.Body = fs.createReadStream(fpath);
|
||||
}
|
||||
client.putObject(cosTarget, (err, data) => {
|
||||
if (err) {
|
||||
return console.log(err, data);
|
||||
}
|
||||
console.log(domain + target);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
GIT.branchLocal((err, branch) => {
|
||||
let name = packageFile.name,
|
||||
version = branch.current;
|
||||
send(DIST_DIR, `${name}/${version}`);
|
||||
if (fs.existsSync(LIB_DIR)) {
|
||||
send(LIB_DIR, `${name}/${version}/lib`);
|
||||
}
|
||||
});
|
||||
51
vue/release/deploy.js
Normal file
51
vue/release/deploy.js
Normal file
@@ -0,0 +1,51 @@
|
||||
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}`);
|
||||
});
|
||||
Reference in New Issue
Block a user