Skip to content

Commit b45c0cd

Browse files
committed
Fix forge configuration
1 parent ec2e909 commit b45c0cd

File tree

3 files changed

+48
-37
lines changed

3 files changed

+48
-37
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
22
.DS_Store
3+
out/

forge.config.js

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
const os = require('os');
22
const path = require('path');
33

4+
const platform = os.platform();
5+
const architecture = os.arch();
6+
7+
const applicationNames = {
8+
'darwin': 'MicroPython-Package-Installer',
9+
'win32': 'MicroPython-Package-Installer',
10+
'linux': 'micropython-package-installer'
11+
};
12+
13+
const applicationName = applicationNames[platform];
414
let filesToExclude = [];
5-
switch (os.platform()) {
15+
16+
switch (platform) {
617
case 'win32':
718
filesToExclude = ["(\/bin\/linux$)",
819
"(\/bin\/darwin$)",
@@ -29,7 +40,7 @@ switch (os.platform()) {
2940
break;
3041
}
3142

32-
renamingRules = {
43+
const distributableRenamingRules = {
3344
"darwin": { from: 'darwin', to: 'macOS' },
3445
"win32": { from: 'Setup', to: 'Windows-Setup' },
3546
"linux": { from: 'amd64', to: 'Linux' }
@@ -38,58 +49,48 @@ renamingRules = {
3849
// Check options at https://electron.github.io/electron-packager/main/interfaces/electronpackager.options.html
3950
module.exports = {
4051
hooks: {
41-
postMake: async (forgeConfig, options) => {
52+
postMake: async (forgeConfig, results) => {
4253
const fs = require('fs');
4354

44-
for(let option of options) {
45-
option.artifacts.forEach((artifact, index) => {
55+
for(let result of results) {
56+
result.artifacts.forEach((artifact, index) => {
4657
const fileName = path.basename(artifact);
47-
const renameInfo = renamingRules[option.platform];
48-
const targetName = fileName.replace(renameInfo.from, renameInfo.to);
58+
const renameRule = distributableRenamingRules[result.platform];
59+
60+
if(!fileName.includes(renameRule.from)) {
61+
return;
62+
}
63+
const targetName = fileName.replace(renameRule.from, renameRule.to);
4964
console.log(`Renaming ${fileName} to ${targetName}`);
5065
const targetPath = path.join(path.dirname(artifact), targetName);
5166

5267
try {
5368
fs.renameSync(artifact, targetPath);
54-
option.artifacts[index] = targetPath;
69+
result.artifacts[index] = targetPath;
5570
} catch (err) {
5671
console.error(err);
5772
}
5873
});
5974
}
60-
return options;
75+
return results;
6176
}
6277
},
6378
packagerConfig: {
6479
icon: './assets/app-icon',
65-
name: 'MicroPython Package Installer',
66-
executableName: 'upy-package-installer',
80+
name: applicationName, // Name cannot contain spaces because gyp doesn't support them
81+
arch: 'all',
6782
ignore: filesToExclude,
6883
prune: true,
6984
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();
85+
protocols: [ {
86+
name: 'micropython-package-installer',
87+
schemes: ['micropython-package-installer']
9088
}],
89+
// osxUniversal: {
90+
// outAppPath: './out/' + applicationName + '-darwin-universal.app',
91+
// },
9192
osxSign: {
92-
app: './out/MicroPython Package Installer-darwin-x64/MicroPython Package Installer.app',
93+
app: './out/' + applicationName + '-darwin-' + architecture + '/' + applicationName + '.app',
9394
optionsForFile: (filePath) => {
9495
return {
9596
entitlements: './config/entitlements.plist'
@@ -99,7 +100,7 @@ module.exports = {
99100
},
100101
osxNotarize: process.env.APPLE_API_KEY_PATH ? {
101102
tool: 'notarytool',
102-
appPath: './out/MicroPython Package Installer-darwin-x64/MicroPython Package Installer.app',
103+
appPath: './out/' + applicationName + '-darwin-' + architecture + '/' + applicationName + '.app',
103104
appleApiKey: process.env.APPLE_API_KEY_PATH,
104105
appleApiKeyId: process.env.APPLE_API_KEY_ID,
105106
appleApiIssuer: process.env.APPLE_API_ISSUER,
@@ -115,7 +116,7 @@ module.exports = {
115116
// See: https://js.electronforge.io/interfaces/_electron_forge_maker_squirrel.InternalOptions.WindowsSignOptions.html
116117
// See: https://www.npmjs.com/package/@electron/windows-sign
117118
signWithParams : process.env.WINDOWS_CERTIFICATE_FILE ? [
118-
'/d', '\"MicroPython Installer\"',
119+
'/d', '\"MicroPython Package Installer\"',
119120
'/f', `\"${process.env.WINDOWS_CERTIFICATE_FILE}\"`,
120121
'/csp', '\"eToken Base Cryptographic Provider\"',
121122
'/kc', `\"[{{${process.env.WINDOWS_CERTIFICATE_PASSWORD}}}]=${process.env.WINDOWS_CERTIFICATE_CONTAINER}\"`,

package.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,19 @@
33
"version": "1.0.0",
44
"main": "main.js",
55
"scripts": {
6-
"start": "electron .",
7-
"test": "echo \"Error: no test specified\" && exit 1"
6+
"test": "echo \"Error: no test specified\" && exit 1",
7+
"start": "electron-forge start",
8+
"package": "electron-forge package",
9+
"make": "electron-forge make",
10+
"publish": "electron-forge publish"
811
},
9-
"keywords": [],
12+
"repository": {
13+
"type": "git",
14+
"url": "git+https://github.com/arduino/lab-micropython-package-installer.git"
15+
},
16+
"keywords": [
17+
"MicroPython"
18+
],
1019
"author": {
1120
"name": "Sebastian Romero",
1221
"email": "[email protected]",

0 commit comments

Comments
 (0)