Skip to content

Commit 16b40ee

Browse files
authored
Merge pull request #45 from NiloCK/no-binary-install
remove binary-install dep...
2 parents 5efddd9 + 0f8c757 commit 16b40ee

File tree

5 files changed

+189
-87
lines changed

5 files changed

+189
-87
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
# the name of my test builds
22
td
3+
4+
node_modules
5+
6+
# npm package build artifacts
7+
tuido-npm/binary/
8+
tuido-npm/node_modules/

tuido-npm/install.js

Lines changed: 65 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const { Binary } = require("binary-install");
21
const os = require("os");
32
const path = require("path");
43
const fs = require("fs");
@@ -32,7 +31,7 @@ function getArch() {
3231
return mappings[arch] || arch;
3332
}
3433

35-
function getBinary() {
34+
function getBinaryInfo() {
3635
const platform = getPlatform();
3736
const arch = getArch();
3837

@@ -72,67 +71,90 @@ function getBinary() {
7271
};
7372
}
7473

75-
async function manualDownload(url, name) {
76-
console.log(`\n📥 Attempting manual download as fallback...`);
74+
async function downloadAndInstall(url, name) {
75+
console.log(`\n📥 Downloading and installing binary...`);
7776

7877
const binaryDir = path.join(__dirname, "binary");
7978
const tarPath = path.join(__dirname, "temp.tar.gz");
8079
const finalBinaryPath = path.join(binaryDir, name);
8180

81+
82+
8283
// Ensure binary directory exists
8384
if (!fs.existsSync(binaryDir)) {
8485
fs.mkdirSync(binaryDir, { recursive: true });
85-
console.log(`Created binary directory: ${binaryDir}`);
8686
}
8787

8888
return new Promise((resolve, reject) => {
8989
console.log(`Downloading from: ${url}`);
9090

91-
const file = fs.createWriteStream(tarPath);
92-
93-
https.get(url, (response) => {
94-
if (response.statusCode !== 200) {
95-
reject(new Error(`HTTP ${response.statusCode}: ${response.statusMessage}`));
91+
const downloadFromUrl = (downloadUrl, redirectCount = 0) => {
92+
if (redirectCount > 5) {
93+
reject(new Error('Too many redirects'));
9694
return;
9795
}
9896

99-
console.log(`Download started, content-length: ${response.headers['content-length'] || 'unknown'}`);
97+
const file = fs.createWriteStream(tarPath);
10098

101-
response.pipe(file);
102-
103-
file.on('finish', () => {
104-
file.close();
105-
console.log(`Download completed, extracting...`);
99+
https.get(downloadUrl, (response) => {
100+
if (response.statusCode === 302 || response.statusCode === 301) {
101+
console.log(`Following redirect to: ${response.headers.location}`);
102+
file.close();
103+
fs.unlink(tarPath, () => {});
104+
downloadFromUrl(response.headers.location, redirectCount + 1);
105+
return;
106+
}
106107

107-
// Extract the tar.gz file
108-
tar.extract({
109-
file: tarPath,
110-
cwd: binaryDir,
111-
sync: true
112-
});
108+
if (response.statusCode !== 200) {
109+
file.close();
110+
fs.unlink(tarPath, () => {});
111+
reject(new Error(`HTTP ${response.statusCode}: ${response.statusMessage}`));
112+
return;
113+
}
114+
115+
console.log(`Download started, content-length: ${response.headers['content-length'] || 'unknown'}`);
113116

114-
console.log(`Extraction completed`);
117+
response.pipe(file);
115118

116-
// Clean up the tar file
117-
fs.unlinkSync(tarPath);
119+
file.on('finish', () => {
120+
file.close();
121+
console.log(`Download completed, extracting...`);
122+
123+
// Extract the tar.gz file
124+
tar.extract({
125+
file: tarPath,
126+
cwd: binaryDir,
127+
sync: true
128+
});
129+
130+
// Clean up the tar file
131+
fs.unlinkSync(tarPath);
132+
133+
// Make binary executable on Unix systems
134+
if (process.platform !== 'win32' && fs.existsSync(finalBinaryPath)) {
135+
fs.chmodSync(finalBinaryPath, 0o755);
136+
}
137+
138+
// Verify installation
139+
if (fs.existsSync(finalBinaryPath)) {
140+
console.log(`✅ Binary successfully installed`);
141+
resolve();
142+
} else {
143+
reject(new Error(`Binary not found after extraction: ${finalBinaryPath}`));
144+
}
145+
});
118146

119-
// Make binary executable on Unix systems
120-
if (process.platform !== 'win32') {
121-
fs.chmodSync(finalBinaryPath, 0o755);
122-
console.log(`Made binary executable`);
123-
}
147+
file.on('error', (err) => {
148+
fs.unlink(tarPath, () => {}); // Clean up on error
149+
reject(err);
150+
});
124151

125-
resolve();
126-
});
127-
128-
file.on('error', (err) => {
129-
fs.unlink(tarPath, () => {}); // Clean up on error
152+
}).on('error', (err) => {
130153
reject(err);
131154
});
132-
133-
}).on('error', (err) => {
134-
reject(err);
135-
});
155+
};
156+
157+
downloadFromUrl(url);
136158
});
137159
}
138160

@@ -143,59 +165,18 @@ async function install() {
143165
console.log(`Installation directory: ${__dirname}`);
144166

145167
try {
146-
const { url, name } = getBinary();
168+
const { url, name } = getBinaryInfo();
147169

148-
console.log(`\nCreating Binary instance...`);
149-
const binary = new Binary(name, url);
150-
151-
console.log(`Binary object created successfully`);
152170
console.log(`Expected binary name: ${name}`);
153171
console.log(`Expected install location: ${path.join(__dirname, "binary", name)}`);
154172

155173
console.log(`\nStarting download and installation...`);
156174

157-
let installSuccess = false;
158-
159-
// Try binary-install first
160-
try {
161-
// Wrap the install call to catch any errors
162-
const installPromise = new Promise((resolve, reject) => {
163-
try {
164-
const result = binary.install();
165-
166-
// Handle both promise and callback style returns
167-
if (result && typeof result.then === 'function') {
168-
result.then(resolve).catch(reject);
169-
} else {
170-
// Assume synchronous success
171-
resolve(result);
172-
}
173-
} catch (error) {
174-
reject(error);
175-
}
176-
});
177-
178-
await installPromise;
179-
installSuccess = true;
180-
console.log(`\n✅ Successfully installed tuido binary using binary-install: ${name}`);
181-
182-
} catch (binaryInstallError) {
183-
console.log(`\n⚠️ binary-install failed: ${binaryInstallError.message}`);
184-
console.log(`Trying manual download fallback...`);
185-
186-
try {
187-
await manualDownload(url, name);
188-
installSuccess = true;
189-
console.log(`\n✅ Successfully installed tuido binary using manual download: ${name}`);
190-
} catch (manualError) {
191-
console.error(`\n❌ Manual download also failed: ${manualError.message}`);
192-
throw manualError;
193-
}
194-
}
175+
// Download and install the binary
176+
await downloadAndInstall(url, name);
195177

196178
// Verify the binary was actually installed
197179
const binaryPath = path.join(__dirname, "binary", name);
198-
const fs = require("fs");
199180

200181
if (fs.existsSync(binaryPath)) {
201182
console.log(`✅ Binary verified at: ${binaryPath}`);
@@ -234,7 +215,7 @@ async function install() {
234215

235216
console.error(`\n🔍 Troubleshooting information:`);
236217
console.error(`1. Check your internet connection`);
237-
console.error(`2. Verify the release exists: ${getBinary().url}`);
218+
console.error(`2. Verify the release exists: ${getBinaryInfo().url}`);
238219
console.error(`3. Check if your platform/architecture is supported`);
239220
console.error(`4. Try manual download from: https://github.com/NiloCK/tuido/releases`);
240221
console.error(`5. Check npm/yarn proxy settings if behind corporate firewall`);

tuido-npm/package-lock.json

Lines changed: 116 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tuido-npm/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tuido",
3-
"version": "0.0.16",
3+
"version": "0.0.17",
44
"description": "Terminal interface for managing tasks and todos in [x]it! format",
55
"bin": {
66
"tuido": "./bin/tuido-cli.js"
@@ -26,7 +26,6 @@
2626
},
2727
"homepage": "https://github.com/NiloCK/tuido#readme",
2828
"dependencies": {
29-
"binary-install": "^1.1.0",
3029
"tar": "^6.0.0"
3130
},
3231
"engines": {

utils/versioning.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"time"
1515
)
1616

17-
const version = "v0.0.16"
17+
const version = "v0.0.17"
1818
const ReleaseURL = "https://github.com/NiloCK/tuido/releases/latest"
1919
const GitHubAPIURL = "https://api.github.com/repos/NiloCK/tuido/releases/latest"
2020

0 commit comments

Comments
 (0)