diff --git a/packages/server/package.json b/packages/server/package.json index e4e5faf1..3f7cbbcf 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -26,10 +26,12 @@ "@types/express": "^4.16.0", "@types/fs-extra": "^5.0.4", "@types/mime-types": "^2.1.0", + "@types/opn": "^5.1.0", "@types/pem": "^1.9.4", "@types/ws": "^6.0.1", "fs-extra": "^7.0.1", "nexe": "^2.0.0-rc.34", + "opn": "^5.4.0", "string-replace-webpack-plugin": "^0.1.3", "ts-node": "^7.0.1", "tsconfig-paths": "^3.7.0", diff --git a/packages/server/src/cli.ts b/packages/server/src/cli.ts index 382ededc..b57fb8ad 100644 --- a/packages/server/src/cli.ts +++ b/packages/server/src/cli.ts @@ -13,6 +13,7 @@ import { SharedProcess, SharedProcessState } from "./vscode/sharedProcess"; import { setup as setupNativeModules } from "./modules"; import { fillFs } from "./fill"; import { isCli, serveStatic, buildDir } from "./constants"; +import opn = require("opn"); export class Entry extends Command { public static description = "Start your own self-hosted browser-accessible VS Code"; @@ -220,10 +221,20 @@ export class Entry extends Command { } else { logger.warn("Launched without authentication."); } + + const url = `http://localhost:${flags.port}/`; logger.info(" "); logger.info("Started (click the link below to open):"); - logger.info(`http://localhost:${flags.port}/`); + logger.info(url); logger.info(" "); + + if (flags["open"]) { + try { + await opn(url); + } catch (e) { + logger.warn("Url couldn't be opened automatically.", field("url", url), field("exception", e)); + } + } } } diff --git a/packages/server/yarn.lock b/packages/server/yarn.lock index c5059c5c..b32dbfe4 100644 --- a/packages/server/yarn.lock +++ b/packages/server/yarn.lock @@ -129,6 +129,13 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.18.tgz#1d3ca764718915584fcd9f6344621b7672665c67" integrity sha512-fh+pAqt4xRzPfqA6eh3Z2y6fyZavRIumvjhaCL753+TVkGKGhpPeyrJG2JftD0T9q4GF00KjefsQ+PQNDdWQaQ== +"@types/opn@^5.1.0": + version "5.1.0" + resolved "https://registry.yarnpkg.com/@types/opn/-/opn-5.1.0.tgz#bff7bc371677f4bdbb37884400e03fd81f743927" + integrity sha512-TNPrB7Y1xl06zDI0aGyqkgxjhIev3oJ+cdqlZ52MTAHauWpEL/gIUdHebIfRHFZk9IqSBpE2ci1DT48iZH81yg== + dependencies: + "@types/node" "*" + "@types/pem@^1.9.4": version "1.9.4" resolved "https://registry.yarnpkg.com/@types/pem/-/pem-1.9.4.tgz#9ef9302dc5f0352503e193003b208cddef4ffa45" @@ -2668,6 +2675,13 @@ onetime@^2.0.0: dependencies: mimic-fn "^1.0.0" +opn@^5.4.0: + version "5.4.0" + resolved "https://registry.yarnpkg.com/opn/-/opn-5.4.0.tgz#cb545e7aab78562beb11aa3bfabc7042e1761035" + integrity sha512-YF9MNdVy/0qvJvDtunAOzFw9iasOQHpVthTCvGzxt61Il64AYSGdK+rYwld7NAfk9qJ7dt+hymBNSc9LNYS+Sw== + dependencies: + is-wsl "^1.1.0" + optionator@^0.8.1: version "0.8.2" resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.8.2.tgz#364c5e409d3f4d6301d6c0b4c05bba50180aeb64"