-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·70 lines (55 loc) · 1.76 KB
/
index.js
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env node
const { spawn } = require('child_process');
const path = require('path');
const os = require('os');
const fs = require('fs');
// Get the binary path based on the platform and architecture
function getBinaryPath() {
const platform = os.platform();
const arch = os.arch();
const platformMap = {
win32: 'win32',
linux: 'linux',
darwin: 'darwin'
};
const archMap = {
x64: 'x64',
arm64: 'arm64'
};
const platformKey = platformMap[platform];
const archKey = archMap[arch];
if (!platformKey || !archKey) {
throw new Error(`Unsupported platform (${platform}) or architecture (${arch})`);
}
// Linux only supports x64
if (platform === 'linux' && arch !== 'x64') {
throw new Error('Linux builds are only available for x64 architecture');
}
const binaryName = platform === 'win32' ? 'aicommit.exe' : 'aicommit';
const binaryPath = path.join(__dirname, 'bin', `${platformKey}-${archKey}`, binaryName);
if (!fs.existsSync(binaryPath)) {
throw new Error(`Binary not found at ${binaryPath}`);
}
return binaryPath;
}
try {
const binaryPath = getBinaryPath();
// Make sure the binary is executable
if (os.platform() !== 'win32') {
fs.chmodSync(binaryPath, '755');
}
// Execute the binary with all arguments
const binary = spawn(binaryPath, process.argv.slice(2), {
stdio: 'inherit'
});
binary.on('error', (err) => {
console.error('Failed to start binary:', err);
process.exit(1);
});
binary.on('exit', (code) => {
process.exit(code);
});
} catch (err) {
console.error('Error:', err.message);
process.exit(1);
}