Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LiveReload #663

Merged
merged 13 commits into from
May 17, 2018
2 changes: 1 addition & 1 deletion admin/testing-changes-on-Docusaurus-itself.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ Feel free to contribute debug instructions for other IDEs

### Observing changes

Now that the server is running, you can make changes to the core Docusaurus code and docs to see the effects on the Docusaurus site. Just refresh the local site, usually running at http://localhost:3000
Now that the server is running, you can make changes to the core Docusaurus code and docs to see the effects on the Docusaurus site. LiveReload will reflect changes to the local site in your browser, usually running at http://localhost:3000
11 changes: 10 additions & 1 deletion lib/core/Site.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@

const React = require('react');
const fs = require('fs');
const classNames = require('classnames');

const HeaderNav = require('./nav/HeaderNav.js');
const Head = require('./Head.js');
const Footer = require(process.cwd() + '/core/Footer.js');
const translation = require('../server/translation.js');
const classNames = require('classnames');
const constants = require('./constants');

const CWD = process.cwd();

Expand Down Expand Up @@ -159,6 +161,13 @@ class Site extends React.Component {
}}
/>
))}
{process.env.NODE_ENV === 'development' && (
<script
src={`http://localhost:${
constants.LIVE_RELOAD_PORT
}/livereload.js`}
/>
)}
</body>
</html>
);
Expand Down
10 changes: 10 additions & 0 deletions lib/core/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

module.exports = {
LIVE_RELOAD_PORT: 35729,
};
31 changes: 31 additions & 0 deletions lib/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ function execute(port) {
const mkdirp = require('mkdirp');
const glob = require('glob');
const chalk = require('chalk');
const gaze = require('gaze');
const tinylr = require('tiny-lr');

const constants = require('../core/constants');
const translate = require('./translate');
const {renderToStaticMarkupWithDoctype} = require('./renderUtils');

Expand Down Expand Up @@ -541,6 +545,33 @@ function execute(port) {
);
});

// Start LiveReload server.
process.env.NODE_ENV = 'development';
const server = tinylr();
server.listen(constants.LIVE_RELOAD_PORT, function() {
console.log(
'LiveReload server started on port %d',
constants.LIVE_RELOAD_PORT
);
});

// gaze watches some specified dirs and triggers a callback when they change.
gaze(
[
'../docs/**/*', // docs
'**/*', // website
],
function() {
// Listen for all kinds of file changes - modified/added/deleted.
this.on('all', function() {
// Notify LiveReload clients that there's a change.
// Typically, LiveReload will only refresh the changed paths,
// so we use / here to force a full-page reload.
server.notifyClients(['/']);
});
}
);

