forked from conductor-oss/conductor-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.js
More file actions
149 lines (122 loc) · 3.61 KB
/
install.js
File metadata and controls
149 lines (122 loc) · 3.61 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env node
const https = require('https');
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
const REPO = 'conductor-oss/conductor-cli';
const BINARY_NAME = 'orkes';
// Detect platform and architecture
function getPlatform() {
const platform = process.platform;
const arch = process.arch;
const platformMap = {
darwin: 'darwin',
linux: 'linux',
win32: 'windows'
};
const archMap = {
x64: 'amd64',
arm64: 'arm64'
};
if (!platformMap[platform]) {
console.error(`Unsupported platform: ${platform}`);
process.exit(1);
}
if (!archMap[arch]) {
console.error(`Unsupported architecture: ${arch}`);
process.exit(1);
}
return {
os: platformMap[platform],
arch: archMap[arch],
isWindows: platform === 'win32'
};
}
// Get latest release version
function getLatestVersion() {
return new Promise((resolve, reject) => {
const options = {
hostname: 'api.github.com',
path: `/repos/${REPO}/releases/latest`,
method: 'GET',
headers: {
'User-Agent': 'conductor-cli-npm-installer'
}
};
https.get(options, (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
try {
const json = JSON.parse(data);
resolve(json.tag_name);
} catch (e) {
reject(new Error('Failed to parse release data'));
}
});
}).on('error', (err) => {
reject(err);
});
});
}
// Download binary
function downloadBinary(url, dest) {
return new Promise((resolve, reject) => {
const file = fs.createWriteStream(dest);
https.get(url, (response) => {
if (response.statusCode === 302 || response.statusCode === 301) {
// Follow redirect
return downloadBinary(response.headers.location, dest).then(resolve).catch(reject);
}
if (response.statusCode !== 200) {
reject(new Error(`Failed to download: ${response.statusCode}`));
return;
}
response.pipe(file);
file.on('finish', () => {
file.close();
resolve();
});
}).on('error', (err) => {
fs.unlink(dest, () => {});
reject(err);
});
});
}
async function install() {
try {
console.log('Installing Orkes CLI...');
const { os, arch, isWindows } = getPlatform();
console.log(`Platform: ${os} ${arch}`);
// Get latest version
console.log('Fetching latest version...');
const version = await getLatestVersion();
console.log(`Latest version: ${version}`);
// Construct download URL
const binaryName = isWindows ? `${BINARY_NAME}.exe` : BINARY_NAME;
const downloadName = isWindows ? `${BINARY_NAME}_${os}_${arch}.exe` : `${BINARY_NAME}_${os}_${arch}`;
const downloadUrl = `https://github.com/${REPO}/releases/download/${version}/${downloadName}`;
console.log(`Downloading from: ${downloadUrl}`);
// Create bin directory
const binDir = path.join(__dirname, 'bin');
if (!fs.existsSync(binDir)) {
fs.mkdirSync(binDir, { recursive: true });
}
// Download binary
const binaryPath = path.join(binDir, binaryName);
await downloadBinary(downloadUrl, binaryPath);
// Make executable (Unix-like systems)
if (!isWindows) {
fs.chmodSync(binaryPath, 0o755);
}
console.log('✓ Installation successful!');
console.log(`Binary installed at: ${binaryPath}`);
console.log(`\nRun 'orkes --version' to verify installation.`);
} catch (error) {
console.error('Installation failed:', error.message);
process.exit(1);
}
}
install();