Open a URL in the default browser. Stays cross-platform with serve.ts.
(url: string)
| 362 | |
| 363 | /** Open a URL in the default browser. Stays cross-platform with serve.ts. */ |
| 364 | function openBrowser(url: string): void { |
| 365 | const platform = process.platform; |
| 366 | let cmd: string; |
| 367 | if (platform === "darwin") cmd = "open"; |
| 368 | else if (platform === "linux") cmd = "xdg-open"; |
| 369 | else { |
| 370 | console.error(`Open this URL in your browser: ${url}`); |
| 371 | return; |
| 372 | } |
| 373 | try { |
| 374 | const child = nodeSpawn(cmd, [url], { stdio: "ignore", detached: true }); |
| 375 | child.unref(); |
| 376 | } catch { |
| 377 | console.error(`Open this URL in your browser: ${url}`); |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | /** |
| 382 | * Resolve image paths from a glob pattern or comma-separated list. |