2021-10-02 06:43:31 +00:00
|
|
|
console.log("Downloading dist");
|
|
|
|
const https = require("https");
|
|
|
|
const tar = require("tar");
|
|
|
|
|
|
|
|
const packageJSON = require("../package.json");
|
|
|
|
const fs = require("fs");
|
|
|
|
const version = packageJSON.version;
|
|
|
|
|
|
|
|
const filename = "dist.tar.gz";
|
|
|
|
|
|
|
|
const url = `https://github.com/louislam/uptime-kuma/releases/download/${version}/${filename}`;
|
|
|
|
download(url);
|
|
|
|
|
2021-11-10 05:24:31 +00:00
|
|
|
/**
|
|
|
|
* Downloads the latest version of the dist from a GitHub release.
|
|
|
|
* @param {string} url The URL to download from.
|
2023-08-11 07:46:41 +00:00
|
|
|
* @returns {void}
|
2021-11-10 05:24:31 +00:00
|
|
|
*
|
|
|
|
* Generated by Trelent
|
|
|
|
*/
|
2021-10-02 06:43:31 +00:00
|
|
|
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")) {
|
2024-10-05 14:27:17 +00:00
|
|
|
fs.rmSync("./dist-backup", {
|
|
|
|
recursive: true,
|
|
|
|
force: true,
|
2021-10-02 06:43:31 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fs.renameSync("./dist", "./dist-backup");
|
|
|
|
}
|
|
|
|
|
|
|
|
const tarStream = tar.x({
|
|
|
|
cwd: "./",
|
|
|
|
});
|
|
|
|
|
|
|
|
tarStream.on("close", () => {
|
2021-10-25 04:29:40 +00:00
|
|
|
if (fs.existsSync("./dist-backup")) {
|
2024-10-05 14:27:17 +00:00
|
|
|
fs.rmSync("./dist-backup", {
|
|
|
|
recursive: true,
|
|
|
|
force: true,
|
2021-10-25 04:29:40 +00:00
|
|
|
});
|
|
|
|
}
|
2021-10-02 06:43:31 +00:00
|
|
|
console.log("Done");
|
2023-02-20 15:15:49 +00:00
|
|
|
process.exit(0);
|
2021-10-02 06:43:31 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
tarStream.on("error", () => {
|
|
|
|
if (fs.existsSync("./dist-backup")) {
|
|
|
|
fs.renameSync("./dist-backup", "./dist");
|
|
|
|
}
|
2021-10-25 04:29:40 +00:00
|
|
|
console.error("Error from tarStream");
|
2021-10-02 06:43:31 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
response.pipe(tarStream);
|
|
|
|
} else if (response.statusCode === 302) {
|
|
|
|
download(response.headers.location);
|
|
|
|
} else {
|
|
|
|
console.log("dist not found");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|