From 52df244e6009328a532c61001f35048908425e0e Mon Sep 17 00:00:00 2001 From: Tony Date: Wed, 10 Nov 2021 21:36:20 -0800 Subject: [PATCH] Pulled electron-builder config out into a function that generates plat-specific config --- packages/app/main/package.json | 129 +------------ .../config/getElectronBuilderConfig.js | 169 ++++++++++++++++++ .../scripts/downloadAndExtractElectron.js | 36 +++- 3 files changed, 206 insertions(+), 128 deletions(-) create mode 100644 packages/app/main/scripts/config/getElectronBuilderConfig.js diff --git a/packages/app/main/package.json b/packages/app/main/package.json index 1e62e67f1..a0b0cf7d8 100644 --- a/packages/app/main/package.json +++ b/packages/app/main/package.json @@ -11,10 +11,10 @@ "rebuild:keytar:electron": "electron-rebuild", "build:electron": "babel ./src --out-dir app/server --extensions \".ts,.tsx\" --ignore \"**/*.spec.ts\" && npm run copy:extension:stubs", "copy:extension:stubs": "ncp src/extensions app/extensions", - "dist": "electron-builder", + "dist": "electron-builder --config scripts/config/getElectronBuilderConfig.js", "lint": "eslint --color --quiet --ext .js,.jsx,.ts,.tsx ./src", "lint:fix": "npm run lint -- --fix", - "pack": "electron-builder --dir", + "pack": "electron-builder --config scripts/config/getElectronBuilderConfig.js --dir", "start": "concurrently --kill-others --names \"electron,react-app\" --success first \"npm run start:electron:dev\" \"npm run start:react-app\"", "start:electron": "./node_modules/.bin/electron --inspect=7777 --remote-debugging-port=7778 .", "start:electron:dev": "cross-env ELECTRON_TARGET_URL=http://localhost:3000/ npm run start:electron", @@ -165,130 +165,5 @@ "tslib": "^1.9.0", "ws": "^5.0.0", "xmldom": "^0.1.27" - }, - "build": { - "asar": true, - "appId": "F3C061A6-FE81-4548-82ED-C1171D9856BB", - "productName": "Bot Framework Emulator", - "copyright": "Copyright © 2018 Microsoft Corporation", - "electronDist": "customElectron", - "protocols": [ - { - "name": "Bot Framework Emulator", - "role": "Viewer", - "schemes": [ - "bfemulator" - ] - } - ], - "fileAssociations": [ - { - "name": "Bot", - "ext": "bot" - }, - { - "name": "Transcript", - "ext": "transcript" - } - ], - "asarUnpack": [ - "app/extensions/**", - "node_modules/@bfemulator/extension-*/**" - ], - "directories": { - "buildResources": "./scripts/config/resources" - }, - "files": [ - "**/*", - "!**/node_modules/*/{README.md,README,readme.md,readme,test}", - "!**/node_modules/.bin", - "!**/*.{o,hprof,orig,pyc,pyo,rbc}", - "!**/._*", - "!**/{.DS_Store,.git,.hg,.svn,CVS,RCS,SCCS,__pycache__,thumbs.db,.gitignore,.gitattributes,.editorconfig,.idea,appveyor.yml,.travis.yml,circle.yml,.babelrc,.eslintignore,.eslintrc.js,.prettierrc,.eslintrc.react.js,.node-version}", - "!.vscode${/*}", - "!doc${/*}", - "!**/{tsconfig.json,README.md,getlicenses.cmd}", - "!**/node_modules/@types", - "!./scripts", - "!**/cache", - "!./installer" - ], - "win": { - "artifactName": "BotFramework-Emulator-${version}-windows-setup.${ext}", - "icon": "./scripts/config/resources/icon.ico", - "target": [ - { - "target": "nsis", - "arch": [ - "ia32" - ] - } - ] - }, - "nsis": { - "include": "./scripts/config/resources/nsis/installer.nsh", - "perMachine": false, - "allowElevation": true, - "allowToChangeInstallationDirectory": true, - "packElevateHelper": true, - "unicode": true, - "runAfterFinish": true, - "installerHeader": "./scripts/config/resources/nsis/installerHeader.bmp", - "installerIcon": "./scripts/config/resources/icon.ico", - "installerSidebar": "./scripts/config/resources/nsis/installerSidebar.bmp", - "uninstallerIcon": "./scripts/config/resources/icon.ico", - "uninstallerSidebar": "./scripts/config/resources/nsis/installerSidebar.bmp", - "createDesktopShortcut": true, - "createStartMenuShortcut": true, - "shortcutName": "Bot Framework Emulator (V4)", - "oneClick": false - }, - "mac": { - "artifactName": "BotFramework-Emulator-${version}-mac.${ext}", - "category": "public.app-category.developer-tools", - "target": [ - { - "target": "dmg", - "arch": [ - "x64" - ] - } - ], - "extendInfo": { - "NSMicrophoneUsageDescription": "This app requires microphone access to record audio." - }, - "entitlements": "./scripts/config/resources/entitlements.plist" - }, - "dmg": { - "background": "./scripts/config/resources/background.tiff", - "icon": "./scripts/config/resources/emulator_dmg.icns", - "title": "Bot Framework Emulator Installer", - "contents": [ - { - "x": 140, - "y": 244 - }, - { - "x": 380, - "y": 244, - "type": "link", - "path": "/Applications" - } - ] - }, - "linux": { - "artifactName": "BotFramework-Emulator-${version}-${platform}-${arch}.${ext}", - "category": "Development", - "target": [ - { - "target": "AppImage", - "arch": [ - "x64" - ] - } - ] - }, - "publish": null, - "remoteBuild": false } } diff --git a/packages/app/main/scripts/config/getElectronBuilderConfig.js b/packages/app/main/scripts/config/getElectronBuilderConfig.js new file mode 100644 index 000000000..35c53d592 --- /dev/null +++ b/packages/app/main/scripts/config/getElectronBuilderConfig.js @@ -0,0 +1,169 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. +// +// Microsoft Bot Framework: http://botframework.com +// +// Bot Framework Emulator Github: +// https://github.com/Microsoft/BotFramwork-Emulator +// +// Copyright (c) Microsoft Corporation +// All rights reserved. +// +// MIT License: +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +const packageJson = require('../../package.json'); +const electronVersion = packageJson.devDependencies.electron; + +const baseConfig = { + asar: true, + appId: 'F3C061A6-FE81-4548-82ED-C1171D9856BB', + productName: 'Bot Framework Emulator', + copyright: 'Copyright © 2018 Microsoft Corporation', + protocols: [ + { + name: 'Bot Framework Emulator', + role: 'Viewer', + schemes: ['bfemulator'], + }, + ], + fileAssociations: [ + { + name: 'Bot', + ext: 'bot', + }, + { + name: 'Transcript', + ext: 'transcript', + }, + ], + asarUnpack: ['app/extensions/**', 'node_modules/@bfemulator/extension-*/**'], + directories: { + buildResources: './scripts/config/resources', + }, + files: [ + '**/*', + '!**/node_modules/*/{README.md,README,readme.md,readme,test}', + '!**/node_modules/.bin', + '!**/*.{o,hprof,orig,pyc,pyo,rbc}', + '!**/._*', + '!**/{.DS_Store,.git,.hg,.svn,CVS,RCS,SCCS,__pycache__,thumbs.db,.gitignore,.gitattributes,.editorconfig,.idea,appveyor.yml,.travis.yml,circle.yml,.babelrc,.eslintignore,.eslintrc.js,.prettierrc,.eslintrc.react.js,.node-version}', + '!.vscode${/*}', + '!doc${/*}', + '!**/{tsconfig.json,README.md,getlicenses.cmd}', + '!**/node_modules/@types', + '!./scripts', + '!**/cache', + '!./installer', + ], + win: { + artifactName: 'BotFramework-Emulator-${version}-windows-setup.${ext}', + icon: './scripts/config/resources/icon.ico', + target: [ + { + target: 'nsis', + arch: ['ia32'], + }, + ], + }, + nsis: { + include: './scripts/config/resources/nsis/installer.nsh', + perMachine: false, + allowElevation: true, + allowToChangeInstallationDirectory: true, + packElevateHelper: true, + unicode: true, + runAfterFinish: true, + installerHeader: './scripts/config/resources/nsis/installerHeader.bmp', + installerIcon: './scripts/config/resources/icon.ico', + installerSidebar: './scripts/config/resources/nsis/installerSidebar.bmp', + uninstallerIcon: './scripts/config/resources/icon.ico', + uninstallerSidebar: './scripts/config/resources/nsis/installerSidebar.bmp', + createDesktopShortcut: true, + createStartMenuShortcut: true, + shortcutName: 'Bot Framework Emulator (V4)', + oneClick: false, + }, + mac: { + artifactName: 'BotFramework-Emulator-${version}-mac.${ext}', + category: 'public.app-category.developer-tools', + target: [ + { + target: 'dmg', + arch: ['x64'], + }, + ], + extendInfo: { + NSMicrophoneUsageDescription: 'This app requires microphone access to record audio.', + }, + entitlements: './scripts/config/resources/entitlements.plist', + }, + dmg: { + background: './scripts/config/resources/background.tiff', + icon: './scripts/config/resources/emulator_dmg.icns', + title: 'Bot Framework Emulator Installer', + contents: [ + { + x: 140, + y: 244, + }, + { + x: 380, + y: 244, + type: 'link', + path: '/Applications', + }, + ], + }, + linux: { + artifactName: 'BotFramework-Emulator-${version}-${platform}-${arch}.${ext}', + category: 'Development', + target: [ + { + target: 'AppImage', + arch: ['x64'], + }, + ], + }, + publish: null, + remoteBuild: false, +}; + +module.exports = () => { + if (process.platform === 'win32') { + // on Windows we need to manually download the internal Electron binary + // and then unsign it before packing it up to be signed + return { + ...baseConfig, + electronDist: 'customElectron', + }; + } else { + // on Mac and Linux we will download the internal Electron binary as-is + // during the electron-builder pack call + return { + ...baseConfig, + electronDownload: { + version: electronVersion, + }, + }; + } +}; diff --git a/packages/app/main/scripts/downloadAndExtractElectron.js b/packages/app/main/scripts/downloadAndExtractElectron.js index f7751440c..321785b7e 100644 --- a/packages/app/main/scripts/downloadAndExtractElectron.js +++ b/packages/app/main/scripts/downloadAndExtractElectron.js @@ -1,6 +1,40 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. +// +// Microsoft Bot Framework: http://botframework.com +// +// Bot Framework Emulator Github: +// https://github.com/Microsoft/BotFramwork-Emulator +// +// Copyright (c) Microsoft Corporation +// All rights reserved. +// +// MIT License: +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +const { join } = require('path'); + const { download } = require('@electron/get'); const extract = require('extract-zip'); -const { join } = require('path'); const packageJson = require('../package.json'); const electronVersion = packageJson.devDependencies.electron;