know-the-quran 0.1.0 → 0.1.1

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.
@@ -5,53 +5,108 @@ const path = require("path");
5
5
  const fs = require("fs");
6
6
  const https = require("https");
7
7
  const { spawn } = require("child_process");
8
+ const unzipper = require("unzipper");
8
9
 
9
10
  const PLATFORM = os.platform();
10
11
  const HOME = os.homedir();
11
12
  const APP_DIR = path.join(HOME, ".know-the-quran");
12
- const VERSION = "v1.0.0";
13
+ const ZIP_PATH = path.join(APP_DIR, "app.zip");
13
14
 
14
15
  let DOWNLOAD_URL;
15
- let EXECUTABLE;
16
+ let EXEC_PATH;
16
17
 
18
+ /**
19
+ * Map platform → zip + executable
20
+ */
17
21
  if (PLATFORM === "darwin") {
18
- DOWNLOAD_URL = `https://github.com/arbendev/know-the-quran/releases/download/${VERSION}/know-the-quran-mac.zip`;
19
- EXECUTABLE = "Know The Quran.app";
22
+ DOWNLOAD_URL = "https://knowthequran.com/npx/Know-The-Quran-1.0.0-mac.zip";
23
+ EXEC_PATH = path.join(
24
+ APP_DIR,
25
+ "Know The Qur'an.app",
26
+ "Contents",
27
+ "MacOS",
28
+ "Know The Qur'an",
29
+ );
20
30
  } else if (PLATFORM === "win32") {
21
- DOWNLOAD_URL = `https://github.com/arbendev/know-the-quran/releases/download/${VERSION}/know-the-quran-win.zip`;
22
- EXECUTABLE = "KnowTheQuran.exe";
31
+ DOWNLOAD_URL = "https://knowthequran.com/npx/Know-The-Quran-1.0.0-win.zip";
32
+ EXEC_PATH = path.join(APP_DIR, "Know The Qur'an.exe");
23
33
  } else {
24
- DOWNLOAD_URL = `https://github.com/arbendev/know-the-quran/releases/download/${VERSION}/know-the-quran-linux.zip`;
25
- EXECUTABLE = "know-the-quran";
26
- }
27
-
28
- if (!fs.existsSync(APP_DIR)) {
29
- fs.mkdirSync(APP_DIR, { recursive: true });
34
+ DOWNLOAD_URL = "https://knowthequran.com/npx/know-the-quran-1.0.0.zip";
35
+ EXEC_PATH = path.join(APP_DIR, "know-the-quran");
30
36
  }
31
37
 
32
- const ZIP_PATH = path.join(APP_DIR, "app.zip");
33
- const EXEC_PATH = path.join(APP_DIR, EXECUTABLE);
38
+ /**
39
+ * Ensure app directory exists
40
+ */
41
+ fs.mkdirSync(APP_DIR, { recursive: true });
34
42
 
35
- function download(url, dest, cb) {
36
- const file = fs.createWriteStream(dest);
37
- https.get(url, (res) => {
38
- res.pipe(file);
39
- file.on("finish", () => file.close(cb));
43
+ /**
44
+ * Download helper
45
+ */
46
+ function download(url, dest) {
47
+ return new Promise((resolve, reject) => {
48
+ const file = fs.createWriteStream(dest);
49
+ https
50
+ .get(url, (res) => {
51
+ if (res.statusCode !== 200) {
52
+ reject(new Error(`Download failed (${res.statusCode})`));
53
+ return;
54
+ }
55
+ res.pipe(file);
56
+ file.on("finish", () => file.close(resolve));
57
+ })
58
+ .on("error", reject);
40
59
  });
41
60
  }
42
61
 
43
- function runApp() {
44
- spawn(EXEC_PATH, [], { stdio: "inherit", detached: true });
62
+ /**
63
+ * Unzip helper
64
+ */
65
+ function unzip(zipPath, dest) {
66
+ return fs
67
+ .createReadStream(zipPath)
68
+ .pipe(unzipper.Extract({ path: dest }))
69
+ .promise();
45
70
  }
46
71
 
47
- if (fs.existsSync(EXEC_PATH)) {
48
- runApp();
49
- } else {
50
- console.log("Downloading Know The Quran…");
72
+ /**
73
+ * Launch app
74
+ */
75
+ function runApp() {
76
+ console.log("Launching Know The Quran…");
51
77
 
52
- download(DOWNLOAD_URL, ZIP_PATH, () => {
53
- console.log("Downloaded. Extract manually for now.");
54
- console.log("ZIP location:", ZIP_PATH);
55
- console.log("Next step: add unzip logic.");
78
+ const child = spawn(EXEC_PATH, [], {
79
+ detached: true,
80
+ stdio: "ignore",
56
81
  });
82
+
83
+ child.unref();
57
84
  }
85
+
86
+ /**
87
+ * Main flow
88
+ */
89
+ (async () => {
90
+ if (fs.existsSync(EXEC_PATH)) {
91
+ runApp();
92
+ return;
93
+ }
94
+
95
+ console.log("Downloading Know The Qur'an…");
96
+ await download(DOWNLOAD_URL, ZIP_PATH);
97
+
98
+ console.log("Extracting…");
99
+ await unzip(ZIP_PATH, APP_DIR);
100
+
101
+ fs.unlinkSync(ZIP_PATH);
102
+
103
+ if (PLATFORM !== "win32") {
104
+ fs.chmodSync(EXEC_PATH, 0o755);
105
+ }
106
+
107
+ runApp();
108
+ })().catch((err) => {
109
+ console.error("Failed to launch Know The Qur'an:");
110
+ console.error(err.message);
111
+ process.exit(1);
112
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "know-the-quran",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Launch Know The Quran desktop app",
5
5
  "bin": {
6
6
  "know-the-quran": "./bin/know-the-quran.js"