Skip to content

Commit 87d2e22

Browse files
fandkylecarbs
authored andcommitted
Open localhost URL with --open (#28)
* Open localhost URL with --open * Catch errors on opn Co-Authored-By: fand <[email protected]>
1 parent 17267bd commit 87d2e22

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

packages/server/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@
2626
"@types/express": "^4.16.0",
2727
"@types/fs-extra": "^5.0.4",
2828
"@types/mime-types": "^2.1.0",
29+
"@types/opn": "^5.1.0",
2930
"@types/pem": "^1.9.4",
3031
"@types/ws": "^6.0.1",
3132
"fs-extra": "^7.0.1",
3233
"nexe": "^2.0.0-rc.34",
34+
"opn": "^5.4.0",
3335
"string-replace-webpack-plugin": "^0.1.3",
3436
"ts-node": "^7.0.1",
3537
"tsconfig-paths": "^3.7.0",

packages/server/src/cli.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { SharedProcess, SharedProcessState } from "./vscode/sharedProcess";
1313
import { setup as setupNativeModules } from "./modules";
1414
import { fillFs } from "./fill";
1515
import { isCli, serveStatic, buildDir } from "./constants";
16+
import opn = require("opn");
1617

1718
export class Entry extends Command {
1819
public static description = "Start your own self-hosted browser-accessible VS Code";
@@ -220,10 +221,20 @@ export class Entry extends Command {
220221
} else {
221222
logger.warn("Launched without authentication.");
222223
}
224+
225+
const url = `http://localhost:${flags.port}/`;
223226
logger.info(" ");
224227
logger.info("Started (click the link below to open):");
225-
logger.info(`http://localhost:${flags.port}/`);
228+
logger.info(url);
226229
logger.info(" ");
230+
231+
if (flags["open"]) {
232+
try {
233+
await opn(url);
234+
} catch (e) {
235+
logger.warn("Url couldn't be opened automatically.", field("url", url), field("exception", e));
236+
}
237+
}
227238
}
228239
}
229240

packages/server/yarn.lock

+14
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@
129129
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.18.tgz#1d3ca764718915584fcd9f6344621b7672665c67"
130130
integrity sha512-fh+pAqt4xRzPfqA6eh3Z2y6fyZavRIumvjhaCL753+TVkGKGhpPeyrJG2JftD0T9q4GF00KjefsQ+PQNDdWQaQ==
131131

132+
"@types/opn@^5.1.0":
133+
version "5.1.0"
134+
resolved "https://registry.yarnpkg.com/@types/opn/-/opn-5.1.0.tgz#bff7bc371677f4bdbb37884400e03fd81f743927"
135+
integrity sha512-TNPrB7Y1xl06zDI0aGyqkgxjhIev3oJ+cdqlZ52MTAHauWpEL/gIUdHebIfRHFZk9IqSBpE2ci1DT48iZH81yg==
136+
dependencies:
137+
"@types/node" "*"
138+
132139
"@types/pem@^1.9.4":
133140
version "1.9.4"
134141
resolved "https://registry.yarnpkg.com/@types/pem/-/pem-1.9.4.tgz#9ef9302dc5f0352503e193003b208cddef4ffa45"
@@ -2668,6 +2675,13 @@ onetime@^2.0.0:
26682675
dependencies:
26692676
mimic-fn "^1.0.0"
26702677

2678+
opn@^5.4.0:
2679+
version "5.4.0"
2680+
resolved "https://registry.yarnpkg.com/opn/-/opn-5.4.0.tgz#cb545e7aab78562beb11aa3bfabc7042e1761035"
2681+
integrity sha512-YF9MNdVy/0qvJvDtunAOzFw9iasOQHpVthTCvGzxt61Il64AYSGdK+rYwld7NAfk9qJ7dt+hymBNSc9LNYS+Sw==
2682+
dependencies:
2683+
is-wsl "^1.1.0"
2684+
26712685
optionator@^0.8.1:
26722686
version "0.8.2"
26732687
resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.8.2.tgz#364c5e409d3f4d6301d6c0b4c05bba50180aeb64"

0 commit comments

Comments
 (0)