termfoto 0.6.2
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/install.js +72 -0
- package/package.json +30 -0
- package/termfoto +4 -0
package/install.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// termfoto npm install — downloads prebuilt binary from GitHub Releases
|
|
3
|
+
|
|
4
|
+
const https = require('https');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
|
|
8
|
+
function getBinaryName() {
|
|
9
|
+
return process.platform === 'win32' ? 'termfoto.exe' : 'termfoto';
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function getDownloadUrl(version, binaryName) {
|
|
13
|
+
return `https://github.com/raconworks/termfoto/releases/download/v${version}/${binaryName}`;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function install() {
|
|
17
|
+
const pkg = require('./package.json');
|
|
18
|
+
const version = pkg.version;
|
|
19
|
+
const binaryName = getBinaryName();
|
|
20
|
+
const url = getDownloadUrl(version, binaryName);
|
|
21
|
+
const dest = path.join(__dirname, binaryName);
|
|
22
|
+
|
|
23
|
+
console.log(`termfoto: downloading v${version}...`);
|
|
24
|
+
|
|
25
|
+
https.get(url, (res) => {
|
|
26
|
+
if (res.statusCode === 302 || res.statusCode === 301) {
|
|
27
|
+
https.get(res.headers.location, (redirectRes) => {
|
|
28
|
+
downloadToFile(redirectRes, dest);
|
|
29
|
+
}).on('error', (err) => {
|
|
30
|
+
handleError(err, url);
|
|
31
|
+
});
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (res.statusCode !== 200) {
|
|
36
|
+
console.error(`termfoto: HTTP ${res.statusCode} — binary not found`);
|
|
37
|
+
console.error(`termfoto: URL: ${url}`);
|
|
38
|
+
console.error(`termfoto: install via cargo instead: cargo install termfoto`);
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
downloadToFile(res, dest);
|
|
43
|
+
}).on('error', (err) => {
|
|
44
|
+
handleError(err, url);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function downloadToFile(res, dest) {
|
|
49
|
+
const file = fs.createWriteStream(dest, { mode: 0o755 });
|
|
50
|
+
res.pipe(file);
|
|
51
|
+
|
|
52
|
+
file.on('finish', () => {
|
|
53
|
+
file.close();
|
|
54
|
+
fs.chmodSync(dest, 0o755);
|
|
55
|
+
console.log('termfoto: installed successfully');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
file.on('error', (err) => {
|
|
59
|
+
fs.unlink(dest, () => {});
|
|
60
|
+
console.error(`termfoto: failed to write binary — ${err.message}`);
|
|
61
|
+
process.exit(1);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function handleError(err, url) {
|
|
66
|
+
console.error(`termfoto: download failed — ${err.message}`);
|
|
67
|
+
console.error(`termfoto: URL: ${url}`);
|
|
68
|
+
console.error(`termfoto: install via cargo instead: cargo install termfoto`);
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
install();
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "termfoto",
|
|
3
|
+
"version": "0.6.2",
|
|
4
|
+
"description": "Fast terminal photo viewer — keyboard-driven, chafa-rendered",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/raconworks/termfoto.git"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"os": [
|
|
11
|
+
"linux"
|
|
12
|
+
],
|
|
13
|
+
"bin": {
|
|
14
|
+
"termfoto": "termfoto"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"postinstall": "node install.js"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"install.js",
|
|
21
|
+
"termfoto"
|
|
22
|
+
],
|
|
23
|
+
"keywords": [
|
|
24
|
+
"tui",
|
|
25
|
+
"image",
|
|
26
|
+
"viewer",
|
|
27
|
+
"terminal",
|
|
28
|
+
"chafa"
|
|
29
|
+
]
|
|
30
|
+
}
|
package/termfoto
ADDED