gitbasher 3.8.0 → 3.8.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/download-release.js +78 -26
- package/package.json +1 -1
package/download-release.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const https = require('https');
|
|
2
|
+
const http = require('http');
|
|
2
3
|
const fs = require('fs');
|
|
3
4
|
const path = require('path');
|
|
4
5
|
|
|
@@ -18,31 +19,82 @@ if (!fs.existsSync(BIN_DIR)) {
|
|
|
18
19
|
fs.mkdirSync(BIN_DIR, { recursive: true });
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
// Download
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
file.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
22
|
+
// Download function with redirect handling
|
|
23
|
+
function download(url, outputPath, maxRedirects = 5) {
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
if (maxRedirects === 0) {
|
|
26
|
+
reject(new Error('Too many redirects'));
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const client = url.startsWith('https') ? https : http;
|
|
31
|
+
const file = fs.createWriteStream(outputPath);
|
|
32
|
+
let downloadedBytes = 0;
|
|
33
|
+
let totalBytes = 0;
|
|
34
|
+
|
|
35
|
+
client.get(url, (response) => {
|
|
36
|
+
// Handle redirects
|
|
37
|
+
if (response.statusCode === 301 || response.statusCode === 302 || response.statusCode === 307 || response.statusCode === 308) {
|
|
38
|
+
file.close();
|
|
39
|
+
fs.unlinkSync(outputPath);
|
|
40
|
+
const redirectUrl = response.headers.location;
|
|
41
|
+
if (!redirectUrl) {
|
|
42
|
+
reject(new Error('Redirect location not found'));
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
// Resolve relative redirects
|
|
46
|
+
const redirectUrlFull = redirectUrl.startsWith('http')
|
|
47
|
+
? redirectUrl
|
|
48
|
+
: new URL(redirectUrl, url).href;
|
|
49
|
+
return download(redirectUrlFull, outputPath, maxRedirects - 1)
|
|
50
|
+
.then(resolve)
|
|
51
|
+
.catch(reject);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Handle errors
|
|
55
|
+
if (response.statusCode !== 200) {
|
|
56
|
+
file.close();
|
|
57
|
+
fs.unlinkSync(outputPath);
|
|
58
|
+
reject(new Error(`HTTP ${response.statusCode}: ${response.statusMessage}`));
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Track download progress
|
|
63
|
+
totalBytes = parseInt(response.headers['content-length'] || '0', 10);
|
|
64
|
+
if (totalBytes > 0) {
|
|
65
|
+
response.on('data', (chunk) => {
|
|
66
|
+
downloadedBytes += chunk.length;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Pipe response to file
|
|
71
|
+
response.pipe(file);
|
|
72
|
+
|
|
73
|
+
file.on('finish', () => {
|
|
74
|
+
file.close();
|
|
75
|
+
fs.chmodSync(outputPath, 0o755);
|
|
76
|
+
if (totalBytes > 0) {
|
|
77
|
+
const sizeKB = (downloadedBytes / 1024).toFixed(1);
|
|
78
|
+
console.log(`✓ Downloaded ${sizeKB}KB`);
|
|
79
|
+
} else {
|
|
80
|
+
console.log('✓ Download complete');
|
|
81
|
+
}
|
|
82
|
+
resolve();
|
|
83
|
+
});
|
|
84
|
+
}).on('error', (err) => {
|
|
85
|
+
file.close();
|
|
86
|
+
if (fs.existsSync(outputPath)) {
|
|
87
|
+
fs.unlinkSync(outputPath);
|
|
88
|
+
}
|
|
89
|
+
reject(err);
|
|
34
90
|
});
|
|
35
91
|
});
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
})
|
|
45
|
-
fs.unlinkSync(BIN_PATH);
|
|
46
|
-
console.error(`Error downloading release: ${err.message}`);
|
|
47
|
-
process.exit(1);
|
|
48
|
-
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Download the release asset
|
|
95
|
+
console.log(`Downloading gitbasher v${VERSION}...`);
|
|
96
|
+
download(RELEASE_URL, BIN_PATH)
|
|
97
|
+
.catch((err) => {
|
|
98
|
+
console.error(`✗ Error downloading release: ${err.message}`);
|
|
99
|
+
process.exit(1);
|
|
100
|
+
});
|