68 lines
1.5 KiB
JavaScript
68 lines
1.5 KiB
JavaScript
const fs = require("fs");
|
|
const gulp = require("gulp");
|
|
const uglify = require("gulp-uglify");
|
|
const header = require("gulp-header");
|
|
const License = fs.readFileSync("LICENSE");
|
|
const chinese2unicode = require("gulp-chinese2unicode");
|
|
const ftpModule = require("ftp");
|
|
|
|
const ftpConfig = {
|
|
host: "115.28.154.128",
|
|
port: "21",
|
|
user: "vscode",
|
|
password: "MPzFE5tRThAMGnZf",
|
|
remotePath: "/",
|
|
connTimeout: 20000,
|
|
};
|
|
const ftp = new ftpModule();
|
|
|
|
// 构建
|
|
gulp.task("minify", async () => {
|
|
console.log("开始构建...");
|
|
gulp
|
|
.src("Pandora.min.js", {
|
|
//sourcemaps: true,
|
|
})
|
|
.pipe(uglify())
|
|
.pipe(chinese2unicode())
|
|
.pipe(header(`/*\n${License.toString("utf-8")}\n*/\n`))
|
|
.on("data", function () {
|
|
console.log("构建完成!");
|
|
})
|
|
.pipe(
|
|
gulp.dest("./", {
|
|
// sourcemaps: ".",
|
|
})
|
|
);
|
|
});
|
|
|
|
// 上传
|
|
const uploadFile = fileName => {
|
|
return new Promise((success, fail) => {
|
|
ftp.put(fileName, fileName, err => {
|
|
if (err) {
|
|
console.log(err);
|
|
fail(err);
|
|
} else {
|
|
success();
|
|
}
|
|
});
|
|
});
|
|
};
|
|
gulp.task("upload", async () => {
|
|
ftp.connect(ftpConfig);
|
|
ftp.on("ready", e => {
|
|
console.info("开始发布...");
|
|
const uploadList = [uploadFile("Pandora.min.js"), uploadFile("Pandora.min.js.map")];
|
|
|
|
Promise.all(uploadList)
|
|
.then(() => {
|
|
console.info("发布成功!");
|
|
ftp.end();
|
|
})
|
|
.catch(err => {
|
|
console.error(`发布失败!${err}`);
|
|
});
|
|
});
|
|
});
|