Skip to content

Commit 3ea6d97

Browse files
committed
make executable open morphaweb in default browser
1 parent 8324937 commit 3ea6d97

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

server.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
11
import { serve } from "bun";
2+
import { version } from './package.json'
23
import index from "./src/index.html";
34

5+
const openBrowser = (url: string) => {
6+
const platform = process.platform
7+
let command: string;
8+
9+
if (platform === "darwin") {
10+
command = "open";
11+
} else if (platform === "win32") {
12+
command = "start";
13+
} else {
14+
command = "xdg-open";
15+
}
16+
17+
Bun.spawn([command, url]);
18+
}
19+
420
const server = serve({
521
routes: {
622
"/": index
723
}
824
})
925

10-
console.log(`Morphaweb is running at: http://localhost:${server.port} (Cmd+click to open)`);
26+
const url = `http://localhost:${server.port}`;
27+
28+
console.log(`Morphaweb v${version} is running at: ${url} (Cmd+click to open). `);
29+
console.log(`Attempting to start in your default browser...`);
30+
31+
openBrowser(url)

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Morphaweb from './Morphaweb'
2-
import{ version} from '../package.json'
2+
import { version } from '../package.json'
33

44
const morphaweb = new Morphaweb()
55

0 commit comments

Comments
 (0)