Merge pull request #568 from hashicorp/generate-forge-config-on-build

feat: Generate config file for desktop build
This commit is contained in:
Susmitha Girumala authored and GitHub committed 2021-06-02 13:32:09 -04:00
commit d4a4828b67
11 files changed
+81 -43

No files matched your search

+3
View File
@@ -88,6 +88,9 @@ typings/
# Electron-Forge
out/
# Generated config
config/config.js
# Ember build
ember-dist/
ember-test/
+32
View File
@@ -0,0 +1,32 @@
const fs = require('fs');
const path = require('path');
// Create config for use in electron forge
const createConfig = () => {
const config = {
name: 'boundary',
productName: 'Boundary',
copyright: `Copyright © ${new Date().getFullYear()} HashiCorp, Inc.`,
releaseVersion: process.env.RELEASE_VERSION,
releaseCommit: process.env.RELEASE_COMMIT,
};
if (!config.releaseVersion) config.releaseVersion = '0.0.0';
return config;
};
// Save config file
const saveConfig = (config, destination) => {
const configPath = `${destination}/config.js`;
const content = `module.exports = ${JSON.stringify(config, null, 2)}`;
fs.writeFileSync(configPath, content);
console.log(`Create: ${configPath}`);
};
module.exports = {
setup: () => {
const config = createConfig();
const destination = path.resolve(__dirname);
saveConfig(config, destination);
},
};
+23 -39
View File
@@ -1,59 +1,43 @@
const process = require('process');
const { version } = require('../src/cli/index.js');
// Generated during build
const config = require('./config.js');
const formattedCLIVersion = version().formatted;
console.log(`\n[forge-config] Release commit: ${config.releaseCommit}`);
console.log(`[forge-config] Release version: ${config.releaseVersion}`);
const appVersion = process.env.RELEASE_VERSION
? `Version: ${process.env.RELEASE_VERSION}\n`
: '';
const appCommit = process.env.RELEASE_COMMIT
? `Commit: ${process.env.RELEASE_COMMIT}\n`
: '';
const formattedAppVersion = `${appVersion}${appCommit}`;
// Output version strings for debugging
console.log('\n\nVersion Env Vars:');
console.log('RELEASE_VERSION ', process.env.RELEASE_VERSION);
console.log('RELEASE_COMMIT ', process.env.RELEASE_COMMIT);
// MacOS signing identity
if (process.env.BOUNDARY_DESKTOP_SIGNING_IDENTITY)
console.warn(
'[forge-config] WARNING: Could not find signing identity. Proceeding without signing.'
);
module.exports = {
releaseVersion: process.env.RELEASE_VERSION,
hooks: {
prePackage: () => {
if (!process.env.BOUNDARY_DESKTOP_SIGNING_IDENTITY) {
console.warn('\nWARNING: Could not find signing identity.');
}
},
},
packagerConfig: {
ignore: ['/ember-test(/|$)', '/tests(/|$)'],
name: 'Boundary',
icon: './assets/app-icons/icon',
name: config.productName,
appVersion: config.version,
appBundleId: 'com.electron.boundary',
// TODO: where should the client version number come from?
appVersion: `${formattedAppVersion}${formattedCLIVersion}\n`,
appCopyright: 'Copyright © 2021 HashiCorp, Inc.',
icon: './config/macos/icon.icns',
appCopyright: config.copyright,
osxSign: {
identity: process.env.BOUNDARY_DESKTOP_SIGNING_IDENTITY,
'hardened-runtime': true,
entitlements: './config/macos/entitlements.plist',
'entitlements-inherit': './config/macos/entitlements.plist',
entitlements: './assets/macos/entitlements.plist',
'entitlements-inherit': './assets/macos/entitlements.plist',
'signature-flags': 'library',
},
},
makers: [
{
name: '@electron-forge/maker-dmg',
config: {
title: 'Boundary',
name: 'boundary',
icon: './config/macos/disk.icns',
background: './config/macos/background.png',
},
name: '@electron-forge/maker-zip',
},
{
name: '@electron-forge/maker-zip',
name: '@electron-forge/maker-dmg',
config: {
title: config.productName,
name: config.name,
icon: './assets/macos/disk.icns',
background: './assets/macos/background.png',
},
},
],
};
+2 -1
View File
@@ -9,9 +9,10 @@
"main": "src/index.js",
"scripts": {
"build:cli": "node -e 'require(\"./config/cli.js\").setup()'",
"build:config": "node -e 'require(\"./config/desktop.js\").setup()'",
"start": "electron-forge start",
"package": "electron-forge package",
"premake": "yarn build:cli",
"premake": "yarn build:cli && yarn build:config",
"make": "electron-forge make",
"publish": "electron-forge publish",
"lint": "echo \"No linting configured\""
+20 -2
View File
@@ -1,5 +1,7 @@
const { shell } = require('electron');
const { shell, dialog } = require('electron');
const appUpdater = require('../helpers/app-updater.js');
const config = require('../../config/config.js');
const { version } = require('../cli/index.js');
const generateMenuTemplate = () => {
return [
@@ -7,7 +9,23 @@ const generateMenuTemplate = () => {
{
label: 'Boundary',
submenu: [
{ role: 'about' },
// { role: 'about' },
{
label: `About ${config.productName}`,
click: () => {
const appVersion = `Version: ${config.releaseVersion}`;
const appCommit = `Commit: ${config.releaseCommit}`;
const cliVersion = version().formatted;
const copyright = config.copyright;
const dialogOpts = {
type: 'none',
message: config.productName,
detail: `${appVersion}\n${appCommit}\n\n${cliVersion}\n\n${copyright}`,
};
dialog.showMessageBox(dialogOpts);
},
},
{
id: 'update',
label: 'Check for Updates',
+1 -1
View File
@@ -29,7 +29,7 @@
"format:sass": "prettier --write app/**/*.scss",
"lint:js:fix": "eslint . --fix",
"start": "ember serve",
"prestart:desktop": "cd electron-app && yarn build:cli",
"prestart:desktop": "cd electron-app && yarn premake",
"start:desktop": "ember electron",
"clean:coverage": "rm -rf coverage_*",
"pretest": "yarn clean:coverage",