Skip to content

Commit 5640d87

Browse files
committed
build: electron dist test build scripts
1 parent da9dad4 commit 5640d87

3 files changed

Lines changed: 191 additions & 51 deletions

File tree

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@
66
"scripts": {
77
"tauri": "tauri",
88
"tauriBuildDemoApp": "node src-build/createDemoReleaseConfig.js && tauri build --config ./src-tauri/tauri-local.conf.json",
9-
"_createDistTestReleaseConfig": "node src-build/createDistTestReleaseConfig.js",
109
"_ci-createDistReleaseConfig": "node src-build/ci-createDistReleaseConfig.js",
1110
"_ci-env-warn": "echo !!!This script is supposed to executed in github actions only. Ignore if you are seeing this message in a github actions log.",
1211
"releaseSrc": "node src-build/createSrcRelease.js",
1312
"releaseSrcDebug": "node src-build/createSrcRelease.js --debug",
1413
"releaseDist": "node src-build/createDistRelease.js",
1514
"releaseDistBundle": "node src-build/createDistRelease.js --bundle",
1615
"releaseDistDebug": "node src-build/createDistRelease.js --debug",
17-
"releaseDistTest": "npm run _make_src-node && npm run _createDistTestReleaseConfig && tauri build --config ./src-tauri/tauri-local.conf.json",
18-
"releaseDistTestDebug": "npm run _make_src-node && npm run _createDistTestReleaseConfig && tauri build --config ./src-tauri/tauri-local.conf.json --debug",
16+
"releaseDistTest": "node src-build/createDistTestRelease.js",
17+
"releaseDistTestDebug": "node src-build/createDistTestRelease.js --debug",
1918
"_make_src-node": "node ./src-build/makeSrcNode.js ../phoenix/src-node",
2019
"_ci_make_src-node": "node ./src-build/makeSrcNode.js phoenix/src-node",
2120
"_ci-clonePhoenixForTests": "npm run _ci-env-warn && node ./src-build/clonePhoenixForTests.js",

src-build/createDistTestRelease.js

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
import { execSync } from 'child_process';
2+
import { fileURLToPath } from 'url';
3+
import { dirname, join } from 'path';
4+
import fs from 'fs';
5+
import * as os from 'os';
6+
import chalk from 'chalk';
7+
import { getPlatformDetails } from './utils.js';
8+
9+
const __filename = fileURLToPath(import.meta.url);
10+
const __dirname = dirname(__filename);
11+
const projectRoot = join(__dirname, '..');
12+
13+
// Parse command line args
14+
const args = process.argv.slice(2);
15+
const isDebug = args.includes('--debug');
16+
const { platform } = getPlatformDetails();
17+
18+
// Determine target from CLI or auto-detect
19+
let target;
20+
if (args.includes('electron')) {
21+
target = 'electron';
22+
} else if (args.includes('tauri')) {
23+
target = 'tauri';
24+
} else {
25+
// Auto-detect: Linux uses Electron, Windows/Mac use Tauri
26+
target = (platform === 'linux') ? 'electron' : 'tauri';
27+
}
28+
29+
// Print build info
30+
console.log(chalk.cyan('\n=== Phoenix Code Dist-Test Release Build ===\n'));
31+
console.log(`Platform: ${platform}, Target: ${target}${isDebug ? ' (debug)' : ''}\n`);
32+
console.log(chalk.gray('To force a different target:'));
33+
console.log(chalk.gray(` npm run releaseDistTest -- tauri # Force Tauri build`));
34+
console.log(chalk.gray(` npm run releaseDistTest -- electron # Force Electron build\n`));
35+
36+
// Warn about non-standard platform/target combinations
37+
const recommendedTarget = (platform === 'linux') ? 'electron' : 'tauri';
38+
if (target !== recommendedTarget) {
39+
const y = chalk.yellow;
40+
const b = chalk.bold.yellow;
41+
const line1 = ` Building ${target} on ${platform} is not officially supported.`;
42+
const line2 = ` Recommended: npm run releaseDistTest (auto-detects ${recommendedTarget} for ${platform})`;
43+
const width = Math.max(50, line1.length, line2.length) + 2;
44+
const border = '═'.repeat(width);
45+
const pad = (str) => str + ' '.repeat(width - str.length);
46+
47+
console.warn(y(`╔${border}╗`));
48+
console.warn(y('║') + b(pad(' ⚠️ NON-STANDARD PLATFORM CONFIGURATION')) + y('║'));
49+
console.warn(y(`╠${border}╣`));
50+
console.warn(y('║') + y(pad(line1)) + y('║'));
51+
console.warn(y('║') + y(pad(line2)) + y('║'));
52+
console.warn(y(`╚${border}╝\n`));
53+
}
54+
55+
function run(cmd, options = {}) {
56+
console.log(chalk.blue(`> ${cmd}`));
57+
execSync(cmd, { stdio: 'inherit', ...options });
58+
}
59+
60+
function setupSrcNode(targetDir) {
61+
console.log(chalk.cyan('\n=== Setting up src-node ===\n'));
62+
const srcNodeSource = join(projectRoot, '..', 'phoenix', 'src-node');
63+
const destPath = join(projectRoot, targetDir, 'src-node');
64+
65+
console.log(`Setting up ${destPath}...`);
66+
run(`shx rm -rf "${destPath}"`);
67+
run(`shx cp -r "${srcNodeSource}" "${destPath}"`);
68+
console.log('Installing production dependencies...');
69+
execSync('npm ci --production', { cwd: destPath, stdio: 'inherit' });
70+
// Remove unsupported musl binaries
71+
execSync(`shx rm -f "${destPath}/node_modules/@msgpackr-extract/msgpackr-extract-linux-*/*.musl.node"`, { stdio: 'pipe' });
72+
execSync(`shx rm -f "${destPath}/node_modules/@lmdb/lmdb-linux-*/*.musl.node"`, { stdio: 'pipe' });
73+
}
74+
75+
function createDistTestConfig() {
76+
console.log(chalk.cyan('\n=== Creating Tauri Config (dist-test) ===\n'));
77+
const tauriConfigPath = join(projectRoot, 'src-tauri', 'tauri.conf.json');
78+
const tauriLocalConfigPath = join(projectRoot, 'src-tauri', 'tauri-local.conf.json');
79+
80+
console.log('Reading Tauri config file:', tauriConfigPath);
81+
let configJson = JSON.parse(fs.readFileSync(tauriConfigPath));
82+
83+
// Test-specific settings
84+
configJson.package.productName = "phoenix-test";
85+
configJson.tauri.windows[0].title = "phoenix-tester";
86+
87+
console.log(chalk.cyan('\n!Only creating executables. Creating msi, appimage and dmg installers are disabled in this build. If you want to create an installer, use: npm run tauri build manually after setting distDir in tauri conf!\n'));
88+
configJson.tauri.bundle.active = false;
89+
90+
configJson.build.distDir = '../../phoenix/dist-test/';
91+
92+
const phoenixVersion = configJson.package.version;
93+
if (os.platform() === 'win32') {
94+
configJson.tauri.windows[0].url = `https://phtauri.localhost/v${phoenixVersion}/`;
95+
} else {
96+
configJson.tauri.windows[0].url = `phtauri://localhost/v${phoenixVersion}/`;
97+
}
98+
99+
// For tests we only need the main window. Other windows seem to be breaking tests in github actions.
100+
configJson.tauri.windows = [configJson.tauri.windows[0]];
101+
102+
if (os.platform() === 'darwin') {
103+
// inject macos icons
104+
configJson.tauri.bundle.icon = [
105+
"icons-mac/32x32.png",
106+
"icons-mac/128x128.png",
107+
"icons-mac/128x128@2x.png",
108+
"icons-mac/icon.icns",
109+
"icons-mac/icon.ico"
110+
];
111+
}
112+
113+
console.log('Window Boot url:', configJson.tauri.windows[0].url);
114+
console.log('Writing new local config json:', tauriLocalConfigPath);
115+
fs.writeFileSync(tauriLocalConfigPath, JSON.stringify(configJson, null, 4));
116+
}
117+
118+
function buildTauri() {
119+
console.log(chalk.cyan('\n=== Building Tauri (dist-test) ===\n'));
120+
setupSrcNode('src-tauri');
121+
createDistTestConfig();
122+
const debugFlags = isDebug ? '--debug --verbose' : '';
123+
run(`tauri build --config ./src-tauri/tauri-local.conf.json ${debugFlags}`.trim().replace(/\s+/g, ' '));
124+
}
125+
126+
function createElectronConfig() {
127+
console.log(chalk.cyan('\n=== Creating Electron Config (dist-test) ===\n'));
128+
const electronDir = join(projectRoot, 'src-electron');
129+
const configPath = join(electronDir, 'config.json');
130+
const configEffectivePath = join(electronDir, 'config-effective.json');
131+
132+
// Read ../phoenix/dist-test/src/config.json to get environment (note: src subfolder for dist-test)
133+
const phoenixDistTestConfigPath = join(projectRoot, '..', 'phoenix', 'dist-test', 'src', 'config.json');
134+
console.log('Reading Phoenix dist-test config:', phoenixDistTestConfigPath);
135+
const phoenixDistTestConfig = JSON.parse(fs.readFileSync(phoenixDistTestConfigPath));
136+
const environment = phoenixDistTestConfig.config.environment; // "dev", "stage", or "production"
137+
138+
// Map environment to config file
139+
const envConfigMap = {
140+
'dev': 'config-dev.json',
141+
'stage': 'config-staging.json',
142+
'production': 'config-prod.json'
143+
};
144+
const envConfigFile = envConfigMap[environment] || 'config-dev.json';
145+
const envConfigPath = join(electronDir, envConfigFile);
146+
147+
console.log(`Environment: ${environment} -> using ${envConfigFile}`);
148+
149+
// Merge config.json + env-specific config
150+
const baseConfig = JSON.parse(fs.readFileSync(configPath));
151+
const envConfig = JSON.parse(fs.readFileSync(envConfigPath));
152+
const effectiveConfig = { ...baseConfig, ...envConfig };
153+
154+
console.log('phoenixLoadURL:', effectiveConfig.phoenixLoadURL);
155+
console.log('gaMetricsURL:', effectiveConfig.gaMetricsURL);
156+
fs.writeFileSync(configEffectivePath, JSON.stringify(effectiveConfig, null, 2));
157+
}
158+
159+
function buildElectron() {
160+
console.log(chalk.cyan('\n=== Building Electron AppImage (dist-test) ===\n'));
161+
setupSrcNode('src-electron');
162+
createElectronConfig();
163+
164+
const phoenixDistTestSrc = join(projectRoot, '..', 'phoenix', 'dist-test');
165+
const phoenixDistDest = join(projectRoot, 'src-electron', 'phoenix-dist');
166+
167+
// Copy dist-test to electron
168+
console.log('Copying phoenix dist-test...');
169+
run(`shx rm -rf "${phoenixDistDest}"`);
170+
run(`shx cp -r "${phoenixDistTestSrc}" "${phoenixDistDest}"`);
171+
172+
// Build AppImage
173+
console.log('Building AppImage...');
174+
run('npm run build:appimage', { cwd: join(projectRoot, 'src-electron') });
175+
}
176+
177+
async function main() {
178+
if (target === 'tauri') {
179+
buildTauri();
180+
} else {
181+
buildElectron();
182+
}
183+
console.log(chalk.green('\n=== Dist-test release build complete! ===\n'));
184+
}
185+
186+
main().catch(err => {
187+
console.error(chalk.red('Build failed:'), err);
188+
process.exit(1);
189+
});

src-build/createDistTestReleaseConfig.js

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)