2018-09-12 14:03:52 -04:00
|
|
|
/**
|
2020-02-25 10:12:28 -05:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2018-09-12 14:03:52 -04:00
|
|
|
*
|
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
const gaze = require('gaze');
|
|
|
|
|
const tinylr = require('tiny-lr');
|
2019-05-20 12:31:41 -04:00
|
|
|
const program = require('commander');
|
2018-09-12 14:03:52 -04:00
|
|
|
const readMetadata = require('./readMetadata.js');
|
|
|
|
|
|
|
|
|
|
function start(port) {
|
|
|
|
|
process.env.NODE_ENV = 'development';
|
2018-11-11 09:36:11 -05:00
|
|
|
process.env.LIVERELOAD_PORT = port;
|
2018-09-12 14:03:52 -04:00
|
|
|
const server = tinylr();
|
|
|
|
|
server.listen(port, () => {
|
|
|
|
|
console.log('LiveReload server started on port %d', port);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
gaze(
|
|
|
|
|
[`../${readMetadata.getDocsPath()}/**/*`, '**/*', '!node_modules/**/*'],
|
|
|
|
|
function() {
|
|
|
|
|
this.on('all', () => {
|
|
|
|
|
server.notifyClients(['/']);
|
|
|
|
|
});
|
2018-09-17 03:34:55 -04:00
|
|
|
},
|
2018-09-12 14:03:52 -04:00
|
|
|
);
|
|
|
|
|
}
|
2018-11-11 09:36:11 -05:00
|
|
|
const getReloadScriptUrl = () => {
|
|
|
|
|
const port = process.env.LIVERELOAD_PORT;
|
2019-05-20 12:31:41 -04:00
|
|
|
const host = program.host || 'localhost';
|
|
|
|
|
|
|
|
|
|
return `http://${host}:${port}/livereload.js`;
|
2018-11-11 09:36:11 -05:00
|
|
|
};
|
2018-09-12 14:03:52 -04:00
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
start,
|
|
|
|
|
getReloadScriptUrl,
|
|
|
|
|
};
|