Skip to content

Commit 4fc1a08

Browse files
committed
build: npm run serve scripts auto detect tauri/electron based on platform
1 parent df616fd commit 4fc1a08

File tree

2 files changed

+52
-7
lines changed

2 files changed

+52
-7
lines changed

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,15 @@
2121
"releaseDistTestDebug": "npm run _make_src-node && npm run _createDistTestReleaseConfig && tauri build --config ./src-tauri/tauri-local.conf.json --debug",
2222
"_make_src-node": "node ./src-build/makeSrcNode.js ../phoenix/src-node",
2323
"_ci_make_src-node": "node ./src-build/makeSrcNode.js phoenix/src-node",
24-
"_servePhoenix": "echo -e \"\nEnsure to start phoenix server at http://localhost:8000 for development.\n Follow https://github.com/phcode-dev/phoenix#running-phoenix for instructions.\"",
2524
"_ci-clonePhoenixForTests": "npm run _ci-env-warn && node ./src-build/clonePhoenixForTests.js",
2625
"_ci-cloneAndBuildPhoenix": "npm run _ci-env-warn && node ./src-build/clonePhoenix.js && cd phoenix && npm ci && npm run build && cd ..",
2726
"_ci-release:dev": "npm run _ci-env-warn && npm run _ci-cloneAndBuildPhoenix && cd phoenix && npm run release:dev && cd .. && npm run _ci-createDistReleaseConfig && npm run _ci_make_src-node",
2827
"_ci-release:staging": "npm run _ci-env-warn && npm run _ci-cloneAndBuildPhoenix && cd phoenix && npm run release:staging && cd .. && npm run _ci-createDistReleaseConfig && npm run _ci_make_src-node",
2928
"_ci-release:prod": "npm run _ci-env-warn && npm run _ci-cloneAndBuildPhoenix && cd phoenix && npm run release:prod && cd .. && npm run _ci-createDistReleaseConfig && npm run _ci_make_src-node",
3029
"_ci-update-phcode-build": "node src-build/update-phcode-build.js",
3130
"serve": "node src-build/serveForPlatform.js",
32-
"_serveTauri": "npm run _servePhoenix && npm run _make_src-node && tauri dev",
33-
"_serveElectron": "npm run _servePhoenix && npm run _make_src-node && ./src-electron/node_modules/.bin/electron src-electron/main.js",
31+
"serve:tauri": "node src-build/serveForPlatform.js tauri",
32+
"serve:electron": "node src-build/serveForPlatform.js electron",
3433
"postinstall": "node ./src-build/downloadNodeBinary.js && node ./src-build/setupElectron.js",
3534
"cleanNodeBinary": "node src-build/cleanNodeBinary.js",
3635
"installNodeArmDarwin": "node ./src-build/downloadNodeBinary.js '{\"platform\":\"darwin\",\"arch\":\"arm64\"}'",

src-build/serveForPlatform.js

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,57 @@
11
import {getPlatformDetails} from "./utils.js";
22
import {execa} from "execa";
3+
import chalk from "chalk";
34

45
const {platform} = getPlatformDetails();
56

6-
// Linux uses Electron, Windows/Mac use Tauri
7-
const serveScript = (platform === "linux") ? "_serveElectron" : "_serveTauri";
7+
// Get target from CLI arg, or detect from platform
8+
const cliArg = process.argv[2];
9+
let target;
810

9-
console.log(`Platform: ${platform}, running: npm run ${serveScript}`);
11+
if (cliArg === 'tauri' || cliArg === 'electron') {
12+
target = cliArg;
13+
} else if (cliArg) {
14+
console.error(`Unknown target: ${cliArg}`);
15+
console.error('Usage: npm run serve [tauri|electron]');
16+
process.exit(1);
17+
} else {
18+
// Auto-detect: Linux uses Electron, Windows/Mac use Tauri
19+
target = (platform === "linux") ? "electron" : "tauri";
20+
}
1021

11-
await execa("npm", ["run", serveScript], {stdio: "inherit"});
22+
// Warn about non-standard platform/target combinations
23+
const recommendedTarget = (platform === "linux") ? "electron" : "tauri";
24+
if (target !== recommendedTarget) {
25+
const y = chalk.yellow;
26+
const b = chalk.bold.yellow;
27+
const line1 = ` Running ${target} on ${platform} is not officially supported.`;
28+
const line2 = ` Recommended: npm run serve (auto-detects ${recommendedTarget} for ${platform})`;
29+
const width = Math.max(50, line1.length, line2.length) + 2;
30+
const border = '═'.repeat(width);
31+
const pad = (str) => str + ' '.repeat(width - str.length);
32+
33+
console.warn(y(`\n╔${border}╗`));
34+
console.warn(y('║') + b(pad(' ⚠️ NON-STANDARD PLATFORM CONFIGURATION')) + y('║'));
35+
console.warn(y(`╠${border}╣`));
36+
console.warn(y('║') + y(pad(line1)) + y('║'));
37+
console.warn(y('║') + y(pad(line2)) + y('║'));
38+
console.warn(y(`╚${border}╝\n`));
39+
}
40+
41+
console.log(`Platform: ${platform}, target: ${target}`);
42+
43+
// Run common setup
44+
console.log('\nEnsure to start phoenix server at http://localhost:8000 for development.');
45+
console.log('Follow https://github.com/phcode-dev/phoenix#running-phoenix for instructions.\n');
46+
47+
console.log('Setting up src-node...');
48+
await execa("npm", ["run", "_make_src-node"], {stdio: "inherit"});
49+
50+
// Run platform-specific command
51+
if (target === "tauri") {
52+
console.log('Starting Tauri dev server...');
53+
await execa("npx", ["tauri", "dev"], {stdio: "inherit"});
54+
} else {
55+
console.log('Starting Electron...');
56+
await execa("./src-electron/node_modules/.bin/electron", ["src-electron/main.js"], {stdio: "inherit"});
57+
}

0 commit comments

Comments
 (0)