@@ -50,40 +50,27 @@ if (customUrl) {
5050 }
5151}
5252
53- // Inject build configuration into the main process file
53+ // Create build configuration file
5454try {
55- const mainPath = path . join ( __dirname , '..' , 'src' , 'main' , 'index.js' ) ;
56- console . log ( `\x1b[36mInjecting build configuration into: ${ mainPath } \x1b[0m` ) ;
57-
58- // Read the main file
59- let mainContent = fs . readFileSync ( mainPath , 'utf8' ) ;
60-
61- // Remove any existing injected build configuration
62- mainContent = mainContent . replace (
63- / \/ \/ I n j e c t e d b u i l d c o n f i g u r a t i o n \n c o n s t B U I L D _ C O N F I G = .* ?; \n \n / g,
64- ''
65- ) ;
55+ const buildConfigPath = path . join ( __dirname , '..' , 'src' , 'main' , 'build-config.js' ) ;
56+ console . log ( `\x1b[36mCreating build configuration file: ${ buildConfigPath } \x1b[0m` ) ;
6657
6758 // Define build configuration
6859 const buildConfig = {
6960 packagingMethod : isPortable ? 'portable' : 'installed'
7061 } ;
7162
72- // Inject BUILD_CONFIG before the main logic
73- const buildConfigInjection = `// Injected build configuration
74- const BUILD_CONFIG = ${ JSON . stringify ( buildConfig ) } ;
75-
63+ // Create the build config file content
64+ const buildConfigContent = `// Auto-generated build configuration - do not edit manually
65+ // This file is created during build and should be in .gitignore
66+ module.exports = ${ JSON . stringify ( buildConfig , null , 2 ) } ;
7667` ;
7768
78- // Add it at the beginning of the file (after requires)
79- const requiresEndPattern = / c o n s t i s D e v = ! a p p \. i s P a c k a g e d ; / ;
80- mainContent = mainContent . replace ( requiresEndPattern , `${ buildConfigInjection } const isDev = !app.isPackaged;` ) ;
81-
82- // Write the updated main file back
83- fs . writeFileSync ( mainPath , mainContent , 'utf8' ) ;
84- console . log ( `\x1b[32mBuild configuration injected: ${ JSON . stringify ( buildConfig ) } \x1b[0m` ) ;
69+ // Write the build config file
70+ fs . writeFileSync ( buildConfigPath , buildConfigContent , 'utf8' ) ;
71+ console . log ( `\x1b[32mBuild configuration file created: ${ JSON . stringify ( buildConfig ) } \x1b[0m` ) ;
8572} catch ( error ) {
86- console . error ( `\x1b[31mError injecting build configuration: ${ error . message } \x1b[0m` ) ;
73+ console . error ( `\x1b[31mError creating build configuration file : ${ error . message } \x1b[0m` ) ;
8774 process . exit ( 1 ) ;
8875} // Run the compilation step
8976console . log ( '\x1b[36mCompiling the application...\x1b[0m' ) ;
@@ -127,4 +114,20 @@ try {
127114} catch ( error ) {
128115 console . error ( '\x1b[31mBuild failed!\x1b[0m' ) ;
129116 process . exit ( 1 ) ;
117+ } finally {
118+ // Clean up build configuration file
119+ try {
120+ const buildConfigPath = path . join ( __dirname , '..' , 'src' , 'main' , 'build-config.js' ) ;
121+ console . log ( `\x1b[36mCleaning up build configuration file...\x1b[0m` ) ;
122+
123+ // Remove the build config file if it exists
124+ if ( fs . existsSync ( buildConfigPath ) ) {
125+ fs . unlinkSync ( buildConfigPath ) ;
126+ console . log ( `\x1b[32mBuild configuration file cleaned up successfully!\x1b[0m` ) ;
127+ } else {
128+ console . log ( `\x1b[33mBuild configuration file not found (already cleaned up)\x1b[0m` ) ;
129+ }
130+ } catch ( cleanupError ) {
131+ console . warn ( `\x1b[33mWarning: Could not clean up build configuration file: ${ cleanupError . message } \x1b[0m` ) ;
132+ }
130133}
0 commit comments