()
| 497 | // ─── main ──────────────────────────────────────────────────────────────────── |
| 498 | |
| 499 | async function main() { |
| 500 | const args = process.argv.slice(2); |
| 501 | const platform = |
| 502 | args.find((a) => /^(android|ios|browser)$/i.test(a)) || "android"; |
| 503 | const target = |
| 504 | args.find((a) => a.startsWith("--target="))?.split("=")[1] || null; |
| 505 | const emulator = args.includes("--emulator") || args.includes("-e"); |
| 506 | |
| 507 | console.log("\n ⚡ Acode Dev Mode\n"); |
| 508 | |
| 509 | const host = getLocalIP(); |
| 510 | const port = await getFreePort(); |
| 511 | |
| 512 | log("info", `Local IP: ${host}`); |
| 513 | log("info", `Port: ${port}`); |
| 514 | |
| 515 | // 1. Ensure cordova files are in www/ for the dev server |
| 516 | ensureCordovaFiles(); |
| 517 | |
| 518 | // 2. Start HTTPS (or HTTP fallback) + WebSocket server |
| 519 | const { server, broadcast, protocol } = await createServer(port); |
| 520 | const origin = `${protocol}://${host}:${port}`; |
| 521 | log("info", `Dev Origin: ${origin}`); |
| 522 | server.listen(port, () => { |
| 523 | log("ok", "Dev server started"); |
| 524 | }); |
| 525 | |
| 526 | // 3. Start rspack --watch |
| 527 | let appLaunched = false; |
| 528 | |
| 529 | startRspackWatch(host, port, protocol, () => { |
| 530 | broadcast("reload"); |
| 531 | |
| 532 | if (!appLaunched) { |
| 533 | appLaunched = true; |
| 534 | setTimeout(async () => { |
| 535 | try { |
| 536 | await launchApp(target, platform, emulator); |
| 537 | } catch (err) { |
| 538 | log("warn", `Launch failed: ${err.message}`); |
| 539 | } |
| 540 | }, 3000); // give APK install time |
| 541 | } |
| 542 | }); |
| 543 | |
| 544 | // 4. Start plugin file watcher |
| 545 | startPluginWatcher(platform); |
| 546 | |
| 547 | // Graceful shutdown |
| 548 | process.on("SIGINT", () => { |
| 549 | log("info", "Shutting down..."); |
| 550 | server.close(); |
| 551 | process.exit(0); |
| 552 | }); |
| 553 | |
| 554 | process.on("SIGTERM", () => { |
| 555 | server.close(); |
| 556 | process.exit(0); |
no test coverage detected