-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.js
More file actions
129 lines (105 loc) · 3.56 KB
/
install.js
File metadata and controls
129 lines (105 loc) · 3.56 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const https = require('https');
const { execSync } = require('child_process');
const GITHUB_REPO = 'PinataCloud/grapevine-cli';
const VERSION = '0.1.0'; // This should match package.json version
function getPlatformInfo() {
const platform = process.platform;
const arch = process.arch;
// Map Node.js platform names to your GitHub release names
const platformMap = {
'win32': 'windows',
'darwin': 'darwin',
'linux': 'linux'
};
// Map Node.js arch names to your GitHub release names
const archMap = {
'x64': 'amd64',
'arm64': 'arm64'
};
const mappedPlatform = platformMap[platform];
const mappedArch = archMap[arch];
if (!mappedPlatform || !mappedArch) {
throw new Error(`Unsupported platform: ${platform}-${arch}`);
}
return {
platform: mappedPlatform,
arch: mappedArch,
extension: platform === 'win32' ? '.exe' : ''
};
}
function getDownloadUrl(platform, arch, extension) {
// Based on your GitHub release assets
const filename = `grapevine-${platform}-${arch}${extension}`;
return `https://github.com/${GITHUB_REPO}/releases/download/v${VERSION}/${filename}`;
}
function downloadFile(url, destination) {
return new Promise((resolve, reject) => {
console.log(`Downloading ${url}...`);
const file = fs.createWriteStream(destination);
https.get(url, (response) => {
if (response.statusCode === 302 || response.statusCode === 301) {
// Handle redirects
file.close();
fs.unlinkSync(destination);
return downloadFile(response.headers.location, destination)
.then(resolve)
.catch(reject);
}
if (response.statusCode !== 200) {
file.close();
fs.unlinkSync(destination);
reject(new Error(`Failed to download: HTTP ${response.statusCode}`));
return;
}
response.pipe(file);
file.on('finish', () => {
file.close();
resolve();
});
file.on('error', (err) => {
file.close();
fs.unlinkSync(destination);
reject(err);
});
}).on('error', (err) => {
file.close();
fs.unlinkSync(destination);
reject(err);
});
});
}
async function install() {
try {
const { platform, arch, extension } = getPlatformInfo();
const url = getDownloadUrl(platform, arch, extension);
// Create bin directory if it doesn't exist
const binDir = path.join(__dirname, 'bin');
if (!fs.existsSync(binDir)) {
fs.mkdirSync(binDir, { recursive: true });
}
// Download the binary, replacing the placeholder
const binaryPath = path.join(binDir, `grapevine${extension}`);
await downloadFile(url, binaryPath);
// Make executable on Unix systems
if (process.platform !== 'win32') {
execSync(`chmod +x "${binaryPath}"`);
}
console.log('✅ Grapevine CLI installed successfully!');
console.log('Run "grapevine --help" to get started.');
} catch (error) {
console.error('❌ Installation failed:', error.message);
console.error('\nTroubleshooting:');
console.error('1. Check your internet connection');
console.error('2. Verify the release exists at: https://github.com/PinataCloud/grapevine-cli/releases');
console.error('3. Try installing from source: https://github.com/PinataCloud/grapevine-cli#from-source');
process.exit(1);
}
}
// Only run if this script is executed directly
if (require.main === module) {
install();
}
module.exports = { install };