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.
- package/bin/know-the-quran.js +84 -29
- package/package.json +1 -1
package/bin/know-the-quran.js
CHANGED
|
@@ -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
|
|
13
|
+
const ZIP_PATH = path.join(APP_DIR, "app.zip");
|
|
13
14
|
|
|
14
15
|
let DOWNLOAD_URL;
|
|
15
|
-
let
|
|
16
|
+
let EXEC_PATH;
|
|
16
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Map platform → zip + executable
|
|
20
|
+
*/
|
|
17
21
|
if (PLATFORM === "darwin") {
|
|
18
|
-
DOWNLOAD_URL =
|
|
19
|
-
|
|
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 =
|
|
22
|
-
|
|
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 =
|
|
25
|
-
|
|
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
|
-
|
|
33
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Ensure app directory exists
|
|
40
|
+
*/
|
|
41
|
+
fs.mkdirSync(APP_DIR, { recursive: true });
|
|
34
42
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
44
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
72
|
+
/**
|
|
73
|
+
* Launch app
|
|
74
|
+
*/
|
|
75
|
+
function runApp() {
|
|
76
|
+
console.log("Launching Know The Quran…");
|
|
51
77
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
+
});
|