const axios = require('axios');
const { chmodSync, constants, existsSync } = require('fs');
const os = require('os');
const unzip = require('unzip-stream');
const { repository, version } = require('./package.json');
async function main() {
if (os.arch() !== 'x64') {
process.stderr.write('Your platform is currently not supported.\n');
process.exit(1);
}
let filename;
switch (process.platform) {
case 'cygwin':
case 'win32':
filename = 'gr-bin_x86_64-pc-windows-gnu.zip';
break;
case 'linux':
filename = 'gr-bin_x86_64-unknown-linux-gnu.zip';
break;
default:
process.stderr.write('Your platform is currently not supported.\n');
process.exit(1);
}
const url = `${repository.url}/releases/download/v${version}/${filename}`;
const file = await axios.get(url, { responseType: 'stream' }).catch(() => {
throw new Error(`Cannot download binary from ${url}.`);
});
file.data.pipe(unzip.Extract({ path: '.' })).on('close', () => {
if (existsSync('gr')) {
chmodSync('gr', 0755);
}
});
}
main().catch((err) => {
console.error(err);
process.exit(1);
});