-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathcreateDistRelease.js
More file actions
201 lines (170 loc) · 8.36 KB
/
Copy pathcreateDistRelease.js
File metadata and controls
201 lines (170 loc) · 8.36 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
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, patchTauriConfigWithMetricsHTML, 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 isBundle = args.includes('--bundle');
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 build info
console.log(chalk.cyan('\n=== Phoenix Code Dist Release Build ===\n'));
console.log(`Platform: ${platform}, Target: ${target}, Bundle: ${isBundle}${isDebug ? ' (debug)' : ''}\n`);
console.log(chalk.gray('To force a different target:'));
console.log(chalk.gray(` npm run releaseDist -- tauri # Force Tauri build`));
console.log(chalk.gray(` npm run releaseDist -- electron # Force Electron 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 releaseDist (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 createDistConfig() {
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 Tauri config file:', tauriConfigPath);
let configJson = JSON.parse(fs.readFileSync(tauriConfigPath));
if (isBundle) {
console.log(chalk.cyan('\n!Updates and signing is disabled while creating msi, appimage and dmg installers. If you want to sign, use tauri build commands directly.\n'));
configJson.tauri.bundle.active = true;
configJson.tauri.updater.active = false;
} else {
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 releaseDistBundle\n'));
configJson.tauri.bundle.active = false;
}
configJson.build.distDir = '../../phoenix/dist/';
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') {
// inject macos icons
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"
];
}
patchTauriConfigWithMetricsHTML(configJson);
console.log('Window Boot url:', configJson.tauri.windows[0].url);
console.log('Writing new local config json:', tauriLocalConfigPath);
fs.writeFileSync(tauriLocalConfigPath, JSON.stringify(configJson, null, 4));
}
function buildTauri() {
console.log(chalk.cyan('\n=== Building Tauri ===\n'));
setupSrcNode('src-tauri');
createDistConfig();
const debugFlags = isDebug ? '--debug --verbose' : '';
const verboseFlag = isBundle && !isDebug ? '--verbose' : '';
run(`tauri build --config ./src-tauri/tauri-local.conf.json ${debugFlags} ${verboseFlag}`.trim().replace(/\s+/g, ' '));
}
function createElectronConfig() {
console.log(chalk.cyan('\n=== Creating Electron Config ===\n'));
const electronDir = join(projectRoot, 'src-electron');
const configPath = join(electronDir, 'config.json');
const configEffectivePath = join(electronDir, 'config-effective.json');
// Read ../phoenix/dist/config.json to get environment
const phoenixDistConfigPath = join(projectRoot, '..', 'phoenix', 'dist', 'config.json');
console.log('Reading Phoenix dist config:', phoenixDistConfigPath);
const phoenixDistConfig = JSON.parse(fs.readFileSync(phoenixDistConfigPath));
const environment = phoenixDistConfig.config.environment; // "dev", "stage", or "production"
// Map environment to config file
const envConfigMap = {
'dev': 'config-dev.json',
'stage': 'config-staging.json',
'production': 'config-prod.json'
};
const envConfigFile = envConfigMap[environment] || 'config-dev.json';
const envConfigPath = join(electronDir, envConfigFile);
console.log(`Environment: ${environment} -> using ${envConfigFile}`);
// Merge config.json + env-specific config
const baseConfig = JSON.parse(fs.readFileSync(configPath));
const envConfig = JSON.parse(fs.readFileSync(envConfigPath));
const effectiveConfig = { ...baseConfig, ...envConfig };
// 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 phoenixDistSrc = join(projectRoot, '..', 'phoenix', 'dist');
const phoenixDistDest = join(projectRoot, 'src-electron', 'phoenix-dist');
// 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=== Dist release build complete! ===\n'));
}
main().catch(err => {
console.error(chalk.red('Build failed:'), err);
process.exit(1);
});