Skip to content

Commit 9a0f0eb

Browse files
Avoid any duplicate build configs
1 parent d0e4c0b commit 9a0f0eb

File tree

3 files changed

+40
-30
lines changed

3 files changed

+40
-30
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
dist/
22
node_modules/
33
yarn-error.log
4-
yarn.lock
4+
yarn.lock
5+
6+
# Build configuration file (auto-generated during build)
7+
src/main/build-config.js

scripts/build.js

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,40 +50,27 @@ if (customUrl) {
5050
}
5151
}
5252

53-
// Inject build configuration into the main process file
53+
// Create build configuration file
5454
try {
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-
/\/\/ Injected build configuration\nconst BUILD_CONFIG = .*?;\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 = /const isDev = !app\.isPackaged;/;
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
8976
console.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
}

src/main/index.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ const url = require("url");
55
// Import centralized configuration
66
const { createConfig } = require("../config");
77

8+
// Import build configuration safely (file may not exist in development)
9+
let buildConfig = {};
10+
try {
11+
buildConfig = require("./build-config");
12+
} catch (error) {
13+
// build-config.js doesn't exist, use empty config (development mode)
14+
buildConfig = {};
15+
}
16+
817
// Helper function to create proper file URLs
918
function pathToFileURL(filePath) {
1019
const formattedPath = path.resolve(filePath).replace(/\\/g, '/');
@@ -18,14 +27,9 @@ if (process.platform == "win32") {
1827
}
1928
let win;
2029
let pluginName;
21-
// Injected build configuration
22-
const BUILD_CONFIG = {"packagingMethod":"installed"};
23-
2430
const isDev = !app.isPackaged;
2531

2632
// Create configuration with proper isDev detection and build config
27-
// BUILD_CONFIG will be replaced during build process
28-
const buildConfig = typeof BUILD_CONFIG !== 'undefined' ? BUILD_CONFIG : {};
2933
const config = createConfig(isDev, buildConfig);
3034

3135
let rendererPath, preloadPath;

0 commit comments

Comments
 (0)