Skip to content

Commit

Permalink
Merge pull request #1803 from lbryio/fix-build-tom
Browse files Browse the repository at this point in the history
Improve daemon download process
  • Loading branch information
Sean Yesmunt committed Jul 23, 2018
2 parents 3f2aeb3 + 2030305 commit 04f7acf
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 75 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -4,4 +4,5 @@
/static/locales
yarn-error.log
package-lock.json
.idea/
.idea/
/build/daemon.ver
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -33,7 +33,7 @@ script:
- |
if [ "$TARGET" == "windows" ]; then
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 \
electronuserland/builder:wine \
/bin/bash -c "yarn --link-duplicates --pure-lockfile && yarn build --win --publish onTag";
Expand Down
29 changes: 0 additions & 29 deletions build/checkDaemonPlatform.js

This file was deleted.

110 changes: 69 additions & 41 deletions build/downloadDaemon.js
@@ -1,6 +1,6 @@
/* eslint-disable no-console,import/no-extraneous-dependencies,import/no-commonjs */
const path = require('path');
const fs = require('fs-path');
const fs = require('fs');
const packageJSON = require('../package.json');
const axios = require('axios');
const decompress = require('decompress');
Expand All @@ -11,56 +11,84 @@ const downloadDaemon = targetPlatform =>
new Promise((resolve, reject) => {
const daemonURLTemplate = packageJSON.lbrySettings.lbrynetDaemonUrlTemplate;
const daemonVersion = packageJSON.lbrySettings.lbrynetDaemonVersion;
const daemonDir = packageJSON.lbrySettings.lbrynetDaemonDir;
const daemonFileName = packageJSON.lbrySettings.lbrynetDaemonFileName;
const daemonDir = path.join(__dirname,'..',packageJSON.lbrySettings.lbrynetDaemonDir);
let daemonFileName = packageJSON.lbrySettings.lbrynetDaemonFileName;

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
.replace(/DAEMONVER/g, daemonVersion)
.replace(/OSNAME/g, daemonPlatform);
const tmpZipPath = 'dist/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 =>
new Promise((newResolve, newReject) => {
fs.writeFile(tmpZipPath, result.data, error => {
if (error) return newReject(error);
return newResolve();
});
// If a daemon and daemon.ver exists, check to see if it matches the current daemon version
const hasDaemonDownloaded = fs.existsSync(daemonFilePath);
const hasDaemonVersion = fs.existsSync(daemonVersionPath);
let downloadedDaemonVersion;
if (hasDaemonVersion) {
downloadedDaemonVersion = fs.readFileSync(daemonVersionPath, "utf8");
}

if (hasDaemonDownloaded && hasDaemonVersion && downloadedDaemonVersion === daemonVersion) {
console.log('\x1b[34minfo\x1b[0m Daemon already downloaded');
resolve('Done');
return;
} else {
console.log('\x1b[34minfo\x1b[0m Downloading daemon...');
axios
.request({
responseType: 'arraybuffer',
url: daemonURL,
method: 'get',
headers: {
'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(`${daemonDir}/${daemonFileName}*`))
.then(() =>
decompress(tmpZipPath, daemonDir, {
)
.then(() => del(`${daemonFilePath}*`))
.then(() => decompress(tmpZipPath, daemonDir, {
filter: file =>
path.basename(file.path).replace(path.extname(file.path), '') === daemonFileName,
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);
})
)
.then(() => {
console.log('\x1b[32msuccess\x1b[0m Daemon downloaded!');
resolve(true);
})
.catch(error => {
console.error(
`\x1b[31merror\x1b[0m Daemon download failed due to: \x1b[35m${error}\x1b[0m`
);
reject(error);
});
};
});

module.exports = downloadDaemon;
Expand Down
3 changes: 1 addition & 2 deletions electron-builder.json
Expand Up @@ -73,6 +73,5 @@
}
]
},
"artifactName": "${productName}_${version}.${ext}",
"beforeBuild": "./build/checkDaemonPlatform.js"
"artifactName": "${productName}_${version}.${ext}"
}
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -31,7 +31,7 @@
"release": "yarn compile && electron-builder build",
"precommit": "lint-staged",
"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": {
"bluebird": "^3.5.1",
Expand Down
Empty file removed static/daemon/.gitkeep
Empty file.

0 comments on commit 04f7acf

Please sign in to comment.