Skip to content

Commit

Permalink
Migrate away from electron-packager directly in favor of electron-forge.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgreene-r7 committed Apr 10, 2023
1 parent 1f40db0 commit 6e282e8
Show file tree
Hide file tree
Showing 5 changed files with 1,401 additions and 38 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ yarn-error.log*
!.yarn/releases
!.yarn/sdks
!.yarn/versions
test-results.xml
102 changes: 102 additions & 0 deletions forge.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
const util = require('node:util');
const fs = require('node:fs');
const path = require('node:path');
const exec = util.promisify(require('node:child_process').exec);
const { globSync } = require('glob');
const awsaml = require('./package.json');

const includeFiles = [
// we need to make sure the project root directory is included
'',
'out',
...globSync('api/**'),
...globSync('build/**'),
...globSync('electron/**'),
'LICENSE.md',
'package.json',
// per electron-packager's docs, a set of files in the node_modules directory are always ignored
// unless we are providing an IgnoreFunction. Because we want to ignore a lot more files than
// packager does by default, we need to ensure that we're including the relevant node_modules
// while ignoring what packager normally would.
// See https://electron.github.io/electron-packager/main/interfaces/electronpackager.options.html#ignore.
...globSync('node_modules/**', {
ignore: [
'node_modules/.bin/**',
'node_modules/electron/**',
'node_modules/electron-prebuilt/**',
'node_modules/electron-prebuilt-compile/**',
],
}),
];

const outDirName = path.join(__dirname, 'out');
const outDirStat = fs.statSync(outDirName, {
throwIfNoEntry: false,
});
const buildDirName = path.join(__dirname, 'build');
const buildDirStat = fs.statSync(buildDirName, {
throwIfNoEntry: false,
});

const config = {
packagerConfig: {
appBundleId: 'com.rapid7.awsaml',
asar: true,
helperBundleId: 'com.rapid7.awsaml.helper',
prune: true,
ignore: (p) => !includeFiles.includes(p.replace('/', '')),
name: 'Awsaml',
},
rebuildConfig: {},
hooks: {
generateAssets: async () => {
// Clear the build directory if it exists
if (buildDirStat && buildDirStat.isDirectory()) {
fs.rmSync(buildDirName, {
force: true,
recursive: true,
});
}

await exec('yarn react-build');
},
prePackage: () => {
// Clear the out directory if it exists
if (outDirStat && outDirStat.isDirectory()) {
fs.rmSync(outDirName, {
force: true,
recursive: true,
});
}
},
},
makers: [
{
name: '@electron-forge/maker-squirrel',
config: {
authors: awsaml.contributors.join(', '),
},
},
{
name: '@electron-forge/maker-zip',
platforms: ['darwin'],
},
{
name: '@electron-forge/maker-deb',
config: {
options: {
homepage: awsaml.repository.url.replace('.git', ''),
maintainer: awsaml.contributors.join(', '),
},
},
},
],
};

// If we're running in Jenkins (or the env indicates we are) attempt to
// code sign.
if (process.env.BUILD_NUMBER && process.env.BUILD_NUMBER !== '') {
config.packagerConfig.osxSign = {};
}

module.exports = config;
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ module.exports = {
testMatch: [
'**/test/**/*.js',
],
reporters: [
'default',
['jest-junit', { outputName: 'test-results.xml' }],
],
};
25 changes: 20 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"version": "2.3.0",
"description": "Periodically refreshes AWS access keys",
"license": "MIT",
"contributors": [
"Opal Mitchell <[email protected]>",
"Dave Greene <[email protected]"
],
"repository": {
"type": "git",
"url": "https://github.com/rapid7/awsaml.git"
Expand All @@ -23,10 +27,12 @@
"lint": "eslint '*.js' 'electron/**/*.js' 'api/**/*.js' 'src/**/*.js' 'test/**/*.js'",
"report": "coveralls < ./coverage/lcov.info",
"prebuild": "rm -rf dist/ && rm -rf build/",
"build": "yarn react-build && node packager.js",
"postbuild": "for platform in `echo $PLATFORM | sed 's/,/ /g'`; do export platform=$platform; npm run zip; done",
"zip": "cd dist/Awsaml-${platform}-x64 && zip -q -y -FS -r ../awsaml-v${npm_package_version}-${platform}-x64.zip .",
"show-appcast-checkpoint": "curl --compressed --location --user-agent 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36' 'https://github.com/rapid7/awsaml/releases.atom' | /usr/bin/sed 's|<pubDate>[^<]*</pubDate>||g' | shasum --algorithm 256"
"build": "yarn prebuild && yarn react-build && node packager.js && yarn postbuild",
"postbuild": "node postbuild.js",
"show-appcast-checkpoint": "curl --compressed --location --user-agent 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36' 'https://github.com/rapid7/awsaml/releases.atom' | /usr/bin/sed 's|<pubDate>[^<]*</pubDate>||g' | shasum --algorithm 256",
"start": "electron-forge start",
"package": "electron-forge package",
"make": "electron-forge make"
},
"homepage": "./",
"proxy": "http://localhost:2600/",
Expand All @@ -37,6 +43,7 @@
"@xmldom/xmldom": "^0.8.7",
"body-parser": "^1.20.2",
"cookie-parser": "^1.4.6",
"electron-squirrel-startup": "^1.0.0",
"express": "^4.18.2",
"express-session": "^1.17.3",
"ini": "^1.3.8",
Expand All @@ -52,8 +59,15 @@
"@babel/eslint-parser": "^7.19.1",
"@babel/preset-env": "^7.21.4",
"@babel/preset-react": "^7.18.6",
"@electron-forge/cli": "^6.1.1",
"@electron-forge/maker-deb": "^6.1.1",
"@electron-forge/maker-rpm": "^6.1.1",
"@electron-forge/maker-squirrel": "^6.1.1",
"@electron-forge/maker-zip": "^6.1.1",
"@electron-forge/plugin-webpack": "^6.1.1",
"@fortawesome/fontawesome-free": "^6.3.0",
"@fortawesome/fontawesome-svg-core": "^6.3.0",
"@fortawesome/free-brands-svg-icons": "^6.3.0",
"@fortawesome/free-regular-svg-icons": "^6.3.0",
"@fortawesome/free-solid-svg-icons": "^6.3.0",
"@fortawesome/react-fontawesome": "^0.2.0",
Expand All @@ -62,7 +76,6 @@
"bootstrap": "^5.2.3",
"coveralls": "^3.1.1",
"electron": "^23.1.2",
"electron-packager": "^17.1.1",
"electron-rebuild": "^3.2.9",
"eslint": "^8.35.0",
"eslint-config-airbnb": "^19.0.4",
Expand All @@ -72,8 +85,10 @@
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"glob": "^10.0.0",
"history": "^5.3.0",
"jest": "^29.5.0",
"jest-junit": "^15.0.0",
"prismjs": "^1.29.0",
"prop-types": "^15.8.1",
"react-is": "^18.2.0",
Expand Down
Loading

0 comments on commit 6e282e8

Please sign in to comment.