know-the-quran 0.1.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.
- package/bin/know-the-quran.js +57 -0
- package/package.json +13 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const os = require("os");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const https = require("https");
|
|
7
|
+
const { spawn } = require("child_process");
|
|
8
|
+
|
|
9
|
+
const PLATFORM = os.platform();
|
|
10
|
+
const HOME = os.homedir();
|
|
11
|
+
const APP_DIR = path.join(HOME, ".know-the-quran");
|
|
12
|
+
const VERSION = "v1.0.0";
|
|
13
|
+
|
|
14
|
+
let DOWNLOAD_URL;
|
|
15
|
+
let EXECUTABLE;
|
|
16
|
+
|
|
17
|
+
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";
|
|
20
|
+
} 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";
|
|
23
|
+
} 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 });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const ZIP_PATH = path.join(APP_DIR, "app.zip");
|
|
33
|
+
const EXEC_PATH = path.join(APP_DIR, EXECUTABLE);
|
|
34
|
+
|
|
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));
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function runApp() {
|
|
44
|
+
spawn(EXEC_PATH, [], { stdio: "inherit", detached: true });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (fs.existsSync(EXEC_PATH)) {
|
|
48
|
+
runApp();
|
|
49
|
+
} else {
|
|
50
|
+
console.log("Downloading Know The Quran…");
|
|
51
|
+
|
|
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.");
|
|
56
|
+
});
|
|
57
|
+
}
|
package/package.json
ADDED