-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnpm-install.js
More file actions
55 lines (45 loc) · 1.6 KB
/
Copy pathnpm-install.js
File metadata and controls
55 lines (45 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
const https = require('https');
const version = '1.0.2';
const repo = 'Correctover/mcp-server';
const platform = process.platform;
const arch = process.arch;
const platformMap = { linux: 'linux', darwin: 'darwin', win32: 'windows' };
const archMap = { x64: 'amd64', arm64: 'arm64' };
const osName = platformMap[platform];
const archName = archMap[arch];
if (!osName || !archName) {
console.error(`Unsupported platform: ${platform}/${arch}`);
process.exit(1);
}
const binaryName = `correctover-mcp-server-${osName}-${archName}${platform === 'win32' ? '.exe' : ''}`;
const url = `https://github.com/${repo}/releases/download/v${version}/${binaryName}`;
const binDir = path.join(__dirname, 'bin');
const binPath = path.join(binDir, binaryName);
if (!fs.existsSync(binDir)) fs.mkdirSync(binDir, { recursive: true });
console.log(`Downloading ${binaryName} from GitHub Releases...`);
https.get(url, (res) => {
if (res.statusCode === 302 || res.statusCode === 301) {
https.get(res.headers.location, downloadBinary);
} else {
downloadBinary(res);
}
}).on('error', (err) => {
console.error('Download failed:', err.message);
process.exit(1);
});
function downloadBinary(res) {
if (res.statusCode !== 200) {
console.error(`Failed to download binary (HTTP ${res.statusCode})`);
process.exit(1);
}
const file = fs.createWriteStream(binPath);
res.pipe(file);
file.on('finish', () => {
file.close();
fs.chmodSync(binPath, 0o755);
console.log(`Binary downloaded to ${binPath}`);
});
}