refactor: 💡 Import generated config into electron forge config
This commit is contained in:
7 files changed
+107
-95
No files matched your search
@@ -88,8 +88,8 @@ typings/
|
||||
# Electron-Forge
|
||||
out/
|
||||
|
||||
# Electron-Forge config
|
||||
config/forge.config.js
|
||||
# Generated config
|
||||
config/config.js
|
||||
|
||||
# Ember build
|
||||
ember-dist/
|
||||
|
||||
File renamed without changes.
@@ -0,0 +1,63 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// Create config for use in electron forge
|
||||
const createConfig = () => {
|
||||
const configPath = path.join(__dirname, '..', 'config');
|
||||
const macosConfigPath = path.join(configPath, 'macos');
|
||||
const appIconPath = path.join(configPath, 'app-icons', 'icon');
|
||||
|
||||
const config = {
|
||||
name: 'boundary',
|
||||
productName: 'Boundary',
|
||||
bundleId: 'com.electron.boundary',
|
||||
copyright: `Copyright © ${new Date().getFullYear()} HashiCorp, Inc.`,
|
||||
releaseVersion: process.env.RELEASE_VERSION,
|
||||
releaseCommit: process.env.RELEASE_COMMIT,
|
||||
icon: appIconPath,
|
||||
macos: {
|
||||
hardenedRuntime: true,
|
||||
entitlements: path.join(macosConfigPath, 'entitlements.plist'),
|
||||
signatureFlags: 'library',
|
||||
signingIdentity: process.env.BOUNDARY_DESKTOP_SIGNING_IDENTITY,
|
||||
dmg: {
|
||||
diskIcon: path.join(macosConfigPath, 'disk.icns'),
|
||||
background: path.join(macosConfigPath, 'background.png'),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
if (!config.releaseVersion) {
|
||||
config.releaseVersion = '0.0.0';
|
||||
console.warn(
|
||||
`[desktop-config] Release version not specified. Using: ${config.releaseVersion} instead`
|
||||
);
|
||||
}
|
||||
|
||||
console.log(`[desktop-config] Release commit: ${config.releaseCommit}`);
|
||||
console.log(`[desktop-config] Release version: ${config.releaseVersion}`);
|
||||
|
||||
// MacOS signing identity
|
||||
if (!config.macos.signingIdentity)
|
||||
console.warn(
|
||||
'[desktop-config] WARNING: Could not find signing identity. Proceeding without signing.'
|
||||
);
|
||||
|
||||
return config;
|
||||
};
|
||||
|
||||
// Save config file
|
||||
const saveConfig = (config, destination) => {
|
||||
const configPath = `${destination}/config.js`;
|
||||
console.log(`[desktop-config] Config: ${configPath}`);
|
||||
const content = `module.exports = ${JSON.stringify(config, null, 2)}`;
|
||||
fs.writeFileSync(configPath, content);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
setup: () => {
|
||||
const config = createConfig();
|
||||
const destination = path.resolve(__dirname);
|
||||
saveConfig(config, destination);
|
||||
},
|
||||
};
|
||||
@@ -1,85 +0,0 @@
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
|
||||
const DEFAULT_CONFIG = {
|
||||
packagerConfig: {
|
||||
ignore: ['/ember-test(/|$)', '/tests(/|$)'],
|
||||
name: 'Boundary',
|
||||
version: '0.0.0',
|
||||
appBundleId: 'com.electron.boundary',
|
||||
appCopyright: `Copyright © ${new Date().getFullYear()} HashiCorp, Inc.`,
|
||||
},
|
||||
makers: [
|
||||
{
|
||||
name: '@electron-forge/maker-zip',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
// Create forge config based on platform
|
||||
const createConfig = () => {
|
||||
const config = {
|
||||
releaseVersion: process.env.RELEASE_VERSION,
|
||||
releaseCommit: process.env.RELEASE_COMMIT,
|
||||
...DEFAULT_CONFIG,
|
||||
};
|
||||
|
||||
console.log(`[electron-config]
|
||||
Release version: ${config.releaseVersion}
|
||||
Release commit: ${config.releaseVersion}
|
||||
`);
|
||||
|
||||
// Version
|
||||
if (config.releaseVersion)
|
||||
config.packagerConfig.version = config.releaseVersion;
|
||||
|
||||
if (os.platform().match(/(darwin)/i)) {
|
||||
config.packagerConfig.icon = './config/macos/icon.icns';
|
||||
config.packagerConfig.osxSign = {
|
||||
'hardened-runtime': true,
|
||||
entitlements: './config/macos/entitlements.plist',
|
||||
'entitlements-inherit': './config/macos/entitlements.plist',
|
||||
'signature-flags': 'library',
|
||||
};
|
||||
|
||||
// Signing identity
|
||||
const signingIdentity = process.env.BOUNDARY_DESKTOP_SIGNING_IDENTITY;
|
||||
if (signingIdentity) {
|
||||
config.packagerConfig.osxSign.identity = signingIdentity;
|
||||
} else {
|
||||
console.warn(
|
||||
'[electron-config] WARNING: Could not find signing identity. Proceeding without signing.'
|
||||
);
|
||||
}
|
||||
|
||||
// Generate DMG file
|
||||
config.makers.push({
|
||||
name: '@electron-forge/maker-dmg',
|
||||
config: {
|
||||
title: 'Boundary',
|
||||
name: 'boundary',
|
||||
icon: './config/macos/disk.icns',
|
||||
background: './config/macos/background.png',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return config;
|
||||
};
|
||||
|
||||
// Save forge config file
|
||||
const saveConfig = (config, destination) => {
|
||||
const configPath = `${destination}/forge.config.js`;
|
||||
console.log(`[electron-config] ${configPath}`);
|
||||
const content = `module.exports = ${JSON.stringify(config, null, 2)}`;
|
||||
fs.writeFileSync(configPath, content);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
setup: () => {
|
||||
const config = createConfig();
|
||||
const destination = path.resolve(__dirname);
|
||||
saveConfig(config, destination);
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
// Generated during build
|
||||
const config = require('./config.js');
|
||||
|
||||
module.exports = {
|
||||
packagerConfig: {
|
||||
ignore: ['/ember-test(/|$)', '/tests(/|$)'],
|
||||
icon: config.icon,
|
||||
name: config.productName,
|
||||
appVersion: config.version,
|
||||
appBundleId: config.bundleId,
|
||||
appCopyright: config.copyright,
|
||||
osxSign: {
|
||||
identity: config.macos.signingIdentity,
|
||||
'hardened-runtime': config.macos.hardenedRuntime,
|
||||
entitlements: config.macos.entitlements,
|
||||
'entitlements-inherit': config.macos.entitlements,
|
||||
'signature-flags': config.macos.signatureFlags,
|
||||
},
|
||||
},
|
||||
makers: [
|
||||
{
|
||||
name: '@electron-forge/maker-zip',
|
||||
},
|
||||
{
|
||||
name: '@electron-forge/maker-dmg',
|
||||
config: {
|
||||
title: config.productName,
|
||||
name: config.name,
|
||||
icon: config.macos.dmg.diskIcon,
|
||||
background: config.macos.dmg.background,
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -9,7 +9,7 @@
|
||||
"main": "src/index.js",
|
||||
"scripts": {
|
||||
"build:cli": "node -e 'require(\"./config/cli.js\").setup()'",
|
||||
"build:config": "node -e 'require(\"./config/electron.js\").setup()'",
|
||||
"build:config": "node -e 'require(\"./config/desktop.js\").setup()'",
|
||||
"start": "electron-forge start",
|
||||
"package": "electron-forge package",
|
||||
"premake": "yarn build:cli && yarn build:config",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const { app, shell, dialog } = require('electron');
|
||||
const { shell, dialog } = require('electron');
|
||||
const appUpdater = require('../helpers/app-updater.js');
|
||||
const electronConfig = require('../../config/forge.config.js');
|
||||
const config = require('../../config/config.js');
|
||||
const { version } = require('../cli/index.js');
|
||||
|
||||
const generateMenuTemplate = () => {
|
||||
@@ -11,16 +11,16 @@ const generateMenuTemplate = () => {
|
||||
submenu: [
|
||||
// { role: 'about' },
|
||||
{
|
||||
label: `About ${app.getName()}`,
|
||||
label: `About ${config.productName}`,
|
||||
click: () => {
|
||||
const appVersion = `Version: ${electronConfig.releaseVersion}`;
|
||||
const appCommit = `Commit: ${electronConfig.releaseCommit}`;
|
||||
const appVersion = `Version: ${config.releaseVersion}`;
|
||||
const appCommit = `Commit: ${config.releaseCommit}`;
|
||||
const cliVersion = version().formatted;
|
||||
const copyright = electronConfig.packagerConfig.appCopyright;
|
||||
const copyright = config.copyright;
|
||||
|
||||
const dialogOpts = {
|
||||
type: 'none',
|
||||
message: app.getName(),
|
||||
message: config.productName,
|
||||
detail: `${appVersion}\n${appCommit}\n\n${cliVersion}\n\n${copyright}`,
|
||||
};
|
||||
dialog.showMessageBox(dialogOpts);
|
||||
|
||||
Reference in new issue
Block a user