Prevent downloading the daemon if it's not necessary #1798
1 changed files with 43 additions and 23 deletions
|
@ -19,34 +19,54 @@ const downloadDaemon = targetPlatform =>
|
||||||
if (currentPlatform === 'win32') currentPlatform = 'windows';
|
if (currentPlatform === 'win32') currentPlatform = 'windows';
|
||||||
|
|
||||||
const daemonPlatform = targetPlatform || currentPlatform;
|
const daemonPlatform = targetPlatform || currentPlatform;
|
||||||
const tmpZipPath = path.join(__dirname,'daemon.zip');
|
const tmpZipPath = path.join(__dirname, '..', 'dist', 'daemon.zip');
|
||||||
const daemonURL = daemonURLTemplate
|
const daemonURL = daemonURLTemplate
|
||||||
.replace(/DAEMONVER/g, daemonVersion)
|
.replace(/DAEMONVER/g, daemonVersion)
|
||||||
.replace(/OSNAME/g, daemonPlatform);
|
.replace(/OSNAME/g, daemonPlatform);
|
||||||
const tmpZipPath = 'dist/daemon.zip';
|
const tmpZipPath = 'dist/daemon.zip';
|
||||||
|
|
||||||
console.log('\x1b[34minfo\x1b[0m Downloading daemon...');
|
|
||||||
axios
|
// If a daemon and daemon.ver exists, check to see if it matches the current daemon version
|
||||||
.request({
|
const hasDaemonDownloaded = fs.existsSync(daemonFilePath);
|
||||||
responseType: 'arraybuffer',
|
const hasDaemonVersion = fs.existsSync(daemonVersionPath);
|
||||||
url: daemonURL,
|
let downloadedDaemonVersion;
|
||||||
method: 'get',
|
if (hasDaemonVersion) {
|
||||||
headers: {
|
downloadedDaemonVersion = fs.readFileSync(daemonVersionPath, "utf8");
|
||||||
'Content-Type': 'application/zip',
|
}
|
||||||
},
|
|
||||||
})
|
if (hasDaemonDownloaded && hasDaemonVersion && downloadedDaemonVersion === daemonVersion) {
|
||||||
.then(
|
console.log('\x1b[34minfo\x1b[0m Daemon already downloaded');
|
||||||
result =>
|
resolve('Done');
|
||||||
new Promise((newResolve, newReject) => {
|
return;
|
||||||
fs.writeFile(tmpZipPath, result.data, error => {
|
} else {
|
||||||
if (error) return newReject(error);
|
console.log('\x1b[34minfo\x1b[0m Downloading daemon...');
|
||||||
return newResolve();
|
axios
|
||||||
});
|
.request({
|
||||||
})
|
responseType: 'arraybuffer',
|
||||||
)
|
url: daemonURL,
|
||||||
.then(() => del(`${daemonDir}/${daemonFileName}*`))
|
method: 'get',
|
||||||
.then(() =>
|
headers: {
|
||||||
decompress(tmpZipPath, daemonDir, {
|
'Content-Type': 'application/zip',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then(
|
||||||
|
result =>
|
||||||
|
new Promise((newResolve, newReject) => {
|
||||||
|
const distPath = path.join(__dirname, '..', 'dist');
|
||||||
|
const hasDistFolder = fs.existsSync(distPath);
|
||||||
|
|
||||||
|
if (!hasDistFolder) {
|
||||||
|
fs.mkdirSync(distPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.writeFile(tmpZipPath, result.data, error => {
|
||||||
|
if (error) return newReject(error);
|
||||||
|
return newResolve();
|
||||||
|
});
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.then(() => del(`${daemonFilePath}*`))
|
||||||
|
.then(() => decompress(tmpZipPath, daemonDir, {
|
||||||
filter: file =>
|
filter: file =>
|
||||||
path.basename(file.path).replace(path.extname(file.path), '') === daemonFileName,
|
path.basename(file.path).replace(path.extname(file.path), '') === daemonFileName,
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Reference in a new issue