Add option to disable live reload server during development (#766)

* add option to disable live reload server

* change live to watch, fix incorrect argument parsing code

* Update api-commands.md
This commit is contained in:
=^._.^= 2018-06-14 23:51:03 -07:00 committed by Yangshun Tay
parent 608e2c85a2
commit 62a2c7c1a5
3 changed files with 38 additions and 31 deletions

View file

@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/
function execute(port) {
function execute(port, options) {
const extractTranslations = require('../write-translations');
const metadataUtils = require('./metadataUtils');
@ -568,35 +568,38 @@ 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(
[
'../' + readMetadata.getDocsPath() + '/**/*', // docs
'**/*', // website
'!node_modules/**/*', // node_modules
],
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(['/']);
});
}
);
if (options.watch) startLiveReload();
app.listen(port);
function startLiveReload() {
// 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(
[
'../' + readMetadata.getDocsPath() + '/**/*', // docs
'**/*', // website
'!node_modules/**/*', // node_modules
],
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(['/']);
});
}
);
}
}
module.exports = execute;