Skip to content

Commit

Permalink
Add open in browser functionality (#643)
Browse files Browse the repository at this point in the history
  • Loading branch information
yangshun authored and JoelMarcey committed May 7, 2018
1 parent 432bdff commit 1a6f2fc
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
1 change: 0 additions & 1 deletion lib/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,6 @@ function execute(port) {
});

app.listen(port);
console.log('Open http://localhost:' + port + '/');
}

module.exports = execute;
5 changes: 4 additions & 1 deletion lib/start-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const tcpPortUsed = require('tcp-port-used');
// initial check that required files are present
const chalk = require('chalk');
const fs = require('fs');
const opn = require('opn');
const CWD = process.cwd();

if (!fs.existsSync(CWD + '/siteConfig.js')) {
Expand Down Expand Up @@ -59,10 +60,12 @@ function checkPort() {
numAttempts += 1;
checkPort();
} else {
console.log('Starting Docusaurus server on port ' + port + '...');
// start local server on specified port
const server = require('./server/server.js');
server(port);
const host = `http://localhost:${port}`;
console.log(`Starting Docusaurus server on ${host}`);
opn(host);
}
})
.catch(function(ex) {
Expand Down
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"front-matter": "^2.3.0",
"glob-promise": "^3.3.0",
"jest": "^21.2.1",
"opn": "^5.3.0",
"prettier": "^1.9.1",
"rimraf": "^2.6.2"
}
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2049,6 +2049,10 @@ is-utf8@^0.2.0:
version "0.2.1"
resolved "https://registry.yarnpkg.com/is-utf8/-/is-utf8-0.2.1.tgz#4b0da1442104d1b336340e80797e865cf39f7d72"

is-wsl@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/is-wsl/-/is-wsl-1.1.0.tgz#1f16e4aa22b04d1336b66188a66af3c600c3a66d"

is2@0.0.9:
version "0.0.9"
resolved "https://registry.yarnpkg.com/is2/-/is2-0.0.9.tgz#119556d1d1651a41ba105af803267c80b299f629"
Expand Down Expand Up @@ -2852,6 +2856,12 @@ once@^1.3.0, once@^1.3.3, once@^1.4.0:
dependencies:
wrappy "1"

opn@^5.3.0:
version "5.3.0"
resolved "https://registry.yarnpkg.com/opn/-/opn-5.3.0.tgz#64871565c863875f052cfdf53d3e3cb5adb53b1c"
dependencies:
is-wsl "^1.1.0"

optimist@^0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/optimist/-/optimist-0.6.1.tgz#da3ea74686fa21a19a111c326e90eb15a0196686"
Expand Down

0 comments on commit 1a6f2fc

Please sign in to comment.