@crafter/hoja 0.0.0-stage → 0.2.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 (3) hide show
  1. package/README.md +21 -2
  2. package/bin/hoja.mjs +110 -0
  3. package/package.json +45 -4
package/README.md CHANGED
@@ -1,3 +1,22 @@
1
- # Temporary Holding Version
1
+ # @crafter/hoja
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ npm/Bun launcher for [hoja](https://hoja.crafter.run), the theme-aware terminal PDF, paper, and LaTeX reader for Ghostty and Rex.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ bun add -g @crafter/hoja
9
+ # or
10
+ npm install -g @crafter/hoja
11
+ ```
12
+
13
+ On first run, `hoja` downloads and SHA-256 verifies the prebuilt native Rust binary for your platform (macOS arm64/x64 or Linux x64/arm64) from [GitHub Releases](https://github.com/crafter-station/hoja/releases).
14
+
15
+ Then initialize PDFium and open any PDF:
16
+
17
+ ```sh
18
+ hoja setup
19
+ hoja document.pdf
20
+ ```
21
+
22
+ See the [main repository](https://github.com/crafter-station/hoja) and [hoja.crafter.run](https://hoja.crafter.run) for full documentation.
package/bin/hoja.mjs ADDED
@@ -0,0 +1,110 @@
1
+ #!/usr/bin/env node
2
+ import { createHash } from "node:crypto";
3
+ import { execFileSync, spawnSync } from "node:child_process";
4
+ import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
5
+ import { homedir, platform, arch } from "node:os";
6
+ import { dirname, join } from "node:path";
7
+ import { fileURLToPath } from "node:url";
8
+
9
+ const REPO = "crafter-station/hoja";
10
+ const PKG_PATH = join(dirname(fileURLToPath(import.meta.url)), "..", "package.json");
11
+ const VERSION = JSON.parse(readFileSync(PKG_PATH, "utf8")).version;
12
+ const TAG = `v${VERSION}`;
13
+
14
+ function resolveTarget() {
15
+ const osMap = {
16
+ darwin: "apple-darwin",
17
+ linux: "unknown-linux-gnu",
18
+ };
19
+ const archMap = {
20
+ arm64: "aarch64",
21
+ x64: "x86_64",
22
+ };
23
+ const osPart = osMap[platform()];
24
+ const archPart = archMap[arch()];
25
+ if (!osPart || !archPart) {
26
+ console.error(`@crafter/hoja: unsupported platform ${platform()}-${arch()}`);
27
+ process.exit(1);
28
+ }
29
+ return `${archPart}-${osPart}`;
30
+ }
31
+
32
+ function cacheDir() {
33
+ if (platform() === "darwin") {
34
+ return join(homedir(), "Library", "Caches", "hoja", "bin", TAG);
35
+ }
36
+ const xdg = process.env.XDG_CACHE_HOME || join(homedir(), ".cache");
37
+ return join(xdg, "hoja", "bin", TAG);
38
+ }
39
+
40
+ async function fetchBuffer(url) {
41
+ const res = await fetch(url, {
42
+ headers: { "User-Agent": `hoja-npm/${VERSION}` },
43
+ redirect: "follow",
44
+ });
45
+ if (!res.ok) {
46
+ throw new Error(`HTTP ${res.status} downloading ${url}`);
47
+ }
48
+ return Buffer.from(await res.arrayBuffer());
49
+ }
50
+
51
+ async function ensureBinary() {
52
+ const target = resolveTarget();
53
+ const dir = cacheDir();
54
+ const binPath = join(dir, "hoja");
55
+ if (existsSync(binPath)) {
56
+ return binPath;
57
+ }
58
+
59
+ mkdirSync(dir, { recursive: true });
60
+ const asset = `hoja-${TAG}-${target}.tar.gz`;
61
+ const base = `https://github.com/${REPO}/releases/download/${TAG}`;
62
+
63
+ process.stderr.write(`@crafter/hoja: downloading hoja ${TAG} (${target})...\n`);
64
+ const [tarBytes, checksumsBuf] = await Promise.all([
65
+ fetchBuffer(`${base}/${asset}`),
66
+ fetchBuffer(`${base}/checksums.txt`),
67
+ ]);
68
+
69
+ const checksums = checksumsBuf.toString("utf8");
70
+ const expectedLine = checksums
71
+ .split(/\r?\n/)
72
+ .map((l) => l.trim().split(/\s+/))
73
+ .find((parts) => parts.length >= 2 && parts[1] === asset);
74
+
75
+ if (!expectedLine) {
76
+ throw new Error(`checksum not found for ${asset}`);
77
+ }
78
+
79
+ const actual = createHash("sha256").update(tarBytes).digest("hex");
80
+ if (actual !== expectedLine[0]) {
81
+ throw new Error(`SHA-256 mismatch for ${asset}`);
82
+ }
83
+
84
+ const tmpDir = join(dir, `.extract-${process.pid}`);
85
+ mkdirSync(tmpDir, { recursive: true });
86
+ try {
87
+ const tgzPath = join(tmpDir, asset);
88
+ writeFileSync(tgzPath, tarBytes);
89
+ execFileSync("tar", ["-xzf", tgzPath, "-C", tmpDir], { stdio: "inherit" });
90
+ const extracted = join(tmpDir, "hoja");
91
+ chmodSync(extracted, 0o755);
92
+ renameSync(extracted, binPath);
93
+ } finally {
94
+ rmSync(tmpDir, { recursive: true, force: true });
95
+ }
96
+
97
+ return binPath;
98
+ }
99
+
100
+ const bin = await ensureBinary().catch((err) => {
101
+ console.error(`@crafter/hoja: ${err.message}`);
102
+ process.exit(1);
103
+ });
104
+
105
+ const result = spawnSync(bin, process.argv.slice(2), { stdio: "inherit" });
106
+ if (result.error) {
107
+ console.error(`@crafter/hoja: failed to launch ${bin}: ${result.error.message}`);
108
+ process.exit(1);
109
+ }
110
+ process.exit(result.status ?? 0);
package/package.json CHANGED
@@ -1,6 +1,47 @@
1
1
  {
2
2
  "name": "@crafter/hoja",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "Theme-aware terminal PDF, paper, and LaTeX reader for Ghostty and Rex",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "bin": {
8
+ "hoja": "bin/hoja.mjs"
9
+ },
10
+ "files": [
11
+ "bin/",
12
+ "README.md"
13
+ ],
14
+ "keywords": [
15
+ "pdf",
16
+ "latex",
17
+ "terminal",
18
+ "kitty",
19
+ "ghostty",
20
+ "rex",
21
+ "arxiv",
22
+ "cli"
23
+ ],
24
+ "homepage": "https://hoja.crafter.run",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/crafter-station/hoja.git",
28
+ "directory": "npm"
29
+ },
30
+ "bugs": {
31
+ "url": "https://github.com/crafter-station/hoja/issues"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "os": [
37
+ "darwin",
38
+ "linux"
39
+ ],
40
+ "cpu": [
41
+ "arm64",
42
+ "x64"
43
+ ],
44
+ "engines": {
45
+ "node": ">=18"
46
+ }
47
+ }