Skip to content

Commit 0b7f2bc

Browse files
committed
build: release dist refactor for tauri
1 parent da38b30 commit 0b7f2bc

6 files changed

Lines changed: 111 additions & 105 deletions

File tree

package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@
66
"scripts": {
77
"tauri": "tauri",
88
"tauriBuildDemoApp": "node src-build/createDemoReleaseConfig.js && tauri build --config ./src-tauri/tauri-local.conf.json",
9-
"_createDistReleaseConfig": "node src-build/createDistReleaseConfig.js",
10-
"_createDistBundleReleaseConfig": "node src-build/createDistBundleReleaseConfig.js",
119
"_createDistTestReleaseConfig": "node src-build/createDistTestReleaseConfig.js",
1210
"_ci-createDistReleaseConfig": "node src-build/ci-createDistReleaseConfig.js",
1311
"_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.",
1412
"releaseSrc": "node src-build/createSrcRelease.js",
1513
"releaseSrcDebug": "node src-build/createSrcRelease.js --debug",
16-
"releaseDist": "npm run _make_src-node && npm run _createDistReleaseConfig && tauri build --config ./src-tauri/tauri-local.conf.json",
17-
"releaseDistBundle": "npm run _make_src-node && npm run _createDistBundleReleaseConfig && tauri build --config ./src-tauri/tauri-local.conf.json --verbose",
18-
"releaseDistDebug": "npm run _make_src-node && npm run _createDistReleaseConfig && tauri build --config ./src-tauri/tauri-local.conf.json --debug --verbose",
14+
"releaseDist": "node src-build/createDistRelease.js",
15+
"releaseDistBundle": "node src-build/createDistRelease.js --bundle",
16+
"releaseDistDebug": "node src-build/createDistRelease.js --debug",
1917
"releaseDistTest": "npm run _make_src-node && npm run _createDistTestReleaseConfig && tauri build --config ./src-tauri/tauri-local.conf.json",
2018
"releaseDistTestDebug": "npm run _make_src-node && npm run _createDistTestReleaseConfig && tauri build --config ./src-tauri/tauri-local.conf.json --debug",
2119
"_make_src-node": "node ./src-build/makeSrcNode.js ../phoenix/src-node",

src-build/createDistBundleReleaseConfig.js

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

src-build/createDistRelease.js

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import { execSync } from 'child_process';
2+
import { fileURLToPath } from 'url';
3+
import { dirname, join } from 'path';
4+
import fs from 'fs';
5+
import os from 'os';
6+
import chalk from 'chalk';
7+
import { getPlatformDetails, patchTauriConfigWithMetricsHTML } 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 isBundle = args.includes('--bundle');
16+
const isDebug = args.includes('--debug');
17+
const { platform } = getPlatformDetails();
18+
19+
// Print build info
20+
console.log(chalk.cyan('\n=== Phoenix Code Dist Release Build ===\n'));
21+
console.log(`Platform: ${platform}, Bundle: ${isBundle}, Debug: ${isDebug}\n`);
22+
23+
function run(cmd, options = {}) {
24+
console.log(chalk.blue(`> ${cmd}`));
25+
execSync(cmd, { stdio: 'inherit', ...options });
26+
}
27+
28+
function setupSrcNode() {
29+
console.log(chalk.cyan('\n=== Setting up src-node ===\n'));
30+
const srcNodeSource = join(projectRoot, '..', 'phoenix', 'src-node');
31+
const destPath = join(projectRoot, 'src-tauri', 'src-node');
32+
33+
console.log(`Setting up ${destPath}...`);
34+
run(`shx rm -rf "${destPath}"`);
35+
run(`shx cp -r "${srcNodeSource}" "${destPath}"`);
36+
console.log('Installing production dependencies...');
37+
execSync('npm ci --production', { cwd: destPath, stdio: 'inherit' });
38+
// Remove unsupported musl binaries
39+
execSync(`shx rm -f "${destPath}/node_modules/@msgpackr-extract/msgpackr-extract-linux-*/*.musl.node"`, { stdio: 'pipe' });
40+
execSync(`shx rm -f "${destPath}/node_modules/@lmdb/lmdb-linux-*/*.musl.node"`, { stdio: 'pipe' });
41+
}
42+
43+
function createDistConfig() {
44+
console.log(chalk.cyan('\n=== Creating Tauri Config ===\n'));
45+
const tauriConfigPath = join(projectRoot, 'src-tauri', 'tauri.conf.json');
46+
const tauriLocalConfigPath = join(projectRoot, 'src-tauri', 'tauri-local.conf.json');
47+
48+
console.log('Reading Tauri config file:', tauriConfigPath);
49+
let configJson = JSON.parse(fs.readFileSync(tauriConfigPath));
50+
51+
if (isBundle) {
52+
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'));
53+
configJson.tauri.bundle.active = true;
54+
configJson.tauri.updater.active = false;
55+
} else {
56+
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'));
57+
configJson.tauri.bundle.active = false;
58+
}
59+
60+
configJson.build.distDir = '../../phoenix/dist/';
61+
62+
const phoenixVersion = configJson.package.version;
63+
if (os.platform() === 'win32') {
64+
configJson.tauri.windows[0].url = `https://phtauri.localhost/v${phoenixVersion}/`;
65+
configJson.tauri.windows[2].url = `https://phtauri.localhost/v${phoenixVersion}/drop-files.html`;
66+
} else {
67+
configJson.tauri.windows[0].url = `phtauri://localhost/v${phoenixVersion}/`;
68+
configJson.tauri.windows[2].url = `phtauri://localhost/v${phoenixVersion}/drop-files.html`;
69+
}
70+
71+
if (os.platform() === 'darwin') {
72+
// inject macos icons
73+
configJson.tauri.bundle.icon = [
74+
"icons-mac/32x32.png",
75+
"icons-mac/128x128.png",
76+
"icons-mac/128x128@2x.png",
77+
"icons-mac/icon.icns",
78+
"icons-mac/icon.ico"
79+
];
80+
}
81+
82+
patchTauriConfigWithMetricsHTML(configJson);
83+
console.log('Window Boot url:', configJson.tauri.windows[0].url);
84+
console.log('Writing new local config json:', tauriLocalConfigPath);
85+
fs.writeFileSync(tauriLocalConfigPath, JSON.stringify(configJson, null, 4));
86+
}
87+
88+
function buildTauri() {
89+
console.log(chalk.cyan('\n=== Building Tauri ===\n'));
90+
const debugFlags = isDebug ? '--debug --verbose' : '';
91+
const verboseFlag = isBundle && !isDebug ? '--verbose' : '';
92+
run(`tauri build --config ./src-tauri/tauri-local.conf.json ${debugFlags} ${verboseFlag}`.trim().replace(/\s+/g, ' '));
93+
}
94+
95+
async function main() {
96+
setupSrcNode();
97+
createDistConfig();
98+
buildTauri();
99+
console.log(chalk.green('\n=== Dist release build complete! ===\n'));
100+
}
101+
102+
main().catch(err => {
103+
console.error(chalk.red('Build failed:'), err);
104+
process.exit(1);
105+
});

src-build/createDistReleaseConfig.js

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

src-build/createSrcRelease.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ function buildElectron() {
141141
const phoenixDistSrc = join(phoenixDir, 'src');
142142
const phoenixDistDest = join(projectRoot, 'src-electron', 'phoenix-dist');
143143

144-
// Build phoenix production dist
144+
// Build phoenix dev src
145145
console.log('Building Phoenix');
146146
run('npm run build', { cwd: phoenixDir });
147147

src-build/serveForPlatform.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,10 @@ if (target !== recommendedTarget) {
4242

4343
console.log(`Platform: ${platform}, target: ${target}`);
4444

45-
// Run common setup
46-
console.log('\nEnsure to start phoenix server at http://localhost:8000 for development.');
47-
console.log('Follow https://github.com/phcode-dev/phoenix#running-phoenix for instructions.\n');
48-
4945
// Run platform-specific command
5046
if (target === "tauri") {
47+
console.log('\nEnsure to start phoenix server at http://localhost:8000 for development.');
48+
console.log('Follow https://github.com/phcode-dev/phoenix#running-phoenix for instructions.\n');
5149
console.log('Setting up src-node...');
5250
await execa("npm", ["run", "_make_src-node"], {stdio: "inherit"});
5351

0 commit comments

Comments
 (0)