|
| 1 | +/** |
| 2 | + * Build script for Sploder-Launcher |
| 3 | + * Handles the build process with URL parameter support |
| 4 | + */ |
| 5 | + |
| 6 | +const { execSync } = require('child_process'); |
| 7 | +const fs = require('fs'); |
| 8 | +const path = require('path'); |
| 9 | + |
| 10 | +// Parse command line arguments |
| 11 | +const args = process.argv.slice(2); |
| 12 | +const urlArgIndex = args.indexOf('--url'); |
| 13 | +let customUrl = null; |
| 14 | + |
| 15 | +if (urlArgIndex !== -1 && args[urlArgIndex + 1]) { |
| 16 | + customUrl = args[urlArgIndex + 1]; |
| 17 | + console.log(`\x1b[36mCustom URL detected: ${customUrl}\x1b[0m`); |
| 18 | +} |
| 19 | + |
| 20 | +// Update config if URL is provided |
| 21 | +if (customUrl) { |
| 22 | + try { |
| 23 | + const configPath = path.join(__dirname, '..', 'src', 'config.js'); |
| 24 | + console.log(`\x1b[36mUpdating config at: ${configPath}\x1b[0m`); |
| 25 | + |
| 26 | + // Read the current config file |
| 27 | + let configContent = fs.readFileSync(configPath, 'utf8'); |
| 28 | + |
| 29 | + // Replace the baseUrl value |
| 30 | + configContent = configContent.replace( |
| 31 | + /baseUrl: ["'].*?["']/, |
| 32 | + `baseUrl: "${customUrl}"` |
| 33 | + ); |
| 34 | + |
| 35 | + // Write the updated config back |
| 36 | + fs.writeFileSync(configPath, configContent, 'utf8'); |
| 37 | + console.log(`\x1b[32mConfig updated with base URL: ${customUrl}\x1b[0m`); |
| 38 | + } catch (error) { |
| 39 | + console.error(`\x1b[31mError updating config: ${error.message}\x1b[0m`); |
| 40 | + process.exit(1); |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +// Run the compilation step |
| 45 | +console.log('\x1b[36mCompiling the application...\x1b[0m'); |
| 46 | +try { |
| 47 | + execSync('yarn compile', { stdio: 'inherit' }); |
| 48 | +} catch (error) { |
| 49 | + console.error('\x1b[31mCompilation failed!\x1b[0m'); |
| 50 | + process.exit(1); |
| 51 | +} |
| 52 | + |
| 53 | +// Run the appropriate electron-builder command based on the platform |
| 54 | +console.log('\x1b[36mBuilding distributable packages...\x1b[0m'); |
| 55 | +try { |
| 56 | + // Pass all original arguments (except --url and the URL) to electron-builder |
| 57 | + const filteredArgs = args.filter((arg, index) => { |
| 58 | + return index !== urlArgIndex && index !== urlArgIndex + 1; |
| 59 | + }).join(' '); |
| 60 | + |
| 61 | + if (process.platform === 'win32') { |
| 62 | + execSync(`npx yarn electron-builder --ia32 --x64 ${filteredArgs}`, { stdio: 'inherit' }); |
| 63 | + } else if (process.platform === 'darwin') { |
| 64 | + execSync(`electron-builder --mac --x64 ${filteredArgs}`, { stdio: 'inherit' }); |
| 65 | + } else { |
| 66 | + execSync(`electron-builder --linux appimage snap deb rpm pacman ${filteredArgs}`, { stdio: 'inherit' }); |
| 67 | + } |
| 68 | + |
| 69 | + console.log('\x1b[32mBuild completed successfully!\x1b[0m'); |
| 70 | +} catch (error) { |
| 71 | + console.error('\x1b[31mBuild failed!\x1b[0m'); |
| 72 | + process.exit(1); |
| 73 | +} |
0 commit comments