Prevent downloading the daemon if it's not necessary #1798
4 changed files with 65 additions and 41 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";
|
||||||
|
|
|
@ -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(
|
||||||
|
|
|
@ -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,49 +18,75 @@ 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';
|
|
||||||
|
|
||||||
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',
|
||||||
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;
|
||||||
|
|
Loading…
Add table
Reference in a new issue