-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathcreateSrcRelease.js
More file actions
179 lines (149 loc) · 7.15 KB
/
Copy pathcreateSrcRelease.js
File metadata and controls
179 lines (149 loc) · 7.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import { execSync } from 'child_process';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
import fs from 'fs';
import * as os from 'os';
import chalk from 'chalk';
import { getPlatformDetails, patchElectronStageBranding } from './utils.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const projectRoot = join(__dirname, '..');
// Parse command line args
const args = process.argv.slice(2);
const isDebug = args.includes('--debug');
const { platform } = getPlatformDetails();
// Determine target from CLI or auto-detect
let target;
if (args.includes('electron')) {
target = 'electron';
} else if (args.includes('tauri')) {
target = 'tauri';
} else {
// Auto-detect: Linux uses Electron, Windows/Mac use Tauri
target = (platform === 'linux') ? 'electron' : 'tauri';
}
// Print override instructions
console.log(chalk.cyan('\n=== Phoenix Code Release Build ===\n'));
console.log(`Platform: ${platform}, Target: ${target}${isDebug ? ' (debug)' : ''}\n`);
console.log(chalk.gray('To force a different target:'));
console.log(chalk.gray(` npm run releaseSrc -- tauri # Force Tauri build`));
console.log(chalk.gray(` npm run releaseSrc -- electron # Force Electron build`));
console.log(chalk.gray(` npm run releaseSrcDebug -- tauri # Force Tauri debug build\n`));
// Warn about non-standard platform/target combinations
const recommendedTarget = (platform === 'linux') ? 'electron' : 'tauri';
if (target !== recommendedTarget) {
const y = chalk.yellow;
const b = chalk.bold.yellow;
const line1 = ` Building ${target} on ${platform} is not officially supported.`;
const line2 = ` Recommended: npm run releaseSrc (auto-detects ${recommendedTarget} for ${platform})`;
const width = Math.max(50, line1.length, line2.length) + 2;
const border = '═'.repeat(width);
const pad = (str) => str + ' '.repeat(width - str.length);
console.warn(y(`╔${border}╗`));
console.warn(y('║') + b(pad(' ⚠️ NON-STANDARD PLATFORM CONFIGURATION')) + y('║'));
console.warn(y(`╠${border}╣`));
console.warn(y('║') + y(pad(line1)) + y('║'));
console.warn(y('║') + y(pad(line2)) + y('║'));
console.warn(y(`╚${border}╝\n`));
}
function run(cmd, options = {}) {
console.log(chalk.blue(`> ${cmd}`));
execSync(cmd, { stdio: 'inherit', ...options });
}
function setupSrcNode(targetDir) {
console.log(chalk.cyan('\n=== Setting up src-node ===\n'));
const srcNodeSource = join(projectRoot, '..', 'phoenix', 'src-node');
const destPath = join(projectRoot, targetDir, 'src-node');
console.log(`Setting up ${destPath}...`);
run(`shx rm -rf "${destPath}"`);
run(`shx cp -r "${srcNodeSource}" "${destPath}"`);
console.log('Installing production dependencies...');
execSync('npm ci --production', { cwd: destPath, stdio: 'inherit' });
// Remove unsupported musl binaries
execSync(`shx rm -f "${destPath}/node_modules/@msgpackr-extract/msgpackr-extract-linux-*/*.musl.node"`, { stdio: 'pipe' });
execSync(`shx rm -f "${destPath}/node_modules/@lmdb/lmdb-linux-*/*.musl.node"`, { stdio: 'pipe' });
}
function createTauriConfig() {
console.log(chalk.cyan('\n=== Creating Tauri Config ===\n'));
const tauriConfigPath = join(projectRoot, 'src-tauri', 'tauri.conf.json');
const tauriLocalConfigPath = join(projectRoot, 'src-tauri', 'tauri-local.conf.json');
console.log('Reading config file:', tauriConfigPath);
let configJson = JSON.parse(fs.readFileSync(tauriConfigPath));
console.log(chalk.cyan('!Only creating executables. Installers are disabled.\n'));
configJson.tauri.bundle.active = false;
configJson.build.distDir = '../../phoenix/src/';
const phoenixVersion = configJson.package.version;
if (os.platform() === 'win32') {
configJson.tauri.windows[0].url = `https://phtauri.localhost/v${phoenixVersion}/`;
configJson.tauri.windows[2].url = `https://phtauri.localhost/v${phoenixVersion}/drop-files.html`;
} else {
configJson.tauri.windows[0].url = `phtauri://localhost/v${phoenixVersion}/`;
configJson.tauri.windows[2].url = `phtauri://localhost/v${phoenixVersion}/drop-files.html`;
}
if (os.platform() === 'darwin') {
configJson.tauri.bundle.icon = [
"icons-mac/32x32.png", "icons-mac/128x128.png",
"icons-mac/128x128@2x.png", "icons-mac/icon.icns", "icons-mac/icon.ico"
];
}
console.log('Window Boot url:', configJson.tauri.windows[0].url);
fs.writeFileSync(tauriLocalConfigPath, JSON.stringify(configJson, null, 4));
}
function buildTauri() {
console.log(chalk.cyan('\n=== Building Tauri ===\n'));
setupSrcNode('src-tauri');
createTauriConfig();
const debugFlags = isDebug ? '--debug --verbose' : '';
run(`tauri build --config ./src-tauri/tauri-local.conf.json ${debugFlags}`.trim());
}
function createElectronConfig() {
console.log(chalk.cyan('\n=== Creating Electron Config ===\n'));
const electronDir = join(projectRoot, 'src-electron');
const configPath = join(electronDir, 'config.json');
const configDevPath = join(electronDir, 'config-dev.json');
const configEffectivePath = join(electronDir, 'config-effective.json');
console.log('Merging config.json + config-dev.json -> config-effective.json');
const baseConfig = JSON.parse(fs.readFileSync(configPath));
const devConfig = JSON.parse(fs.readFileSync(configDevPath));
// Merge: config-dev.json overrides config.json
const effectiveConfig = { ...baseConfig, ...devConfig };
// Inject version from src-electron/package.json
const electronPackagePath = join(electronDir, 'package.json');
const electronPackage = JSON.parse(fs.readFileSync(electronPackagePath));
effectiveConfig.version = electronPackage.version;
console.log('phoenixLoadURL:', effectiveConfig.phoenixLoadURL);
console.log('gaMetricsURL:', effectiveConfig.gaMetricsURL);
console.log('version:', effectiveConfig.version);
fs.writeFileSync(configEffectivePath, JSON.stringify(effectiveConfig, null, 2));
patchElectronStageBranding(electronDir, effectiveConfig.productName);
}
function buildElectron() {
console.log(chalk.cyan('\n=== Building Electron AppImage ===\n'));
setupSrcNode('src-electron');
createElectronConfig();
const phoenixDir = join(projectRoot, '..', 'phoenix');
const phoenixDistSrc = join(phoenixDir, 'src');
const phoenixDistDest = join(projectRoot, 'src-electron', 'phoenix-dist');
// Build phoenix dev src
console.log('Building Phoenix');
run('npm run build', { cwd: phoenixDir });
// Copy dist to electron
console.log('Copying phoenix dist...');
run(`shx rm -rf "${phoenixDistDest}"`);
run(`shx cp -r "${phoenixDistSrc}" "${phoenixDistDest}"`);
// Build AppImage
console.log('Building AppImage...');
run('npm run build:appimage', { cwd: join(projectRoot, 'src-electron') });
}
async function main() {
if (target === 'tauri') {
buildTauri();
} else {
buildElectron();
}
console.log(chalk.green('\n=== Release build complete! ===\n'));
}
main().catch(err => {
console.error(chalk.red('Build failed:'), err);
process.exit(1);
});