-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathinstall.js
80 lines (69 loc) · 1.95 KB
/
install.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
71
72
73
74
75
76
77
78
79
80
const fs = require('fs')
const { https } = require('follow-redirects')
const path = require('path')
const os = require('os')
const { exec } = require('child_process')
const PLATFORM = os.platform()
const ARCH = os.arch()
const BIN_PATH = path.join(__dirname, 'bin')
const SUPERSIM_VERSION = '0.1.0-alpha.31'
const archiveFilename = {
darwin: {
arm64: 'supersim_Darwin_arm64.tar.gz',
x64: 'supersim_Darwin_x86_64.tar.gz',
},
linux: {
arm64: 'supersim_Linux_arm64.tar.gz',
x64: 'supersim_Linux_x86_64.tar.gz',
},
win32: {
arm64: 'supersim_Windows_arm64.zip',
x64: 'supersim_Windows_x86_64.zip',
},
}
function extractRelease(filename, outputPath) {
const cmd = filename.endsWith('.tar.gz')
? `tar -xzf ${outputPath} -C ${BIN_PATH}`
: `unzip ${outputPath} -d ${BIN_PATH}`
exec(cmd, (err) => {
if (err) {
console.error('Error extracting', err)
} else {
console.log('Successfully extracted release')
}
})
}
async function main() {
const filename = archiveFilename[PLATFORM][ARCH]
if (!filename) {
console.error('Unsupported platform/architecture')
process.exit(1)
}
const downloadUrl = `https://github.com/ethereum-optimism/supersim/releases/download/${SUPERSIM_VERSION}/${filename}`
const outputPath = path.join(BIN_PATH, filename)
if (!fs.existsSync(BIN_PATH)) {
fs.mkdirSync(BIN_PATH)
}
console.log(`Attempting to fetch ${filename}`)
https
.get(downloadUrl, (res) => {
const fileStream = fs.createWriteStream(outputPath)
res.pipe(fileStream)
fileStream.on('finish', () => {
console.log(`Downloaded ${filename}`)
fileStream.on('close', () => extractRelease(filename, outputPath))
})
})
.on('error', (err) => {
console.error('Error downloading supersim', err)
process.exit(1)
})
}
;(async () => {
try {
await main()
} catch (err) {
console.error('Error setting up supersim', err)
process.exit(1)
}
})()