2021-10-02 02:43:31 -04:00
|
|
|
console.log("Downloading dist");
|
|
|
|
const https = require("https");
|
|
|
|
const tar = require("tar");
|
|
|
|
|
|
|
|
const packageJSON = require("../package.json");
|
|
|
|
const fs = require("fs");
|
2022-03-02 02:48:08 -05:00
|
|
|
const rmSync = require("./fs-rmSync.js");
|
2021-10-02 02:43:31 -04:00
|
|
|
const version = packageJSON.version;
|
|
|
|
|
|
|
|
const filename = "dist.tar.gz";
|
|
|
|
|
|
|
|
const url = `https://github.com/louislam/uptime-kuma/releases/download/${version}/${filename}`;
|
|
|
|
download(url);
|
|
|
|
|
|
|
|
function download(url) {
|
|
|
|
console.log(url);
|
|
|
|
|
|
|
|
https.get(url, (response) => {
|
|
|
|
if (response.statusCode === 200) {
|
|
|
|
console.log("Extracting dist...");
|
|
|
|
|
|
|
|
if (fs.existsSync("./dist")) {
|
|
|
|
|
|
|
|
if (fs.existsSync("./dist-backup")) {
|
2022-03-02 02:48:08 -05:00
|
|
|
rmSync("./dist-backup", {
|
2021-10-02 02:43:31 -04:00
|
|
|
recursive: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fs.renameSync("./dist", "./dist-backup");
|
|
|
|
}
|
|
|
|
|
|
|
|
const tarStream = tar.x({
|
|
|
|
cwd: "./",
|
|
|
|
});
|
|
|
|
|
|
|
|
tarStream.on("close", () => {
|
2021-10-25 00:29:40 -04:00
|
|
|
if (fs.existsSync("./dist-backup")) {
|
2022-03-02 02:48:08 -05:00
|
|
|
rmSync("./dist-backup", {
|
2021-10-25 00:29:40 -04:00
|
|
|
recursive: true
|
|
|
|
});
|
|
|
|
}
|
2021-10-02 02:43:31 -04:00
|
|
|
console.log("Done");
|
|
|
|
});
|
|
|
|
|
|
|
|
tarStream.on("error", () => {
|
|
|
|
if (fs.existsSync("./dist-backup")) {
|
|
|
|
fs.renameSync("./dist-backup", "./dist");
|
|
|
|
}
|
2021-10-25 00:29:40 -04:00
|
|
|
console.error("Error from tarStream");
|
2021-10-02 02:43:31 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
response.pipe(tarStream);
|
|
|
|
} else if (response.statusCode === 302) {
|
|
|
|
download(response.headers.location);
|
|
|
|
} else {
|
|
|
|
console.log("dist not found");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|