Skip to content

Commit d6c9a5a

Browse files
committed
fixes for wrapping installed binary in npm package
1 parent 5a10af5 commit d6c9a5a

File tree

3 files changed

+111
-32
lines changed

3 files changed

+111
-32
lines changed

tuido-npm/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
An opinionated terminal interface for efficient browsing and management of [x]it! formatted todo items.
44

5+
This npm package downloads the appropriate platform-specific binary from GitHub releases during installation.
6+
57
## Installation
68

79
```bash
@@ -10,6 +12,8 @@ npm install -g tuido
1012
npm install -D tuido
1113
```
1214

15+
**Note**: The package will automatically download the correct binary for your platform (Linux, macOS, Windows) during installation.
16+
1317
## Usage
1418

1519
From any directory containing [x]it! files:
@@ -29,6 +33,17 @@ tuido
2933

3034
See the [full documentation](https://github.com/NiloCK/tuido) for details.
3135

36+
## Troubleshooting
37+
38+
If you encounter issues with the binary installation:
39+
40+
1. **Binary not found**: Try reinstalling the package with `npm uninstall tuido && npm install tuido`
41+
2. **Permission errors**: On Unix systems, ensure the binary has execute permissions
42+
3. **Platform not supported**: Check the [releases page](https://github.com/NiloCK/tuido/releases) for available binaries
43+
4. **Network issues**: The installation requires internet access to download the binary from GitHub
44+
45+
For persistent issues, you can download the binary directly from the [GitHub releases](https://github.com/NiloCK/tuido/releases).
46+
3247
## Configuration
3348

3449
To set a custom write location or to parse additional file types, create a `.tuido` file in your project:

tuido-npm/bin/tuido-cli.js

Lines changed: 76 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env node
22

3-
const { Binary } = require("binary-install");
3+
const { spawn } = require("child_process");
4+
const fs = require("fs");
45
const os = require("os");
56
const path = require("path");
67

@@ -17,17 +18,6 @@ function getPlatform() {
1718
return mappings[platform] || platform;
1819
}
1920

20-
function getArch() {
21-
const arch = os.arch();
22-
const mappings = {
23-
x64: "amd64",
24-
ia32: "386",
25-
arm: "arm",
26-
arm64: "arm64",
27-
};
28-
return mappings[arch] || arch;
29-
}
30-
3121
function getBinaryPath() {
3222
const platform = getPlatform();
3323
let extension = "";
@@ -36,20 +26,82 @@ function getBinaryPath() {
3626
extension = ".exe";
3727
}
3828

39-
return path.join(
40-
__dirname,
41-
"..",
42-
"node_modules",
43-
".bin",
44-
`tuido${extension}`,
45-
);
29+
// binary-install stores binaries in: node_modules/<package>/binary/<name>
30+
return path.join(__dirname, "..", "binary", `tuido${extension}`);
31+
}
32+
33+
function findBinaryPath() {
34+
// Try the standard binary-install location first
35+
let binaryPath = getBinaryPath();
36+
37+
if (fs.existsSync(binaryPath)) {
38+
return binaryPath;
39+
}
40+
41+
// Fallback: check if binary-install used a different location
42+
const alternativePaths = [
43+
path.join(__dirname, "..", "node_modules", ".bin", "tuido"),
44+
path.join(__dirname, "..", "tuido"),
45+
path.join(__dirname, "..", "bin", "tuido"),
46+
];
47+
48+
for (const altPath of alternativePaths) {
49+
const platform = getPlatform();
50+
const withExt = platform === "windows" ? `${altPath}.exe` : altPath;
51+
if (fs.existsSync(withExt)) {
52+
return withExt;
53+
}
54+
if (fs.existsSync(altPath)) {
55+
return altPath;
56+
}
57+
}
58+
59+
return null;
4660
}
4761

4862
try {
49-
const binaryPath = getBinaryPath();
50-
const binary = new Binary("tuido", null, { installDirectory: path.dirname(binaryPath) });
51-
binary.run(process.argv.slice(2));
63+
const binaryPath = findBinaryPath();
64+
65+
if (!binaryPath) {
66+
console.error("Error: tuido binary not found. Please try reinstalling the package.");
67+
console.error("Expected location:", getBinaryPath());
68+
process.exit(1);
69+
}
70+
71+
// Check if binary is executable
72+
try {
73+
fs.accessSync(binaryPath, fs.constants.F_OK | fs.constants.X_OK);
74+
} catch (err) {
75+
console.error(`Error: tuido binary found but not executable: ${binaryPath}`);
76+
console.error("Try reinstalling the package or check file permissions.");
77+
process.exit(1);
78+
}
79+
80+
// Execute the binary
81+
const child = spawn(binaryPath, process.argv.slice(2), {
82+
stdio: "inherit",
83+
windowsHide: false,
84+
});
85+
86+
child.on("error", (err) => {
87+
console.error("Error executing tuido:", err.message);
88+
process.exit(1);
89+
});
90+
91+
child.on("close", (code) => {
92+
process.exit(code || 0);
93+
});
94+
95+
// Handle signals
96+
process.on("SIGINT", () => {
97+
child.kill("SIGINT");
98+
});
99+
100+
process.on("SIGTERM", () => {
101+
child.kill("SIGTERM");
102+
});
103+
52104
} catch (e) {
53-
console.error("Error running tuido:", e);
105+
console.error("Error running tuido:", e.message);
54106
process.exit(1);
55-
}
107+
}

tuido-npm/install.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,24 @@ function getBinary() {
6161
};
6262
}
6363

64-
try {
65-
const { url, name } = getBinary();
66-
console.log(`Downloading tuido binary from ${url}`);
67-
const binary = new Binary(name, url);
68-
binary.install();
69-
} catch (e) {
70-
console.error("Error installing tuido:", e);
71-
process.exit(1);
64+
function install() {
65+
try {
66+
const { url, name } = getBinary();
67+
console.log(`Installing tuido for ${os.platform()}-${os.arch()}`);
68+
console.log(`Downloading tuido binary from ${url}`);
69+
70+
const binary = new Binary(name, url);
71+
binary.install();
72+
console.log(`Successfully installed tuido binary: ${name}`);
73+
} catch (e) {
74+
console.error("Error installing tuido:", e.message || e);
75+
console.error("Please check:");
76+
console.error("1. Your internet connection");
77+
console.error("2. That the release exists on GitHub");
78+
console.error("3. Your platform/architecture is supported");
79+
console.error(`Attempted URL: ${getBinary().url}`);
80+
process.exit(1);
81+
}
7282
}
83+
84+
install();

0 commit comments

Comments
 (0)