app.listen(port);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/start-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function checkPort() {
const server = require('./server/server.js');
server(port);
const host = `http://localhost:${port}`;
console.log(`Starting Docusaurus server on ${host}`);
console.log('Docusaurus server started on port %d', port);
opn(host);
}
})
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"express": "^4.15.3",
"feed": "^1.1.0",
"fs-extra": "^5.0.0",
"gaze": "^1.1.2",
"glob": "^7.1.2",
"highlight.js": "^9.12.0",
"imagemin": "^5.3.1",
Expand All @@ -58,7 +59,8 @@
"shelljs": "^0.7.8",
"sitemap": "^1.13.0",
"tcp-port-used": "^0.1.2",
"tree-node-cli": "^1.1.1"
"tree-node-cli": "^1.1.1",
"tiny-lr": "^1.1.1"
},
"bin": {
"docusaurus-start": "./lib/start-server.js",
Expand Down
99 changes: 94 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,15 @@ body-parser@1.18.2:
raw-body "2.3.2"
type-is "~1.6.15"

body@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/body/-/body-5.1.0.tgz#e4ba0ce410a46936323367609ecb4e6553125069"
dependencies:
continuable-cache "^0.3.1"
error "^7.0.0"
raw-body "~1.1.0"
safe-json-parse "~1.0.1"

boolbase@^1.0.0, boolbase@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/boolbase/-/boolbase-1.0.0.tgz#68dff5fbe60c51eb37725ea9e3ed310dcc1e776e"
Expand Down Expand Up @@ -1071,6 +1080,10 @@ builtin-modules@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-1.1.1.tgz#270f076c5a72c02f5b65a47df94c5fe3a278892f"

bytes@1:
version "1.0.0"
resolved "https://registry.yarnpkg.com/bytes/-/bytes-1.0.0.tgz#3569ede8ba34315fab99c3e92cb04c7220de1fa8"

bytes@3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.0.0.tgz#d32815404d689699f85a4ea4fa8755dd13a96048"
Expand Down Expand Up @@ -1378,6 +1391,10 @@ content-type@~1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/content-type/-/content-type-1.0.4.tgz#e138cc75e040c727b1966fe5e5f8c9aee256fe3b"

continuable-cache@^0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/continuable-cache/-/continuable-cache-0.3.1.tgz#bd727a7faed77e71ff3985ac93351a912733ad0f"

convert-source-map@^1.1.1, convert-source-map@^1.4.0, convert-source-map@^1.5.1:
version "1.5.1"
resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.5.1.tgz#b8278097b9bc229365de5c62cf5fcaed8b5599e5"
Expand Down Expand Up @@ -1835,6 +1852,13 @@ error-ex@^1.2.0:
dependencies:
is-arrayish "^0.2.1"

error@^7.0.0:
version "7.0.2"
resolved "https://registry.yarnpkg.com/error/-/error-7.0.2.tgz#a5f75fff4d9926126ddac0ea5dc38e689153cb02"
dependencies:
string-template "~0.2.1"
xtend "~4.0.0"

es-abstract@^1.5.1, es-abstract@^1.6.1:
version "1.11.0"
resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.11.0.tgz#cce87d518f0496893b1a30cd8461835535480681"
Expand Down Expand Up @@ -2071,6 +2095,12 @@ fast-levenshtein@~2.0.4:
version "2.0.6"
resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917"

faye-websocket@~0.10.0:
version "0.10.0"
resolved "https://registry.yarnpkg.com/faye-websocket/-/faye-websocket-0.10.0.tgz#4e492f8d04dfb6f89003507f6edbf2d501e7c6f4"
dependencies:
websocket-driver ">=0.5.1"

fb-watchman@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/fb-watchman/-/fb-watchman-2.0.0.tgz#54e9abf7dfa2f26cd9b1636c588c1afc05de5d58"
Expand Down Expand Up @@ -2298,6 +2328,12 @@ gauge@~2.7.3:
strip-ansi "^3.0.1"
wide-align "^1.1.0"

gaze@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/gaze/-/gaze-1.1.2.tgz#847224677adb8870d679257ed3388fdb61e40105"
dependencies:
globule "^1.0.0"

get-caller-file@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.2.tgz#f702e63127e7e231c160a80c1554acb70d5047e5"
Expand Down Expand Up @@ -2383,7 +2419,7 @@ glob@^5.0.3:
once "^1.3.0"
path-is-absolute "^1.0.0"

glob@^7.0.0, glob@^7.0.3, glob@^7.0.5, glob@^7.1.1, glob@^7.1.2:
glob@^7.0.0, glob@^7.0.3, glob@^7.0.5, glob@^7.1.1, glob@^7.1.2, glob@~7.1.1:
version "7.1.2"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15"
dependencies:
Expand All @@ -2408,6 +2444,14 @@ globby@^6.1.0:
pify "^2.0.0"
pinkie-promise "^2.0.0"

globule@^1.0.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/globule/-/globule-1.2.0.tgz#1dc49c6822dd9e8a2fa00ba2a295006e8664bd09"
dependencies:
glob "~7.1.1"
lodash "~4.17.4"
minimatch "~3.0.2"

glogg@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/glogg/-/glogg-1.0.1.tgz#dcf758e44789cc3f3d32c1f3562a3676e6a34810"
Expand Down Expand Up @@ -2642,6 +2686,10 @@ http-errors@~1.6.2:
setprototypeof "1.1.0"
statuses ">= 1.4.0 < 2"

http-parser-js@>=0.4.0:
version "0.4.12"
resolved "https://registry.yarnpkg.com/http-parser-js/-/http-parser-js-0.4.12.tgz#b9cfbf4a2cf26f0fc34b10ca1489a27771e3474f"

http-signature@~1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/http-signature/-/http-signature-1.2.0.tgz#9aecd925114772f3d95b65a60abb8f7c18fbace1"
Expand Down Expand Up @@ -3548,6 +3596,10 @@ list-item@^1.1.1:
is-number "^2.1.0"
repeat-string "^1.5.2"

livereload-js@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/livereload-js/-/livereload-js-2.3.0.tgz#c3ab22e8aaf5bf3505d80d098cbad67726548c9a"

load-json-file@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/load-json-file/-/load-json-file-1.1.0.tgz#956905708d58b4bab4c2261b04f59f31c99374c0"
Expand Down Expand Up @@ -3669,7 +3721,7 @@ lodash.uniq@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"

lodash@^4.14.0, lodash@^4.17.4:
lodash@^4.14.0, lodash@^4.17.4, lodash@~4.17.4:
version "4.17.10"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.10.tgz#1b7793cf7259ea38fb3661d4d38b3260af8ae4e7"

Expand Down Expand Up @@ -3873,7 +3925,7 @@ mimic-fn@^1.0.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022"

"minimatch@2 || 3", minimatch@^3.0.3, minimatch@^3.0.4:
"minimatch@2 || 3", minimatch@^3.0.3, minimatch@^3.0.4, minimatch@~3.0.2:
version "3.0.4"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
dependencies:
Expand Down Expand Up @@ -4643,7 +4695,7 @@ qs@6.5.1:
version "6.5.1"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.1.tgz#349cdf6eef89ec45c12d7d5eb3fc0c870343a6d8"

qs@~6.5.1:
qs@^6.4.0, qs@~6.5.1:
version "6.5.2"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36"

Expand Down Expand Up @@ -4674,6 +4726,13 @@ raw-body@2.3.2:
iconv-lite "0.4.19"
unpipe "1.0.0"

raw-body@~1.1.0:
version "1.1.7"
resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-1.1.7.tgz#1d027c2bfa116acc6623bca8f00016572a87d425"
dependencies:
bytes "1"
string_decoder "0.10"

rc@^1.1.2, rc@^1.1.7:
version "1.2.7"
resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.7.tgz#8a10ca30d588d00464360372b890d06dacd02297"
Expand Down Expand Up @@ -4956,6 +5015,10 @@ safe-buffer@^5.0.1, safe-buffer@^5.1.1, safe-buffer@^5.1.2, safe-buffer@~5.1.0,
version "5.1.2"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"

safe-json-parse@~1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/safe-json-parse/-/safe-json-parse-1.0.1.tgz#3e76723e38dfdda13c9b1d29a1e07ffee4b30b57"

safe-regex@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/safe-regex/-/safe-regex-1.1.0.tgz#40a3669f3b077d1e943d44629e157dd48023bf2e"
Expand Down Expand Up @@ -5299,6 +5362,10 @@ string-length@^2.0.0:
astral-regex "^1.0.0"
strip-ansi "^4.0.0"

string-template@~0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/string-template/-/string-template-0.2.1.tgz#42932e598a352d01fc22ec3367d9d84eec6c9add"

string-width@^1.0.1, string-width@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-1.0.2.tgz#118bdf5b8cdc51a2a7e70d211e07e2b0b9b107d3"
Expand All @@ -5314,7 +5381,7 @@ string-width@^2.0.0:
is-fullwidth-code-point "^2.0.0"
strip-ansi "^4.0.0"

string_decoder@~0.10.x:
string_decoder@0.10, string_decoder@~0.10.x:
version "0.10.31"
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94"

Expand Down Expand Up @@ -5542,6 +5609,17 @@ timed-out@^3.0.0:
version "3.1.3"
resolved "https://registry.yarnpkg.com/timed-out/-/timed-out-3.1.3.tgz#95860bfcc5c76c277f8f8326fd0f5b2e20eba217"

tiny-lr@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/tiny-lr/-/tiny-lr-1.1.1.tgz#9fa547412f238fedb068ee295af8b682c98b2aab"
dependencies:
body "^5.1.0"
debug "^3.1.0"
faye-websocket "~0.10.0"
livereload-js "^2.3.0"
object-assign "^4.1.0"
qs "^6.4.0"

tmpl@1.0.x:
version "1.0.4"
resolved "https://registry.yarnpkg.com/tmpl/-/tmpl-1.0.4.tgz#23640dd7b42d00433911140820e5cf440e521dd1"
Expand Down Expand Up @@ -5884,6 +5962,17 @@ webidl-conversions@^4.0.0:
version "4.0.2"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-4.0.2.tgz#a855980b1f0b6b359ba1d5d9fb39ae941faa63ad"

websocket-driver@>=0.5.1:
version "0.7.0"
resolved "https://registry.yarnpkg.com/websocket-driver/-/websocket-driver-0.7.0.tgz#0caf9d2d755d93aee049d4bdd0d3fe2cca2a24eb"
dependencies:
http-parser-js ">=0.4.0"
websocket-extensions ">=0.1.1"

websocket-extensions@>=0.1.1:
version "0.1.3"
resolved "https://registry.yarnpkg.com/websocket-extensions/-/websocket-extensions-0.1.3.tgz#5d2ff22977003ec687a4b87073dfbbac146ccf29"

whatwg-encoding@^1.0.1:
version "1.0.3"
resolved "https://registry.yarnpkg.com/whatwg-encoding/-/whatwg-encoding-1.0.3.tgz#57c235bc8657e914d24e1a397d3c82daee0a6ba3"
Expand Down