Skip to content

Commit

Permalink
Add forge config
Browse files Browse the repository at this point in the history
  • Loading branch information
sebromero committed Nov 21, 2024
1 parent 4aba1c5 commit ec2e909
Show file tree
Hide file tree
Showing 2 changed files with 163 additions and 0 deletions.
14 changes: 14 additions & 0 deletions config/entitlements.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.cs.allow-jit</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.device.usb</key>
<true/>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
</dict>
</plist>
149 changes: 149 additions & 0 deletions forge.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
const os = require('os');
const path = require('path');

let filesToExclude = [];
switch (os.platform()) {
case 'win32':
filesToExclude = ["(\/bin\/linux$)",
"(\/bin\/darwin$)",
"(\/@serialport\/bindings-cpp\/prebuilds\/android.*)",
"(\/@serialport\/bindings-cpp\/prebuilds\/darwin.*)",
"(\/@serialport\/bindings-cpp\/prebuilds\/linux.*)"
];
break;
case 'darwin':
filesToExclude = ["\/bin\/linux$",
"\/bin\/win32$",
"\/@serialport\/bindings-cpp\/prebuilds\/android.*",
"\/@serialport\/bindings-cpp\/prebuilds\/linux.*",
"\/@serialport\/bindings-cpp\/prebuilds\/win32.*",
];
break;
default:
filesToExclude = ["(\/bin\/darwin$)",
"(\/bin\/win32$)",
"(\/@serialport\/bindings-cpp\/prebuilds\/darwin.*)",
"(\/@serialport\/bindings-cpp\/prebuilds\/android.*)",
"(\/@serialport\/bindings-cpp\/prebuilds\/win32.*)",
];
break;
}

renamingRules = {
"darwin": { from: 'darwin', to: 'macOS' },
"win32": { from: 'Setup', to: 'Windows-Setup' },
"linux": { from: 'amd64', to: 'Linux' }
};

// Check options at https://electron.github.io/electron-packager/main/interfaces/electronpackager.options.html
module.exports = {
hooks: {
postMake: async (forgeConfig, options) => {
const fs = require('fs');

for(let option of options) {
option.artifacts.forEach((artifact, index) => {
const fileName = path.basename(artifact);
const renameInfo = renamingRules[option.platform];
const targetName = fileName.replace(renameInfo.from, renameInfo.to);
console.log(`Renaming ${fileName} to ${targetName}`);
const targetPath = path.join(path.dirname(artifact), targetName);

try {
fs.renameSync(artifact, targetPath);
option.artifacts[index] = targetPath;
} catch (err) {
console.error(err);
}
});
}
return options;
}
},
packagerConfig: {
icon: './assets/app-icon',
name: 'MicroPython Package Installer',
executableName: 'upy-package-installer',
ignore: filesToExclude,
prune: true,
derefSymlinks: true,
afterCopy: [(buildPath, electronVersion, platform, arch, callback) => {
const fs = require('fs');
const path = require('path');
// Remove files under node_modules/@serialport/bindings-cpp/build/node_gyp_bins/
// because the cause notarization issues and they are not needed after building.
// One of the files is a symlink to python which is outside of the app bundle.
// SEE: https://github.com/nodejs/node-gyp/issues/2713#issuecomment-1400959609
const nodeGypBinsDir = path.join(buildPath, 'node_modules/@serialport/bindings-cpp/build/node_gyp_bins/');
// Remove files under node_modules/@serialport/bindings-cpp/prebuilds/
// because they are not needed after building and they cause code signing issues under Windows.
// signtool.exe would e.g. try to sign android-arm\node.napi.armv7.node which will in fail.
const nodeGypPrebuildsDir = path.join(buildPath, 'node_modules/@serialport/bindings-cpp/prebuilds/');

[nodeGypBinsDir, nodeGypPrebuildsDir].forEach(dir => {
if (fs.existsSync(dir)) {
fs.rmSync(dir, { recursive: true });
}
});

callback();
}],
osxSign: {
app: './out/MicroPython Package Installer-darwin-x64/MicroPython Package Installer.app',
optionsForFile: (filePath) => {
return {
entitlements: './config/entitlements.plist'
}
},
keychain: process.env.KEYCHAIN_PATH
},
osxNotarize: process.env.APPLE_API_KEY_PATH ? {
tool: 'notarytool',
appPath: './out/MicroPython Package Installer-darwin-x64/MicroPython Package Installer.app',
appleApiKey: process.env.APPLE_API_KEY_PATH,
appleApiKeyId: process.env.APPLE_API_KEY_ID,
appleApiIssuer: process.env.APPLE_API_ISSUER,
} : undefined,
},
rebuildConfig: {},
makers: [
{
name: '@electron-forge/maker-squirrel',
platforms: ['win32'],
config: {
loadingGif: './assets/installer.gif',
// See: https://js.electronforge.io/interfaces/_electron_forge_maker_squirrel.InternalOptions.WindowsSignOptions.html
// See: https://www.npmjs.com/package/@electron/windows-sign
signWithParams : process.env.WINDOWS_CERTIFICATE_FILE ? [
'/d', '\"MicroPython Installer\"',
'/f', `\"${process.env.WINDOWS_CERTIFICATE_FILE}\"`,
'/csp', '\"eToken Base Cryptographic Provider\"',
'/kc', `\"[{{${process.env.WINDOWS_CERTIFICATE_PASSWORD}}}]=${process.env.WINDOWS_CERTIFICATE_CONTAINER}\"`,
'/fd', '\"sha256\"',
'/tr', '\"http://timestamp.digicert.com\"',
'/td', '\"SHA256\"',
// '/v' // Verbose output
].join(' ') : undefined
},
},
{
name: '@electron-forge/maker-zip',
platforms: ['darwin'],
},
{
name: '@electron-forge/maker-deb',
platforms: ['linux'],
},
],
publishers: [
{
"name": "@electron-forge/publisher-github",
"config": {
"repository": {
"owner": "arduino",
"name": "lab-micropython-package-installer"
}
}
}
]
};

0 comments on commit ec2e909

Please sign in to comment.