@assafdori/torah-cli 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/run.js +16 -0
- package/install.js +110 -0
- package/package.json +25 -0
package/bin/run.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { execFileSync } = require("child_process");
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const os = require("os");
|
|
5
|
+
|
|
6
|
+
const ext = os.platform() === "win32" ? ".exe" : "";
|
|
7
|
+
const binary = path.join(__dirname, `torah${ext}`);
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
execFileSync(binary, process.argv.slice(2), { stdio: "inherit" });
|
|
11
|
+
} catch (err) {
|
|
12
|
+
if (err.status !== null) {
|
|
13
|
+
process.exit(err.status);
|
|
14
|
+
}
|
|
15
|
+
throw err;
|
|
16
|
+
}
|
package/install.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
const { execSync } = require("child_process");
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const https = require("https");
|
|
5
|
+
const os = require("os");
|
|
6
|
+
|
|
7
|
+
const REPO = "assafdori/torah-cli";
|
|
8
|
+
const BINARY = "torah";
|
|
9
|
+
|
|
10
|
+
function getPlatform() {
|
|
11
|
+
const platform = os.platform();
|
|
12
|
+
const arch = os.arch();
|
|
13
|
+
|
|
14
|
+
const targets = {
|
|
15
|
+
"darwin-x64": "x86_64-apple-darwin",
|
|
16
|
+
"darwin-arm64": "aarch64-apple-darwin",
|
|
17
|
+
"linux-x64": "x86_64-unknown-linux-gnu",
|
|
18
|
+
"linux-arm64": "aarch64-unknown-linux-gnu",
|
|
19
|
+
"win32-x64": "x86_64-pc-windows-msvc",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const key = `${platform}-${arch}`;
|
|
23
|
+
const target = targets[key];
|
|
24
|
+
|
|
25
|
+
if (!target) {
|
|
26
|
+
console.error(`Unsupported platform: ${key}`);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return { target, isWindows: platform === "win32" };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function getVersion() {
|
|
34
|
+
const pkg = require(path.join(__dirname, "package.json"));
|
|
35
|
+
return pkg.version;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function download(url, dest) {
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
40
|
+
const follow = (url) => {
|
|
41
|
+
https.get(url, { headers: { "User-Agent": "torah-cli-npm" } }, (res) => {
|
|
42
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
43
|
+
follow(res.headers.location);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (res.statusCode !== 200) {
|
|
47
|
+
reject(new Error(`Download failed: HTTP ${res.statusCode}`));
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const total = parseInt(res.headers["content-length"], 10) || 0;
|
|
52
|
+
let downloaded = 0;
|
|
53
|
+
const file = fs.createWriteStream(dest);
|
|
54
|
+
|
|
55
|
+
res.on("data", (chunk) => {
|
|
56
|
+
downloaded += chunk.length;
|
|
57
|
+
if (total > 0) {
|
|
58
|
+
const pct = Math.round((downloaded / total) * 100);
|
|
59
|
+
const mb = (downloaded / 1024 / 1024).toFixed(1);
|
|
60
|
+
const totalMb = (total / 1024 / 1024).toFixed(1);
|
|
61
|
+
const barLen = 24;
|
|
62
|
+
const filled = Math.round((downloaded / total) * barLen);
|
|
63
|
+
const bar = "\u2588".repeat(filled) + "\u2591".repeat(barLen - filled);
|
|
64
|
+
process.stderr.write(`\r [${bar}] ${mb} / ${totalMb} MB ${pct}%`);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
res.pipe(file);
|
|
69
|
+
file.on("close", () => {
|
|
70
|
+
if (total > 0) process.stderr.write("\n");
|
|
71
|
+
resolve();
|
|
72
|
+
});
|
|
73
|
+
file.on("error", reject);
|
|
74
|
+
}).on("error", reject);
|
|
75
|
+
};
|
|
76
|
+
follow(url);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function main() {
|
|
81
|
+
const { target, isWindows } = getPlatform();
|
|
82
|
+
const version = getVersion();
|
|
83
|
+
const ext = isWindows ? "zip" : "tar.gz";
|
|
84
|
+
const url = `https://github.com/${REPO}/releases/download/v${version}/${BINARY}-${target}.${ext}`;
|
|
85
|
+
|
|
86
|
+
console.log(`\n Installing torah-cli v${version} for ${target}...\n`);
|
|
87
|
+
|
|
88
|
+
const binDir = path.join(__dirname, "bin");
|
|
89
|
+
fs.mkdirSync(binDir, { recursive: true });
|
|
90
|
+
|
|
91
|
+
const archivePath = path.join(binDir, `torah.${ext}`);
|
|
92
|
+
await download(url, archivePath);
|
|
93
|
+
|
|
94
|
+
console.log(" Extracting...");
|
|
95
|
+
|
|
96
|
+
if (isWindows) {
|
|
97
|
+
execSync(`tar -xf "${archivePath}" -C "${binDir}"`, { stdio: "pipe" });
|
|
98
|
+
} else {
|
|
99
|
+
execSync(`tar xzf "${archivePath}" -C "${binDir}"`, { stdio: "pipe" });
|
|
100
|
+
fs.chmodSync(path.join(binDir, BINARY), 0o755);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
fs.unlinkSync(archivePath);
|
|
104
|
+
console.log(" torah-cli installed successfully! Run: torah\n");
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
main().catch((err) => {
|
|
108
|
+
console.error("\n Installation failed:", err.message);
|
|
109
|
+
process.exit(1);
|
|
110
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@assafdori/torah-cli",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "A Torah TUI for terminal reading",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/assafdori/torah-cli"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"torah": "bin/run.js"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"postinstall": "node install.js"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"torah",
|
|
18
|
+
"tanakh",
|
|
19
|
+
"cli",
|
|
20
|
+
"tui",
|
|
21
|
+
"judaism",
|
|
22
|
+
"text"
|
|
23
|
+
],
|
|
24
|
+
"author": "whoisyurii"
|
|
25
|
+
}
|