Skip to content

Commit e04d551

Browse files
Update build scripts to use the new URL propagation method
1 parent 24c5e70 commit e04d551

File tree

4 files changed

+77
-15
lines changed

4 files changed

+77
-15
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ jobs:
4040
if: steps.node-modules-cache.outputs.cache-hit != 'true'
4141
run: npm install
4242

43-
- name: Add URL to source files
44-
run: node addurl.js --url ${{ secrets.SITE_URL }}
45-
env:
46-
NODE_OPTIONS: --unhandled-rejections=warn
47-
4843
- name: Install Snapcraft
4944
if: steps.snapcraft-cache.outputs.cache-hit != 'true' && runner.os == 'Linux'
5045
run: |
@@ -67,15 +62,8 @@ jobs:
6762
restore-keys: |
6863
${{ runner.os }}-electron-
6964
70-
- name: Run build script on Linux and MacOS
71-
if: runner.os == 'Linux' || runner.os == 'macOS'
72-
run: yarn dist
73-
env:
74-
PATH: ./node_modules/.bin:$PATH
75-
76-
- name: Run build script on Windows
77-
if: runner.os == 'Windows'
78-
run: npx yarn dist
65+
- name: Run build script
66+
run: npx yarn dist -- --url ${{ secrets.SITE_URL }}
7967

8068
- name: Zip portable builds
8169
if: runner.os == 'Windows'

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"compile": "electron-webpack",
1111
"dist-64bit": "yarn compile && electron-builder",
1212
"dist-32bit": "yarn compile && electron-builder --ia32",
13-
"dist": "yarn compile && (node -e \"if (process.platform === 'win32') { require('child_process').execSync('npx yarn electron-builder --ia32 --x64', { stdio: 'inherit' }); } else if (process.platform === 'darwin') { require('child_process').execSync('electron-builder --mac --x64', { stdio: 'inherit' }); } else { require('child_process').execSync('electron-builder --linux appimage snap deb rpm pacman', { stdio: 'inherit' }); }\")",
13+
"dist": "node scripts/build.js",
1414
"dist:dir": "yarn dist --dir -c.compression=store -c.mac.identity=null"
1515
},
1616
"dependencies": {

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Join the [Discord Server](https://discord.gg/cHGz362sdC) for the active communit
2222
- Run `npm i` to install all necessary packages
2323
- Run `node addurl.js` and type in the website URL, the launcher is supposed to open. This is a one-time operation that should only be performed if you are not using GitHub Actions. See [Configure GitHub Actions](#configure-github-actions) if using GitHub Actions
2424
- Run `npm run dist` to build the project
25+
- You can specify a custom URL with `npm run dist -- --url https://your-custom-url.com`
2526
- The built files will be available in the dist folder.
2627

2728
### Steps to Debug

scripts/build.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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

Comments
 (0)