Skip to content

Commit

Permalink
Implements custom recursive watch for linux
Browse files Browse the repository at this point in the history
  • Loading branch information
lukejacksonn committed Jan 28, 2020
1 parent 891d30e commit 368a5df
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion servor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ const os = require('os');
const net = require('net');
const cwd = process.cwd();

const watch = (path, cb) => {
if (fs.statSync(path).isDirectory()) {
fs.watch(path, cb);
fs.readdirSync(path).forEach(entry => watch(`${path}/${entry}`, cb));
}
};

const fport = (p = 0) =>
new Promise((resolve, reject) => {
const s = net.createServer();
Expand Down Expand Up @@ -122,7 +129,7 @@ module.exports = async ({
// Notify livereload clients on file change

reload &&
fs.watch(root, { recursive: true }, () => {
watch(root, () => {
while (clients.length > 0)
sendMessage(clients.pop(), 'message', 'reload');
});
Expand Down
2 changes: 1 addition & 1 deletion test/assets/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
var $text = document.querySelector('h2');
$text.innerHTML = window.location
$text.innerHTML = window.location;

0 comments on commit 368a5df

Please sign in to comment.