summaryrefslogtreecommitdiffstats
path: root/extra/download-dist.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel@debian.org>2024-11-26 09:28:28 +0100
committerDaniel Baumann <daniel@debian.org>2024-11-26 12:25:58 +0100
commita1882b67c41fe9901a0cd8059b5cc78a5beadec0 (patch)
tree2a24507c67aa99a15416707b2f7e645142230ed8 /extra/download-dist.js
parentInitial commit. (diff)
downloaduptime-kuma-upstream.tar.xz
uptime-kuma-upstream.zip
Adding upstream version 2.0.0~beta.0+dfsg.upstream/2.0.0_beta.0+dfsgupstream
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to 'extra/download-dist.js')
-rw-r--r--extra/download-dist.js69
1 files changed, 69 insertions, 0 deletions
diff --git a/extra/download-dist.js b/extra/download-dist.js
new file mode 100644
index 0000000..b339ac9
--- /dev/null
+++ b/extra/download-dist.js
@@ -0,0 +1,69 @@
+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);
+
+/**
+ * Downloads the latest version of the dist from a GitHub release.
+ * @param {string} url The URL to download from.
+ * @returns {void}
+ *
+ * Generated by Trelent
+ */
+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")) {
+ fs.rmSync("./dist-backup", {
+ recursive: true,
+ force: true,
+ });
+ }
+
+ fs.renameSync("./dist", "./dist-backup");
+ }
+
+ const tarStream = tar.x({
+ cwd: "./",
+ });
+
+ tarStream.on("close", () => {
+ if (fs.existsSync("./dist-backup")) {
+ fs.rmSync("./dist-backup", {
+ recursive: true,
+ force: true,
+ });
+ }
+ console.log("Done");
+ process.exit(0);
+ });
+
+ tarStream.on("error", () => {
+ if (fs.existsSync("./dist-backup")) {
+ fs.renameSync("./dist-backup", "./dist");
+ }
+ console.error("Error from tarStream");
+ });
+
+ response.pipe(tarStream);
+ } else if (response.statusCode === 302) {
+ download(response.headers.location);
+ } else {
+ console.log("dist not found");
+ }
+ });
+}