Don't download the daemon if it is already downloaded
This commit is contained in:
parent
3f2aeb3523
commit
cd44cc3f2d
7 changed files with 76 additions and 76 deletions
|
@ -33,7 +33,7 @@ script:
|
||||||
- |
|
- |
|
||||||
if [ "$TARGET" == "windows" ]; then
|
if [ "$TARGET" == "windows" ]; then
|
||||||
docker run --rm \
|
docker run --rm \
|
||||||
--env-file <(env | grep -iE 'DEBUG|NODE_|ELECTRON_|YARN_|NPM_|CI|CIRCLE|TRAVIS|APPVEYOR_|CSC_|GH_|GITHUB_|BT_|AWS_|STRIP|BUILD_') \
|
--env-file <(env | grep -iE 'DEBUG|TARGET|NODE_|ELECTRON_|YARN_|NPM_|CI|CIRCLE|TRAVIS|APPVEYOR_|CSC_|GH_|GITHUB_|BT_|AWS_|STRIP|BUILD_') \
|
||||||
-v ${PWD}:/project \
|
-v ${PWD}:/project \
|
||||||
electronuserland/builder:wine \
|
electronuserland/builder:wine \
|
||||||
/bin/bash -c "yarn --link-duplicates --pure-lockfile && yarn build --win --publish onTag";
|
/bin/bash -c "yarn --link-duplicates --pure-lockfile && yarn build --win --publish onTag";
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
/* eslint-disable no-console,import/no-extraneous-dependencies,import/no-commonjs */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This script is necessary for checking that the daemon that has been downloaded during the
|
|
||||||
* yarn installing process is the one for the building target. For example, on Travis the
|
|
||||||
* Windows package is built on Linux, thus yarn will download the daemon for Linux instead of
|
|
||||||
* Windows. The script will test that and then download the right daemon for the targeted platform.
|
|
||||||
*/
|
|
||||||
const os = require('os');
|
|
||||||
const downloadDaemon = require('./downloadDaemon');
|
|
||||||
|
|
||||||
module.exports = context => {
|
|
||||||
|
|
||||||
let currentPlatform = os.platform();
|
|
||||||
if (currentPlatform === 'darwin') currentPlatform = 'macoss';
|
|
||||||
if (currentPlatform === 'win32') currentPlatform = 'windows';
|
|
||||||
|
|
||||||
let buildingPlatformTarget = context.platform.toString();
|
|
||||||
if (buildingPlatformTarget === 'mac') buildingPlatformTarget = 'macos';
|
|
||||||
|
|
||||||
if (buildingPlatformTarget !== currentPlatform) {
|
|
||||||
console.log(
|
|
||||||
"\x1b[34minfo\x1b[0m Daemon platform doesn't match target platform. Redownloading the daemon."
|
|
||||||
);
|
|
||||||
|
|
||||||
return downloadDaemon(buildingPlatformTarget);
|
|
||||||
}
|
|
||||||
return Promise.resolve();
|
|
||||||
};
|
|
1
build/daemon.ver
Normal file
1
build/daemon.ver
Normal file
|
@ -0,0 +1 @@
|
||||||
|
0.20.4
|
|
@ -1,6 +1,6 @@
|
||||||
/* eslint-disable no-console,import/no-extraneous-dependencies,import/no-commonjs */
|
/* eslint-disable no-console,import/no-extraneous-dependencies,import/no-commonjs */
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs-path');
|
const fs = require('fs');
|
||||||
const packageJSON = require('../package.json');
|
const packageJSON = require('../package.json');
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
const decompress = require('decompress');
|
const decompress = require('decompress');
|
||||||
|
@ -11,56 +11,85 @@ const downloadDaemon = targetPlatform =>
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
const daemonURLTemplate = packageJSON.lbrySettings.lbrynetDaemonUrlTemplate;
|
const daemonURLTemplate = packageJSON.lbrySettings.lbrynetDaemonUrlTemplate;
|
||||||
const daemonVersion = packageJSON.lbrySettings.lbrynetDaemonVersion;
|
const daemonVersion = packageJSON.lbrySettings.lbrynetDaemonVersion;
|
||||||
const daemonDir = packageJSON.lbrySettings.lbrynetDaemonDir;
|
const daemonDir = path.join(__dirname,'..',packageJSON.lbrySettings.lbrynetDaemonDir);
|
||||||
const daemonFileName = packageJSON.lbrySettings.lbrynetDaemonFileName;
|
let daemonFileName = packageJSON.lbrySettings.lbrynetDaemonFileName;
|
||||||
|
|
||||||
let currentPlatform = os.platform();
|
let currentPlatform = os.platform();
|
||||||
if (currentPlatform === 'darwin') currentPlatform = 'macos';
|
|
||||||
if (currentPlatform === 'win32') currentPlatform = 'windows';
|
|
||||||
|
|
||||||
const daemonPlatform = targetPlatform || currentPlatform;
|
|
||||||
|
|
||||||
|
var daemonPlatform = process.env.TARGET || targetPlatform || currentPlatform;
|
||||||
|
if (daemonPlatform === 'mac' || daemonPlatform === 'darwin') daemonPlatform = 'macos';
|
||||||
|
if (daemonPlatform === 'win32' || daemonPlatform === 'windows') {
|
||||||
|
daemonPlatform = 'windows';
|
||||||
|
daemonFileName = daemonFileName + '.exe';
|
||||||
|
}
|
||||||
|
const daemonFilePath = path.join(daemonDir, daemonFileName);
|
||||||
|
const daemonVersionPath = path.join(__dirname, 'daemon.ver');
|
||||||
|
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';
|
console.log(daemonURL);
|
||||||
|
|
||||||
console.log('\x1b[34minfo\x1b[0m Downloading daemon...');
|
// If a daemon and daemon.ver exists, check to see if it matches the current daemon version
|
||||||
axios
|
const hasDaemonDownloaded = fs.existsSync(daemonFilePath);
|
||||||
.request({
|
const hasDaemonVersion = fs.existsSync(daemonVersionPath);
|
||||||
responseType: 'arraybuffer',
|
let downloadedDaemonVersion;
|
||||||
url: daemonURL,
|
if (hasDaemonVersion) {
|
||||||
method: 'get',
|
downloadedDaemonVersion = fs.readFileSync(daemonVersionPath, "utf8");
|
||||||
headers: {
|
}
|
||||||
'Content-Type': 'application/zip',
|
|
||||||
},
|
if (hasDaemonDownloaded && hasDaemonVersion && downloadedDaemonVersion === daemonVersion) {
|
||||||
})
|
console.log('\x1b[34minfo\x1b[0m Daemon already downloaded');
|
||||||
.then(
|
resolve('Done');
|
||||||
result =>
|
return;
|
||||||
new Promise((newResolve, newReject) => {
|
} else {
|
||||||
fs.writeFile(tmpZipPath, result.data, error => {
|
console.log('\x1b[34minfo\x1b[0m Downloading daemon...');
|
||||||
if (error) return newReject(error);
|
axios
|
||||||
return newResolve();
|
.request({
|
||||||
});
|
responseType: 'arraybuffer',
|
||||||
})
|
url: daemonURL,
|
||||||
)
|
method: 'get',
|
||||||
.then(() => del(`${daemonDir}/${daemonFileName}*`))
|
headers: {
|
||||||
.then(() =>
|
'Content-Type': 'application/zip',
|
||||||
decompress(tmpZipPath, daemonDir, {
|
},
|
||||||
filter: file =>
|
|
||||||
path.basename(file.path).replace(path.extname(file.path), '') === daemonFileName,
|
|
||||||
})
|
})
|
||||||
)
|
.then(
|
||||||
.then(() => {
|
result =>
|
||||||
console.log('\x1b[32msuccess\x1b[0m Daemon downloaded!');
|
new Promise((newResolve, newReject) => {
|
||||||
resolve(true);
|
const distPath = path.join(__dirname, '..', 'dist');
|
||||||
})
|
const hasDistFolder = fs.existsSync(distPath);
|
||||||
.catch(error => {
|
|
||||||
console.error(
|
if (!hasDistFolder) {
|
||||||
`\x1b[31merror\x1b[0m Daemon download failed due to: \x1b[35m${error}\x1b[0m`
|
fs.mkdirSync(distPath);
|
||||||
);
|
}
|
||||||
reject(error);
|
|
||||||
});
|
fs.writeFile(tmpZipPath, result.data, error => {
|
||||||
|
if (error) return newReject(error);
|
||||||
|
return newResolve();
|
||||||
|
});
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.then(() => del(`${daemonFilePath}*`))
|
||||||
|
.then(() => decompress(tmpZipPath, daemonDir, {
|
||||||
|
filter: file =>
|
||||||
|
path.basename(file.path) === daemonFileName,
|
||||||
|
}))
|
||||||
|
.then(() => {
|
||||||
|
console.log('\x1b[32msuccess\x1b[0m Daemon downloaded!');
|
||||||
|
if (hasDaemonVersion) {
|
||||||
|
del(daemonVersionPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.writeFileSync(daemonVersionPath, daemonVersion, "utf8")
|
||||||
|
resolve('Done');
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error(
|
||||||
|
`\x1b[31merror\x1b[0m Daemon download failed due to: \x1b[35m${error}\x1b[0m`
|
||||||
|
);
|
||||||
|
reject(error);
|
||||||
|
})
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = downloadDaemon;
|
module.exports = downloadDaemon;
|
||||||
|
|
|
@ -73,6 +73,5 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"artifactName": "${productName}_${version}.${ext}",
|
"artifactName": "${productName}_${version}.${ext}"
|
||||||
"beforeBuild": "./build/checkDaemonPlatform.js"
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
"release": "yarn compile && electron-builder build",
|
"release": "yarn compile && electron-builder build",
|
||||||
"precommit": "lint-staged",
|
"precommit": "lint-staged",
|
||||||
"preinstall": "yarn cache clean lbry-redux",
|
"preinstall": "yarn cache clean lbry-redux",
|
||||||
"postinstall": "electron-builder install-app-deps & node build/downloadDaemon.js"
|
"postinstall": "electron-builder install-app-deps && node build/downloadDaemon.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bluebird": "^3.5.1",
|
"bluebird": "^3.5.1",
|
||||||
|
|
Loading…
Reference in a new issue