|
1 | 1 | import {getPlatformDetails} from "./utils.js"; |
2 | 2 | import {execa} from "execa"; |
| 3 | +import chalk from "chalk"; |
3 | 4 |
|
4 | 5 | const {platform} = getPlatformDetails(); |
5 | 6 |
|
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; |
8 | 10 |
|
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 | +} |
10 | 21 |
|
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