11const os = require ( 'os' ) ;
22const 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 ] ;
414let 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
3950module . 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 } \"` ,
0 commit comments