summaryrefslogtreecommitdiffstats
path: root/extra/download-dist.js
diff options
context:
space:
mode:
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");
+ }
+ });
+}