@@ -6,7 +6,17 @@ require("dotenv").config({
66} ) ;
77
88const buildEnv = process . env ?. BUILD_ENV || "production" ; // production, staging, development
9- const buildTarget = process . env ?. BUILD_TARGET || process . env ?. ENV_FILE || "unknown" ;
9+ const buildTarget =
10+ process . env ?. BUILD_TARGET || process . env ?. ENV_FILE || "unknown" ;
11+
12+ // Determine which architectures to build based on BUILD_TARGET
13+ const getMacArch = ( ) => {
14+ if ( buildTarget === "darwin-x64" ) return [ "x64" ] ;
15+ if ( buildTarget === "darwin-arm64" ) return [ "arm64" ] ;
16+ // darwin (universal) or fallback: build both
17+ return [ "x64" , "arm64" ] ;
18+ } ;
19+
1020const dir = buildTarget + "/" + dayjs ( ) . format ( "YYYY_MM_DD_HH_mm_ss" ) ;
1121const versionArr = version . split ( "-" ) ;
1222const bundleShortVersion = versionArr [ 0 ] ;
@@ -15,7 +25,9 @@ const bundleVersion = versionArr[1] || versionArr[0];
1525const productName = process . env ?. _PRODUCT_NAME ?? name ;
1626
1727const getAppId = ( ) => {
18- const baseId = process . env ?. _APP_ID || `com.yourcompany.${ name . replace ( / [ ^ a - z 0 - 9 ] / gi, '' ) } ` ;
28+ const baseId =
29+ process . env ?. _APP_ID ||
30+ `com.yourcompany.${ name . replace ( / [ ^ a - z 0 - 9 ] / gi, "" ) } ` ;
1931 if ( buildEnv === "development" ) return `${ baseId } .dev` ;
2032 if ( buildEnv === "staging" ) return `${ baseId } .staging` ;
2133 return baseId ;
@@ -39,56 +51,6 @@ const config = {
3951 to : "assets/icons" ,
4052 } ,
4153 ] ,
42- afterPack : async ( context ) => {
43- const fs = require ( 'fs' ) ;
44- const path = require ( 'path' ) ;
45-
46- // Electron Builder Arch: 0=ia32, 1=x64, 3=arm64
47- const archMap = {
48- 0 : 'ia32' ,
49- 1 : 'x64' ,
50- 3 : 'arm64'
51- } ;
52-
53- const archName = archMap [ context . arch ] ;
54- if ( ! archName ) {
55- console . log ( `[afterPack] Skipping unknown arch: ${ context . arch } ` ) ;
56- return ;
57- }
58-
59- const platform = context . electronPlatformName ; // 'darwin', 'win32', 'linux'
60- const binaryName = platform === 'win32' ? 'node.exe' : 'node' ;
61-
62- // Source: resources/node_bin/<arch>/node
63- // Note: for ia32 we use 'ia32' folder, but download script uses 'ia32' too (mapped from x86 logic if I updated it correctly, let's check).
64- // In download script: if (arch === 'ia32') distArch = 'x86'; folderArch = 'ia32'. Yes.
65-
66- const sourceNode = path . resolve ( __dirname , `./resources/node_bin/${ archName } /${ binaryName } ` ) ;
67-
68- if ( ! fs . existsSync ( sourceNode ) ) {
69- console . warn ( `[afterPack] Warning: Node binary not found at ${ sourceNode } . Skipping copy.` ) ;
70- return ;
71- }
72-
73- // Destination
74- let destNodeDir ;
75- if ( platform === 'darwin' ) {
76- destNodeDir = path . join ( context . appOutDir , 'Contents/Resources/node_bin' ) ;
77- } else {
78- destNodeDir = path . join ( context . appOutDir , 'resources/node_bin' ) ;
79- }
80-
81- if ( ! fs . existsSync ( destNodeDir ) ) {
82- fs . mkdirSync ( destNodeDir , { recursive : true } ) ;
83- }
84-
85- const destNode = path . join ( destNodeDir , binaryName ) ;
86- fs . copyFileSync ( sourceNode , destNode ) ;
87- if ( platform !== 'win32' ) {
88- fs . chmodSync ( destNode , 0o755 ) ;
89- }
90- console . log ( `[afterPack] Copied ${ archName } node binary to ${ destNode } ` ) ;
91- } ,
9254 icon : resolve ( __dirname , `./public/assets/icons/icon.icns` ) ,
9355 asarUnpack : "**\\*.{node,dll}" ,
9456 mac : {
@@ -106,11 +68,11 @@ const config = {
10668 target : [
10769 {
10870 target : "dmg" ,
109- arch : [ "x64" , "arm64" ] ,
71+ arch : getMacArch ( ) ,
11072 } ,
11173 {
11274 target : "zip" ,
113- arch : [ "x64" , "arm64" ] ,
75+ arch : getMacArch ( ) ,
11476 } ,
11577 ] ,
11678 } ,
0 commit comments