wheretf 0.0.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/wtf +28 -0
- package/install.js +109 -0
- package/package.json +35 -0
package/bin/wtf
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { spawn } = require('child_process');
|
|
6
|
+
|
|
7
|
+
const isWindows = process.platform === 'win32';
|
|
8
|
+
const binaryName = isWindows ? 'wtf.exe' : 'wtf';
|
|
9
|
+
const binaryPath = path.join(__dirname, binaryName);
|
|
10
|
+
|
|
11
|
+
if (!fs.existsSync(binaryPath)) {
|
|
12
|
+
console.error(`ā WTF binary is missing from: ${binaryPath}`);
|
|
13
|
+
console.error(' Please run "npm rebuild wheretf" or build it manually in the package folder: "go build -o bin/wtf main.go"');
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Forward all CLI arguments, pipes, and exit codes
|
|
18
|
+
const args = process.argv.slice(2);
|
|
19
|
+
const child = spawn(binaryPath, args, { stdio: 'inherit' });
|
|
20
|
+
|
|
21
|
+
child.on('close', (code) => {
|
|
22
|
+
process.exit(code === null ? 0 : code);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
child.on('error', (err) => {
|
|
26
|
+
console.error(`ā Failed to launch WTF binary: ${err.message}`);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
});
|
package/install.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const https = require('https');
|
|
4
|
+
const { execSync } = require('child_process');
|
|
5
|
+
|
|
6
|
+
const REPO = 'hariharen9/wtf';
|
|
7
|
+
const VERSION = '0.0.1'; // Falls back to latest or matches npm package version
|
|
8
|
+
|
|
9
|
+
function getTargetAsset() {
|
|
10
|
+
const platform = process.platform;
|
|
11
|
+
const arch = process.arch;
|
|
12
|
+
|
|
13
|
+
if (platform === 'darwin') {
|
|
14
|
+
if (arch === 'arm64') return `wtf-darwin-arm64.tar.gz`;
|
|
15
|
+
return `wtf-darwin-amd64.tar.gz`;
|
|
16
|
+
}
|
|
17
|
+
if (platform === 'linux') {
|
|
18
|
+
if (arch === 'x64') return `wtf-linux-amd64.tar.gz`;
|
|
19
|
+
}
|
|
20
|
+
if (platform === 'win32') {
|
|
21
|
+
if (arch === 'x64' || arch === 'ia32') return `wtf-windows-amd64.zip`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
throw new Error(`Unsupported platform/architecture: ${platform}/${arch}`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function downloadFile(url, destPath) {
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
https.get(url, (res) => {
|
|
30
|
+
// Handle HTTP redirects (vital for GitHub Releases)
|
|
31
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
32
|
+
return downloadFile(res.headers.location, destPath).then(resolve).catch(reject);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (res.statusCode !== 200) {
|
|
36
|
+
return reject(new Error(`Failed to download binary: Status Code ${res.statusCode}`));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const file = fs.createWriteStream(destPath);
|
|
40
|
+
res.pipe(file);
|
|
41
|
+
|
|
42
|
+
file.on('finish', () => {
|
|
43
|
+
file.close();
|
|
44
|
+
resolve();
|
|
45
|
+
});
|
|
46
|
+
}).on('error', (err) => {
|
|
47
|
+
fs.unlink(destPath, () => {});
|
|
48
|
+
reject(err);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function main() {
|
|
54
|
+
const binDir = path.join(__dirname, 'bin');
|
|
55
|
+
if (!fs.existsSync(binDir)) {
|
|
56
|
+
fs.mkdirSync(binDir, { recursive: true });
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
const assetName = getTargetAsset();
|
|
61
|
+
const tempFile = path.join(__dirname, assetName);
|
|
62
|
+
|
|
63
|
+
// Construct download URL
|
|
64
|
+
// e.g. https://github.com/hariharen9/wtf/releases/latest/download/wtf-windows-amd64.zip
|
|
65
|
+
const downloadUrl = `https://github.com/${REPO}/releases/latest/download/${assetName}`;
|
|
66
|
+
|
|
67
|
+
console.log(`š Downloading WTF binary for ${process.platform}-${process.arch}...`);
|
|
68
|
+
console.log(` Source: ${downloadUrl}`);
|
|
69
|
+
|
|
70
|
+
await downloadFile(downloadUrl, tempFile);
|
|
71
|
+
console.log(`š¦ Extracting archive to ${binDir}...`);
|
|
72
|
+
|
|
73
|
+
// Use system extraction tools (tar works on Win10+, macOS, and Linux)
|
|
74
|
+
if (assetName.endsWith('.tar.gz')) {
|
|
75
|
+
execSync(`tar -xzf "${tempFile}" -C "${binDir}"`);
|
|
76
|
+
} else if (assetName.endsWith('.zip')) {
|
|
77
|
+
// Windows tar natively handles zip files
|
|
78
|
+
execSync(`tar -xf "${tempFile}" -C "${binDir}"`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Clean up temporary archive file
|
|
82
|
+
fs.unlinkSync(tempFile);
|
|
83
|
+
|
|
84
|
+
// Verify binary exists and set permissions on Unix systems
|
|
85
|
+
const isWindows = process.platform === 'win32';
|
|
86
|
+
const binaryName = isWindows ? 'wtf.exe' : 'wtf';
|
|
87
|
+
const binaryPath = path.join(binDir, binaryName);
|
|
88
|
+
|
|
89
|
+
if (!fs.existsSync(binaryPath)) {
|
|
90
|
+
throw new Error(`Binary file was not found in extracted archive at ${binaryPath}`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (!isWindows) {
|
|
94
|
+
fs.chmodSync(binaryPath, 0o755); // make executable
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
console.log('⨠WTF native binary installed successfully!');
|
|
98
|
+
} catch (err) {
|
|
99
|
+
console.error('ā Failed to install WTF binary.');
|
|
100
|
+
console.error(` Error details: ${err.message}`);
|
|
101
|
+
console.warn('\nš” Running in offline mode or dev environment?');
|
|
102
|
+
console.warn(' Ensure you build the binary locally: "go build -o npm/bin/wtf main.go"');
|
|
103
|
+
|
|
104
|
+
// We exit with 0 so npm install doesn't crash completely in offline/dev workspaces
|
|
105
|
+
process.exit(0);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
main();
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "wheretf",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Where's The File? Blazing-fast interactive terminal file finder and CLI searcher.",
|
|
5
|
+
"main": "bin/wtf",
|
|
6
|
+
"bin": {
|
|
7
|
+
"wtf": "./bin/wtf"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"postinstall": "node install.js"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"file",
|
|
14
|
+
"search",
|
|
15
|
+
"finder",
|
|
16
|
+
"locate",
|
|
17
|
+
"tui",
|
|
18
|
+
"cli",
|
|
19
|
+
"everything",
|
|
20
|
+
"fzf"
|
|
21
|
+
],
|
|
22
|
+
"author": "hariharen9",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/hariharen9/wtf.git"
|
|
27
|
+
},
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/hariharen9/wtf/issues"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://github.com/hariharen9/wtf#readme",
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=12.0.0"
|
|
34
|
+
}
|
|
35
|
+
}
|