lbry-desktop/build/downloadDaemon.js
Igor Gassmann b9f4d7b307
chore: migrate to AppImage and update publish workflow (#1010)
The app now uses AppImage instead of .deb files for Linux. Thanks to this change, the app supports now auto-updates on Linux too.

The publishing workflow has been updated. It uses now the publishing mechanisms offered by electron-builder.
2018-03-07 18:03:45 -05:00

47 lines
1.5 KiB
JavaScript

/* eslint-disable no-console,import/no-commonjs */
const path = require('path');
const fs = require('fs');
const packageJSON = require('../package.json');
// eslint-disable-next-line import/no-extraneous-dependencies
const axios = require('axios');
// eslint-disable-next-line import/no-extraneous-dependencies
const decompress = require('decompress');
const os = require('os');
const daemonURLTemplate = packageJSON.lbrySettings.lbrynetDaemonUrlTemplate;
const daemonVersion = packageJSON.lbrySettings.lbrynetDaemonVersion;
let currentPlatform = os.platform();
if (currentPlatform === 'darwin') currentPlatform = 'macos';
if (currentPlatform === 'win32') currentPlatform = 'windows';
const daemonURL = daemonURLTemplate
.replace(/DAEMONVER/g, daemonVersion)
.replace(/OSNAME/g, currentPlatform);
const tmpZipPath = 'build/daemon.zip';
console.log('\x1b[34minfo\x1b[0m Downloading daemon...');
axios
.request({
responseType: 'arraybuffer',
url: daemonURL,
method: 'get',
headers: {
'Content-Type': 'application/zip',
},
})
.then(result => {
fs.writeFileSync(tmpZipPath, result.data);
return true;
})
.then(() => {
decompress(tmpZipPath, 'static/daemon', {
filter: file =>
path.basename(file.path).replace(path.extname(file.path), '') === 'lbrynet-daemon',
});
})
.then(() => {
console.log('\x1b[32msuccess\x1b[0m Daemon downloaded!');
})
.catch(error => {
console.error(`\x1b[31merror\x1b[0m Daemon download failed due to: \x1b[35m${error}\x1b[0m`);
});