diff --git a/packages/app-desktop/gulpfile.js b/packages/app-desktop/gulpfile.js index a41765ff0d..5789d859ba 100644 --- a/packages/app-desktop/gulpfile.js +++ b/packages/app-desktop/gulpfile.js @@ -21,6 +21,9 @@ const tasks = { electronRebuild: { fn: require('./tools/electronRebuild.js'), }, + electronBuilder: { + fn: require('./tools/electronBuilder.js'), + }, tsc: require('@joplin/tools/gulp/tasks/tsc'), updateIgnoredTypeScriptBuild: require('@joplin/tools/gulp/tasks/updateIgnoredTypeScriptBuild'), buildCommandIndex: require('@joplin/tools/gulp/tasks/buildCommandIndex'), diff --git a/packages/app-desktop/package.json b/packages/app-desktop/package.json index 49d6b9f754..3b97945a00 100644 --- a/packages/app-desktop/package.json +++ b/packages/app-desktop/package.json @@ -5,9 +5,10 @@ "main": "main.js", "private": true, "scripts": { - "dist": "yarn run electronRebuild && npx electron-builder", + "dist": "yarn run electronRebuild && yarn run electronBuilder", "build": "gulp build", "postinstall": "yarn run build", + "electronBuilder": "gulp electronBuilder", "electronRebuild": "gulp electronRebuild", "tsc": "tsc --project tsconfig.json", "watch": "tsc --watch --preserveWatchOutput --project tsconfig.json", diff --git a/packages/app-desktop/tools/electronBuilder.js b/packages/app-desktop/tools/electronBuilder.js new file mode 100644 index 0000000000..b74d9fd871 --- /dev/null +++ b/packages/app-desktop/tools/electronBuilder.js @@ -0,0 +1,27 @@ +const execCommand = require('./execCommand'); + +async function main() { + process.chdir(`${__dirname}/..`); + + const maxTries = 3; + + for (let i = 0; i < maxTries; i++) { + try { + console.info(await execCommand(['yarn', 'run', 'electron-builder'].join(' '))); + console.info('electronBuilder: electron-builder completed successfully'); + break; + } catch (error) { + console.info(error.stdout); + console.error(error); + + if (error.stdout.includes('cannot resolve') && i !== maxTries - 1) { + console.info(`electronBuilder: electron-builder could not download an asset - trying again (${i + 1})`); + continue; + } else { + throw error; + } + } + } +} + +module.exports = main; diff --git a/packages/app-desktop/tools/electronRebuild.js b/packages/app-desktop/tools/electronRebuild.js index ba66dd4f10..d61bee7ffa 100644 --- a/packages/app-desktop/tools/electronRebuild.js +++ b/packages/app-desktop/tools/electronRebuild.js @@ -1,22 +1,4 @@ -const execCommand = function(command) { - const exec = require('child_process').exec; - - console.info(`Running: ${command}`); - - return new Promise((resolve, reject) => { - exec(command, (error, stdout) => { - if (error) { - if (error.signal === 'SIGTERM') { - resolve('Process was killed'); - } else { - reject(error); - } - } else { - resolve(stdout.trim()); - } - }); - }); -}; +const execCommand = require('./execCommand'); const isWindows = () => { return process && process.platform === 'win32'; diff --git a/packages/app-desktop/tools/execCommand.js b/packages/app-desktop/tools/execCommand.js new file mode 100644 index 0000000000..64213de891 --- /dev/null +++ b/packages/app-desktop/tools/execCommand.js @@ -0,0 +1,22 @@ +const execCommand = (command) => { + const exec = require('child_process').exec; + + console.info(`Running: ${command}`); + + return new Promise((resolve, reject) => { + exec(command, (error, stdout) => { + if (error) { + if (error.signal === 'SIGTERM') { + resolve('Process was killed'); + } else { + error.stdout = stdout; + reject(error); + } + } else { + resolve(stdout.trim()); + } + }); + }); +}; + +module.exports = execCommand; diff --git a/packages/app-desktop/tools/notarizeMacApp.js b/packages/app-desktop/tools/notarizeMacApp.js index f56f53e39b..805e618fc1 100644 --- a/packages/app-desktop/tools/notarizeMacApp.js +++ b/packages/app-desktop/tools/notarizeMacApp.js @@ -1,24 +1,7 @@ const fs = require('fs'); const path = require('path'); const electron_notarize = require('electron-notarize'); - -function execCommand(command) { - const exec = require('child_process').exec; - - return new Promise((resolve, reject) => { - exec(command, (error, stdout, stderr) => { - if (error) { - if (error.signal === 'SIGTERM') { - resolve('Process was killed'); - } else { - reject(new Error([stdout.trim(), stderr.trim()].join('\n'))); - } - } else { - resolve([stdout.trim(), stderr.trim()].join('\n')); - } - }); - }); -} +const execCommand = require('./execCommand'); function isDesktopAppTag(tagName) { if (!tagName) return false;