@@ -2,7 +2,7 @@ import { execSync } from 'child_process';
22import { fileURLToPath } from 'url' ;
33import { dirname , join } from 'path' ;
44import fs from 'fs' ;
5- import os from 'os' ;
5+ import * as os from 'os' ;
66import chalk from 'chalk' ;
77import { getPlatformDetails , patchTauriConfigWithMetricsHTML } from './utils.js' ;
88
@@ -16,19 +16,52 @@ const isBundle = args.includes('--bundle');
1616const isDebug = args . includes ( '--debug' ) ;
1717const { platform } = getPlatformDetails ( ) ;
1818
19+ // Determine target from CLI or auto-detect
20+ let target ;
21+ if ( args . includes ( 'electron' ) ) {
22+ target = 'electron' ;
23+ } else if ( args . includes ( 'tauri' ) ) {
24+ target = 'tauri' ;
25+ } else {
26+ // Auto-detect: Linux uses Electron, Windows/Mac use Tauri
27+ target = ( platform === 'linux' ) ? 'electron' : 'tauri' ;
28+ }
29+
1930// Print build info
2031console . log ( chalk . cyan ( '\n=== Phoenix Code Dist Release Build ===\n' ) ) ;
21- console . log ( `Platform: ${ platform } , Bundle: ${ isBundle } , Debug: ${ isDebug } \n` ) ;
32+ console . log ( `Platform: ${ platform } , Target: ${ target } , Bundle: ${ isBundle } ${ isDebug ? ' (debug)' : '' } \n` ) ;
33+ console . log ( chalk . gray ( 'To force a different target:' ) ) ;
34+ console . log ( chalk . gray ( ` npm run releaseDist -- tauri # Force Tauri build` ) ) ;
35+ console . log ( chalk . gray ( ` npm run releaseDist -- electron # Force Electron build\n` ) ) ;
36+
37+ // Warn about non-standard platform/target combinations
38+ const recommendedTarget = ( platform === 'linux' ) ? 'electron' : 'tauri' ;
39+ if ( target !== recommendedTarget ) {
40+ const y = chalk . yellow ;
41+ const b = chalk . bold . yellow ;
42+ const line1 = ` Building ${ target } on ${ platform } is not officially supported.` ;
43+ const line2 = ` Recommended: npm run releaseDist (auto-detects ${ recommendedTarget } for ${ platform } )` ;
44+ const width = Math . max ( 50 , line1 . length , line2 . length ) + 2 ;
45+ const border = '═' . repeat ( width ) ;
46+ const pad = ( str ) => str + ' ' . repeat ( width - str . length ) ;
47+
48+ console . warn ( y ( `╔${ border } ╗` ) ) ;
49+ console . warn ( y ( '║' ) + b ( pad ( ' ⚠️ NON-STANDARD PLATFORM CONFIGURATION' ) ) + y ( '║' ) ) ;
50+ console . warn ( y ( `╠${ border } ╣` ) ) ;
51+ console . warn ( y ( '║' ) + y ( pad ( line1 ) ) + y ( '║' ) ) ;
52+ console . warn ( y ( '║' ) + y ( pad ( line2 ) ) + y ( '║' ) ) ;
53+ console . warn ( y ( `╚${ border } ╝\n` ) ) ;
54+ }
2255
2356function run ( cmd , options = { } ) {
2457 console . log ( chalk . blue ( `> ${ cmd } ` ) ) ;
2558 execSync ( cmd , { stdio : 'inherit' , ...options } ) ;
2659}
2760
28- function setupSrcNode ( ) {
61+ function setupSrcNode ( targetDir ) {
2962 console . log ( chalk . cyan ( '\n=== Setting up src-node ===\n' ) ) ;
3063 const srcNodeSource = join ( projectRoot , '..' , 'phoenix' , 'src-node' ) ;
31- const destPath = join ( projectRoot , 'src-tauri' , 'src-node' ) ;
64+ const destPath = join ( projectRoot , targetDir , 'src-node' ) ;
3265
3366 console . log ( `Setting up ${ destPath } ...` ) ;
3467 run ( `shx rm -rf "${ destPath } "` ) ;
@@ -87,15 +120,70 @@ function createDistConfig() {
87120
88121function buildTauri ( ) {
89122 console . log ( chalk . cyan ( '\n=== Building Tauri ===\n' ) ) ;
123+ setupSrcNode ( 'src-tauri' ) ;
124+ createDistConfig ( ) ;
90125 const debugFlags = isDebug ? '--debug --verbose' : '' ;
91126 const verboseFlag = isBundle && ! isDebug ? '--verbose' : '' ;
92127 run ( `tauri build --config ./src-tauri/tauri-local.conf.json ${ debugFlags } ${ verboseFlag } ` . trim ( ) . replace ( / \s + / g, ' ' ) ) ;
93128}
94129
130+ function createElectronConfig ( ) {
131+ console . log ( chalk . cyan ( '\n=== Creating Electron Config ===\n' ) ) ;
132+ const electronDir = join ( projectRoot , 'src-electron' ) ;
133+ const configPath = join ( electronDir , 'config.json' ) ;
134+ const configEffectivePath = join ( electronDir , 'config-effective.json' ) ;
135+
136+ // Read ../phoenix/dist/config.json to get environment
137+ const phoenixDistConfigPath = join ( projectRoot , '..' , 'phoenix' , 'dist' , 'config.json' ) ;
138+ console . log ( 'Reading Phoenix dist config:' , phoenixDistConfigPath ) ;
139+ const phoenixDistConfig = JSON . parse ( fs . readFileSync ( phoenixDistConfigPath ) ) ;
140+ const environment = phoenixDistConfig . config . environment ; // "dev", "stage", or "production"
141+
142+ // Map environment to config file
143+ const envConfigMap = {
144+ 'dev' : 'config-dev.json' ,
145+ 'stage' : 'config-staging.json' ,
146+ 'production' : 'config-prod.json'
147+ } ;
148+ const envConfigFile = envConfigMap [ environment ] || 'config-dev.json' ;
149+ const envConfigPath = join ( electronDir , envConfigFile ) ;
150+
151+ console . log ( `Environment: ${ environment } -> using ${ envConfigFile } ` ) ;
152+
153+ // Merge config.json + env-specific config
154+ const baseConfig = JSON . parse ( fs . readFileSync ( configPath ) ) ;
155+ const envConfig = JSON . parse ( fs . readFileSync ( envConfigPath ) ) ;
156+ const effectiveConfig = { ...baseConfig , ...envConfig } ;
157+
158+ console . log ( 'phoenixLoadURL:' , effectiveConfig . phoenixLoadURL ) ;
159+ console . log ( 'gaMetricsURL:' , effectiveConfig . gaMetricsURL ) ;
160+ fs . writeFileSync ( configEffectivePath , JSON . stringify ( effectiveConfig , null , 2 ) ) ;
161+ }
162+
163+ function buildElectron ( ) {
164+ console . log ( chalk . cyan ( '\n=== Building Electron AppImage ===\n' ) ) ;
165+ setupSrcNode ( 'src-electron' ) ;
166+ createElectronConfig ( ) ;
167+
168+ const phoenixDistSrc = join ( projectRoot , '..' , 'phoenix' , 'dist' ) ;
169+ const phoenixDistDest = join ( projectRoot , 'src-electron' , 'phoenix-dist' ) ;
170+
171+ // Copy dist to electron
172+ console . log ( 'Copying phoenix dist...' ) ;
173+ run ( `shx rm -rf "${ phoenixDistDest } "` ) ;
174+ run ( `shx cp -r "${ phoenixDistSrc } " "${ phoenixDistDest } "` ) ;
175+
176+ // Build AppImage
177+ console . log ( 'Building AppImage...' ) ;
178+ run ( 'npm run build:appimage' , { cwd : join ( projectRoot , 'src-electron' ) } ) ;
179+ }
180+
95181async function main ( ) {
96- setupSrcNode ( ) ;
97- createDistConfig ( ) ;
98- buildTauri ( ) ;
182+ if ( target === 'tauri' ) {
183+ buildTauri ( ) ;
184+ } else {
185+ buildElectron ( ) ;
186+ }
99187 console . log ( chalk . green ( '\n=== Dist release build complete! ===\n' ) ) ;
100188}
101189
0 commit comments