Prevent downloading the daemon if it's not necessary #1798

Closed
neb-b wants to merge 6 commits from fix-build into master
4 changed files with 65 additions and 41 deletions

View file

@ -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";

View file

@ -12,11 +12,9 @@ const downloadDaemon = require('./downloadDaemon');
module.exports = context => { module.exports = context => {
let currentPlatform = os.platform(); let currentPlatform = os.platform();
if (currentPlatform === 'darwin') currentPlatform = 'macoss';
if (currentPlatform === 'win32') currentPlatform = 'windows'; if (currentPlatform === 'win32') currentPlatform = 'windows';
let buildingPlatformTarget = context.platform.toString(); let buildingPlatformTarget = context.platform.toString();
if (buildingPlatformTarget === 'mac') buildingPlatformTarget = 'macos';
if (buildingPlatformTarget !== currentPlatform) { if (buildingPlatformTarget !== currentPlatform) {
console.log( console.log(

View file

@ -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');
@ -18,13 +18,28 @@ const downloadDaemon = targetPlatform =>
if (currentPlatform === 'darwin') currentPlatform = 'macos'; if (currentPlatform === 'darwin') currentPlatform = 'macos';
if (currentPlatform === 'win32') currentPlatform = 'windows'; if (currentPlatform === 'win32') currentPlatform = 'windows';
const daemonFilePath = path.join(daemonDir, daemonFileName);
const daemonVersionPath = path.join(__dirname, 'daemon.ver');
const daemonPlatform = targetPlatform || currentPlatform; const daemonPlatform = targetPlatform || currentPlatform;
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';
// 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...'); console.log('\x1b[34minfo\x1b[0m Downloading daemon...');
axios axios
.request({ .request({
@ -38,29 +53,40 @@ const downloadDaemon = targetPlatform =>
.then( .then(
result => result =>
new Promise((newResolve, newReject) => { 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 => { fs.writeFile(tmpZipPath, result.data, error => {
if (error) return newReject(error); if (error) return newReject(error);
return newResolve(); return newResolve();
}); });
}) })
) )
.then(() => del(`${daemonDir}/${daemonFileName}*`)) .then(() => del(`${daemonFilePath}*`))
.then(() => .then(() => decompress(tmpZipPath, daemonDir, {
decompress(tmpZipPath, daemonDir, {
filter: file => filter: file =>
path.basename(file.path).replace(path.extname(file.path), '') === daemonFileName, path.basename(file.path) === daemonFileName,
}) }))
)
.then(() => { .then(() => {
console.log('\x1b[32msuccess\x1b[0m Daemon downloaded!'); console.log('\x1b[32msuccess\x1b[0m Daemon downloaded!');
resolve(true); if (hasDaemonVersion) {
del(daemonVersionPath);
}
fs.writeFileSync(daemonVersionPath, daemonVersion, "utf8")
resolve('Done');
}) })
.catch(error => { .catch(error => {
console.error( console.error(
`\x1b[31merror\x1b[0m Daemon download failed due to: \x1b[35m${error}\x1b[0m` `\x1b[31merror\x1b[0m Daemon download failed due to: \x1b[35m${error}\x1b[0m`
); );
reject(error); reject(error);
}); })
};
}); });
module.exports = downloadDaemon; module.exports = downloadDaemon;

View file