Skip to content

Commit ec2e909

Browse files
committed
Add forge config
1 parent 4aba1c5 commit ec2e909

File tree

2 files changed

+163
-0
lines changed

2 files changed

+163
-0
lines changed

config/entitlements.plist

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>com.apple.security.cs.allow-jit</key>
6+
<true/>
7+
<key>com.apple.security.network.client</key>
8+
<true/>
9+
<key>com.apple.security.device.usb</key>
10+
<true/>
11+
<key>com.apple.security.cs.disable-library-validation</key>
12+
<true/>
13+
</dict>
14+
</plist>

forge.config.js

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
const os = require('os');
2+
const path = require('path');
3+
4+
let filesToExclude = [];
5+
switch (os.platform()) {
6+
case 'win32':
7+
filesToExclude = ["(\/bin\/linux$)",
8+
"(\/bin\/darwin$)",
9+
"(\/@serialport\/bindings-cpp\/prebuilds\/android.*)",
10+
"(\/@serialport\/bindings-cpp\/prebuilds\/darwin.*)",
11+
"(\/@serialport\/bindings-cpp\/prebuilds\/linux.*)"
12+
];
13+
break;
14+
case 'darwin':
15+
filesToExclude = ["\/bin\/linux$",
16+
"\/bin\/win32$",
17+
"\/@serialport\/bindings-cpp\/prebuilds\/android.*",
18+
"\/@serialport\/bindings-cpp\/prebuilds\/linux.*",
19+
"\/@serialport\/bindings-cpp\/prebuilds\/win32.*",
20+
];
21+
break;
22+
default:
23+
filesToExclude = ["(\/bin\/darwin$)",
24+
"(\/bin\/win32$)",
25+
"(\/@serialport\/bindings-cpp\/prebuilds\/darwin.*)",
26+
"(\/@serialport\/bindings-cpp\/prebuilds\/android.*)",
27+
"(\/@serialport\/bindings-cpp\/prebuilds\/win32.*)",
28+
];
29+
break;
30+
}
31+
32+
renamingRules = {
33+
"darwin": { from: 'darwin', to: 'macOS' },
34+
"win32": { from: 'Setup', to: 'Windows-Setup' },
35+
"linux": { from: 'amd64', to: 'Linux' }
36+
};
37+
38+
// Check options at https://electron.github.io/electron-packager/main/interfaces/electronpackager.options.html
39+
module.exports = {
40+
hooks: {
41+
postMake: async (forgeConfig, options) => {
42+
const fs = require('fs');
43+
44+
for(let option of options) {
45+
option.artifacts.forEach((artifact, index) => {
46+
const fileName = path.basename(artifact);
47+
const renameInfo = renamingRules[option.platform];
48+
const targetName = fileName.replace(renameInfo.from, renameInfo.to);
49+
console.log(`Renaming ${fileName} to ${targetName}`);
50+
const targetPath = path.join(path.dirname(artifact), targetName);
51+
52+
try {
53+
fs.renameSync(artifact, targetPath);
54+
option.artifacts[index] = targetPath;
55+
} catch (err) {
56+
console.error(err);
57+
}
58+
});
59+
}
60+
return options;
61+
}
62+
},
63+
packagerConfig: {
64+
icon: './assets/app-icon',
65+
name: 'MicroPython Package Installer',
66+
executableName: 'upy-package-installer',
67+
ignore: filesToExclude,
68+
prune: true,
69+
derefSymlinks: true,
70+
afterCopy: [(buildPath, electronVersion, platform, arch, callback) => {
71+
const fs = require('fs');
72+
const path = require('path');
73+
// Remove files under node_modules/@serialport/bindings-cpp/build/node_gyp_bins/
74+
// because the cause notarization issues and they are not needed after building.
75+
// One of the files is a symlink to python which is outside of the app bundle.
76+
// SEE: https://github.com/nodejs/node-gyp/issues/2713#issuecomment-1400959609
77+
const nodeGypBinsDir = path.join(buildPath, 'node_modules/@serialport/bindings-cpp/build/node_gyp_bins/');
78+
// Remove files under node_modules/@serialport/bindings-cpp/prebuilds/
79+
// because they are not needed after building and they cause code signing issues under Windows.
80+
// signtool.exe would e.g. try to sign android-arm\node.napi.armv7.node which will in fail.
81+
const nodeGypPrebuildsDir = path.join(buildPath, 'node_modules/@serialport/bindings-cpp/prebuilds/');
82+
83+
[nodeGypBinsDir, nodeGypPrebuildsDir].forEach(dir => {
84+
if (fs.existsSync(dir)) {
85+
fs.rmSync(dir, { recursive: true });
86+
}
87+
});
88+
89+
callback();
90+
}],
91+
osxSign: {
92+
app: './out/MicroPython Package Installer-darwin-x64/MicroPython Package Installer.app',
93+
optionsForFile: (filePath) => {
94+
return {
95+
entitlements: './config/entitlements.plist'
96+
}
97+
},
98+
keychain: process.env.KEYCHAIN_PATH
99+
},
100+
osxNotarize: process.env.APPLE_API_KEY_PATH ? {
101+
tool: 'notarytool',
102+
appPath: './out/MicroPython Package Installer-darwin-x64/MicroPython Package Installer.app',
103+
appleApiKey: process.env.APPLE_API_KEY_PATH,
104+
appleApiKeyId: process.env.APPLE_API_KEY_ID,
105+
appleApiIssuer: process.env.APPLE_API_ISSUER,
106+
} : undefined,
107+
},
108+
rebuildConfig: {},
109+
makers: [
110+
{
111+
name: '@electron-forge/maker-squirrel',
112+
platforms: ['win32'],
113+
config: {
114+
loadingGif: './assets/installer.gif',
115+
// See: https://js.electronforge.io/interfaces/_electron_forge_maker_squirrel.InternalOptions.WindowsSignOptions.html
116+
// See: https://www.npmjs.com/package/@electron/windows-sign
117+
signWithParams : process.env.WINDOWS_CERTIFICATE_FILE ? [
118+
'/d', '\"MicroPython Installer\"',
119+
'/f', `\"${process.env.WINDOWS_CERTIFICATE_FILE}\"`,
120+
'/csp', '\"eToken Base Cryptographic Provider\"',
121+
'/kc', `\"[{{${process.env.WINDOWS_CERTIFICATE_PASSWORD}}}]=${process.env.WINDOWS_CERTIFICATE_CONTAINER}\"`,
122+
'/fd', '\"sha256\"',
123+
'/tr', '\"http://timestamp.digicert.com\"',
124+
'/td', '\"SHA256\"',
125+
// '/v' // Verbose output
126+
].join(' ') : undefined
127+
},
128+
},
129+
{
130+
name: '@electron-forge/maker-zip',
131+
platforms: ['darwin'],
132+
},
133+
{
134+
name: '@electron-forge/maker-deb',
135+
platforms: ['linux'],
136+
},
137+
],
138+
publishers: [
139+
{
140+
"name": "@electron-forge/publisher-github",
141+
"config": {
142+
"repository": {
143+
"owner": "arduino",
144+
"name": "lab-micropython-package-installer"
145+
}
146+
}
147+
}
148+
]
149+
};

0 commit comments

Comments
 (0)