Open localhost URL with --open (#28)

* Open localhost URL with --open

* Catch errors on opn

Co-Authored-By: fand <fand@users.noreply.github.com>
This commit is contained in:
Takayosi Amagi 2019-03-08 02:23:54 +09:00 committed by Kyle Carberry
parent 17267bd801
commit 87d2e22a6b
3 changed files with 28 additions and 1 deletions

View File

@ -26,10 +26,12 @@
"@types/express": "^4.16.0", "@types/express": "^4.16.0",
"@types/fs-extra": "^5.0.4", "@types/fs-extra": "^5.0.4",
"@types/mime-types": "^2.1.0", "@types/mime-types": "^2.1.0",
"@types/opn": "^5.1.0",
"@types/pem": "^1.9.4", "@types/pem": "^1.9.4",
"@types/ws": "^6.0.1", "@types/ws": "^6.0.1",
"fs-extra": "^7.0.1", "fs-extra": "^7.0.1",
"nexe": "^2.0.0-rc.34", "nexe": "^2.0.0-rc.34",
"opn": "^5.4.0",
"string-replace-webpack-plugin": "^0.1.3", "string-replace-webpack-plugin": "^0.1.3",
"ts-node": "^7.0.1", "ts-node": "^7.0.1",
"tsconfig-paths": "^3.7.0", "tsconfig-paths": "^3.7.0",

View File

@ -13,6 +13,7 @@ import { SharedProcess, SharedProcessState } from "./vscode/sharedProcess";
import { setup as setupNativeModules } from "./modules"; import { setup as setupNativeModules } from "./modules";
import { fillFs } from "./fill"; import { fillFs } from "./fill";
import { isCli, serveStatic, buildDir } from "./constants"; import { isCli, serveStatic, buildDir } from "./constants";
import opn = require("opn");
export class Entry extends Command { export class Entry extends Command {
public static description = "Start your own self-hosted browser-accessible VS Code"; public static description = "Start your own self-hosted browser-accessible VS Code";
@ -220,10 +221,20 @@ export class Entry extends Command {
} else { } else {
logger.warn("Launched without authentication."); logger.warn("Launched without authentication.");
} }
const url = `http://localhost:${flags.port}/`;
logger.info(" "); logger.info(" ");
logger.info("Started (click the link below to open):"); logger.info("Started (click the link below to open):");
logger.info(`http://localhost:${flags.port}/`); logger.info(url);
logger.info(" "); 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));
}
}
} }
} }

View File

@ -129,6 +129,13 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.18.tgz#1d3ca764718915584fcd9f6344621b7672665c67" resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.18.tgz#1d3ca764718915584fcd9f6344621b7672665c67"
integrity sha512-fh+pAqt4xRzPfqA6eh3Z2y6fyZavRIumvjhaCL753+TVkGKGhpPeyrJG2JftD0T9q4GF00KjefsQ+PQNDdWQaQ== 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": "@types/pem@^1.9.4":
version "1.9.4" version "1.9.4"
resolved "https://registry.yarnpkg.com/@types/pem/-/pem-1.9.4.tgz#9ef9302dc5f0352503e193003b208cddef4ffa45" resolved "https://registry.yarnpkg.com/@types/pem/-/pem-1.9.4.tgz#9ef9302dc5f0352503e193003b208cddef4ffa45"
@ -2668,6 +2675,13 @@ onetime@^2.0.0:
dependencies: dependencies:
mimic-fn "^1.0.0" 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: optionator@^0.8.1:
version "0.8.2" version "0.8.2"
resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.8.2.tgz#364c5e409d3f4d6301d6c0b4c05bba50180aeb64" resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.8.2.tgz#364c5e409d3f4d6301d6c0b4c05bba50180aeb64"